Skip to content

Commit

Permalink
Big parser rebump
Browse files Browse the repository at this point in the history
Signed-off-by: Miquel Sabaté Solà <[email protected]>
  • Loading branch information
mssola committed Oct 7, 2024
1 parent 6c48d7f commit 286ed62
Show file tree
Hide file tree
Showing 3 changed files with 1,255 additions and 557 deletions.
6 changes: 5 additions & 1 deletion lib/xixanta/src/instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ impl PString {
}
}

pub fn is_valid(&self) -> bool {
!(self.value.is_empty() || self.range.is_empty())
}

pub fn is_valid_identifier(&self) -> Result<(), String> {
if self.value.trim().is_empty() {
return Err(format!("empty identifier"));
Expand Down Expand Up @@ -120,7 +124,7 @@ impl Bundle {

#[derive(Eq, Hash, PartialEq, Debug, Clone)]
pub enum AddressingMode {
Unknown,
Unknown, // TODO: is this really used?
Implied,
Immediate,
Absolute,
Expand Down
27 changes: 27 additions & 0 deletions lib/xixanta/src/opcodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ pub struct Entry {
pub affected_on_page: bool,
}

#[derive(Debug)]
pub struct Control {
pub has_identifier: bool,
pub required_args: Option<usize>,
}

lazy_static! {
pub static ref INSTRUCTIONS: HashMap<String, HashMap<AddressingMode, ShortEntry>> = {
let mut instrs = HashMap::new();
Expand Down Expand Up @@ -669,4 +675,25 @@ lazy_static! {

opcodes
};

pub static ref CONTROL_FUNCTIONS: HashMap<String, Control> = {
let mut functions = HashMap::new();

functions.insert(String::from(".hibyte"), Control { has_identifier: false, required_args: Some(1) });
functions.insert(String::from(".lobyte"), Control { has_identifier: false, required_args: Some(1) });
functions.insert(String::from(".macro"), Control { has_identifier: true, required_args: None });
functions.insert(String::from(".proc"), Control { has_identifier: true, required_args: Some(0) });
functions.insert(String::from(".scope"), Control { has_identifier: true, required_args: Some(0) });
functions.insert(String::from(".end"), Control { has_identifier: false, required_args: Some(0) });
functions.insert(String::from(".endscope"), Control { has_identifier: false, required_args: Some(0) });
functions.insert(String::from(".endproc"), Control { has_identifier: false, required_args: Some(0) });
functions.insert(String::from(".endmacro"), Control { has_identifier: false, required_args: Some(0) });
functions.insert(String::from(".segment"), Control { has_identifier: false, required_args: Some(1) });
functions.insert(String::from(".byte"), Control { has_identifier: false, required_args: None });
functions.insert(String::from(".db"), Control { has_identifier: false, required_args: None });
functions.insert(String::from(".word"), Control { has_identifier: false, required_args: None });
functions.insert(String::from(".dw"), Control { has_identifier: false, required_args: None });

functions
};
}
Loading

0 comments on commit 286ed62

Please sign in to comment.