Skip to content

Commit

Permalink
Fixed the break/continue allocator
Browse files Browse the repository at this point in the history
  • Loading branch information
EthanSK committed Mar 26, 2019
1 parent 1253c82 commit bcbc77b
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 23 deletions.
10 changes: 8 additions & 2 deletions src/context/mipsContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,10 @@ void MIPSContext::postProcessInstrs()
{
if (!Utils::vectorContains(_instrs[j].extraData, std::string("#raw")))
{
deallocSize += std::stoi(_instrs[j].input2);
if (!Utils::vectorContains(_instrs[j].extraData, std::string("#pop")))
{
deallocSize += std::stoi(_instrs[j].input2);
}
}
}

Expand All @@ -333,7 +336,10 @@ void MIPSContext::postProcessInstrs()
{
if (!Utils::vectorContains(_instrs[j].extraData, std::string("#raw")))
{
allocSize -= std::stoi(_instrs[j].input2);
if (!Utils::vectorContains(_instrs[j].extraData, std::string("#pop")))
{
allocSize -= std::stoi(_instrs[j].input2);
}
}
}

Expand Down
11 changes: 11 additions & 0 deletions test/compiler/tests/loops/while_break_return.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
int while_break_return()
{
int x, y, z;
while (x > 0)
{
break;
return 10;
}

return 1;
}
6 changes: 6 additions & 0 deletions test/compiler/tests/loops/while_break_return_driver.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
int while_break_return();

int main()
{
return !(while_break_return() == 1);
}
27 changes: 6 additions & 21 deletions test/parser/testProgram.c
Original file line number Diff line number Diff line change
@@ -1,26 +1,11 @@
int switch_complex()
int main()
{
int a = 3;
int b = 0;
switch (a)
int x, y, z;
while (x > 0)
{
b = 4;
case 69:
{
return 69;
}
case 3:

b += 5;
a = b + 6;

case 5:
a += 45;
a++;
break;
default:
return 2;
return 10;
}

return a;
}
return 1;
}

0 comments on commit bcbc77b

Please sign in to comment.