totalspectrum/spin2cpp

Nucode generates a lot of "PUSH 0; ADD" sequences

Wuerfel21 opened this issue · 4 comments

Basically this. I think many of these kinds of funnies are already solved by the OptimizeOperator function in the BC backend. Maybe see if you can reuse it.

Also, relatedly, I still haven't gotten it to work on any actual big codebase. The emulator upcodes just blackscreen (even putting a print at the top of main doesn't come through) and the cinepak decoder fails with a bunch of error: Address type not handled yet and error: Address type not handled yet...

Thanks, I've refactored the code so both backends can use OptimizeOperator, which seems like a very useful function.

The cinepak decoder won't work on nucode because it has too many locals in inline asm (it'll have the same problem in PNut). I'm not sure about the emulators, but I did fix a significant bug in large programs (the trampoline function was totally bogus before).

I think the way it is now doesn't work at all when the start address is too high?

Also note that you still have to check for x+0 expressions after OptimizeOperator, because that's what it turns all no-ops into. (IIRC, anyways)

The code checks for PUSH 0; ADD now and removes it. Also, I fixed a really significant problem in inline assembly, which was totally bogus before (I don't know how any inline assembly ever worked at all, but some of it did).