From b85997a1df2c050855837989d7c7aa73be8e3a9b Mon Sep 17 00:00:00 2001 From: David Srbecky Date: Sun, 26 Mar 2017 20:08:41 +0100 Subject: [PATCH] Add various accessors needed to read and edit SPIRV code. --- source/opt/basic_block.h | 2 ++ source/opt/function.h | 2 ++ source/opt/module.h | 2 ++ source/opt/types.h | 2 ++ 4 files changed, 8 insertions(+) diff --git a/source/opt/basic_block.h b/source/opt/basic_block.h index f1ed7bd..895ea44 100644 --- a/source/opt/basic_block.h +++ b/source/opt/basic_block.h @@ -44,6 +44,8 @@ class BasicBlock { void SetParent(Function* function) { function_ = function; } // Appends an instruction to this basic block. inline void AddInstruction(std::unique_ptr i); + // The label starting this basic block. + Instruction& Label() { return *label_; } iterator begin() { return iterator(&insts_, insts_.begin()); } iterator end() { return iterator(&insts_, insts_.end()); } diff --git a/source/opt/function.h b/source/opt/function.h index 0d2d03a..12166fa 100644 --- a/source/opt/function.h +++ b/source/opt/function.h @@ -38,6 +38,8 @@ class Function { // Creates a function instance declared by the given OpFunction instruction // |def_inst|. inline explicit Function(std::unique_ptr def_inst); + // The OpFunction instruction that begins the definition of this function. + Instruction& DefInst() { return *def_inst_; } // Sets the enclosing module for this function. void SetParent(Module* module) { module_ = module; } diff --git a/source/opt/module.h b/source/opt/module.h index 690cba0..87410e1 100644 --- a/source/opt/module.h +++ b/source/opt/module.h @@ -52,6 +52,8 @@ class Module { void SetHeader(const ModuleHeader& header) { header_ = header; } // Sets the Id bound. void SetIdBound(uint32_t bound) { header_.bound = bound; } + // Returns the Id bound. + uint32_t IdBound() { return header_.bound; } // Appends a capability instruction to this module. inline void AddCapability(std::unique_ptr c); // Appends an extension instruction to this module. diff --git a/source/opt/types.h b/source/opt/types.h index a7d9e7c..a46e411 100644 --- a/source/opt/types.h +++ b/source/opt/types.h @@ -231,6 +231,7 @@ class Array : public Type { bool IsSame(Type* that) const override; std::string str() const override; const Type* element_type() const { return element_type_; } + uint32_t LengthId() const { return length_id_; } Array* AsArray() override { return this; } const Array* AsArray() const override { return this; } @@ -265,6 +266,7 @@ class Struct : public Type { bool IsSame(Type* that) const override; std::string str() const override; + const std::vector& element_types() const { return element_types_; } bool decoration_empty() const override { return decorations_.empty() && element_decorations_.empty(); } -- 2.7.4