mirror of
https://git.suyu.dev/suyu/sirit.git
synced 2025-12-24 16:25:59 +01:00
Use unique_ptr for instruction implementations
This commit is contained in:
parent
63ca1b5243
commit
f3a63aa55f
9 changed files with 77 additions and 89 deletions
|
|
@ -84,7 +84,6 @@ void Module::AddEntryPoint(spv::ExecutionModel execution_model, Id entry_point,
|
|||
}
|
||||
|
||||
Id Module::Emit(Id op) {
|
||||
assert(op);
|
||||
code.push_back(op);
|
||||
return op;
|
||||
}
|
||||
|
|
@ -95,34 +94,31 @@ Id Module::AddGlobalVariable(Id variable) {
|
|||
return variable;
|
||||
}
|
||||
|
||||
Id Module::AddCode(Op* op) {
|
||||
assert(op);
|
||||
code_store.push_back(std::unique_ptr<Op>(op));
|
||||
return op;
|
||||
Id Module::AddCode(std::unique_ptr<Op> op) {
|
||||
code_store.push_back(std::move(op));
|
||||
return op.get();
|
||||
}
|
||||
|
||||
Id Module::AddCode(spv::Op opcode, std::optional<u32> id) {
|
||||
return AddCode(new Op(opcode, id));
|
||||
return AddCode(std::make_unique<Op>(opcode, id));
|
||||
}
|
||||
|
||||
Id Module::AddDeclaration(Op* op) {
|
||||
Id Module::AddDeclaration(std::unique_ptr<Op> op) {
|
||||
const auto& found{
|
||||
std::find_if(declarations.begin(), declarations.end(),
|
||||
[&op](const auto& other) { return *other == *op; })};
|
||||
if (found != declarations.end()) {
|
||||
delete op;
|
||||
return found->get();
|
||||
} else {
|
||||
declarations.push_back(std::unique_ptr<Op>(op));
|
||||
bound++;
|
||||
return op;
|
||||
}
|
||||
const auto id = op.get();
|
||||
declarations.push_back(std::move(op));
|
||||
bound++;
|
||||
return id;
|
||||
}
|
||||
|
||||
Id Module::AddAnnotation(Op* op) {
|
||||
assert(op);
|
||||
annotations.push_back(std::unique_ptr<Op>(op));
|
||||
return op;
|
||||
Id Module::AddAnnotation(std::unique_ptr<Op> op) {
|
||||
annotations.push_back(std::move(op));
|
||||
return op.get();
|
||||
}
|
||||
|
||||
} // namespace Sirit
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue