2018-08-26 10:01:31 +02:00
|
|
|
/* 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-27 04:28:39 +02:00
|
|
|
* Lesser General Public License version 2.1 or any later version.
|
2018-08-26 10:01:31 +02:00
|
|
|
*/
|
|
|
|
|
|
2018-08-28 09:05:47 +02:00
|
|
|
#include "insts.h"
|
2018-10-28 17:44:12 +01:00
|
|
|
#include "sirit/sirit.h"
|
2018-08-26 10:01:31 +02:00
|
|
|
|
|
|
|
|
namespace Sirit {
|
|
|
|
|
|
2018-11-01 02:20:49 +01:00
|
|
|
Id Module::OpLoopMerge(Id merge_block, Id continue_target,
|
2018-11-01 01:22:00 +01:00
|
|
|
spv::LoopControlMask loop_control,
|
2018-11-01 02:20:49 +01:00
|
|
|
const std::vector<Id>& literals) {
|
2018-10-23 10:05:40 +02:00
|
|
|
auto op{new Op(spv::Op::OpLoopMerge)};
|
2018-08-31 08:55:43 +02:00
|
|
|
op->Add(merge_block);
|
|
|
|
|
op->Add(continue_target);
|
|
|
|
|
AddEnum(op, loop_control);
|
|
|
|
|
op->Add(literals);
|
|
|
|
|
return AddCode(op);
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-01 02:20:49 +01:00
|
|
|
Id Module::OpSelectionMerge(Id merge_block,
|
2018-11-01 01:22:00 +01:00
|
|
|
spv::SelectionControlMask selection_control) {
|
2018-10-23 10:05:40 +02:00
|
|
|
auto op{new Op(spv::Op::OpSelectionMerge)};
|
2018-08-31 09:05:12 +02:00
|
|
|
op->Add(merge_block);
|
|
|
|
|
AddEnum(op, selection_control);
|
|
|
|
|
return AddCode(op);
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-01 02:20:49 +01:00
|
|
|
Id Module::OpLabel() { return AddCode(spv::Op::OpLabel, bound++); }
|
2018-08-26 10:01:31 +02:00
|
|
|
|
2018-11-01 02:20:49 +01:00
|
|
|
Id Module::OpBranch(Id target_label) {
|
2018-10-23 10:05:40 +02:00
|
|
|
auto op{new Op(spv::Op::OpBranch)};
|
2018-08-31 09:10:05 +02:00
|
|
|
op->Add(target_label);
|
|
|
|
|
return AddCode(op);
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-01 02:20:49 +01:00
|
|
|
Id Module::OpBranchConditional(Id condition, Id true_label, Id false_label,
|
2018-11-01 01:22:00 +01:00
|
|
|
std::uint32_t true_weight,
|
|
|
|
|
std::uint32_t false_weight) {
|
2018-10-23 10:05:40 +02:00
|
|
|
auto op{new Op(spv::Op::OpBranchConditional)};
|
2018-08-31 09:17:16 +02:00
|
|
|
op->Add(condition);
|
|
|
|
|
op->Add(true_label);
|
|
|
|
|
op->Add(false_label);
|
|
|
|
|
if (true_weight != 0 || false_weight != 0) {
|
2018-10-28 17:44:12 +01:00
|
|
|
op->Add(true_weight);
|
|
|
|
|
op->Add(false_weight);
|
2018-08-31 09:17:16 +02:00
|
|
|
}
|
|
|
|
|
return AddCode(op);
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-01 02:20:49 +01:00
|
|
|
Id Module::OpReturn() { return AddCode(spv::Op::OpReturn); }
|
2018-08-26 10:01:31 +02:00
|
|
|
|
|
|
|
|
} // namespace Sirit
|