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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
use crate::unit::Label;
use crate::{Source, Span};
#[derive(Debug, Default)]
pub struct DebugInfo {
pub sources: Vec<Source>,
pub instructions: Vec<DebugInst>,
}
impl DebugInfo {
pub fn source_at(&self, source_id: usize) -> Option<&Source> {
self.sources.get(source_id)
}
pub fn instruction_at(&self, ip: usize) -> Option<&DebugInst> {
self.instructions.get(ip)
}
pub fn insert_source(&mut self, source: Source) -> usize {
let source_id = self.sources.len();
self.sources.push(source);
source_id
}
pub fn sources(&self) -> impl Iterator<Item = (usize, &Source)> {
self.sources.iter().enumerate()
}
}
#[derive(Debug)]
pub struct DebugInst {
pub source_id: usize,
pub span: Span,
pub comment: Option<String>,
pub label: Option<Label>,
}