Skip to content

Commit

Permalink
nuke suspicious code duplication in mangle
Browse files Browse the repository at this point in the history
  • Loading branch information
Hugobros3 committed Jun 21, 2021
1 parent 1ce5a62 commit a6d1a1b
Showing 1 changed file with 0 additions and 28 deletions.
28 changes: 0 additions & 28 deletions src/thorin/transform/mangle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,34 +117,6 @@ Continuation* Mangler::mangle_head(Continuation* old_continuation) {
void Mangler::mangle_body(Continuation* old_continuation, Continuation* new_continuation) {
assert(!old_continuation->empty());

// fold branch and match
// TODO find a way to factor this out in continuation.cpp
if (auto callee = old_continuation->callee()->isa_continuation()) {
switch (callee->intrinsic()) {
case Intrinsic::Branch: {
if (auto lit = mangle(old_continuation->arg(0))->isa<PrimLit>()) {
auto cont = lit->value().get_bool() ? old_continuation->arg(1) : old_continuation->arg(2);
return new_continuation->jump(mangle(cont), {}, old_continuation->debug()); // TODO debug
}
break;
}
case Intrinsic::Match:
if (old_continuation->num_args() == 2)
return new_continuation->jump(mangle(old_continuation->arg(1)), {}, old_continuation->debug()); // TODO debug

if (auto lit = mangle(old_continuation->arg(0))->isa<PrimLit>()) {
for (size_t i = 2; i < old_continuation->num_args(); i++) {
auto new_arg = mangle(old_continuation->arg(i));
if (world().extract(new_arg, 0_s)->as<PrimLit>() == lit)
return new_continuation->jump(world().extract(new_arg, 1), {}, old_continuation->debug()); // TODO debug
}
}
break;
default:
break;
}
}

Array<const Def*> nops(old_continuation->num_ops());
for (size_t i = 0, e = nops.size(); i != e; ++i)
nops[i] = mangle(old_continuation->op(i));
Expand Down

0 comments on commit a6d1a1b

Please sign in to comment.