Given a proficient developer with 10-20 years of experience that has never built either a compiler or an emulator, which would be more of challenge?
Could you compare the issues that would be road blocks for either.
Thanks.
Emulation and compilation are quite different, but tend to get lumped together because of both being considered "low-level".
Emulation of a simple architecture such as a 6502 or Z80 will be fairly straightforward for the CPU chunk of the work, but there will be a fair chunk of code to write since you need to have a function for each instruction. You'll want to automate this in some way, from an instruction set specification with all the timings and such, as typing this all out will be very tedious indeed :) Old CPU instruction set specs are easy to find, so this helps a lot when building emulators.
On top of that you'll need to implement some level of hardware emulation, which usually involves handling and generating interrupts (such as the vertical-blank interrupt of a display device if the emulator is for a game console, say). This again will need some level of specification and code generation, but you'll likely have to write most of this by hand as it's not going to be quite so repetitive (and hence automatable) as the instruction set code.
Compilation will involve some sort of language spec of whatever language you are going to be implementing the compiler for, and a target which you will be aiming to output code for. The output could be straight to binary, could be assembly or could even be another language (this is really just a translator, but it counts as compilation when the target is considered "sufficiently" low-level). Since you'll be running on some sort of hardware or VM platform then you will be unlikely to have to worry about interrupt handling and that sort of thing.
Stumbling blocks for both are complexity and correctness -- for the emulator you'll need to make it work very accurately unless you pick very simple things to emulate. You'll also need to create some sort of integrated debugger for the emulator, otherwise it's close to impossible to tell what is going wrong when it invariably does so. For a compiler it should be fairly straightforwward to translate a toy language or a small subset of a more complex language, and build it up as you go along.
Remember, that with both of these items you need to be able to produce input to test them, and if you cannot produce simple inputs then you'll find it very difficult to get debug from the very beginning. This alone makes compiler work easier to get into, imho (That and that you'll want to have something which emulates a full console or something straight away :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With