Skip to content

Commit

Permalink
Merge pull request #67 from AjayBrahmakshatriya/master
Browse files Browse the repository at this point in the history
Added support for with_name with deferred_init and disabled hoisting …
  • Loading branch information
AjayBrahmakshatriya authored Feb 24, 2024
2 parents 817222c + fdc19be commit 51e6512
Show file tree
Hide file tree
Showing 10 changed files with 112 additions and 135 deletions.
7 changes: 7 additions & 0 deletions include/builder/dyn_var.h
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,13 @@ class dyn_var_impl : public var {
void deferred_init(void) {
create_dyn_var(false);
}
// This version allows deferred init to accept other constructor helpers
void deferred_init(const with_name &v) {
create_dyn_var(!v.with_decl);
block_var->var_name = v.name;
block_var->preferred_name = "";
var_name = v.name;
}
// Constructor to initialize a dyn_var as member
// This declaration does not produce a declaration
dyn_var_impl(const as_member &a) {
Expand Down
17 changes: 8 additions & 9 deletions samples/outputs.var_names/sample40
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include <string.h>
int match_re (char* arg1) {
int var3;
int var4;
int var5;
int str_len_1 = strlen(arg1);
int to_match_2 = 0;
if (to_match_2 < str_len_1) {
Expand All @@ -27,28 +27,27 @@ int match_re (char* arg1) {
var3 = 0;
return var3;
}
var4 = 1;
return var4;
return 1;
}
var3 = 0;
return var3;
}
var4 = 0;
return var4;
var5 = 0;
return var5;
}
if (arg1[to_match_2] == 100) {
goto label2;
}
var3 = 0;
return var3;
}
var4 = 0;
return var4;
var5 = 0;
return var5;
}
var3 = 0;
return var3;
}
var4 = 0;
return var4;
var5 = 0;
return var5;
}

49 changes: 16 additions & 33 deletions samples/outputs.var_names/sample52
Original file line number Diff line number Diff line change
@@ -1,66 +1,49 @@
int isEven (int arg0) {
int var1;
if (arg0 == 0) {
var1 = 1;
return var1;
return 1;
}
if (arg0 == 1) {
var1 = 0;
return var1;
return 0;
}
if (arg0 == 2) {
var1 = 1;
return var1;
return 1;
}
if (arg0 == 3) {
var1 = 0;
return var1;
return 0;
}
if (arg0 == 4) {
var1 = 1;
return var1;
return 1;
}
if (arg0 == 5) {
var1 = 0;
return var1;
return 0;
}
if (arg0 == 6) {
var1 = 1;
return var1;
return 1;
}
if (arg0 == 7) {
var1 = 0;
return var1;
return 0;
}
if (arg0 == 8) {
var1 = 1;
return var1;
return 1;
}
if (arg0 == 9) {
var1 = 0;
return var1;
return 0;
}
if (arg0 == 10) {
var1 = 1;
return var1;
return 1;
}
if (arg0 == 11) {
var1 = 0;
return var1;
return 0;
}
if (arg0 == 12) {
var1 = 1;
return var1;
return 1;
}
if (arg0 == 13) {
var1 = 0;
return var1;
return 0;
}
if (arg0 == 14) {
var1 = 1;
return var1;
return 1;
}
var1 = 0;
return var1;
return 0;
}

50 changes: 25 additions & 25 deletions samples/outputs.var_names/sample53
Original file line number Diff line number Diff line change
@@ -1,40 +1,40 @@
void foo (void) {
int obj_0;
int x_1 = 0;
if (x_1) {
obj_0 = 1;
int member_var;
int x_0 = 0;
if (x_0) {
member_var = 1;
} else {
obj_0 = 2;
member_var = 2;
}
if ((obj_0 % 2) == 0) {
obj_0 = obj_0 + 0;
if ((member_var % 2) == 0) {
member_var = member_var + 0;
}
if ((obj_0 % 2) == 0) {
obj_0 = obj_0 + 1;
if ((member_var % 2) == 0) {
member_var = member_var + 1;
}
if ((obj_0 % 2) == 0) {
obj_0 = obj_0 + 2;
if ((member_var % 2) == 0) {
member_var = member_var + 2;
}
if ((obj_0 % 2) == 0) {
obj_0 = obj_0 + 3;
if ((member_var % 2) == 0) {
member_var = member_var + 3;
}
if ((obj_0 % 2) == 0) {
obj_0 = obj_0 + 4;
if ((member_var % 2) == 0) {
member_var = member_var + 4;
}
if ((obj_0 % 2) == 0) {
obj_0 = obj_0 + 5;
if ((member_var % 2) == 0) {
member_var = member_var + 5;
}
if ((obj_0 % 2) == 0) {
obj_0 = obj_0 + 6;
if ((member_var % 2) == 0) {
member_var = member_var + 6;
}
if ((obj_0 % 2) == 0) {
obj_0 = obj_0 + 7;
if ((member_var % 2) == 0) {
member_var = member_var + 7;
}
if ((obj_0 % 2) == 0) {
obj_0 = obj_0 + 8;
if ((member_var % 2) == 0) {
member_var = member_var + 8;
}
if ((obj_0 % 2) == 0) {
obj_0 = obj_0 + 9;
if ((member_var % 2) == 0) {
member_var = member_var + 9;
}
}

17 changes: 8 additions & 9 deletions samples/outputs/sample40
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include <string.h>
int match_re (char* arg1) {
int var3;
int var4;
int var5;
int var1 = strlen(arg1);
int var2 = 0;
if (var2 < var1) {
Expand All @@ -27,28 +27,27 @@ int match_re (char* arg1) {
var3 = 0;
return var3;
}
var4 = 1;
return var4;
return 1;
}
var3 = 0;
return var3;
}
var4 = 0;
return var4;
var5 = 0;
return var5;
}
if (arg1[var2] == 100) {
goto label2;
}
var3 = 0;
return var3;
}
var4 = 0;
return var4;
var5 = 0;
return var5;
}
var3 = 0;
return var3;
}
var4 = 0;
return var4;
var5 = 0;
return var5;
}

49 changes: 16 additions & 33 deletions samples/outputs/sample52
Original file line number Diff line number Diff line change
@@ -1,66 +1,49 @@
int isEven (int arg0) {
int var1;
if (arg0 == 0) {
var1 = 1;
return var1;
return 1;
}
if (arg0 == 1) {
var1 = 0;
return var1;
return 0;
}
if (arg0 == 2) {
var1 = 1;
return var1;
return 1;
}
if (arg0 == 3) {
var1 = 0;
return var1;
return 0;
}
if (arg0 == 4) {
var1 = 1;
return var1;
return 1;
}
if (arg0 == 5) {
var1 = 0;
return var1;
return 0;
}
if (arg0 == 6) {
var1 = 1;
return var1;
return 1;
}
if (arg0 == 7) {
var1 = 0;
return var1;
return 0;
}
if (arg0 == 8) {
var1 = 1;
return var1;
return 1;
}
if (arg0 == 9) {
var1 = 0;
return var1;
return 0;
}
if (arg0 == 10) {
var1 = 1;
return var1;
return 1;
}
if (arg0 == 11) {
var1 = 0;
return var1;
return 0;
}
if (arg0 == 12) {
var1 = 1;
return var1;
return 1;
}
if (arg0 == 13) {
var1 = 0;
return var1;
return 0;
}
if (arg0 == 14) {
var1 = 1;
return var1;
return 1;
}
var1 = 0;
return var1;
return 0;
}

Loading

0 comments on commit 51e6512

Please sign in to comment.