Skip to content

Commit

Permalink
Fixed sample54 output
Browse files Browse the repository at this point in the history
  • Loading branch information
AjayBrahmakshatriya committed Jan 1, 2024
1 parent 3673e3b commit c1ed013
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 21 deletions.
2 changes: 1 addition & 1 deletion include/blocks/var_namer.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class var_hoister : public block_replacer {
virtual void visit(decl_stmt::Ptr) override;
};

class var_reference_promoter: public block_replacer {
class var_reference_promoter : public block_replacer {
public:
using block_replacer::visit;
virtual void visit(var_expr::Ptr) override;
Expand Down
16 changes: 11 additions & 5 deletions samples/outputs.var_names/sample54
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
void bar (void) {
int z_1;
int z_3;
int* k_4;
int y_0 = 0;
int m_1;
int n_2;
if (y_0) {
z_1 = 1;
z_3 = 1;
k_4 = (&(m_1));
} else {
z_1 = 2;
z_3 = 2;
k_4 = (&(m_1));
}
int b_2;
int a_3 = z_1;
int b_5;
int a_6 = z_3;
z_3 = z_3 + k_4[0];
}

16 changes: 11 additions & 5 deletions samples/outputs/sample54
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
void bar (void) {
int var1;
int var3;
int* var4;
int var0 = 0;
int var1;
int var2;
if (var0) {
var1 = 1;
var3 = 1;
var4 = (&(var1));
} else {
var1 = 2;
var3 = 2;
var4 = (&(var1));
}
int var2;
int var3 = var1;
int var5;
int var6 = var3;
var3 = var3 + var4[0];
}

4 changes: 1 addition & 3 deletions samples/sample54.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ static void bar(void) {
}
// When z is declared, x is in different states
dyn_var<int> z = x;
dyn_var<int&> k = m;
dyn_var<int &> k = m;

// Executions can now merge, but z is still in different states
x = 0;
Expand All @@ -34,8 +34,6 @@ static void bar(void) {
dyn_var<int> a = z;

z = z + k;


}

int main(int argc, char *argv[]) {
Expand Down
2 changes: 1 addition & 1 deletion src/blocks/loop_finder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ void loop_finder::visit_label(label_stmt::Ptr a, stmt_block::Ptr parent) {
// this currently happens when two statements have the same tag
// For now we will just delete this label
std::vector<stmt::Ptr> new_stmts;
for (auto stmt: parent->stmts) {
for (auto stmt : parent->stmts) {
if (stmt == a)
continue;
new_stmts.push_back(stmt);
Expand Down
8 changes: 2 additions & 6 deletions src/blocks/var_namer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ void var_hoister::visit(decl_stmt::Ptr a) {
std::string so = get_apt_tag(a->decl_var, escaping_tags);
if (decls_to_hoist.find(so) != decls_to_hoist.end()) {

// if the variable is of reference type, we need to convert it to a pointer
// if the variable is of reference type, we need to convert it to a pointer
// type

if (isa<reference_type>(a->decl_var->var_type)) {
Expand All @@ -83,7 +83,6 @@ void var_hoister::visit(decl_stmt::Ptr a) {
a->init_expr = addr_expr;
}


// This decl needs to be flattened into an assignment
// but if it doesn't have an init_expr, just make a simple var_expr
expr_stmt::Ptr estmt = std::make_shared<expr_stmt>();
Expand Down Expand Up @@ -119,7 +118,7 @@ void var_hoister::visit(decl_stmt::Ptr a) {
// to dereferences since they have been converted to pointers
void var_reference_promoter::visit(var_expr::Ptr a) {
node = a;
if (a->getBoolMetadata("is_reference_init") || !a->var1->getBoolMetadata("was_reference"))
if (a->getBoolMetadata("is_reference_init") || !a->var1->getBoolMetadata("was_reference"))
return;
auto sq_bkt = std::make_shared<sq_bkt_expr>();
sq_bkt->static_offset = a->static_offset;
Expand All @@ -131,10 +130,8 @@ void var_reference_promoter::visit(var_expr::Ptr a) {

sq_bkt->index = index;
node = sq_bkt;

}


void var_namer::name_vars(block::Ptr a) {
var_namer namer;

Expand All @@ -149,7 +146,6 @@ void var_namer::name_vars(block::Ptr a) {
var_hoister hoister(namer.decls_to_hoist, namer.escaping_tags);
a->accept(&hoister);


var_reference_promoter promoter;
a->accept(&promoter);

Expand Down

0 comments on commit c1ed013

Please sign in to comment.