Skip to content

Commit

Permalink
Fix the handling of global values
Browse files Browse the repository at this point in the history
Prior to this commit, global values were being allocated directly as
variables of their type `T`. This is incorrect, as LLVM expects globals
to be of type `ptr` with a `T` able to be loaded from it.

This commit changes the global initialization logic to comply with this
requirement, allocating a pointer of the correct size and then writing
the constant initializer value into that variable. This ensures that
programs expecting to load from globals can now do so correctly.

It also updates the Memory Model documentation to record the solution to
properly handle global pointers in Hieratika.
  • Loading branch information
iamrecursion committed Jan 13, 2025
1 parent 16e90c3 commit 3af45ce
Show file tree
Hide file tree
Showing 5 changed files with 305 additions and 234 deletions.
4 changes: 2 additions & 2 deletions crates/compiler/input/compilation/constants.ll
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ target triple = "riscv64"

@test_const = constant { i1, [9 x i8] } { i1 0, [9 x i8] c"hieratika" }

; @constant_pointer_const = constant ptr @test_const
; @constant_pointer_const_in_struct = constant { i1, ptr } { i1 0, ptr @test_const }
@constant_pointer_const = constant ptr @test_const
@constant_pointer_const_in_struct = constant { i1, ptr } { i1 0, ptr @test_const }

; @function_pointer_const = constant ptr @hieratika_test_const_integer
; @function_pointer_const_in_struct = constant { i1, ptr } { i1 0, ptr @hieratika_test_const_integer }
Expand Down
Loading

0 comments on commit 3af45ce

Please sign in to comment.