omarandlorraine / strop

Stochastically generates machine code
MIT License
97 stars 1 forks source link

Add Z80 support #51

Closed omarandlorraine closed 9 months ago

omarandlorraine commented 9 months ago

This pull request is intended to demonstrate how to add a new backend to strop.

omarandlorraine commented 9 months ago

The first thing we need to do is pick an emulator to use to execute the generated programs.

The reason to do this first is to test that this new backend generates correct instructions. In other words, strop will be tested against the third-party emulator. The emulator I picked, iz80, panics if it's set to execute an unimplemented opcode, so we'll make sure our unit tests execute all the instructions.

omarandlorraine commented 9 months ago

So we've now got two emulators. One emulates the Z80, and the other emulates the Intel 8080.

I am intending to use these two emulators to test what I'm going to do next: the types Z80Instruction and Z80InstructionSet. (There is no I8080Instruction or I8080InstructionSet, since 8080 is a subset of Z80, and so can be handled by static analysis.)

Definitely src/z80/emulators.rs has a lot of duplicated code which violates DRY, but this pull request is supposed to show what I'm doing and why. Prettiness is a secondary concern at this point.