mirror of
https://git.suyu.dev/suyu/sirit.git
synced 2024-12-22 20:22:02 +00:00
Add OpBranchConditional
This commit is contained in:
parent
cdeeb9127c
commit
a6946d3c8e
2 changed files with 17 additions and 0 deletions
|
@ -167,6 +167,10 @@ public:
|
|||
/// Unconditional jump to label.
|
||||
Ref Branch(Ref target_label);
|
||||
|
||||
/// If condition is true branch to true_label, otherwise branch to false_label.
|
||||
Ref BranchConditional(Ref condition, Ref true_label, Ref false_label,
|
||||
std::uint32_t true_weight = 0, std::uint32_t false_weight = 0);
|
||||
|
||||
/// Returns with no value from a function with void return type.
|
||||
Ref Return();
|
||||
|
||||
|
|
|
@ -36,6 +36,19 @@ Ref Module::Branch(Ref target_label) {
|
|||
return AddCode(op);
|
||||
}
|
||||
|
||||
Ref Module::BranchConditional(Ref condition, Ref true_label, Ref false_label,
|
||||
std::uint32_t true_weight, std::uint32_t false_weight) {
|
||||
Op* op{new Op(spv::Op::OpBranchConditional)};
|
||||
op->Add(condition);
|
||||
op->Add(true_label);
|
||||
op->Add(false_label);
|
||||
if (true_weight != 0 || false_weight != 0) {
|
||||
op->Add(Literal(true_weight));
|
||||
op->Add(Literal(false_weight));
|
||||
}
|
||||
return AddCode(op);
|
||||
}
|
||||
|
||||
Ref Module::Return() {
|
||||
return AddCode(spv::Op::OpReturn);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue