-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Basic implementation for defering jumps from the loop that cut throug…
…h the outer loop
- Loading branch information
1 parent
d065b21
commit 521ca37
Showing
5 changed files
with
453 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
FUNC_DECL | ||
SCALAR_TYPE (VOID) | ||
STMT_BLOCK | ||
DECL_STMT | ||
SCALAR_TYPE (INT) | ||
VAR (x_0) | ||
INT_CONST (5) | ||
WHILE_STMT | ||
LT_EXPR | ||
VAR_EXPR | ||
VAR (x_0) | ||
INT_CONST (10) | ||
STMT_BLOCK | ||
DECL_STMT | ||
SCALAR_TYPE (INT) | ||
VAR (control_guard0) | ||
INT_CONST (0) | ||
WHILE_STMT | ||
GT_EXPR | ||
VAR_EXPR | ||
VAR (x_0) | ||
INT_CONST (100) | ||
STMT_BLOCK | ||
EXPR_STMT | ||
ASSIGN_EXPR | ||
VAR_EXPR | ||
VAR (control_guard0) | ||
INT_CONST (0) | ||
IF_STMT | ||
EQUALS_EXPR | ||
VAR_EXPR | ||
VAR (x_0) | ||
INT_CONST (0) | ||
STMT_BLOCK | ||
EXPR_STMT | ||
ASSIGN_EXPR | ||
VAR_EXPR | ||
VAR (x_0) | ||
PLUS_EXPR | ||
VAR_EXPR | ||
VAR (x_0) | ||
INT_CONST (5) | ||
WHILE_STMT | ||
NE_EXPR | ||
VAR_EXPR | ||
VAR (x_0) | ||
INT_CONST (-1) | ||
STMT_BLOCK | ||
EXPR_STMT | ||
ASSIGN_EXPR | ||
VAR_EXPR | ||
VAR (x_0) | ||
PLUS_EXPR | ||
VAR_EXPR | ||
VAR (x_0) | ||
INT_CONST (6) | ||
EXPR_STMT | ||
ASSIGN_EXPR | ||
VAR_EXPR | ||
VAR (control_guard0) | ||
INT_CONST (1) | ||
BREAK_STMT | ||
STMT_BLOCK | ||
EXPR_STMT | ||
ASSIGN_EXPR | ||
VAR_EXPR | ||
VAR (x_0) | ||
PLUS_EXPR | ||
VAR_EXPR | ||
VAR (x_0) | ||
INT_CONST (4) | ||
IF_STMT | ||
VAR_EXPR | ||
VAR (control_guard0) | ||
STMT_BLOCK | ||
CONTINUE_STMT | ||
STMT_BLOCK | ||
EXPR_STMT | ||
ASSIGN_EXPR | ||
VAR_EXPR | ||
VAR (x_0) | ||
PLUS_EXPR | ||
VAR_EXPR | ||
VAR (x_0) | ||
INT_CONST (5) | ||
WHILE_STMT | ||
NE_EXPR | ||
VAR_EXPR | ||
VAR (x_0) | ||
INT_CONST (-1) | ||
STMT_BLOCK | ||
EXPR_STMT | ||
ASSIGN_EXPR | ||
VAR_EXPR | ||
VAR (x_0) | ||
PLUS_EXPR | ||
VAR_EXPR | ||
VAR (x_0) | ||
INT_CONST (6) | ||
void bar (void) { | ||
int x_0 = 5; | ||
while (x_0 < 10) { | ||
int control_guard0 = 0; | ||
while (x_0 > 100) { | ||
control_guard0 = 0; | ||
if (x_0 == 0) { | ||
x_0 = x_0 + 5; | ||
while (x_0 != -1) { | ||
x_0 = x_0 + 6; | ||
} | ||
control_guard0 = 1; | ||
break; | ||
} | ||
x_0 = x_0 + 4; | ||
} | ||
if (control_guard0) { | ||
continue; | ||
} | ||
x_0 = x_0 + 5; | ||
while (x_0 != -1) { | ||
x_0 = x_0 + 6; | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
FUNC_DECL | ||
SCALAR_TYPE (VOID) | ||
STMT_BLOCK | ||
DECL_STMT | ||
SCALAR_TYPE (INT) | ||
VAR (var0) | ||
INT_CONST (5) | ||
WHILE_STMT | ||
LT_EXPR | ||
VAR_EXPR | ||
VAR (var0) | ||
INT_CONST (10) | ||
STMT_BLOCK | ||
DECL_STMT | ||
SCALAR_TYPE (INT) | ||
VAR (control_guard0) | ||
INT_CONST (0) | ||
WHILE_STMT | ||
GT_EXPR | ||
VAR_EXPR | ||
VAR (var0) | ||
INT_CONST (100) | ||
STMT_BLOCK | ||
EXPR_STMT | ||
ASSIGN_EXPR | ||
VAR_EXPR | ||
VAR (control_guard0) | ||
INT_CONST (0) | ||
IF_STMT | ||
EQUALS_EXPR | ||
VAR_EXPR | ||
VAR (var0) | ||
INT_CONST (0) | ||
STMT_BLOCK | ||
EXPR_STMT | ||
ASSIGN_EXPR | ||
VAR_EXPR | ||
VAR (var0) | ||
PLUS_EXPR | ||
VAR_EXPR | ||
VAR (var0) | ||
INT_CONST (5) | ||
WHILE_STMT | ||
NE_EXPR | ||
VAR_EXPR | ||
VAR (var0) | ||
INT_CONST (-1) | ||
STMT_BLOCK | ||
EXPR_STMT | ||
ASSIGN_EXPR | ||
VAR_EXPR | ||
VAR (var0) | ||
PLUS_EXPR | ||
VAR_EXPR | ||
VAR (var0) | ||
INT_CONST (6) | ||
EXPR_STMT | ||
ASSIGN_EXPR | ||
VAR_EXPR | ||
VAR (control_guard0) | ||
INT_CONST (1) | ||
BREAK_STMT | ||
STMT_BLOCK | ||
EXPR_STMT | ||
ASSIGN_EXPR | ||
VAR_EXPR | ||
VAR (var0) | ||
PLUS_EXPR | ||
VAR_EXPR | ||
VAR (var0) | ||
INT_CONST (4) | ||
IF_STMT | ||
VAR_EXPR | ||
VAR (control_guard0) | ||
STMT_BLOCK | ||
CONTINUE_STMT | ||
STMT_BLOCK | ||
EXPR_STMT | ||
ASSIGN_EXPR | ||
VAR_EXPR | ||
VAR (var0) | ||
PLUS_EXPR | ||
VAR_EXPR | ||
VAR (var0) | ||
INT_CONST (5) | ||
WHILE_STMT | ||
NE_EXPR | ||
VAR_EXPR | ||
VAR (var0) | ||
INT_CONST (-1) | ||
STMT_BLOCK | ||
EXPR_STMT | ||
ASSIGN_EXPR | ||
VAR_EXPR | ||
VAR (var0) | ||
PLUS_EXPR | ||
VAR_EXPR | ||
VAR (var0) | ||
INT_CONST (6) | ||
void bar (void) { | ||
int var0 = 5; | ||
while (var0 < 10) { | ||
int control_guard0 = 0; | ||
while (var0 > 100) { | ||
control_guard0 = 0; | ||
if (var0 == 0) { | ||
var0 = var0 + 5; | ||
while (var0 != -1) { | ||
var0 = var0 + 6; | ||
} | ||
control_guard0 = 1; | ||
break; | ||
} | ||
var0 = var0 + 4; | ||
} | ||
if (control_guard0) { | ||
continue; | ||
} | ||
var0 = var0 + 5; | ||
while (var0 != -1) { | ||
var0 = var0 + 6; | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#include "blocks/c_code_generator.h" | ||
#include "builder/builder_context.h" | ||
#include "builder/dyn_var.h" | ||
#include "builder/static_var.h" | ||
#include <iostream> | ||
using builder::dyn_var; | ||
using builder::static_var; | ||
|
||
static void bar(void) { | ||
// This example tests the case where a jump cuts | ||
// through the parent loop | ||
dyn_var<int> x = 5; | ||
while (x < 10) { | ||
while (x > 100) { | ||
if (x == 0) | ||
break; | ||
x = x + 4; | ||
} | ||
x = x + 5; | ||
while (x != -1) | ||
x = x + 6; | ||
} | ||
} | ||
|
||
int main(int argc, char *argv[]) { | ||
builder::builder_context context; | ||
auto ast = context.extract_function_ast(bar, "bar"); | ||
ast->dump(std::cout, 0); | ||
block::c_code_generator::generate_code(ast, std::cout, 0); | ||
return 0; | ||
} |
Oops, something went wrong.