From 47c4cd3705bee9d7154c42ce95aef6f8a19e0661 Mon Sep 17 00:00:00 2001 From: Mel Date: Fri, 27 May 2022 16:44:22 +0000 Subject: Add debug info to compiled VM code --- pkg/lang/vm/code/debug.go | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 pkg/lang/vm/code/debug.go (limited to 'pkg/lang/vm/code/debug.go') 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) +} -- cgit 1.4.1