diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/instructions/flow.cpp | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/instructions/flow.cpp b/src/instructions/flow.cpp index 8ff856e..4c0036f 100644 --- a/src/instructions/flow.cpp +++ b/src/instructions/flow.cpp @@ -7,6 +7,7 @@ #include "common_types.h" #include "op.h" #include "sirit/sirit.h" +#include <cassert> #include <vector> namespace Sirit { @@ -51,6 +52,21 @@ Id Module::OpBranchConditional(Id condition, Id true_label, Id false_label, return AddCode(std::move(op)); } +Id Module::OpSwitch(Id selector, Id default_label, + const std::vector<Literal>& literals, + const std::vector<Id>& labels) { + const std::size_t size = literals.size(); + assert(literals.size() == labels.size()); + auto op{std::make_unique<Op>(spv::Op::OpSwitch)}; + op->Add(selector); + op->Add(default_label); + for (std::size_t i = 0; i < size; ++i) { + op->Add(literals[i]); + op->Add(labels[i]); + } + return AddCode(std::move(op)); +} + Id Module::OpReturn() { return AddCode(spv::Op::OpReturn); } Id Module::OpReturnValue(Id value) { |