ssa: TestUnOp

This commit is contained in:
xushiwei
2024-04-20 17:31:49 +08:00
parent 96f9226923
commit 905c05e099
6 changed files with 138 additions and 413 deletions

View File

@@ -228,3 +228,25 @@ define i64 @fn(i64 %0, double %1) {
}
`)
}
func TestUnOp(t *testing.T) {
prog := NewProgram(nil)
pkg := prog.NewPackage("bar", "foo/bar")
params := types.NewTuple(
types.NewVar(0, nil, "p", types.NewPointer(types.Typ[types.Int])),
)
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)
b := fn.MakeBody("")
ret := b.UnOp(token.MUL, fn.Param(0))
b.Return(ret)
assertPkg(t, pkg, `; ModuleID = 'foo/bar'
source_filename = "foo/bar"
define i64 @fn(ptr %0) {
%2 = load i64, ptr %0, align 4
ret i64 %2
}
`)
}