Remove Emit entry in favor of auto-emitting code

All instructions but OpVariable and OpLabel are automatically emitted.
These functions have to call AddLocalVariable/AddGlobalVariable or
AddLabel respectively.
This commit is contained in:
ReinUsesLisp
2019-10-18 04:25:57 -03:00
parent 8cf3d225db
commit 42248408a9
5 changed files with 48 additions and 32 deletions

View File

@@ -30,7 +30,7 @@ Id Module::OpSelectionMerge(Id merge_block, spv::SelectionControlMask selection_
}
Id Module::OpLabel() {
return AddCode(spv::Op::OpLabel, bound++);
return code_store.emplace_back(std::make_unique<Op>(spv::Op::OpLabel, bound++)).get();
}
Id Module::OpBranch(Id target_label) {

View File

@@ -16,7 +16,7 @@ Id Module::OpVariable(Id result_type, spv::StorageClass storage_class, Id initia
if (initializer) {
op->Add(initializer);
}
return AddCode(std::move(op));
return code_store.emplace_back(std::move(op)).get();
}
Id Module::OpLoad(Id result_type, Id pointer, std::optional<spv::MemoryAccessMask> memory_access) {

View File

@@ -98,22 +98,24 @@ void Module::AddExecutionMode(Id entry_point, spv::ExecutionMode mode,
execution_modes.push_back(std::move(op));
}
Id Module::Emit(Id op) {
assert(op != nullptr);
code.push_back(op);
return op;
Id Module::AddLabel(Id label) {
assert(label != nullptr);
return code.emplace_back(label);
}
Id Module::AddLocalVariable(Id variable) {
assert(variable != nullptr);
return code.emplace_back(variable);
}
Id Module::AddGlobalVariable(Id variable) {
assert(variable);
global_variables.push_back(variable);
return variable;
return global_variables.emplace_back(variable);
}
Id Module::AddCode(std::unique_ptr<Op> op) {
const auto id = op.get();
code_store.push_back(std::move(op));
return id;
const Id id = code_store.emplace_back(std::move(op)).get();
return code.emplace_back(id);
}
Id Module::AddCode(spv::Op opcode, std::optional<u32> id) {