From 80b0757ab6e770cc44e93aff4cd74f488dd1e13e Mon Sep 17 00:00:00 2001 From: ReinUsesLisp Date: Wed, 31 Oct 2018 05:05:06 -0300 Subject: [PATCH] Add OpStore --- include/sirit/sirit.h | 8 ++++++++ src/insts/memory.cpp | 20 ++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/include/sirit/sirit.h b/include/sirit/sirit.h index 3456110..7061621 100644 --- a/include/sirit/sirit.h +++ b/include/sirit/sirit.h @@ -204,11 +204,19 @@ class Module { Ref Load(Ref result_type, Ref pointer, std::optional memory_access = {}); + /// Store through a pointer. + Ref Store(Ref pointer, Ref object, + std::optional memory_access = {}); + /// Create a pointer into a composite object that can be used with OpLoad /// and OpStore. Ref AccessChain(Ref result_type, Ref base, const std::vector& indexes = {}); + /// Make a copy of a composite object, while modifying one part of it. + Ref CompositeInsert(Ref result_type, Ref object, Ref composite, + const std::vector& indexes = {}); + // Annotation /// Add a decoration to target. diff --git a/src/insts/memory.cpp b/src/insts/memory.cpp index bf0147d..de1373d 100644 --- a/src/insts/memory.cpp +++ b/src/insts/memory.cpp @@ -30,6 +30,17 @@ Ref Module::Load(Ref result_type, Ref pointer, return AddCode(op); } +Ref Module::Store(Ref pointer, Ref object, + std::optional memory_access) { + auto op{new Op(spv::Op::OpStore)}; + op->Add(pointer); + op->Add(object); + if (memory_access) { + AddEnum(op, *memory_access); + } + return AddCode(op); +} + Ref Module::AccessChain(Ref result_type, Ref base, const std::vector& indexes) { assert(indexes.size() > 0); @@ -39,4 +50,13 @@ Ref Module::AccessChain(Ref result_type, Ref base, return AddCode(op); } +Ref Module::CompositeInsert(Ref result_type, Ref object, Ref composite, + const std::vector& indexes) { + auto op{new Op(spv::Op::OpCompositeInsert, bound++, result_type)}; + op->Add(object); + op->Add(composite); + op->Add(indexes); + return AddCode(op); +} + } // namespace Sirit