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.
pub fn assemble(
&self,
main_path: &Path,
output_path: Option<&Path>,
) -> Result<Vec<Instruction>, AssembleError> {
pub fn assemble(&self, main_path: &Path) -> Result<Vec<Instruction>, 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<Vec<Instruction>, 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<Vec<Instruction>, AssembleError> {
pub fn assemble_to_object(input_path: &Path) -> Result<Vec<Instruction>, 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<Vec<Instruction>, AssembleError> {
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)? {
tokens.push(token);
} 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)]
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<usize>,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]