From bf52ad2d9f4001b66058864249fdfe649ff0bfce Mon Sep 17 00:00:00 2001 From: ReinUsesLisp Date: Sun, 26 Aug 2018 19:35:48 -0300 Subject: [PATCH] Add boolean constants --- include/sirit/sirit.h | 8 ++++++++ src/CMakeLists.txt | 1 + src/opcodes/constant.cpp | 21 +++++++++++++++++++++ src/opcodes/type.cpp | 2 +- tests/main.cpp | 3 +++ 5 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 src/opcodes/constant.cpp diff --git a/include/sirit/sirit.h b/include/sirit/sirit.h index 255b89b..771c9c5 100644 --- a/include/sirit/sirit.h +++ b/include/sirit/sirit.h @@ -120,6 +120,14 @@ public: /// Returns type pipe. const Op* TypePipe(spv::AccessQualifier access_qualifier); + // Constant + + /// Returns a true scalar constant. + const Op* ConstantTrue(const Op* result_type); + + /// Returns a false scalar constant. + const Op* ConstantFalse(const Op* result_type); + // Function /// Emits a function. diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 25bc732..e5c53ab 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -10,6 +10,7 @@ add_library(sirit common_types.h opcodes.h opcodes/type.cpp + opcodes/constant.cpp opcodes/function.cpp opcodes/flow.cpp ) diff --git a/src/opcodes/constant.cpp b/src/opcodes/constant.cpp new file mode 100644 index 0000000..bb88d3b --- /dev/null +++ b/src/opcodes/constant.cpp @@ -0,0 +1,21 @@ +/* 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 + * General Public License version 2 or any later version. + */ + +#include +#include "sirit/sirit.h" +#include "opcodes.h" + +namespace Sirit { + +const Op* Module::ConstantTrue(const Op* result_type) { + return AddDeclaration(new Op(spv::Op::OpConstantTrue, bound, result_type)); +} + +const Op* Module::ConstantFalse(const Op* result_type) { + return AddDeclaration(new Op(spv::Op::OpConstantFalse, bound, result_type)); +} + +} // namespace Sirit diff --git a/src/opcodes/type.cpp b/src/opcodes/type.cpp index 6513e81..8b2c078 100644 --- a/src/opcodes/type.cpp +++ b/src/opcodes/type.cpp @@ -227,7 +227,7 @@ const Op* Module::TypeQueue() { const Op* Module::TypePipe(spv::AccessQualifier access_qualifier) { AddCapability(spv::Capability::Pipes); Op* op{new Op(spv::Op::OpTypePipe, bound)}; - op->Add(static_cast(access_qualifier); + op->Add(static_cast(access_qualifier)); return AddDeclaration(op); } diff --git a/tests/main.cpp b/tests/main.cpp index b801239..159a8d9 100644 --- a/tests/main.cpp +++ b/tests/main.cpp @@ -38,6 +38,9 @@ public: TypeRuntimeArray(TypeInt(32, true)); TypeStruct({TypeInt(32, true), TypeFloat(64)}); TypePointer(spv::StorageClass::Private, TypeFloat(16)); + ConstantTrue(TypeBool()); + ConstantTrue(TypeBool()); + ConstantFalse(TypeBool()); auto main_type{TypeFunction(TypeVoid())}; auto main_func{Emit(Function(TypeVoid(), spv::FunctionControlMask::MaskNone, main_type))};