dreasgrech / yabfcompiler

Yet another brainfuck (and Ook!) compiler...
http://blog.dreasgrech.com
1 stars 1 forks source link

Do not emit the array and the pointer variables if they're not needed #11

Open dreasgrech opened 11 years ago

dreasgrech commented 11 years ago

If the full constant substitution optimization step is successful, then the pointer initialization and declaration do not need to be emitted in the compiled assembly.

Similarly, if there is no need for the char array (ex: after the string walk, we ended up with only a bunch of WriteLiteralOps), do not emit it.

dreasgrech commented 11 years ago

To decide whether to emit the pointer variable or not, I'm now checking the final list of DIL operations to see if it contains any PtrOps.

If there are any PtrOps still remaining after the entire optimization process, then I emit the pointer variable; otherwise, I don't.

This makes the size of the compiled assembly slightly smaller.

dreasgrech commented 11 years ago

I currently have bug #17 as regards emitting the pointer variable.