aboutsummaryrefslogtreecommitdiff
path: root/crates/nasm/src/main.rs
diff options
context:
space:
mode:
authorMiquel Sabaté Solà <mikisabate@gmail.com>2024-09-26 15:53:57 +0200
committerMiquel Sabaté Solà <mikisabate@gmail.com>2024-12-12 07:41:30 +0100
commit184c39579227c0add80a61d489c242120001d6b6 (patch)
tree48737e0e00b5fb655090a1c9a4fc216dcf278cc0 /crates/nasm/src/main.rs
parent54e1239fcccb2383e5caa88844a7229b5441c31e (diff)
downloadtools.nes-184c39579227.tar.gz
tools.nes-184c39579227.zip
Re-work the parser from scratch
The initial implementation was incredibly naive on how complex an assembler can actually be. Because of this, it never bothered to define and produce a proper AST, and hence it was overall extremely fragile on (not so) corner cases. This commit re-writes everything from scratch for the parser, and it should really be the last fundamental change to the parser other than minor additions/features here and there. Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
Diffstat (limited to 'crates/nasm/src/main.rs')
-rw-r--r--crates/nasm/src/main.rs25
1 files changed, 9 insertions, 16 deletions
diff --git a/crates/nasm/src/main.rs b/crates/nasm/src/main.rs
index 5242784..52de035 100644
--- a/crates/nasm/src/main.rs
+++ b/crates/nasm/src/main.rs
@@ -55,24 +55,17 @@ fn main() -> Result<()> {
// After the parse operation, just print the results.
if args.disassemble {
- let instructions = assembler.disassemble(input)?;
+ // let instructions = assembler.disassemble(input)?;
- for instr in instructions {
- output.write_all(instr.to_human().as_bytes())?;
- output.write_all("\n".as_bytes())?;
- }
+ // for instr in instructions {
+ // output.write_all(instr.to_human().as_bytes())?;
+ // output.write_all("\n".as_bytes())?;
+ // }
} else {
- let instructions = assembler.assemble(input)?;
-
- for instr in instructions {
- let bs = instr.to_bytes();
-
- if instr.size() == 1 {
- output.write_all(&[bs[0]])?;
- } else if instr.size() == 2 {
- output.write_all(&[bs[0], bs[1]])?;
- } else {
- output.write_all(&[bs[0], bs[1], bs[2]])?;
+ let bundles = assembler.assemble(input)?;
+ for b in bundles {
+ for i in 0..b.size {
+ output.write_all(&[b.bytes[i as usize]])?;
}
}
}