diff options
author | Ayke van Laethem <[email protected]> | 2019-04-21 15:39:27 +0200 |
---|---|---|
committer | Ron Evans <[email protected]> | 2019-04-26 08:52:10 +0200 |
commit | 45cacda7b343ad50c4caa9718dfd9bf46bc491ab (patch) | |
tree | 849b44f465ca3134e9706a9f81c79a4bcb3aa448 /compiler/defer.go | |
parent | c25fe609a9d1431e43c39fa8f0816b83ee6e7f1e (diff) | |
download | tinygo-45cacda7b343ad50c4caa9718dfd9bf46bc491ab.tar.gz tinygo-45cacda7b343ad50c4caa9718dfd9bf46bc491ab.zip |
compiler: refactor parseExpr
This commit adds getValue which gets a const, global, or result of a
local SSA expression and replaces (almost) all uses of parseExpr with
getValue. The only remaining use is in parseInstr, which makes sure an
instruction is only evaluated once.
Diffstat (limited to 'compiler/defer.go')
-rw-r--r-- | compiler/defer.go | 30 |
1 files changed, 6 insertions, 24 deletions
diff --git a/compiler/defer.go b/compiler/defer.go index 35408a074..9a7f3717a 100644 --- a/compiler/defer.go +++ b/compiler/defer.go @@ -56,18 +56,12 @@ func (c *Compiler) emitDefer(frame *Frame, instr *ssa.Defer) error { // Collect all values to be put in the struct (starting with // runtime._defer fields, followed by the call parameters). - itf, err := c.parseExpr(frame, instr.Call.Value) // interface - if err != nil { - return err - } + itf := c.getValue(frame, instr.Call.Value) // interface receiverValue := c.builder.CreateExtractValue(itf, 1, "invoke.func.receiver") values = []llvm.Value{callback, next, receiverValue} valueTypes = append(valueTypes, c.i8ptrType) for _, arg := range instr.Call.Args { - val, err := c.parseExpr(frame, arg) - if err != nil { - return err - } + val := c.getValue(frame, arg) values = append(values, val) valueTypes = append(valueTypes, val.Type()) } @@ -86,10 +80,7 @@ func (c *Compiler) emitDefer(frame *Frame, instr *ssa.Defer) error { // runtime._defer fields). values = []llvm.Value{callback, next} for _, param := range instr.Call.Args { - llvmParam, err := c.parseExpr(frame, param) - if err != nil { - return err - } + llvmParam := c.getValue(frame, param) values = append(values, llvmParam) valueTypes = append(valueTypes, llvmParam.Type()) } @@ -101,10 +92,7 @@ func (c *Compiler) emitDefer(frame *Frame, instr *ssa.Defer) error { // pointer. // TODO: ignore this closure entirely and put pointers to the free // variables directly in the defer struct, avoiding a memory allocation. - closure, err := c.parseExpr(frame, instr.Call.Value) - if err != nil { - return err - } + closure := c.getValue(frame, instr.Call.Value) context := c.builder.CreateExtractValue(closure, 0, "") // Get the callback number. @@ -120,10 +108,7 @@ func (c *Compiler) emitDefer(frame *Frame, instr *ssa.Defer) error { // context pointer). values = []llvm.Value{callback, next} for _, param := range instr.Call.Args { - llvmParam, err := c.parseExpr(frame, param) - if err != nil { - return err - } + llvmParam := c.getValue(frame, param) values = append(values, llvmParam) valueTypes = append(valueTypes, llvmParam.Type()) } @@ -239,10 +224,7 @@ func (c *Compiler) emitRunDefers(frame *Frame) error { // Parent coroutine handle. forwardParams = append(forwardParams, llvm.Undef(c.i8ptrType)) - fnPtr, _, err := c.getInvokeCall(frame, callback) - if err != nil { - return err - } + fnPtr, _ := c.getInvokeCall(frame, callback) c.createCall(fnPtr, forwardParams, "") case *ir.Function: |