mirror of
https://github.com/yuzu-emu/sirit
synced 2024-11-22 22:34:06 +00:00
Add OpSwitch
This commit is contained in:
parent
e7971b4451
commit
2b0a59d890
2 changed files with 21 additions and 0 deletions
|
@ -192,6 +192,11 @@ class Module {
|
||||||
std::uint32_t true_weight = 0,
|
std::uint32_t true_weight = 0,
|
||||||
std::uint32_t false_weight = 0);
|
std::uint32_t false_weight = 0);
|
||||||
|
|
||||||
|
/// Multi-way branch to one of the operand label.
|
||||||
|
Id OpSwitch(Id selector, Id default_label,
|
||||||
|
const std::vector<Literal>& literals,
|
||||||
|
const std::vector<Id>& labels);
|
||||||
|
|
||||||
/// Returns with no value from a function with void return type.
|
/// Returns with no value from a function with void return type.
|
||||||
Id OpReturn();
|
Id OpReturn();
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
#include "common_types.h"
|
#include "common_types.h"
|
||||||
#include "op.h"
|
#include "op.h"
|
||||||
#include "sirit/sirit.h"
|
#include "sirit/sirit.h"
|
||||||
|
#include <cassert>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
namespace Sirit {
|
namespace Sirit {
|
||||||
|
@ -51,6 +52,21 @@ Id Module::OpBranchConditional(Id condition, Id true_label, Id false_label,
|
||||||
return AddCode(std::move(op));
|
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::OpReturn() { return AddCode(spv::Op::OpReturn); }
|
||||||
|
|
||||||
Id Module::OpReturnValue(Id value) {
|
Id Module::OpReturnValue(Id value) {
|
||||||
|
|
Loading…
Reference in a new issue