diff options
Diffstat (limited to 'src/relooper')
33 files changed, 2223 insertions, 875 deletions
diff --git a/src/relooper/Relooper.cpp b/src/relooper/Relooper.cpp index a457914b..aefcad93 100644 --- a/src/relooper/Relooper.cpp +++ b/src/relooper/Relooper.cpp @@ -104,12 +104,14 @@ void Branch::Render(Block *Target, bool SetLabel) { int Block::IdCounter = 1; // 0 is reserved for clearings -Block::Block(const char *CodeInit) : Parent(NULL), Id(Block::IdCounter++), IsCheckedMultipleEntry(false) { +Block::Block(const char *CodeInit, const char *BranchVarInit) : Parent(NULL), Id(Block::IdCounter++), IsCheckedMultipleEntry(false) { Code = strdup(CodeInit); + BranchVar = BranchVarInit ? strdup(BranchVarInit) : NULL; } Block::~Block() { if (Code) free((void*)Code); + if (BranchVar) free((void*)BranchVar); for (BlockBranchMap::iterator iter = ProcessedBranchesOut.begin(); iter != ProcessedBranchesOut.end(); iter++) { delete iter->second; } @@ -189,8 +191,16 @@ void Block::Render(bool InLoop) { } assert(DefaultTarget); // Since each block *must* branch somewhere, this must be set + if (ProcessedBranchesOut.size() > 2) assert(BranchVar); // must have a branch variable if multiple conditions + + bool useSwitch = BranchVar != NULL; + + if (useSwitch) { + PrintIndented("switch (%s) {\n", BranchVar); + } + ministring RemainingConditions; - bool First = true; + bool First = !useSwitch; // when using a switch, there is no special first for (BlockBranchMap::iterator iter = ProcessedBranchesOut.begin();; iter++) { Block *Target; Branch *Details; @@ -208,26 +218,39 @@ void Block::Render(bool InLoop) { bool HasContent = SetCurrLabel || Details->Type != Branch::Direct || HasFusedContent || Details->Code; if (iter != ProcessedBranchesOut.end()) { // If there is nothing to show in this branch, omit the condition - if (HasContent) { - PrintIndented("%sif (%s) {\n", First ? "" : "} else ", Details->Condition); - First = false; + if (useSwitch) { + PrintIndented("%s {\n", Details->Condition); } else { - if (RemainingConditions.size() > 0) RemainingConditions += " && "; - RemainingConditions += "!("; - RemainingConditions += Details->Condition; - RemainingConditions += ")"; + if (HasContent) { + PrintIndented("%sif (%s) {\n", First ? "" : "} else ", Details->Condition); + First = false; + } else { + if (RemainingConditions.size() > 0) RemainingConditions += " && "; + RemainingConditions += "!("; + if (BranchVar) { + RemainingConditions += BranchVar; + RemainingConditions += " == "; + } + RemainingConditions += Details->Condition; + RemainingConditions += ")"; + } } } else { - if (HasContent) { - if (RemainingConditions.size() > 0) { - if (First) { - PrintIndented("if (%s) {\n", RemainingConditions.c_str()); - First = false; - } else { - PrintIndented("} else if (%s) {\n", RemainingConditions.c_str()); + // this is the default + if (useSwitch) { + PrintIndented("default: {\n"); + } else { + if (HasContent) { + if (RemainingConditions.size() > 0) { + if (First) { + PrintIndented("if (%s) {\n", RemainingConditions.c_str()); + First = false; + } else { + PrintIndented("} else if (%s) {\n", RemainingConditions.c_str()); + } + } else if (!First) { + PrintIndented("} else {\n"); } - } else if (!First) { - PrintIndented("} else {\n"); } } } @@ -236,7 +259,13 @@ void Block::Render(bool InLoop) { if (HasFusedContent) { Fused->InnerMap.find(Target)->second->Render(InLoop); } + if (useSwitch && iter != ProcessedBranchesOut.end()) { + PrintIndented("break;\n"); + } if (!First) Indenter::Unindent(); + if (useSwitch) { + PrintIndented("}\n"); + } if (iter == ProcessedBranchesOut.end()) break; } if (!First) PrintIndented("}\n"); @@ -392,7 +421,7 @@ void Relooper::Calculate(Block *Entry) { PrintDebug("Splitting block %d\n", Original->Id); for (BlockSet::iterator iter = Original->BranchesIn.begin(); iter != Original->BranchesIn.end(); iter++) { Block *Prior = *iter; - Block *Split = new Block(Original->Code); + Block *Split = new Block(Original->Code, Original->BranchVar); Parent->Blocks.push_back(Split); PrintDebug(" to %d\n", Split->Id); Split->BranchesIn.insert(Prior); @@ -975,6 +1004,8 @@ void Relooper::Calculate(Block *Entry) { Root = Next; Next = NULL; SHAPE_SWITCH(Root, { + if (Simple->Inner->BranchVar) LastLoop = NULL; // a switch clears out the loop (TODO: only for breaks, not continue) + // If there is a next block, we already know at Simple creation time to make direct branches, // and we can do nothing more. If there is no next however, then Natural is where we will // go to by doing nothing, so we can potentially optimize some branches to direct. @@ -1028,6 +1059,11 @@ void Relooper::Calculate(Block *Entry) { // If we are fusing a Multiple with a loop into this Simple, then visit it now if (Fused && Fused->NeedLoop) { LoopStack.push(Fused); + } + if (Simple->Inner->BranchVar) { + LoopStack.push(NULL); // a switch means breaks are now useless, push a dummy + } + if (Fused) { RECURSE_Multiple(Fused, FindLabeledLoops); } for (BlockBranchMap::iterator iter = Simple->Inner->ProcessedBranchesOut.begin(); iter != Simple->Inner->ProcessedBranchesOut.end(); iter++) { @@ -1038,14 +1074,18 @@ void Relooper::Calculate(Block *Entry) { if (Details->Ancestor != LoopStack.top() && Details->Labeled) { LabeledShape *Labeled = Shape::IsLabeled(Details->Ancestor); Labeled->Labeled = true; - Details->Labeled = true; } else { Details->Labeled = false; } } } + if (Simple->Inner->BranchVar) { + LoopStack.pop(); + } if (Fused && Fused->NeedLoop) { LoopStack.pop(); + } + if (Fused) { Next = Fused->Next; } else { Next = Root->Next; @@ -1173,8 +1213,8 @@ void rl_set_asm_js_mode(int on) { Relooper::SetAsmJSMode(on); } -void *rl_new_block(const char *text) { - Block *ret = new Block(text); +void *rl_new_block(const char *text, const char *branch_var) { + Block *ret = new Block(text, branch_var); #if DEBUG printf(" void *b%d = rl_new_block(\"// code %d\");\n", ret->Id, ret->Id); __blockDebugMap__[ret] = ret->Id; diff --git a/src/relooper/Relooper.h b/src/relooper/Relooper.h index e54b578c..f3dedf8c 100644 --- a/src/relooper/Relooper.h +++ b/src/relooper/Relooper.h @@ -59,9 +59,10 @@ struct Block { Shape *Parent; // The shape we are directly inside int Id; // A unique identifier const char *Code; // The string representation of the code in this block. Owning pointer (we copy the input) + const char *BranchVar; // If we have more than one branch out, the variable whose value determines where we go bool IsCheckedMultipleEntry; // If true, we are a multiple entry, so reaching us requires setting the label variable - Block(const char *CodeInit); + Block(const char *CodeInit, const char *BranchVarInit); ~Block(); void AddBranchTo(Block *Target, const char *Condition, const char *Code=NULL); @@ -235,7 +236,7 @@ extern "C" { RELOOPERDLL_API void rl_set_output_buffer(char *buffer, int size); RELOOPERDLL_API void rl_make_output_buffer(int size); RELOOPERDLL_API void rl_set_asm_js_mode(int on); -RELOOPERDLL_API void *rl_new_block(const char *text); +RELOOPERDLL_API void *rl_new_block(const char *text, const char *branch_var); RELOOPERDLL_API void rl_delete_block(void *block); RELOOPERDLL_API void rl_block_add_branch_to(void *from, void *to, const char *condition, const char *code); RELOOPERDLL_API void *rl_new_relooper(); diff --git a/src/relooper/emscripten/glue.js b/src/relooper/emscripten/glue.js index 36922185..40ddabec 100644 --- a/src/relooper/emscripten/glue.js +++ b/src/relooper/emscripten/glue.js @@ -6,15 +6,22 @@ var TBUFFER_SIZE = 10*1024*1024; var tbuffer = _malloc(TBUFFER_SIZE); + var VBUFFER_SIZE = 256; + var vbuffer = _malloc(VBUFFER_SIZE); + var RelooperGlue = {}; RelooperGlue['init'] = function() { this.r = _rl_new_relooper(); }, - RelooperGlue['addBlock'] = function(text) { + RelooperGlue['addBlock'] = function(text, branchVar) { assert(this.r); assert(text.length+1 < TBUFFER_SIZE); writeStringToMemory(text, tbuffer); - var b = _rl_new_block(tbuffer); + if (branchVar) { + assert(branchVar.length+1 < VBUFFER_SIZE); + writeStringToMemory(branchVar, vbuffer); + } + var b = _rl_new_block(tbuffer, branchVar ? vbuffer : 0); _rl_relooper_add_block(this.r, b); return b; }; diff --git a/src/relooper/fuzzer.py b/src/relooper/fuzzer.py index 5f6bae3d..50846d10 100644 --- a/src/relooper/fuzzer.py +++ b/src/relooper/fuzzer.py @@ -26,13 +26,13 @@ while True: pass # parts - entry = '''print('entry'); var label; var state; var decisions = %s; var index = 0; function check() { if (index == decisions.length) throw 'HALT'; return decisions[index++] }''' % str(decisions) + entry = '''print('entry'); var label; var state; var modded; var decisions = %s; var index = 0; function check() { if (index == decisions.length) throw 'HALT'; return decisions[index++] }''' % str(decisions) slow = entry + '\n' for i in range(len(branches[0])): if i > 0: slow += 'else ' b = branches[0] - slow += 'if (state %% %d == %d) { label = %d; }\n' % (len(b)+1, i, b[i]) # TODO: split range 1-n into these options + slow += 'if (modded == %d) { label = %d; }\n' % (i, b[i]) # TODO: split range 1-n into these options if len(branches[0]): slow += 'else ' slow += 'label = %d;\n' % defaults[0] @@ -51,26 +51,35 @@ int main() { ''' for i in range(1, num): - slow += ' case %d: print(%d); state = check(); \n' % (i, i) + slow += ' case %d: print(%d); state = check(); modded = state %% %d\n' % (i, i, len(branches[i])+1) b = branches[i] for j in range(len(b)): - slow += ' if (state %% %d == %d) { label = %d; break }\n' % (len(b)+1, j, b[j]) # TODO: split range 1-n into these options + slow += ' if (modded == %d) { label = %d; break }\n' % (j, b[j]) # TODO: split range 1-n into these options slow += ' label = %d; break\n' % defaults[i] + branch_vars = [] for i in range(num): + branch_var = '"modded"' if len(branches[i]) > 0 and not (len(branches[i]) == 1 and random.random() < 0.5) else 'NULL' + branch_vars.append(branch_var) + if i == 0: fast += ''' - Block *b%d = new Block("%s"); -''' % (i, entry) + Block *b%d = new Block("%s", %s); +''' % (i, entry, branch_var) else: - fast += ''' Block *b%d = new Block("print(%d); state = check();%s"); -''' % (i, i, '// ' + ('.' * int(random.expovariate(0.5/num)))) + fast += ''' Block *b%d = new Block("print(%d); state = check(); modded = state %% %d; %s", %s); +''' % (i, i, len(branches[i])+1, '// ' + ('.' * int(random.expovariate(0.5/num))), branch_var) for i in range(num): + branch_var = branch_vars[i] b = branches[i] for j in range(len(b)): - fast += ''' b%d->AddBranchTo(b%d, "state %% %d == %d"); -''' % (i, b[j], len(b)+1, j) + if branch_var == 'NULL': + fast += ''' b%d->AddBranchTo(b%d, "modded == %d"); +''' % (i, b[j], j) + else: + fast += ''' b%d->AddBranchTo(b%d, "case %d:"); +''' % (i, b[j], j) fast += ''' b%d->AddBranchTo(b%d, NULL); ''' % (i, defaults[i]) diff --git a/src/relooper/test.cpp b/src/relooper/test.cpp index b2d500d7..fbd9c7aa 100644 --- a/src/relooper/test.cpp +++ b/src/relooper/test.cpp @@ -7,11 +7,11 @@ int main() { if (1) { Relooper::SetOutputBuffer(buffer, sizeof(buffer)); - printf("\n\n-- If pattern --\n\n"); + printf("\n\n-- If pattern --\n\n", "the_var"); - Block *b_a = new Block("// block A\n"); - Block *b_b = new Block("// block B\n"); - Block *b_c = new Block("// block C\n"); + Block *b_a = new Block("// block A\n", "the_var"); + Block *b_b = new Block("// block B\n", "the_var"); + Block *b_c = new Block("// block C\n", "the_var"); b_a->AddBranchTo(b_b, "check == 10", "atob();"); b_a->AddBranchTo(b_c, NULL, "atoc();"); @@ -24,7 +24,7 @@ int main() { r.AddBlock(b_c); r.Calculate(b_a); - printf("\n\n"); + printf("\n\n", "the_var"); r.Render(); puts(buffer); @@ -33,12 +33,12 @@ int main() { if (1) { Relooper::SetOutputBuffer(buffer, sizeof(buffer)); - printf("\n\n-- If-else pattern --\n\n"); + printf("\n\n-- If-else pattern --\n\n", "the_var"); - Block *b_a = new Block("// block A\n"); - Block *b_b = new Block("// block B\n"); - Block *b_c = new Block("// block C\n"); - Block *b_d = new Block("// block D\n"); + Block *b_a = new Block("// block A\n", "the_var"); + Block *b_b = new Block("// block B\n", "the_var"); + Block *b_c = new Block("// block C\n", "the_var"); + Block *b_d = new Block("// block D\n", "the_var"); b_a->AddBranchTo(b_b, "check == 15"); b_a->AddBranchTo(b_c, NULL); @@ -54,7 +54,7 @@ int main() { r.AddBlock(b_d); r.Calculate(b_a); - printf("\n\n"); + printf("\n\n", "the_var"); r.Render(); puts(buffer); @@ -63,11 +63,11 @@ int main() { if (1) { Relooper::SetOutputBuffer(buffer, sizeof(buffer)); - printf("\n\n-- Loop + tail pattern --\n\n"); + printf("\n\n-- Loop + tail pattern --\n\n", "the_var"); - Block *b_a = new Block("// block A\nvar check = maybe();\n"); - Block *b_b = new Block("// block B\n"); - Block *b_c = new Block("// block C\n"); + Block *b_a = new Block("// block A\nvar check = maybe();\n", "the_var"); + Block *b_b = new Block("// block B\n", "the_var"); + Block *b_c = new Block("// block C\n", "the_var"); b_a->AddBranchTo(b_b, NULL); @@ -80,7 +80,7 @@ int main() { r.AddBlock(b_c); r.Calculate(b_a); - printf("\n\n"); + printf("\n\n", "the_var"); r.Render(); puts(buffer); @@ -89,29 +89,29 @@ int main() { if (1) { Relooper::SetOutputBuffer(buffer, sizeof(buffer)); - printf("\n\n-- Loop with phi to head \n\n"); + printf("\n\n-- Loop with phi to head \n\n", "the_var"); void *block_map[10000]; void *rl = rl_new_relooper(); - void *b1 = rl_new_block("// code 1"); + void *b1 = rl_new_block("// code 1", "the_var"); block_map[1] = b1; rl_relooper_add_block(rl, block_map[1]); - void *b2 = rl_new_block("// code 2"); + void *b2 = rl_new_block("// code 2", "the_var"); block_map[2] = b2; rl_relooper_add_block(rl, block_map[2]); - void *b3 = rl_new_block("// code 3"); + void *b3 = rl_new_block("// code 3", "the_var"); block_map[3] = b3; rl_relooper_add_block(rl, block_map[3]); - void *b4 = rl_new_block("// code 4"); + void *b4 = rl_new_block("// code 4", "the_var"); block_map[4] = b4; rl_relooper_add_block(rl, block_map[4]); - void *b5 = rl_new_block("// code 5"); + void *b5 = rl_new_block("// code 5", "the_var"); block_map[5] = b5; rl_relooper_add_block(rl, block_map[5]); - void *b6 = rl_new_block("// code 6"); + void *b6 = rl_new_block("// code 6", "the_var"); block_map[6] = b6; rl_relooper_add_block(rl, block_map[6]); - void *b7 = rl_new_block("// code 7"); + void *b7 = rl_new_block("// code 7", "the_var"); block_map[7] = b7; rl_relooper_add_block(rl, block_map[7]); rl_block_add_branch_to(block_map[1], block_map[2], NULL, "var $i_0 = 0;var $x_0 = 5; "); @@ -132,13 +132,13 @@ int main() { if (1) { Relooper::SetOutputBuffer(buffer, sizeof(buffer)); - printf("\n\n-- phi on split dead ends --\n\n"); + printf("\n\n-- phi on split dead ends --\n\n", "the_var"); - Block *b_a = new Block("// block A...................................................................................................\n"); - Block *b_b = new Block("// block B...................................................................................................\n"); - Block *b_c = new Block("// block C...................................................................................................\n"); - Block *b_d = new Block("// block D\n"); // small and splittable! - Block *b_e = new Block("// block E\n"); + Block *b_a = new Block("// block A...................................................................................................\n", "the_var"); + Block *b_b = new Block("// block B...................................................................................................\n", "the_var"); + Block *b_c = new Block("// block C...................................................................................................\n", "the_var"); + Block *b_d = new Block("// block D\n", "the_var"); // small and splittable! + Block *b_e = new Block("// block E\n", "the_var"); b_a->AddBranchTo(b_b, "chak()", "atob();"); b_a->AddBranchTo(b_c, NULL, "atoc();"); @@ -155,7 +155,7 @@ int main() { r.AddBlock(b_e); r.Calculate(b_a); - printf("\n\n"); + printf("\n\n", "the_var"); r.Render(); puts(buffer); @@ -164,12 +164,12 @@ int main() { if (1) { Relooper::SetOutputBuffer(buffer, sizeof(buffer)); - printf("\n\n-- Unbalanced with a dead end --\n\n"); + printf("\n\n-- Unbalanced with a dead end --\n\n", "the_var"); - Block *b_a = new Block("// block A\n"); - Block *b_b = new Block("// block B\n"); - Block *b_c = new Block("return C;\n"); - Block *b_d = new Block("// block D\n"); + Block *b_a = new Block("// block A\n", "the_var"); + Block *b_b = new Block("// block B\n", "the_var"); + Block *b_c = new Block("return C;\n", "the_var"); + Block *b_d = new Block("// block D\n", "the_var"); b_a->AddBranchTo(b_b, "check == 10"); b_a->AddBranchTo(b_c, NULL); // c is a dead end @@ -185,7 +185,7 @@ int main() { r.AddBlock(b_d); r.Calculate(b_a); - printf("\n\n"); + printf("\n\n", "the_var"); r.Render(); puts(buffer); @@ -194,14 +194,14 @@ int main() { if (1) { Relooper::SetOutputBuffer(buffer, sizeof(buffer)); - printf("\n\n-- if (expensive || expensive2) X else Y; Z --\n\n"); + printf("\n\n-- if (expensive || expensive2) X else Y; Z --\n\n", "the_var"); - Block *b_a = new Block("// block A\n"); - Block *b_b = new Block("// block B\n"); - Block *b_c = new Block("// block C;\n"); - Block *b_d = new Block("// block D\n"); - Block *b_e = new Block("// block E\n"); - Block *b_f = new Block("// block F\n"); + Block *b_a = new Block("// block A\n", "the_var"); + Block *b_b = new Block("// block B\n", "the_var"); + Block *b_c = new Block("// block C;\n", "the_var"); + Block *b_d = new Block("// block D\n", "the_var"); + Block *b_e = new Block("// block E\n", "the_var"); + Block *b_f = new Block("// block F\n", "the_var"); b_a->AddBranchTo(b_c, "expensive()"); b_a->AddBranchTo(b_b, NULL); @@ -226,7 +226,7 @@ int main() { r.AddBlock(b_f); r.Calculate(b_a); - printf("\n\n"); + printf("\n\n", "the_var"); r.Render(); puts(buffer); @@ -235,11 +235,11 @@ int main() { if (1) { Relooper::SetOutputBuffer(buffer, sizeof(buffer)); - printf("\n\n-- conditional loop --\n\n"); + printf("\n\n-- conditional loop --\n\n", "the_var"); - Block *b_a = new Block("// block A\n"); - Block *b_b = new Block("// block B\n"); - Block *b_c = new Block("// block C\n"); + Block *b_a = new Block("// block A\n", "the_var"); + Block *b_b = new Block("// block B\n", "the_var"); + Block *b_c = new Block("// block C\n", "the_var"); b_a->AddBranchTo(b_b, "shouldLoop()"); b_a->AddBranchTo(b_c, NULL); @@ -253,7 +253,7 @@ int main() { r.AddBlock(b_c); r.Calculate(b_a); - printf("\n\n"); + printf("\n\n", "the_var"); r.Render(); puts(buffer); diff --git a/src/relooper/test.txt b/src/relooper/test.txt index 6c910846..2c530567 100644 --- a/src/relooper/test.txt +++ b/src/relooper/test.txt @@ -5,13 +5,21 @@ // block A -if (check == 10) { +switch (the_var) { +check == 10 { atob(); // block B - btoc(); -} else { + switch (the_var) { + default: { + btoc(); + } + } + break; +} +default: { atoc(); } +} // block C @@ -21,10 +29,22 @@ if (check == 10) { // block A -if (check == 15) { +switch (the_var) { +check == 15 { // block B -} else { + switch (the_var) { + default: { + } + } + break; +} +default: { // block C + switch (the_var) { + default: { + } + } +} } // block D @@ -34,13 +54,22 @@ if (check == 15) { -while(1) { +L9: while(1) { // block A var check = maybe(); + switch (the_var) { + default: { + } + } // block B - if (!(check == 41)) { + switch (the_var) { + check == 41 { break; } + default: { + break L9; + } + } } // block C @@ -49,30 +78,56 @@ while(1) { -- Loop with phi to head // code 1 -var $i_0 = 0;var $x_0 = 5; -while(1) { +switch (the_var) { +default: { + var $i_0 = 0;var $x_0 = 5; +} +} +L14: while(1) { // code 2 - if (!($2)) { + switch (the_var) { + $2 { + break; + } + default: { var $x_1 = $x_0; label = 18; - break; + break L14; + } } // code 3 - if ($6) { + switch (the_var) { + $6 { + break L14; break; - } else { + } + default: { var $i_0 = $7;var $x_0 = $5; } + } } if (label == 18) { // code 7 } // code 4 -if ($10) { +switch (the_var) { +$10 { // code 5 + switch (the_var) { + default: { + } + } + break; +} +default: { +} } // code 6 -var $x_1 = $13; +switch (the_var) { +default: { + var $x_1 = $13; +} +} // code 7 @@ -82,17 +137,29 @@ var $x_1 = $13; // block A................................................................................................... -if (chak()) { +switch (the_var) { +chak() { atob(); // block B................................................................................................... - btod(); + switch (the_var) { + default: { + btod(); + } + } // block D -} else { + break; +} +default: { atoc(); // block C................................................................................................... - ctod2(); + switch (the_var) { + default: { + ctod2(); + } + } // block D } +} @@ -101,12 +168,25 @@ if (chak()) { // block A -if (!(check == 10)) { +switch (the_var) { +check == 10 { + break; +} +default: { return C; } +} while(1) { // block B + switch (the_var) { + default: { + } + } // block D + switch (the_var) { + default: { + } + } } @@ -116,24 +196,49 @@ while(1) { // block A -do { - if (expensive()) { +L37: do { + switch (the_var) { + expensive() { label = 33; - } else { + break; + } + default: { // block B - if (expensive2()) { + switch (the_var) { + expensive2() { label = 33; + break L37; break; } + default: { + } + } // block D + switch (the_var) { + default: { + } + } + } } } while(0); if (label == 33) { // block C; + switch (the_var) { + default: { + } + } } while(1) { // block E + switch (the_var) { + default: { + } + } // block F + switch (the_var) { + default: { + } + } } @@ -143,13 +248,25 @@ while(1) { // block A -if (shouldLoop()) { - while(1) { - // block B - if (!(moarLoop())) { - break; +L46: do { + switch (the_var) { + shouldLoop() { + while(1) { + // block B + switch (the_var) { + moarLoop() { + break; + } + default: { + break L46; + } + } } + break; } -} + default: { + } + } +} while(0); // block C diff --git a/src/relooper/test2.c b/src/relooper/test2.c index 118a2627..156945c3 100644 --- a/src/relooper/test2.c +++ b/src/relooper/test2.c @@ -6,20 +6,20 @@ int main() { rl_set_output_buffer(buffer, sizeof(buffer)); void *r = rl_new_relooper(); - void *ep = rl_new_block("ep"); + void *ep = rl_new_block("ep", "var"); rl_relooper_add_block(r, ep); - void *LBB1 = rl_new_block("LBB1"); + void *LBB1 = rl_new_block("LBB1", "the_var"); rl_relooper_add_block(r, LBB1); - void *LBB2 = rl_new_block("LBB2"); + void *LBB2 = rl_new_block("LBB2", "the_var"); rl_relooper_add_block(r, LBB2); - void *LBB3 = rl_new_block("LBB3"); + void *LBB3 = rl_new_block("LBB3", "the_var"); rl_relooper_add_block(r, LBB3); /* - void *LBB4 = rl_new_block("LBB4"); + void *LBB4 = rl_new_block("LBB4", "the_var"); rl_relooper_add_block(r, LBB4); - void *LBB5 = rl_new_block("LBB5"); + void *LBB5 = rl_new_block("LBB5", "the_var"); rl_relooper_add_block(r, LBB5); - void *LBB6 = rl_new_block("LBB6"); + void *LBB6 = rl_new_block("LBB6", "the_var"); rl_relooper_add_block(r, LBB6); */ rl_block_add_branch_to(ep, LBB1, "ep -> LBB1", NULL); @@ -27,13 +27,13 @@ int main() { rl_block_add_branch_to(LBB1, LBB2, "LBB1 -> LBB2", NULL); rl_block_add_branch_to(LBB1, LBB3, NULL, NULL); rl_block_add_branch_to(LBB2, LBB3, NULL, NULL); -// rl_block_add_branch_to(LBB3, LBB4, "LBB3 -> LBB4"); -// rl_block_add_branch_to(LBB3, LBB6, "LBB3 -> LBB6"); +// rl_block_add_branch_to(LBB3, LBB4, "LBB3 -> LBB4", "the_var"); +// rl_block_add_branch_to(LBB3, LBB6, "LBB3 -> LBB6", "the_var"); /* - rl_block_add_branch_to(LBB4, LBB5, "LBB4 -> LBB5"); - rl_block_add_branch_to(LBB4, LBB6, "LBB4 -> LBB6"); - rl_block_add_branch_to(LBB5, LBB6, "LBB5 -> LBB6"); - rl_block_add_branch_to(LBB5, LBB5, "LBB5 -> LBB5"); + rl_block_add_branch_to(LBB4, LBB5, "LBB4 -> LBB5", "the_var"); + rl_block_add_branch_to(LBB4, LBB6, "LBB4 -> LBB6", "the_var"); + rl_block_add_branch_to(LBB5, LBB6, "LBB5 -> LBB6", "the_var"); + rl_block_add_branch_to(LBB5, LBB5, "LBB5 -> LBB5", "the_var"); */ rl_relooper_calculate(r, ep); rl_relooper_render(r); diff --git a/src/relooper/test2.txt b/src/relooper/test2.txt index 2f3e5ca1..a558a8b7 100644 --- a/src/relooper/test2.txt +++ b/src/relooper/test2.txt @@ -1,11 +1,25 @@ ep -do { - if (ep -> LBB1) { +L1: do { + switch (var) { + ep -> LBB1 { LBB1 - if (!(LBB1 -> LBB2)) { + switch (the_var) { + LBB1 -> LBB2 { break; } + default: { + break L1; + } + } LBB2 + switch (the_var) { + default: { + } + } + break; + } + default: { + } } } while(0); LBB3 diff --git a/src/relooper/test3.c b/src/relooper/test3.c index 2cef14fb..f652a2bc 100644 --- a/src/relooper/test3.c +++ b/src/relooper/test3.c @@ -6,19 +6,19 @@ int main() { rl_set_output_buffer(buffer, sizeof(buffer)); void *r = rl_new_relooper(); - void *ep = rl_new_block("ep"); + void *ep = rl_new_block("ep", "the_var"); rl_relooper_add_block(r, ep); - void *LBB1 = rl_new_block("LBB1"); + void *LBB1 = rl_new_block("LBB1", "the_var"); |