diff options
Diffstat (limited to 'pkg/lang/vm/code/debug.go')
| -rw-r--r-- | pkg/lang/vm/code/debug.go | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/pkg/lang/vm/code/debug.go b/pkg/lang/vm/code/debug.go new file mode 100644 index 0000000..b96c834 --- /dev/null +++ b/pkg/lang/vm/code/debug.go @@ -0,0 +1,31 @@ +package code + +import "jinx/pkg/libs/rangemap" + +type DebugInfo struct { + file string + pcToLine rangemap.RangeMap[int] +} + +func NewDebugInfo(file string) DebugInfo { + return DebugInfo{ + file: file, + pcToLine: rangemap.New[int](), + } +} + +func (di *DebugInfo) File() string { + return di.file +} + +func (di *DebugInfo) PCToLine(pc int) int { + line, ok := di.pcToLine.Get(pc) + if !ok { + return -1 + } + return *line +} + +func (di *DebugInfo) AppendLine(uptoPc, line int) { + di.pcToLine.AppendToLast(uptoPc, line) +} |
