assembler: save currently broken refactors, its simpler to wipe then rebuild the assembler

This commit is contained in:
2025-06-25 02:19:00 +01:00
parent 11ba09ab43
commit f72f36cd47
3 changed files with 18 additions and 33 deletions
+5 -13
View File
@@ -60,11 +60,7 @@ impl CompilerEngine {
} }
/// Main assembly function that orchestrates the entire compilation process. /// Main assembly function that orchestrates the entire compilation process.
pub fn assemble( pub fn assemble(&self, main_path: &Path) -> Result<Vec<Instruction>, AssembleError> {
&self,
main_path: &Path,
output_path: Option<&Path>,
) -> Result<Vec<Instruction>, AssembleError> {
let program = Program::new(); let program = Program::new();
// Set the main path in the program // Set the main path in the program
@@ -139,23 +135,19 @@ impl Default for CompilerEngine {
/// Convenience function for simple assembly with default settings. /// Convenience function for simple assembly with default settings.
pub fn assemble(input_path: &Path) -> Result<Vec<Instruction>, AssembleError> { pub fn assemble(input_path: &Path) -> Result<Vec<Instruction>, AssembleError> {
let engine = CompilerEngine::new(); let engine = CompilerEngine::new();
engine.assemble(input_path, None) engine.assemble(input_path)
} }
/// Convenience function for assembling to ELF object format. /// Convenience function for assembling to ELF object format.
pub fn assemble_to_object( pub fn assemble_to_object(input_path: &Path) -> Result<Vec<Instruction>, AssembleError> {
input_path: &Path,
output_path: Option<&Path>,
) -> Result<Vec<Instruction>, AssembleError> {
let engine = CompilerEngine::with_output_format(OutputFormat::ElfObject); 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. /// Convenience function for assembling to ELF executable format.
pub fn assemble_to_executable( pub fn assemble_to_executable(
input_path: &Path, input_path: &Path,
output_path: Option<&Path>,
) -> Result<Vec<Instruction>, AssembleError> { ) -> Result<Vec<Instruction>, AssembleError> {
let engine = CompilerEngine::with_output_format(OutputFormat::ElfExecutable); let engine = CompilerEngine::with_output_format(OutputFormat::ElfExecutable);
engine.assemble(input_path, output_path) engine.assemble(input_path)
} }
+1 -1
View File
@@ -56,7 +56,7 @@ pub fn lexer(mut program: String, module: u64) -> Result<Vec<Token>, AssembleErr
} else if let Some(token) = parse_symbol(token, module)? { } else if let Some(token) = parse_symbol(token, module)? {
tokens.push(token); tokens.push(token);
} else { } else {
return Err(AssembleError::Generic); return Err(AssembleError::Generic("Token not matched!".to_string()));
} }
} }
} }
+12 -19
View File
@@ -157,7 +157,7 @@ impl PartialEq for Symbol {
} }
#[derive(Debug, Clone, PartialEq, Eq, Hash)] #[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum Token { pub enum TokenType {
Symbol(Symbol), Symbol(Symbol),
Register(Register), Register(Register),
Immediate(u32), Immediate(u32),
@@ -165,26 +165,19 @@ pub enum Token {
Opcode(Opcode), Opcode(Opcode),
} }
#[derive(Debug, PartialEq, Eq, Copy, Clone)] pub struct Token {
pub enum TokenType { token_type: TokenType,
Symbol, source_info: SourceInfo,
Register,
Immediate,
StringLit,
Opcode,
} }
impl TokenType { /// Information on where the token is within the source.
#[must_use] pub struct SourceInfo {
pub const fn from_token(token: &Token) -> Self { /// The line number within the source file underpinned by `module_id`.
match token { pub line_no: usize,
Token::Symbol(_) => Self::Symbol, /// The ID of the module containing this token.
Token::Register(_) => Self::Register, pub module_id: Uuid,
Token::Immediate(_) => Self::Immediate, /// The indexes where this token may be found (line-local).
Token::StringLit(_) => Self::StringLit, pub span: std::ops::Range<usize>,
Token::Opcode(_) => Self::Opcode,
}
}
} }
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]