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

@@ -149,7 +149,8 @@ func isPredOp(op token.Token) bool {
return op >= predOpBase && op <= predOpLast
}
// op:
// The BinOp instruction yields the result of binary operation (x op y).
// op can be:
// ADD SUB MUL QUO REM + - * / %
// AND OR XOR SHL SHR AND_NOT & | ^ << >> &^
// EQL NEQ LSS LEQ GTR GEQ == != < <= < >=
@@ -195,6 +196,27 @@ func (b Builder) BinOp(op token.Token, x, y Expr) Expr {
panic("todo")
}
// The UnOp instruction yields the result of (op x).
// ARROW is channel receive.
// MUL is pointer indirection (load).
// XOR is bitwise complement.
// SUB is negation.
// NOT is logical negation.
func (b Builder) UnOp(op token.Token, x Expr) Expr {
switch op {
case token.MUL:
return b.Load(x)
}
panic("todo")
}
// Load returns the value at the pointer ptr.
func (b Builder) Load(ptr Expr) Expr {
elem := ptr.t.(*types.Pointer).Elem()
telem := b.prog.llvmType(elem)
return Expr{llvm.CreateLoad(b.impl, telem.ll, ptr.impl), telem}
}
// -----------------------------------------------------------------------------
func (b Builder) Call(fn Expr, args ...Expr) (ret Expr) {