Add various accessors needed to read and edit SPIRV code.
authorDavid Srbecky <dsrbecky@google.com>
Sun, 26 Mar 2017 19:08:41 +0000 (20:08 +0100)
committerDavid Srbecky <dsrbecky@google.com>
Wed, 29 Mar 2017 13:38:57 +0000 (14:38 +0100)
source/opt/basic_block.h
source/opt/function.h
source/opt/module.h
source/opt/types.h

index f1ed7bd..895ea44 100644 (file)
@@ -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<Instruction> 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()); }
index 0d2d03a..12166fa 100644 (file)
@@ -38,6 +38,8 @@ class Function {
   // Creates a function instance declared by the given OpFunction instruction
   // |def_inst|.
   inline explicit Function(std::unique_ptr<Instruction> 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; }
index 690cba0..87410e1 100644 (file)
@@ -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<Instruction> c);
   // Appends an extension instruction to this module.
index a7d9e7c..a46e411 100644 (file)
@@ -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<Type*>& element_types() const { return element_types_; }
   bool decoration_empty() const override {
     return decorations_.empty() && element_decorations_.empty();
   }