From acea9030c544ca48dc5e274abd864d5bc1717ed8 Mon Sep 17 00:00:00 2001 From: ReinUsesLisp Date: Fri, 31 Aug 2018 04:40:15 -0300 Subject: [PATCH] Add OpName and debug symbols --- include/sirit/sirit.h | 5 +++++ src/CMakeLists.txt | 1 + src/insts/debug.cpp | 19 +++++++++++++++++++ src/sirit.cpp | 4 +++- tests/main.cpp | 9 +++++---- 5 files changed, 33 insertions(+), 5 deletions(-) create mode 100644 src/insts/debug.cpp diff --git a/include/sirit/sirit.h b/include/sirit/sirit.h index 499f068..7a5b265 100644 --- a/include/sirit/sirit.h +++ b/include/sirit/sirit.h @@ -174,6 +174,11 @@ public: /// Returns with no value from a function with void return type. Ref Return(); + // Debug + + /// Assign a name string to a reference. + void Name(Ref target, const std::string& name); + // Literals static Operand* Literal(std::uint32_t value); static Operand* Literal(std::uint64_t value); diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index dca3b91..fc9bbbf 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -18,6 +18,7 @@ add_library(sirit insts/constant.cpp insts/function.cpp insts/flow.cpp + insts/debug.cpp ) target_include_directories(sirit PUBLIC ../include diff --git a/src/insts/debug.cpp b/src/insts/debug.cpp new file mode 100644 index 0000000..e12b61c --- /dev/null +++ b/src/insts/debug.cpp @@ -0,0 +1,19 @@ +/* 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 + * Lesser General Public License version 2.1 or any later version. + */ + +#include "sirit/sirit.h" +#include "insts.h" + +namespace Sirit { + +void Module::Name(Ref target, const std::string& name) { + Op* op{new Op(spv::Op::OpName)}; + op->Add(target); + op->Add(name); + debug.push_back(std::unique_ptr(op)); +} + +} // namespace Sirit diff --git a/src/sirit.cpp b/src/sirit.cpp index 4eeb411..7f01cb6 100644 --- a/src/sirit.cpp +++ b/src/sirit.cpp @@ -53,7 +53,9 @@ std::vector Module::Assemble() const { // TODO write execution mode - // TODO write debug symbols + for (const auto& debug_symbol : debug) { + debug_symbol->Write(stream); + } // TODO write annotations diff --git a/tests/main.cpp b/tests/main.cpp index 4261ab3..f7542c0 100644 --- a/tests/main.cpp +++ b/tests/main.cpp @@ -51,15 +51,16 @@ public: Constant(TypeFloat(32), Literal(50.0f))}); ConstantNull(TypeVector(TypeInt(64, false), 4)); + auto cont{Label()}; auto skip{Label()}; - auto end{Label()}; + Name(skip, "skip"); auto main_type{TypeFunction(TypeVoid())}; auto main_func{Emit(Function(TypeVoid(), spv::FunctionControlMask::MaskNone, main_type))}; Emit(Label()); - Emit(BranchConditional(ConstantTrue(TypeBool()), skip, end, 5, 0)); + Emit(BranchConditional(ConstantTrue(TypeBool()), cont, skip, 5, 0)); + Emit(cont); + Emit(Branch(skip)); Emit(skip); - Emit(Branch(end)); - Emit(end); Emit(Return()); Emit(FunctionEnd());