Merge pull request #13 from xushiwei/q

TestFuncMultiRet
This commit is contained in:
xushiwei
2024-04-19 00:40:23 +08:00
committed by GitHub
3 changed files with 27 additions and 3 deletions

View File

@@ -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

View File

@@ -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 {

View File

@@ -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")