global var init
This commit is contained in:
@@ -46,11 +46,13 @@ type aGlobal struct {
|
||||
|
||||
// A Global is a named Value holding the address of a package-level
|
||||
// variable.
|
||||
//
|
||||
// Pos() returns the position of the ast.ValueSpec.Names[*]
|
||||
// identifier.
|
||||
type Global = *aGlobal
|
||||
|
||||
// Init initializes the global variable with the given value.
|
||||
func (g Global) Init(v Expr) {
|
||||
g.impl.SetInitializer(v.impl)
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
// Function represents the parameters, results, and code of a function
|
||||
|
||||
@@ -43,6 +43,10 @@ func llvmValues(vals []Expr) []llvm.Value {
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
func (p Program) Null(t Type) Expr {
|
||||
return Expr{llvm.ConstNull(t.ll), t}
|
||||
}
|
||||
|
||||
func (p Program) BoolVal(v bool) Expr {
|
||||
t := p.Bool()
|
||||
var bv uint64
|
||||
|
||||
@@ -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
|
||||
`)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user