diff options
author | Hendiadyoin1 <leon.a@serenityos.org> | 2022-11-02 14:32:51 +0100 |
---|---|---|
committer | Ali Mohammad Pur <Ali.mpfard@gmail.com> | 2022-12-03 17:07:30 +0330 |
commit | ded7545db1eddf5a0e152d591b7aa5cdb13d9655 (patch) | |
tree | 8afb2aeb058f7132abf693290b99f3d5625341a6 /Userland/Libraries/LibJS | |
parent | 7697e096604693c3e8ec4af272673e4aca12fe1e (diff) | |
download | serenity-ded7545db1eddf5a0e152d591b7aa5cdb13d9655.zip |
LibJS: Use a switch statement in GenerateCFG
Diffstat (limited to 'Userland/Libraries/LibJS')
-rw-r--r-- | Userland/Libraries/LibJS/Bytecode/Pass/GenerateCFG.cpp | 48 |
1 files changed, 25 insertions, 23 deletions
diff --git a/Userland/Libraries/LibJS/Bytecode/Pass/GenerateCFG.cpp b/Userland/Libraries/LibJS/Bytecode/Pass/GenerateCFG.cpp index e6cafc443d..476cc937b7 100644 --- a/Userland/Libraries/LibJS/Bytecode/Pass/GenerateCFG.cpp +++ b/Userland/Libraries/LibJS/Bytecode/Pass/GenerateCFG.cpp @@ -45,38 +45,39 @@ void GenerateCFG::perform(PassPipelineExecutable& executable) iterators.take_last(); continue; } - auto& instruction = *iterators.last(); + auto const& instruction = *iterators.last(); ++iterators.last(); if (!instruction.is_terminator()) continue; - auto& current_block = entered_blocks.last(); + auto const& current_block = entered_blocks.last(); - if (instruction.type() == Instruction::Type::Jump) { - auto& true_target = static_cast<Op::Jump const&>(instruction).true_target(); + using enum Instruction::Type; + switch (instruction.type()) { + case Jump: { + auto const& true_target = static_cast<Op::Jump const&>(instruction).true_target(); enter_label(true_target, current_block); continue; } - - if (instruction.type() == Instruction::Type::JumpConditional || instruction.type() == Instruction::Type::JumpNullish || instruction.type() == Instruction::Type::JumpUndefined) { - auto& true_target = static_cast<Op::Jump const&>(instruction).true_target(); + case JumpConditional: + case JumpNullish: + case JumpUndefined: { + auto const& true_target = static_cast<Op::Jump const&>(instruction).true_target(); 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); continue; } - - if (instruction.type() == Instruction::Type::Yield) { - auto& continuation = static_cast<Op::Yield const&>(instruction).continuation(); + case Yield: { + auto const& continuation = static_cast<Op::Yield const&>(instruction).continuation(); if (continuation.has_value()) enter_label(continuation, current_block, true); continue; } - - if (instruction.type() == Instruction::Type::EnterUnwindContext) { - auto& entry_point = static_cast<Op::EnterUnwindContext const&>(instruction).entry_point(); - auto& handler_target = static_cast<Op::EnterUnwindContext const&>(instruction).handler_target(); - auto& finalizer_target = static_cast<Op::EnterUnwindContext const&>(instruction).finalizer_target(); + case EnterUnwindContext: { + auto const& entry_point = static_cast<Op::EnterUnwindContext const&>(instruction).entry_point(); + auto const& handler_target = static_cast<Op::EnterUnwindContext const&>(instruction).handler_target(); + auto const& finalizer_target = static_cast<Op::EnterUnwindContext const&>(instruction).finalizer_target(); enter_label(&entry_point, current_block); if (handler_target.has_value()) enter_label(handler_target, current_block); @@ -84,16 +85,17 @@ void GenerateCFG::perform(PassPipelineExecutable& executable) enter_label(finalizer_target, current_block); continue; } - - if (instruction.type() == Instruction::Type::ContinuePendingUnwind) { - auto& resume_target = static_cast<Op::ContinuePendingUnwind const&>(instruction).resume_target(); + case ContinuePendingUnwind: { + auto const& resume_target = static_cast<Op::ContinuePendingUnwind const&>(instruction).resume_target(); enter_label(&resume_target, current_block); continue; } - - // Otherwise, pop the current block off, it doesn't jump anywhere. - iterators.take_last(); - entered_blocks.take_last(); + default: + // Otherwise, pop the current block off, it doesn't jump anywhere. + iterators.take_last(); + entered_blocks.take_last(); + continue; + } } finished(); |