mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-15 08:23:41 +00:00
Implement comparing a pointer to nil
This commit is contained in:
+16
-4
@@ -1500,11 +1500,11 @@ func (c *Compiler) parseBinOp(frame *Frame, binop *ssa.BinOp) (llvm.Value, error
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return llvm.Value{}, err
|
return llvm.Value{}, err
|
||||||
}
|
}
|
||||||
typ := binop.X.Type()
|
typ := binop.X.Type().Underlying()
|
||||||
if typNamed, ok := typ.(*types.Named); ok {
|
signed := false
|
||||||
typ = typNamed.Underlying()
|
if typ, ok := typ.(*types.Basic); ok {
|
||||||
|
signed = typ.Info()&types.IsUnsigned == 0
|
||||||
}
|
}
|
||||||
signed := typ.(*types.Basic).Info()&types.IsUnsigned == 0
|
|
||||||
switch binop.Op {
|
switch binop.Op {
|
||||||
case token.ADD: // +
|
case token.ADD: // +
|
||||||
return c.builder.CreateAdd(x, y, ""), nil
|
return c.builder.CreateAdd(x, y, ""), nil
|
||||||
@@ -1560,6 +1560,12 @@ func (c *Compiler) parseBinOp(frame *Frame, binop *ssa.BinOp) (llvm.Value, error
|
|||||||
} else {
|
} else {
|
||||||
return llvm.Value{}, errors.New("todo: equality operator on unknown basic type: " + typ.String())
|
return llvm.Value{}, errors.New("todo: equality operator on unknown basic type: " + typ.String())
|
||||||
}
|
}
|
||||||
|
case *types.Pointer:
|
||||||
|
if binop.Op == token.EQL {
|
||||||
|
return c.builder.CreateICmp(llvm.IntEQ, x, y, ""), nil
|
||||||
|
} else {
|
||||||
|
return c.builder.CreateICmp(llvm.IntNE, x, y, ""), nil
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
return llvm.Value{}, errors.New("todo: equality operator on unknown type: " + typ.String())
|
return llvm.Value{}, errors.New("todo: equality operator on unknown type: " + typ.String())
|
||||||
}
|
}
|
||||||
@@ -1635,6 +1641,12 @@ func (c *Compiler) parseConst(expr *ssa.Const) (llvm.Value, error) {
|
|||||||
} else {
|
} else {
|
||||||
return llvm.Value{}, errors.New("todo: unknown constant: " + typ.String())
|
return llvm.Value{}, errors.New("todo: unknown constant: " + typ.String())
|
||||||
}
|
}
|
||||||
|
case *types.Pointer:
|
||||||
|
llvmType, err := c.getLLVMType(typ)
|
||||||
|
if err != nil {
|
||||||
|
return llvm.Value{}, err
|
||||||
|
}
|
||||||
|
return llvm.ConstPointerNull(llvmType), nil
|
||||||
default:
|
default:
|
||||||
return llvm.Value{}, errors.New("todo: unknown constant: " + typ.String())
|
return llvm.Value{}, errors.New("todo: unknown constant: " + typ.String())
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user