diff options
-rw-r--r-- | include/sirit/sirit.h | 8 | ||||
-rw-r--r-- | src/CMakeLists.txt | 1 | ||||
-rw-r--r-- | src/opcodes/constant.cpp | 21 | ||||
-rw-r--r-- | src/opcodes/type.cpp | 2 | ||||
-rw-r--r-- | tests/main.cpp | 3 |
5 files changed, 34 insertions, 1 deletions
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 <cassert> +#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<u32>(access_qualifier); + op->Add(static_cast<u32>(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))}; |