I am writing a compiler that generates C++ code at the end, I can't use while\for
or any other normal loop so I translate it to goto\if
and assigments\call lines like this:
if (i<b) goto loop_959__again;
loop_959__end: ;
}
{
int inumber;
int i;
i=0;
inumber=3;
if (!(inumber<30)) goto loop_4482__end;
loop_4482__again:
float fnumber;
_A1__main__increase(__owner);
i++;
inumber++;
fnumber=3;
loop_4482__step_begin:
if (inumber<30) goto loop_4482__again;
loop_4482__end: ;
}
This is really painful to watch, but can GCC compiler compile and optimize code like the one above as if it consisted of normal loops and etc?
Compilers optimize program control flow with flow graphs analysis, using a goto
instead of an if
branch at that level is practically equivalent from a compiler's standpoint.
A caveat to keep in mind: since gotos
can jump around practically everywhere in your function, if your generator generates irreducible control flow graphs, that might definitely affect the compiler's optimization capabilities.
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