Use unique_ptr for instruction implementations

This commit is contained in:
ReinUsesLisp
2018-11-01 00:02:45 -03:00
parent 63ca1b5243
commit f3a63aa55f
9 changed files with 77 additions and 89 deletions

View File

@@ -4,29 +4,32 @@
* Lesser General Public License version 2.1 or any later version.
*/
#include "insts.h"
#include "common_types.h"
#include "op.h"
#include "sirit/sirit.h"
#include <memory>
#include <vector>
namespace Sirit {
Id Module::Decorate(Id target, spv::Decoration decoration,
const std::vector<Literal>& literals) {
auto op{new Op(spv::Op::OpDecorate)};
const std::vector<Literal>& literals) {
auto op{std::make_unique<Op>(spv::Op::OpDecorate)};
op->Add(target);
AddEnum(op, decoration);
op->Add(static_cast<u32>(decoration));
op->Add(literals);
return AddAnnotation(op);
return AddAnnotation(std::move(op));
}
Id Module::MemberDecorate(Id structure_type, Literal member,
spv::Decoration decoration,
const std::vector<Literal>& literals) {
auto op{new Op(spv::Op::OpMemberDecorate)};
spv::Decoration decoration,
const std::vector<Literal>& literals) {
auto op{std::make_unique<Op>(spv::Op::OpMemberDecorate)};
op->Add(structure_type);
op->Add(member);
AddEnum(op, decoration);
op->Add(static_cast<u32>(decoration));
op->Add(literals);
return AddAnnotation(op);
return AddAnnotation(std::move(op));
}
} // namespace Sirit

View File

@@ -4,48 +4,53 @@
* Lesser General Public License version 2.1 or any later version.
*/
#include "insts.h"
#include "op.h"
#include "sirit/sirit.h"
#include <cassert>
namespace Sirit {
Id Module::OpConstantTrue(Id result_type) {
return AddDeclaration(new Op(spv::Op::OpConstantTrue, bound, result_type));
return AddDeclaration(
std::make_unique<Op>(spv::Op::OpConstantTrue, bound, result_type));
}
Id Module::OpConstantFalse(Id result_type) {
return AddDeclaration(new Op(spv::Op::OpConstantFalse, bound, result_type));
return AddDeclaration(
std::make_unique<Op>(spv::Op::OpConstantFalse, bound, result_type));
}
Id Module::OpConstant(Id result_type, const Literal& literal) {
auto op{new Op(spv::Op::OpConstant, bound, result_type)};
auto op{std::make_unique<Op>(spv::Op::OpConstant, bound, result_type)};
op->Add(literal);
return AddDeclaration(op);
return AddDeclaration(std::move(op));
}
Id Module::OpConstantComposite(Id result_type,
const std::vector<Id>& constituents) {
auto op{new Op(spv::Op::OpConstantComposite, bound, result_type)};
const std::vector<Id>& constituents) {
auto op{
std::make_unique<Op>(spv::Op::OpConstantComposite, bound, result_type)};
op->Add(constituents);
return AddDeclaration(op);
return AddDeclaration(std::move(op));
}
Id Module::OpConstantSampler(Id result_type,
spv::SamplerAddressingMode addressing_mode,
bool normalized,
spv::SamplerFilterMode filter_mode) {
spv::SamplerAddressingMode addressing_mode,
bool normalized,
spv::SamplerFilterMode filter_mode) {
AddCapability(spv::Capability::LiteralSampler);
AddCapability(spv::Capability::Kernel);
auto op{new Op(spv::Op::OpConstantSampler, bound, result_type)};
AddEnum(op, addressing_mode);
auto op{
std::make_unique<Op>(spv::Op::OpConstantSampler, bound, result_type)};
op->Add(static_cast<u32>(addressing_mode));
op->Add(normalized ? 1 : 0);
AddEnum(op, filter_mode);
return AddDeclaration(op);
op->Add(static_cast<u32>(filter_mode));
return AddDeclaration(std::move(op));
}
Id Module::OpConstantNull(Id result_type) {
return AddDeclaration(new Op(spv::Op::OpConstantNull, bound, result_type));
return AddDeclaration(
std::make_unique<Op>(spv::Op::OpConstantNull, bound, result_type));
}
} // namespace Sirit

View File

@@ -4,16 +4,18 @@
* Lesser General Public License version 2.1 or any later version.
*/
#include "insts.h"
#include "op.h"
#include "sirit/sirit.h"
#include <memory>
#include <string>
namespace Sirit {
Id Module::Name(Id target, const std::string& name) {
auto op{new Op(spv::Op::OpName)};
auto op{std::make_unique<Op>(spv::Op::OpName)};
op->Add(target);
op->Add(name);
debug.push_back(std::unique_ptr<Op>(op));
debug.push_back(std::move(op));
return target;
}

View File

@@ -4,42 +4,43 @@
* Lesser General Public License version 2.1 or any later version.
*/
#include "insts.h"
#include "common_types.h"
#include "op.h"
#include "sirit/sirit.h"
#include <vector>
namespace Sirit {
Id Module::OpLoopMerge(Id merge_block, Id continue_target,
spv::LoopControlMask loop_control,
const std::vector<Id>& literals) {
auto op{new Op(spv::Op::OpLoopMerge)};
spv::LoopControlMask loop_control,
const std::vector<Id>& literals) {
auto op{std::make_unique<Op>(spv::Op::OpLoopMerge)};
op->Add(merge_block);
op->Add(continue_target);
AddEnum(op, loop_control);
op->Add(static_cast<u32>(loop_control));
op->Add(literals);
return AddCode(op);
return AddCode(std::move(op));
}
Id Module::OpSelectionMerge(Id merge_block,
spv::SelectionControlMask selection_control) {
auto op{new Op(spv::Op::OpSelectionMerge)};
spv::SelectionControlMask selection_control) {
auto op{std::make_unique<Op>(spv::Op::OpSelectionMerge)};
op->Add(merge_block);
AddEnum(op, selection_control);
return AddCode(op);
op->Add(static_cast<u32>(selection_control));
return AddCode(std::move(op));
}
Id Module::OpLabel() { return AddCode(spv::Op::OpLabel, bound++); }
Id Module::OpBranch(Id target_label) {
auto op{new Op(spv::Op::OpBranch)};
auto op{std::make_unique<Op>(spv::Op::OpBranch)};
op->Add(target_label);
return AddCode(op);
return AddCode(std::move(op));
}
Id Module::OpBranchConditional(Id condition, Id true_label, Id false_label,
std::uint32_t true_weight,
std::uint32_t false_weight) {
auto op{new Op(spv::Op::OpBranchConditional)};
u32 true_weight, u32 false_weight) {
auto op{std::make_unique<Op>(spv::Op::OpBranchConditional)};
op->Add(condition);
op->Add(true_label);
op->Add(false_label);
@@ -47,7 +48,7 @@ Id Module::OpBranchConditional(Id condition, Id true_label, Id false_label,
op->Add(true_weight);
op->Add(false_weight);
}
return AddCode(op);
return AddCode(std::move(op));
}
Id Module::OpReturn() { return AddCode(spv::Op::OpReturn); }

View File

@@ -4,18 +4,18 @@
* Lesser General Public License version 2.1 or any later version.
*/
#include "insts.h"
#include "common_types.h"
#include "op.h"
#include "sirit/sirit.h"
namespace Sirit {
Id Module::OpFunction(Id result_type,
spv::FunctionControlMask function_control,
Id function_type) {
auto op{new Op{spv::Op::OpFunction, bound++, result_type}};
Id Module::OpFunction(Id result_type, spv::FunctionControlMask function_control,
Id function_type) {
auto op{std::make_unique<Op>(spv::Op::OpFunction, bound++, result_type)};
op->Add(static_cast<u32>(function_control));
op->Add(function_type);
return AddCode(op);
return AddCode(std::move(op));
}
Id Module::OpFunctionEnd() { return AddCode(spv::Op::OpFunctionEnd); }