views:

75

answers:

2

I'm building a toy compiler as a learning project, and I'm hovering around the code generation phase right now. I found this page describing a host of different assemblers that I could target, and I'd like some recommendations on which to choose.

My goal is to optimize my learning experience - to that end, I've tried to make decisions that will give me the most useful knowledge going forward. Some examples of that are:

  • using a lot of intermediate steps rather than going straight from an AST to ASM
  • targeting x64/Linux rather than the JVM or LLVM

I understand this is pretty subjective, so to try to clarify further: I prefer open-source to proprietary, widely-used to not-widely-used, broad to specific. To this end, I would avoid something like HLA as it is more "specific" than true ASM.

If any of this sounds particularly uninformed, I'm still learning, so feel free to let me know if I'm "doing it wrong".

+2  A: 

Would you consider a non-x86 target, such a cleaner RISC (reduced instruction set computer) processor like the MIPS, which you could test using a software MIPS emulator?

Otherwise I'd say for Linux, I'd consider NASM style for your assembly output, or intermediary format. I believe YASM, FASM support compatibility either by default or by flags, and uses Intel's syntax, versus GNU's gas which uses AT&T's syntax, which is widely considered awkward or worse, but is compatible with gcc output.

mctylr
A: 

If your generating ASM, there's no reason to use any advanced features so I don't think there is much to sell any one over the rest. You might take a quick scan over several and then just pick whichever you can get up and running the most easily.

Also, keep in mind that if you avoid anything but basic feature and architect the ASM output code with a little care, you should be able to switch to a different assemblers format with only a little more than switching output format strings (IIRC printf can select parameters by position so you can even reverse parameter orders). I wouldn't write it to do that up front, but if you keep in mind that you might want to later, it might pay later on.

BCS