diff options
author | Ben Bridle <bridle.benjamin@gmail.com> | 2025-05-22 15:58:34 +1200 |
---|---|---|
committer | Ben Bridle <bridle.benjamin@gmail.com> | 2025-05-22 15:59:00 +1200 |
commit | 204896ef6887969ac218fada7c5919ea4e275732 (patch) | |
tree | 0dd2c79e3a12eb60c95362372723c2a18c7c7820 /src/stages/bytecode_tokens.rs | |
download | bedrock-asm-204896ef6887969ac218fada7c5919ea4e275732.zip |
Initial commit
Diffstat (limited to 'src/stages/bytecode_tokens.rs')
-rw-r--r-- | src/stages/bytecode_tokens.rs | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/stages/bytecode_tokens.rs b/src/stages/bytecode_tokens.rs new file mode 100644 index 0000000..902fcd7 --- /dev/null +++ b/src/stages/bytecode_tokens.rs @@ -0,0 +1,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); +} |