github.com/tinygo-org/tinygo@v0.31.3-0.20240404173401-90b0bf646c27/transform/errors.go (about) 1 package transform 2 3 import ( 4 "go/scanner" 5 "go/token" 6 "path/filepath" 7 8 "tinygo.org/x/go-llvm" 9 ) 10 11 // errorAt returns an error value at the location of the value. 12 // The location information may not be complete as it depends on debug 13 // information in the IR. 14 func errorAt(val llvm.Value, msg string) scanner.Error { 15 return scanner.Error{ 16 Pos: getPosition(val), 17 Msg: msg, 18 } 19 } 20 21 // getPosition returns the position information for the given value, as far as 22 // it is available. 23 func getPosition(val llvm.Value) token.Position { 24 if !val.IsAInstruction().IsNil() { 25 loc := val.InstructionDebugLoc() 26 if loc.IsNil() { 27 return token.Position{} 28 } 29 file := loc.LocationScope().ScopeFile() 30 return token.Position{ 31 Filename: filepath.Join(file.FileDirectory(), file.FileFilename()), 32 Line: int(loc.LocationLine()), 33 Column: int(loc.LocationColumn()), 34 } 35 } else if !val.IsAFunction().IsNil() { 36 loc := val.Subprogram() 37 if loc.IsNil() { 38 return token.Position{} 39 } 40 file := loc.ScopeFile() 41 return token.Position{ 42 Filename: filepath.Join(file.FileDirectory(), file.FileFilename()), 43 Line: int(loc.SubprogramLine()), 44 } 45 } else { 46 return token.Position{} 47 } 48 } 49 50 // ErrMissingIntrinsic is an error indicating that a required intrinsic was not found in the module. 51 type ErrMissingIntrinsic struct { 52 Name string 53 } 54 55 func (err ErrMissingIntrinsic) Error() string { 56 return "missing intrinsic: " + err.Name 57 }