summaryrefslogtreecommitdiff
path: root/src/stages/bytecode_tokens.rs
blob: 902fcd70472c3f13619e05be773855db155ccad4 (plain) (blame)
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
use crate::*;


pub struct AssembledProgram {
    pub bytecode: Vec<u8>,
    pub symbols: Vec<AssembledSymbol>,
}

pub struct AssembledSymbol {
    pub name: String,
    pub address: usize,
    pub source: SourceSpan,
}

pub enum BytecodeError {
    InvalidLabelAddress(usize),
    InvalidBlockAddress(usize),
}


pub fn report_bytecode_errors(errors: &[Tracked<BytecodeError>], source_code: &str) {
    for error in errors {
        report_bytecode_error(error, source_code);
    }
}


fn report_bytecode_error(error: &Tracked<BytecodeError>, source_code: &str) {
    let context = Context { source_code: &source_code, source: &error.source };
    let message = match &error.value {
        BytecodeError::InvalidLabelAddress(address) =>
            &format!("The label address exceeds 0xFFFF: 0x{address:X}"),
        BytecodeError::InvalidBlockAddress(address) =>
            &format!("The block address exceeds 0xFFFF: 0x{address:X}"),
    };
    report_source_issue(LogLevel::Error, &context, message);
}