mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-14 16:03:41 +00:00
compiler: Comments
This commit is contained in:
@@ -832,8 +832,8 @@ func (c *Compiler) parseExpr(frame *Frame, expr ssa.Value) (llvm.Value, error) {
|
|||||||
return llvm.Value{}, errors.New("todo: indexaddr: len")
|
return llvm.Value{}, errors.New("todo: indexaddr: len")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bounds check
|
// Bounds check.
|
||||||
// TODO: inline, and avoid if possible
|
// LLVM optimizes this away in most cases.
|
||||||
constZero := llvm.ConstInt(c.intType, 0, false)
|
constZero := llvm.ConstInt(c.intType, 0, false)
|
||||||
isNegative := c.builder.CreateICmp(llvm.IntSLT, index, constZero, "") // index < 0
|
isNegative := c.builder.CreateICmp(llvm.IntSLT, index, constZero, "") // index < 0
|
||||||
isTooBig := c.builder.CreateICmp(llvm.IntSGE, index, buflen, "") // index >= len(value)
|
isTooBig := c.builder.CreateICmp(llvm.IntSGE, index, buflen, "") // index >= len(value)
|
||||||
@@ -865,8 +865,8 @@ func (c *Compiler) parseExpr(frame *Frame, expr ssa.Value) (llvm.Value, error) {
|
|||||||
return llvm.Value{}, nil
|
return llvm.Value{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bounds check
|
// Bounds check.
|
||||||
// TODO: inline, and avoid if possible
|
// LLVM optimizes this away in most cases.
|
||||||
if frame.llvmFn.Name() != "runtime.boundsCheck" {
|
if frame.llvmFn.Name() != "runtime.boundsCheck" {
|
||||||
constZero := llvm.ConstInt(c.intType, 0, false)
|
constZero := llvm.ConstInt(c.intType, 0, false)
|
||||||
isNegative := c.builder.CreateICmp(llvm.IntSLT, index, constZero, "") // index < 0
|
isNegative := c.builder.CreateICmp(llvm.IntSLT, index, constZero, "") // index < 0
|
||||||
@@ -1134,11 +1134,11 @@ func (c *Compiler) parseUnOp(frame *Frame, unop *ssa.UnOp) (llvm.Value, error) {
|
|||||||
return llvm.Value{}, err
|
return llvm.Value{}, err
|
||||||
}
|
}
|
||||||
switch unop.Op {
|
switch unop.Op {
|
||||||
case token.NOT: // !
|
case token.NOT: // !x
|
||||||
return c.builder.CreateNot(x, ""), nil
|
return c.builder.CreateNot(x, ""), nil
|
||||||
case token.SUB: // -num
|
case token.SUB: // -x
|
||||||
return c.builder.CreateSub(llvm.ConstInt(x.Type(), 0, false), x, ""), nil
|
return c.builder.CreateSub(llvm.ConstInt(x.Type(), 0, false), x, ""), nil
|
||||||
case token.MUL: // *ptr, dereference pointer
|
case token.MUL: // *x, dereference pointer
|
||||||
return c.builder.CreateLoad(x, ""), nil
|
return c.builder.CreateLoad(x, ""), nil
|
||||||
default:
|
default:
|
||||||
return llvm.Value{}, errors.New("todo: unknown unop")
|
return llvm.Value{}, errors.New("todo: unknown unop")
|
||||||
|
|||||||
Reference in New Issue
Block a user