TestFuncMultiRet
This commit is contained in:
@@ -45,8 +45,7 @@ type NamedConst = *aNamedConst
|
||||
// Pos() returns the position of the ast.ValueSpec.Names[*]
|
||||
// identifier.
|
||||
type aGlobal struct {
|
||||
impl llvm.Value
|
||||
Type
|
||||
Expr
|
||||
}
|
||||
|
||||
type Global = *aGlobal
|
||||
|
||||
@@ -163,7 +163,7 @@ func (p Package) NewConst(name string, val constant.Value) NamedConst {
|
||||
func (p Package) NewVar(name string, typ types.Type) Global {
|
||||
t := p.prog.llvmType(typ)
|
||||
gbl := llvm.AddGlobal(p.mod, t.ll, name)
|
||||
return &aGlobal{gbl, t}
|
||||
return &aGlobal{Expr{gbl, t}}
|
||||
}
|
||||
|
||||
func (p Package) NewFunc(name string, sig *types.Signature) Function {
|
||||
|
||||
@@ -167,6 +167,31 @@ define void @main() {
|
||||
`)
|
||||
}
|
||||
|
||||
func TestFuncMultiRet(t *testing.T) {
|
||||
prog := NewProgram(nil)
|
||||
pkg := prog.NewPackage("bar", "foo/bar")
|
||||
params := types.NewTuple(
|
||||
types.NewVar(0, nil, "b", types.Typ[types.Float64]))
|
||||
rets := types.NewTuple(
|
||||
types.NewVar(0, nil, "c", types.Typ[types.Int]),
|
||||
types.NewVar(0, nil, "d", types.Typ[types.Float64]))
|
||||
sig := types.NewSignatureType(nil, nil, nil, params, rets, false)
|
||||
a := pkg.NewVar("a", types.Typ[types.Int])
|
||||
fn := pkg.NewFunc("fn", sig)
|
||||
b := fn.MakeBody("")
|
||||
b.Return(a.Expr, fn.Param(0))
|
||||
assertPkg(t, pkg, `; ModuleID = 'foo/bar'
|
||||
source_filename = "foo/bar"
|
||||
|
||||
@a = external global i64
|
||||
|
||||
define { i64, double } @fn(double %0) {
|
||||
%mrv = insertvalue { i64, double } { ptr @a, double poison }, double %0, 1
|
||||
ret { i64, double } %mrv
|
||||
}
|
||||
`)
|
||||
}
|
||||
|
||||
func TestBinOp(t *testing.T) {
|
||||
prog := NewProgram(nil)
|
||||
pkg := prog.NewPackage("bar", "foo/bar")
|
||||
|
||||
Reference in New Issue
Block a user