aboutsummaryrefslogtreecommitdiff
path: root/lib/xixanta/src/assembler.rs
diff options
context:
space:
mode:
authorMiquel Sabaté Solà <mikisabate@gmail.com>2024-12-18 11:31:55 +0100
committerMiquel Sabaté Solà <mikisabate@gmail.com>2024-12-18 11:31:55 +0100
commitd8c0a7f32954bd12303773c4cf8e47bb00fd0ed3 (patch)
tree06430143ae8363f9c08781db38aa099ed937cdeb /lib/xixanta/src/assembler.rs
parent6f917d1f58c7b87502e1c94cfff2a4badbb80287 (diff)
downloadtools.nes-d8c0a7f32954bd12303773c4cf8e47bb00fd0ed3.tar.gz
tools.nes-d8c0a7f32954bd12303773c4cf8e47bb00fd0ed3.zip
Remove unneeded Init and Parsing stage values
These two enum values were actually never used and they are not relevant for the assembling process. Let's remove it for simplicity's sake. Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
Diffstat (limited to 'lib/xixanta/src/assembler.rs')
-rw-r--r--lib/xixanta/src/assembler.rs26
1 files changed, 19 insertions, 7 deletions
diff --git a/lib/xixanta/src/assembler.rs b/lib/xixanta/src/assembler.rs
index 35f7ada..bf7b5a0 100644
--- a/lib/xixanta/src/assembler.rs
+++ b/lib/xixanta/src/assembler.rs
@@ -9,20 +9,35 @@ use std::collections::HashMap;
use std::io::Read;
use std::ops::Range;
+/// The mode in which a literal is expressed.
#[derive(Clone, PartialEq)]
pub enum LiteralMode {
+ /// An 8/16 bit hexadecimal value.
Hexadecimal,
+
+ /// A byte expressed in binary format.
Binary,
+
+ /// A byte expressed in plain decimal format.
Plain,
}
-// TODO: is it really necessary to be this fully fledged?
+/// The different stages that the assembler goes through and which are relevant
+/// for the process.
#[derive(PartialEq)]
pub enum Stage {
- Init,
- Parsing,
+ /// The context is still building up (i.e. we don't have all the variable
+ /// values, labels and their addresses yet).
Context,
+
+ /// An initial context is there, and we can already consume most bundles. We
+ /// only need to leave some of them as pending if they require a value that
+ /// is relative to the end size of segments.
Bundling,
+
+ /// We have most bundles, and we already know the size for all segments.
+ /// Hence, we can resolve (crunch) the nodes that were pending to be
+ /// bundled.
Crunching,
}
@@ -62,7 +77,7 @@ impl Assembler {
Self {
context: Context::new(),
literal_mode: None,
- stage: Stage::Init,
+ stage: Stage::Context,
macros: HashMap::new(),
can_bundle: true,
mappings,
@@ -76,7 +91,6 @@ impl Assembler {
pub fn assemble(&mut self, reader: impl Read) -> Result<Vec<Bundle>, Vec<Error>> {
// First of all, parse the input so we get a list of nodes we can work
// with.
- self.stage = Stage::Parsing;
let mut parser = Parser::default();
if let Err(errors) = parser.parse(reader) {
return Err(errors.iter().map(|e| Error::Parse(e.clone())).collect());
@@ -84,7 +98,6 @@ impl Assembler {
// Build the context by iterating over the parsed nodes and checking
// where scopes start/end, evaluating values for variables, labels, etc.
- self.stage = Stage::Context;
self.eval_context(&parser.nodes)?;
// Finally convert the relevant nodes into binary bundles which can be
@@ -304,7 +317,6 @@ impl Assembler {
}
let mut res = vec![];
- // TODO: trainer support.
for mapping in &mut self.mappings {
for segment in mapping.segments.iter_mut() {