global var init

This commit is contained in:
xushiwei
2024-04-21 00:22:39 +08:00
parent 358e18b9de
commit 8f31e4a6d3
7 changed files with 22 additions and 11 deletions

View File

@@ -37,11 +37,15 @@ func assertPkg(t *testing.T, p Package, expected string) {
func TestVar(t *testing.T) {
prog := NewProgram(nil)
pkg := prog.NewPackage("bar", "foo/bar")
pkg.NewVar("a", types.Typ[types.Int])
a := pkg.NewVar("a", types.Typ[types.Int])
a.Init(prog.Val(100))
b := pkg.NewVar("b", types.Typ[types.Int])
b.Init(a.Expr)
assertPkg(t, pkg, `; ModuleID = 'foo/bar'
source_filename = "foo/bar"
@a = external global i64
@a = global i64 100
@b = global i64 @a
`)
}