diff --git a/assembler/src/assembler/engine.rs b/assembler/src/assembler/engine.rs index 72628a7..cfc19b2 100644 --- a/assembler/src/assembler/engine.rs +++ b/assembler/src/assembler/engine.rs @@ -60,11 +60,7 @@ impl CompilerEngine { } /// Main assembly function that orchestrates the entire compilation process. - pub fn assemble( - &self, - main_path: &Path, - output_path: Option<&Path>, - ) -> Result, AssembleError> { + pub fn assemble(&self, main_path: &Path) -> Result, AssembleError> { let program = Program::new(); // Set the main path in the program @@ -139,23 +135,19 @@ impl Default for CompilerEngine { /// Convenience function for simple assembly with default settings. pub fn assemble(input_path: &Path) -> Result, AssembleError> { let engine = CompilerEngine::new(); - engine.assemble(input_path, None) + engine.assemble(input_path) } /// Convenience function for assembling to ELF object format. -pub fn assemble_to_object( - input_path: &Path, - output_path: Option<&Path>, -) -> Result, AssembleError> { +pub fn assemble_to_object(input_path: &Path) -> Result, AssembleError> { let engine = CompilerEngine::with_output_format(OutputFormat::ElfObject); - engine.assemble(input_path, output_path) + engine.assemble(input_path) } /// Convenience function for assembling to ELF executable format. pub fn assemble_to_executable( input_path: &Path, - output_path: Option<&Path>, ) -> Result, AssembleError> { let engine = CompilerEngine::with_output_format(OutputFormat::ElfExecutable); - engine.assemble(input_path, output_path) + engine.assemble(input_path) } diff --git a/assembler/src/assembler/lexer.rs b/assembler/src/assembler/lexer.rs index f5adfb5..9b624a4 100644 --- a/assembler/src/assembler/lexer.rs +++ b/assembler/src/assembler/lexer.rs @@ -56,7 +56,7 @@ pub fn lexer(mut program: String, module: u64) -> Result, AssembleErr } else if let Some(token) = parse_symbol(token, module)? { tokens.push(token); } else { - return Err(AssembleError::Generic); + return Err(AssembleError::Generic("Token not matched!".to_string())); } } } diff --git a/assembler/src/assembler/model.rs b/assembler/src/assembler/model.rs index 615b7da..5173f49 100644 --- a/assembler/src/assembler/model.rs +++ b/assembler/src/assembler/model.rs @@ -157,7 +157,7 @@ impl PartialEq for Symbol { } #[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub enum Token { +pub enum TokenType { Symbol(Symbol), Register(Register), Immediate(u32), @@ -165,26 +165,19 @@ pub enum Token { Opcode(Opcode), } -#[derive(Debug, PartialEq, Eq, Copy, Clone)] -pub enum TokenType { - Symbol, - Register, - Immediate, - StringLit, - Opcode, +pub struct Token { + token_type: TokenType, + source_info: SourceInfo, } -impl TokenType { - #[must_use] - pub const fn from_token(token: &Token) -> Self { - match token { - Token::Symbol(_) => Self::Symbol, - Token::Register(_) => Self::Register, - Token::Immediate(_) => Self::Immediate, - Token::StringLit(_) => Self::StringLit, - Token::Opcode(_) => Self::Opcode, - } - } +/// Information on where the token is within the source. +pub struct SourceInfo { + /// The line number within the source file underpinned by `module_id`. + pub line_no: usize, + /// The ID of the module containing this token. + pub module_id: Uuid, + /// The indexes where this token may be found (line-local). + pub span: std::ops::Range, } #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]