asar
asar copied to clipboard
Rewrite of arch-65816
Would you be interested in a rewrite of arch-65816? This code would be a port of my implementation in my assembler and some kind of test bed for it, since I don't have a complete implementation of the rest of the assembler yet :).
The idea would be to replace the long if-then-else chains with a (even longer) table containing entries like:
[ OPCODE_ADC ][ PARSE_MODE_INDIRECT_Y][1] = { .byte = 0x71, .mode = ASSEMBLE_MODE_1 },
to specify that ADC (stuff),y should assemble to 71 stuff, if stuff has length 1 (the third column). ASSEMBLE_MODE_XYZ would correspond to the as_xyz macros we currently use. Then for each statement I would look up the opcode in some kind of hash map, try to match with all kinds of match("", ",y"), which gives me the parse mode, and then would make a lookup on the opcode, parse mode and length of the argument to get the correct as_xyz macro/function to call.
Sadly these tables are really long (about 400 lines), so we don't get that much of an improvement on readability, since we have a huge wall of text, which simply hides the details of the previous implementation, but it might be easier to follow what is going on, since the control flow is much smaller.
Another thing which might be difficult to implement is the opAfallback thing, which is seemingly used to be able to allow labels with the name 'A'. I wouldn't say it is impossible and would like some input if it would be okay to simply disallow labels with this name, which is definitely easier and a bit more sane if you ask me.
I'd say it's something to consider for an Asar 2.0/Asar rewrite (if that ever happens). Probably not the current version, since technically the current implementation already works and changing a lot of code always has the risk of introducing new bugs, but for a complete rewrite that risk would be acceptable and I'd probably want to change the implementation, anyways, since I don't like the excessive use of macros in Asar.