interp: show backtrace with error

This should make it much easier to figure out why and where an error
happens at package initialization time.
This commit is contained in:
Ayke van Laethem
2020-03-28 20:46:09 +01:00
committed by Ron Evans
parent 2501602b4f
commit cc4a4c755f
6 changed files with 70 additions and 73 deletions
+3 -2
View File
@@ -1,6 +1,7 @@
package interp
import (
"errors"
"strings"
"tinygo.org/x/go-llvm"
@@ -40,7 +41,7 @@ type sideEffectResult struct {
// hasSideEffects scans this function and all descendants, recursively. It
// returns whether this function has side effects and if it does, which globals
// it mentions anywhere in this function or any called functions.
func (e *evalPackage) hasSideEffects(fn llvm.Value) (*sideEffectResult, error) {
func (e *evalPackage) hasSideEffects(fn llvm.Value) (*sideEffectResult, *Error) {
name := fn.Name()
switch {
case name == "runtime.alloc":
@@ -99,7 +100,7 @@ func (e *evalPackage) hasSideEffects(fn llvm.Value) (*sideEffectResult, error) {
switch inst.InstructionOpcode() {
case llvm.IndirectBr, llvm.Invoke:
// Not emitted by the compiler.
return nil, e.errorAt(inst, "unknown instructions")
return nil, e.errorAt(inst, errors.New("unknown instructions"))
case llvm.Call:
child := inst.CalledValue()
if !child.IsAInlineAsm().IsNil() {