about summary refs log tree commit diff
path: root/pkg/lang/vm/code/debug.go
diff options
context:
space:
mode:
authorMel <einebeere@gmail.com>2022-05-27 16:44:22 +0000
committerGitHub <noreply@github.com>2022-05-27 16:49:02 +0000
commit47c4cd3705bee9d7154c42ce95aef6f8a19e0661 (patch)
treef6b2d502cbc256914a6f7181e2cf623460f9d912 /pkg/lang/vm/code/debug.go
parentc2d4bf51de9a2d721168c62b14b89f5281ed366e (diff)
downloadjinx-47c4cd3705bee9d7154c42ce95aef6f8a19e0661.tar.zst
jinx-47c4cd3705bee9d7154c42ce95aef6f8a19e0661.zip
Add debug info to compiled VM code
Diffstat (limited to 'pkg/lang/vm/code/debug.go')
-rw-r--r--pkg/lang/vm/code/debug.go31
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)
+}