From 97825750a3b281e265039d0eff4be144bc56230e Mon Sep 17 00:00:00 2001 From: ReinUsesLisp Date: Wed, 31 Oct 2018 03:37:36 -0300 Subject: [PATCH] Add OpAccessChain --- include/sirit/sirit.h | 5 +++++ src/insts/memory.cpp | 10 ++++++++++ 2 files changed, 15 insertions(+) diff --git a/include/sirit/sirit.h b/include/sirit/sirit.h index 8ddf9b5..b54699f 100644 --- a/include/sirit/sirit.h +++ b/include/sirit/sirit.h @@ -200,6 +200,11 @@ class Module { Ref Variable(Ref result_type, spv::StorageClass storage_class, Ref initializer = nullptr); + /// 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 = {}); + // Annotation /// Add a decoration to target. diff --git a/src/insts/memory.cpp b/src/insts/memory.cpp index 502f949..b3e55b8 100644 --- a/src/insts/memory.cpp +++ b/src/insts/memory.cpp @@ -6,6 +6,7 @@ #include "insts.h" #include "sirit/sirit.h" +#include namespace Sirit { @@ -19,4 +20,13 @@ Ref Module::Variable(Ref result_type, spv::StorageClass storage_class, return AddCode(op); } +Ref Module::AccessChain(Ref result_type, Ref base, + const std::vector& indexes) { + assert(indexes.size() > 0); + auto op{new Op(spv::Op::OpAccessChain, bound++, result_type)}; + op->Add(base); + op->Add(indexes); + return AddCode(op); +} + } // namespace Sirit