sirit/src/insts/flow.cpp

63 lines
1.9 KiB
C++
Raw Normal View History

/* This file is part of the sirit project.
* Copyright (c) 2018 ReinUsesLisp
* This software may be used and distributed according to the terms of the GNU
2018-08-26 23:28:39 -03:00
* Lesser General Public License version 2.1 or any later version.
*/
#include "common_types.h"
#include "op.h"
#include "sirit/sirit.h"
#include <vector>
namespace Sirit {
2018-10-31 22:20:49 -03:00
Id Module::OpLoopMerge(Id merge_block, Id continue_target,
spv::LoopControlMask loop_control,
const std::vector<Id>& literals) {
auto op{std::make_unique<Op>(spv::Op::OpLoopMerge)};
2018-08-31 03:55:43 -03:00
op->Add(merge_block);
op->Add(continue_target);
op->Add(static_cast<u32>(loop_control));
2018-08-31 03:55:43 -03:00
op->Add(literals);
return AddCode(std::move(op));
2018-08-31 03:55:43 -03:00
}
2018-10-31 22:20:49 -03:00
Id Module::OpSelectionMerge(Id merge_block,
spv::SelectionControlMask selection_control) {
auto op{std::make_unique<Op>(spv::Op::OpSelectionMerge)};
2018-08-31 04:05:12 -03:00
op->Add(merge_block);
op->Add(static_cast<u32>(selection_control));
return AddCode(std::move(op));
2018-08-31 04:05:12 -03:00
}
2018-10-31 22:20:49 -03:00
Id Module::OpLabel() { return AddCode(spv::Op::OpLabel, bound++); }
2018-10-31 22:20:49 -03:00
Id Module::OpBranch(Id target_label) {
auto op{std::make_unique<Op>(spv::Op::OpBranch)};
2018-08-31 04:10:05 -03:00
op->Add(target_label);
return AddCode(std::move(op));
2018-08-31 04:10:05 -03:00
}
2018-10-31 22:20:49 -03:00
Id Module::OpBranchConditional(Id condition, Id true_label, Id false_label,
u32 true_weight, u32 false_weight) {
auto op{std::make_unique<Op>(spv::Op::OpBranchConditional)};
2018-08-31 04:17:16 -03:00
op->Add(condition);
op->Add(true_label);
op->Add(false_label);
if (true_weight != 0 || false_weight != 0) {
op->Add(true_weight);
op->Add(false_weight);
2018-08-31 04:17:16 -03:00
}
return AddCode(std::move(op));
2018-08-31 04:17:16 -03:00
}
2018-10-31 22:20:49 -03:00
Id Module::OpReturn() { return AddCode(spv::Op::OpReturn); }
2018-11-01 01:12:52 -03:00
Id Module::OpReturnValue(Id value) {
auto op{std::make_unique<Op>(spv::Op::OpReturnValue)};
op->Add(value);
return AddCode(std::move(op));
}
} // namespace Sirit