TestFuncCall

This commit is contained in:
xushiwei
2024-04-19 00:05:57 +08:00
parent a966e02273
commit c784a2e63b
7 changed files with 188 additions and 58 deletions

View File

@@ -22,6 +22,10 @@ import (
"testing"
)
func init() {
Initialize(InitAll)
}
/*
func asmPkg(t *testing.T, p *Package) {
b, err := p.CodeGen(AssemblyFile)
@@ -131,6 +135,38 @@ define i64 @fn(i64 %0, double %1) {
`)
}
func TestFuncCall(t *testing.T) {
prog := NewProgram(nil)
pkg := prog.NewPackage("bar", "foo/bar")
params := types.NewTuple(
types.NewVar(0, nil, "a", types.Typ[types.Int]),
types.NewVar(0, nil, "b", types.Typ[types.Float64]))
rets := types.NewTuple(types.NewVar(0, nil, "", types.Typ[types.Int]))
sig := types.NewSignatureType(nil, nil, nil, params, rets, false)
fn := pkg.NewFunc("fn", sig)
fn.MakeBody("").
Return(prog.Val(1))
sigMain := types.NewSignatureType(nil, nil, nil, nil, nil, false)
b := pkg.NewFunc("main", sigMain).MakeBody("")
b.Call(fn.Expr, prog.Val(1), prog.Val(1.2))
b.Return()
assertPkg(t, pkg, `; ModuleID = 'foo/bar'
source_filename = "foo/bar"
define i64 @fn(i64 %0, double %1) {
ret i64 1
}
define void @main() {
%1 = call i64 @fn(i64 1, double 1.200000e+00)
ret void
}
`)
}
func TestBinOp(t *testing.T) {
prog := NewProgram(nil)
pkg := prog.NewPackage("bar", "foo/bar")