diff options
author | ReinUsesLisp <[email protected]> | 2020-08-01 01:50:01 -0300 |
---|---|---|
committer | ReinUsesLisp <[email protected]> | 2020-08-01 01:50:01 -0300 |
commit | 0b9ee36247758920e51811cbde06f6b24f969eb1 (patch) | |
tree | 84d39ca441d60781197aa963bf7ec387935c4719 /src/instructions/debug.cpp | |
parent | c4ea8f4b76d416db1a53819390bc9581ae038116 (diff) | |
download | sirit-0b9ee36247758920e51811cbde06f6b24f969eb1.tar.gz sirit-0b9ee36247758920e51811cbde06f6b24f969eb1.zip |
Stream SPIR-V instructions directly to a binary
Before this commit sirit generated a stream of tokens that would then be
inserted to the final SPIR-V binary. This design was carried from the
initial design of manually inserting opcodes into the code. Now that
all instructions but labels are inserted when their respective function
is called, the old design can be dropped in favor of generating a valid
stream of SPIR-V opcodes.
The API for variables is broken, but adopting the new one is trivial.
Instead of calling OpVariable and then adding a global or local
variable, OpVariable was removed and global or local variables are
generated when they are called.
Avoiding duplicates is now done with an std::unordered_set instead of
using a linear search jumping through vtables.
Diffstat (limited to 'src/instructions/debug.cpp')
-rw-r--r-- | src/instructions/debug.cpp | 39 |
1 files changed, 14 insertions, 25 deletions
diff --git a/src/instructions/debug.cpp b/src/instructions/debug.cpp index abbf02a..1ca3462 100644 --- a/src/instructions/debug.cpp +++ b/src/instructions/debug.cpp @@ -4,44 +4,33 @@ * 3-Clause BSD License */ -#include <memory> -#include <string> -#include "op.h" #include "sirit/sirit.h" +#include "common_types.h" +#include "stream.h" + namespace Sirit { -Id Module::Name(Id target, std::string name) { - auto op{std::make_unique<Op>(spv::Op::OpName)}; - op->Add(target); - op->Add(std::move(name)); - debug.push_back(std::move(op)); +Id Module::Name(Id target, std::string_view name) { + debug->Reserve(3 + WordsInString(name)); + *debug << spv::Op::OpName << target << name << EndOp{}; return target; } -Id Module::MemberName(Id type, u32 member, std::string name) { - auto op{std::make_unique<Op>(spv::Op::OpMemberName)}; - op->Add(type); - op->Add(member); - op->Add(std::move(name)); - debug.push_back(std::move(op)); +Id Module::MemberName(Id type, u32 member, std::string_view name) { + debug->Reserve(4 + WordsInString(name)); + *debug << spv::Op::OpMemberName << type << member << name << EndOp{}; return type; } -Id Module::String(std::string string) { - auto op{std::make_unique<Op>(spv::Op::OpString, bound++)}; - op->Add(std::move(string)); - const auto id = op.get(); - debug.push_back(std::move(op)); - return id; +Id Module::String(std::string_view string) { + debug->Reserve(3 + WordsInString(string)); + return *debug << OpId{spv::Op::OpString} << string << EndOp{}; } Id Module::OpLine(Id file, Literal line, Literal column) { - auto op{std::make_unique<Op>(spv::Op::OpLine)}; - op->Add(file); - op->Add(line); - op->Add(column); - return AddCode(std::move(op)); + debug->Reserve(4); + return *debug << spv::Op::OpLine << file << line << column << EndOp{}; } } // namespace Sirit |