assembler: enhance error handling and tokenization logic
This commit is contained in:
@@ -5,10 +5,9 @@
|
||||
use common::prelude::*;
|
||||
|
||||
use crate::source::{
|
||||
opcode::Opcode,
|
||||
source_info::SourceInfo,
|
||||
token_info::{
|
||||
DirectiveToken, InstructionToken, LabelToken, RegisterToken, SymbolToken,
|
||||
},
|
||||
token_info::{DirectiveToken, LabelToken, RegisterToken, SymbolToken},
|
||||
};
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
@@ -22,7 +21,7 @@ pub enum TokenType {
|
||||
/// String literal (e.g., `"hello world"`).
|
||||
String(String),
|
||||
/// Assembly instruction (e.g., `add`, `jmp`, `nop`).
|
||||
Instruction(InstructionToken),
|
||||
Instruction(Opcode),
|
||||
/// Label definition (e.g., `loop_start:`).
|
||||
Label(LabelToken),
|
||||
/// Assembler directive (e.g., `.global`, `.section`, `.dw`, `.resb`).
|
||||
@@ -65,11 +64,8 @@ impl Token {
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub const fn instruction(mnemonic: String, source_info: SourceInfo) -> Self {
|
||||
Self::new(
|
||||
TokenType::Instruction(InstructionToken { mnemonic }),
|
||||
source_info,
|
||||
)
|
||||
pub const fn instruction(op: Opcode, source_info: SourceInfo) -> Self {
|
||||
Self::new(TokenType::Instruction(op), source_info)
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
|
||||
Reference in New Issue
Block a user