mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-17 03:03:27 +00:00
Add heap allocation (without escape analysis!)
This commit is contained in:
@@ -457,14 +457,16 @@ func (c *Compiler) parseExpr(frame *Frame, expr ssa.Value) (llvm.Value, error) {
|
|||||||
|
|
||||||
switch expr := expr.(type) {
|
switch expr := expr.(type) {
|
||||||
case *ssa.Alloc:
|
case *ssa.Alloc:
|
||||||
if expr.Heap {
|
|
||||||
return llvm.Value{}, errors.New("todo: heap alloc")
|
|
||||||
}
|
|
||||||
typ, err := c.getLLVMType(expr.Type().Underlying().(*types.Pointer).Elem())
|
typ, err := c.getLLVMType(expr.Type().Underlying().(*types.Pointer).Elem())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return llvm.Value{}, err
|
return llvm.Value{}, err
|
||||||
}
|
}
|
||||||
return c.builder.CreateAlloca(typ, expr.Comment), nil
|
if expr.Heap {
|
||||||
|
// TODO: escape analysis
|
||||||
|
return c.builder.CreateMalloc(typ, expr.Comment), nil
|
||||||
|
} else {
|
||||||
|
return c.builder.CreateAlloca(typ, expr.Comment), nil
|
||||||
|
}
|
||||||
case *ssa.Const:
|
case *ssa.Const:
|
||||||
return c.parseConst(expr)
|
return c.parseConst(expr)
|
||||||
case *ssa.BinOp:
|
case *ssa.BinOp:
|
||||||
|
|||||||
Reference in New Issue
Block a user