From a3022e496992ac70440d25edab276e5f116994d1 Mon Sep 17 00:00:00 2001 From: ReinUsesLisp Date: Thu, 18 Oct 2018 04:27:17 -0300 Subject: [PATCH] Add OpVariable --- include/sirit/sirit.h | 6 ++++++ src/CMakeLists.txt | 1 + src/insts/memory.cpp | 22 ++++++++++++++++++++++ 3 files changed, 29 insertions(+) create mode 100644 src/insts/memory.cpp diff --git a/include/sirit/sirit.h b/include/sirit/sirit.h index 5aee8b8..be921c3 100644 --- a/include/sirit/sirit.h +++ b/include/sirit/sirit.h @@ -191,6 +191,12 @@ class Module { /// @return target Ref Name(Ref target, const std::string& name); + // Memory + + /// Allocate an object in memory, resulting in a copy to it. + Ref Variable(Ref result_type, spv::StorageClass storage_class, + Ref initializer = nullptr); + // 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 fc9bbbf..dd2df1d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -19,6 +19,7 @@ add_library(sirit insts/function.cpp insts/flow.cpp insts/debug.cpp + insts/memory.cpp ) target_include_directories(sirit PUBLIC ../include diff --git a/src/insts/memory.cpp b/src/insts/memory.cpp new file mode 100644 index 0000000..14525ab --- /dev/null +++ b/src/insts/memory.cpp @@ -0,0 +1,22 @@ +/* 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 "insts.h" +#include "sirit/sirit.h" + +namespace Sirit { + +Ref Module::Variable(Ref result_type, spv::StorageClass storage_class, + Ref initializer) { + auto const op{new Op(spv::Op::OpVariable, bound++, result_type)}; + AddEnum(op, storage_class); + if (initializer) { + op->Add(initializer); + } + return AddCode(op); +} + +} // namespace Sirit