Simplifying generated code
mchalupa opened this issue · 0 comments
mchalupa commented
(Just tracking the ideas for the future...)
// struct declarations
// anonymous struct declarations
// type definitions
// struct definitions
// function declarations
int main();
void test_assert(unsigned int var0);
// global variable definitions
int main(){
unsigned int var0;
unsigned int var1;
unsigned int var2;
unsigned int var3;
block0: ;
var0 = 0;
var1 = 0;
var2 = 1;
var3 = 3;
var1 = (((int)var2) + ((int)var3));
var2 = 3;
var3 = 5;
test_assert((unsigned int)(var1 == 4));
return 0;
}
This code has several issues that we could remove:
-
the comments at the beginning of the program are not needed if nothing is generated for them
-
#26 (var2 and var3)
-
#25 (the main function)
-
we could get rid of the
;
afterblock0:
in cases where there's no declaration immediately after the label -
we can remove labels that are not referred to by any goto (
block0
in this case) -
we can remove unconditional jumps on labels that are going to be executed even without the jump (when the C code immediately follows the jump) (not in this code)