From 184c39579227c0add80a61d489c242120001d6b6 Mon Sep 17 00:00:00 2001 From: Miquel Sabaté Solà Date: Thu, 26 Sep 2024 15:53:57 +0200 Subject: Re-work the parser from scratch MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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à --- crates/nasm/src/main.rs | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) (limited to 'crates/nasm/src') 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]])?; } } } -- cgit v1.2.3