forked from tinygo-org/tinygo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
compiler: move IR checker to separate package
This is a preparation for moving the Optimize function to the transform package.
- Loading branch information
1 parent
599670c
commit 2f88c7a
Showing
3 changed files
with
74 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package ircheck | ||
|
||
import ( | ||
"go/scanner" | ||
"go/token" | ||
"path/filepath" | ||
|
||
"tinygo.org/x/go-llvm" | ||
) | ||
|
||
// errorAt returns an error value at the location of the instruction. | ||
// The location information may not be complete as it depends on debug | ||
// information in the IR. | ||
func errorAt(inst llvm.Value, msg string) scanner.Error { | ||
return scanner.Error{ | ||
Pos: getPosition(inst), | ||
Msg: msg, | ||
} | ||
} | ||
|
||
// getPosition returns the position information for the given value, as far as | ||
// it is available. | ||
func getPosition(val llvm.Value) token.Position { | ||
if !val.IsAInstruction().IsNil() { | ||
loc := val.InstructionDebugLoc() | ||
if loc.IsNil() { | ||
return token.Position{} | ||
} | ||
file := loc.LocationScope().ScopeFile() | ||
return token.Position{ | ||
Filename: filepath.Join(file.FileDirectory(), file.FileFilename()), | ||
Line: int(loc.LocationLine()), | ||
Column: int(loc.LocationColumn()), | ||
} | ||
} else if !val.IsAFunction().IsNil() { | ||
loc := val.Subprogram() | ||
if loc.IsNil() { | ||
return token.Position{} | ||
} | ||
file := loc.ScopeFile() | ||
return token.Position{ | ||
Filename: filepath.Join(file.FileDirectory(), file.FileFilename()), | ||
Line: int(loc.SubprogramLine()), | ||
} | ||
} else { | ||
return token.Position{} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters