diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index b362331..9d32797 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -8,6 +8,8 @@ add_library(sirit operand.cpp operand.h common_types.h + opcodes.h + opcodes_type.cpp ) target_include_directories(sirit PUBLIC ../include diff --git a/src/impl.h b/src/impl.h deleted file mode 100644 index cb53e1e..0000000 --- a/src/impl.h +++ /dev/null @@ -1,15 +0,0 @@ -/* 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. - */ - -#pragma once - -struct Impl final { -public: - explicit Impl(); - ~Impl(); - -private: -}; diff --git a/src/opcodes.h b/src/opcodes.h new file mode 100644 index 0000000..910531a --- /dev/null +++ b/src/opcodes.h @@ -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. + */ + +#pragma once + +#include "stream.h" +#include "op.h" + +namespace Sirit { + +template +inline void WriteEnum(Stream& stream, spv::Op opcode, T value) { + Op op{opcode}; + op.Add(static_cast(value)); + op.Write(stream); +} + +} // namespace Sirit diff --git a/src/opcodes_type.cpp b/src/opcodes_type.cpp new file mode 100644 index 0000000..8c754ac --- /dev/null +++ b/src/opcodes_type.cpp @@ -0,0 +1,25 @@ +/* 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 "sirit/sirit.h" +#include "opcodes.h" + +namespace Sirit { + +const Op* Module::TypeVoid() { + return AddDeclaration(new Op(spv::Op::OpTypeVoid, bound)); +} + +const Op* Module::TypeFunction(const Op* return_type, const std::vector& arguments) { + Op* type_func{new Op(spv::Op::OpTypeFunction, bound)}; + type_func->Add(return_type); + for (const Op* arg : arguments) { + type_func->Add(arg); + } + return AddDeclaration(type_func); +} + +} // namespace Sirit diff --git a/src/sirit.cpp b/src/sirit.cpp index 8131ada..2739cf2 100644 --- a/src/sirit.cpp +++ b/src/sirit.cpp @@ -10,16 +10,10 @@ #include "common_types.h" #include "op.h" #include "stream.h" +#include "opcodes.h" namespace Sirit { -template -static void WriteEnum(Stream& stream, spv::Op opcode, T value) { - Op op{opcode}; - op.Add(static_cast(value)); - op.Write(stream); -} - Module::Module() {} Module::~Module() = default; @@ -89,19 +83,6 @@ void Module::AddEntryPoint(spv::ExecutionModel execution_model, const Op* entry_ entry_points.push_back(std::unique_ptr(op)); } -const Op* Module::TypeVoid() { - return AddDeclaration(new Op(spv::Op::OpTypeVoid, bound)); -} - -const Op* Module::TypeFunction(const Op* return_type, const std::vector& arguments) { - Op* type_func{new Op(spv::Op::OpTypeFunction, bound)}; - type_func->Add(return_type); - for (const Op* arg : arguments) { - type_func->Add(arg); - } - return AddDeclaration(type_func); -} - const Op* Module::Emit(const Op* op) { assert(op); code.push_back(op); diff --git a/src/type.h b/src/type.h deleted file mode 100644 index b7faf86..0000000 --- a/src/type.h +++ /dev/null @@ -1,33 +0,0 @@ -/* 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. - */ - -#pragma once - -#include -#include "sirit/sirit.h" -#include "ref.h" - -namespace Sirit { - -class TypeConstant : public Ref { -public: - Type(spv::Op opcode, u32 id, std::); - ~Type(); - - bool operator==(const Type& other) const; - -private: - /// Arguments can be type references or constants - std::vector args; - - friend Type; -}; - -using Type = TypeConstant; - -using Constant = TypeConstant; - -} // namespace Sirit