1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-24 15:07:45 +00:00

LibJS: Use a switch statement in GenerateCFG

This commit is contained in:
Hendiadyoin1 2022-11-02 14:32:51 +01:00 committed by Ali Mohammad Pur
parent 7697e09660
commit ded7545db1

View file

@ -45,38 +45,39 @@ void GenerateCFG::perform(PassPipelineExecutable& executable)
iterators.take_last(); iterators.take_last();
continue; continue;
} }
auto& instruction = *iterators.last(); auto const& instruction = *iterators.last();
++iterators.last(); ++iterators.last();
if (!instruction.is_terminator()) if (!instruction.is_terminator())
continue; continue;
auto& current_block = entered_blocks.last(); auto const& current_block = entered_blocks.last();
if (instruction.type() == Instruction::Type::Jump) { using enum Instruction::Type;
auto& true_target = static_cast<Op::Jump const&>(instruction).true_target(); switch (instruction.type()) {
case Jump: {
auto const& true_target = static_cast<Op::Jump const&>(instruction).true_target();
enter_label(true_target, current_block); enter_label(true_target, current_block);
continue; continue;
} }
case JumpConditional:
if (instruction.type() == Instruction::Type::JumpConditional || instruction.type() == Instruction::Type::JumpNullish || instruction.type() == Instruction::Type::JumpUndefined) { case JumpNullish:
auto& true_target = static_cast<Op::Jump const&>(instruction).true_target(); case JumpUndefined: {
auto const& true_target = static_cast<Op::Jump const&>(instruction).true_target();
enter_label(true_target, current_block); enter_label(true_target, current_block);
auto& false_target = static_cast<Op::Jump const&>(instruction).false_target(); auto const& false_target = static_cast<Op::Jump const&>(instruction).false_target();
enter_label(false_target, current_block); enter_label(false_target, current_block);
continue; continue;
} }
case Yield: {
if (instruction.type() == Instruction::Type::Yield) { auto const& continuation = static_cast<Op::Yield const&>(instruction).continuation();
auto& continuation = static_cast<Op::Yield const&>(instruction).continuation();
if (continuation.has_value()) if (continuation.has_value())
enter_label(continuation, current_block, true); enter_label(continuation, current_block, true);
continue; continue;
} }
case EnterUnwindContext: {
if (instruction.type() == Instruction::Type::EnterUnwindContext) { auto const& entry_point = static_cast<Op::EnterUnwindContext const&>(instruction).entry_point();
auto& entry_point = static_cast<Op::EnterUnwindContext const&>(instruction).entry_point(); auto const& handler_target = static_cast<Op::EnterUnwindContext const&>(instruction).handler_target();
auto& handler_target = static_cast<Op::EnterUnwindContext const&>(instruction).handler_target(); auto const& finalizer_target = static_cast<Op::EnterUnwindContext const&>(instruction).finalizer_target();
auto& finalizer_target = static_cast<Op::EnterUnwindContext const&>(instruction).finalizer_target();
enter_label(&entry_point, current_block); enter_label(&entry_point, current_block);
if (handler_target.has_value()) if (handler_target.has_value())
enter_label(handler_target, current_block); enter_label(handler_target, current_block);
@ -84,16 +85,17 @@ void GenerateCFG::perform(PassPipelineExecutable& executable)
enter_label(finalizer_target, current_block); enter_label(finalizer_target, current_block);
continue; continue;
} }
case ContinuePendingUnwind: {
if (instruction.type() == Instruction::Type::ContinuePendingUnwind) { auto const& resume_target = static_cast<Op::ContinuePendingUnwind const&>(instruction).resume_target();
auto& resume_target = static_cast<Op::ContinuePendingUnwind const&>(instruction).resume_target();
enter_label(&resume_target, current_block); enter_label(&resume_target, current_block);
continue; continue;
} }
default:
// Otherwise, pop the current block off, it doesn't jump anywhere. // Otherwise, pop the current block off, it doesn't jump anywhere.
iterators.take_last(); iterators.take_last();
entered_blocks.take_last(); entered_blocks.take_last();
continue;
}
} }
finished(); finished();