diff options
author | ReinUsesLisp <[email protected]> | 2019-01-05 23:58:43 -0300 |
---|---|---|
committer | ReinUsesLisp <[email protected]> | 2019-01-05 23:58:43 -0300 |
commit | 2b0a59d89098aef40b4400771587b6691810f97b (patch) | |
tree | ca596ccd4e8be20cf735a67e394c77965e07056c /src | |
parent | e7971b445177d3a4b793def9c1479479371312c2 (diff) | |
download | sirit-2b0a59d89098aef40b4400771587b6691810f97b.tar.gz sirit-2b0a59d89098aef40b4400771587b6691810f97b.zip |
Add OpSwitch
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) { |