about summary refs log tree commit diff
path: root/pkg/lang/vm/code/debug.go
blob: ebf0ea196bd5083d3b2b766cc2512aa17599bd67 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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 := di.pcToLine.Get(pc)
	if line == nil {
		return -1
	}
	return *line
}

func (di *DebugInfo) AppendLine(uptoPc, line int) {
	di.pcToLine.AppendToLast(uptoPc, line)
}