ir_constant: Add get_record_field query
authorIan Romanick <ian.d.romanick@intel.com>
Thu, 10 Jun 2010 00:28:54 +0000 (17:28 -0700)
committerIan Romanick <ian.d.romanick@intel.com>
Fri, 11 Jun 2010 22:36:05 +0000 (15:36 -0700)
ir.cpp
ir.h

diff --git a/ir.cpp b/ir.cpp
index bb1c4589a57be6d31657f68b595c045fe901b031..38e2739449c9fa68f7ce997f69dfb01271409e2b 100644 (file)
--- a/ir.cpp
+++ b/ir.cpp
@@ -406,6 +406,32 @@ ir_constant::get_uint_component(unsigned i) const
 }
 
 
+ir_constant *
+ir_constant::get_record_field(const char *name)
+{
+   int idx = this->type->field_index(name);
+
+   if (idx < 0)
+      return NULL;
+
+   if (this->components.is_empty())
+      return NULL;
+
+   exec_node *node = this->components.head;
+   for (int i = 0; i < idx; i++) {
+      node = node->next;
+
+      /* If the end of the list is encountered before the element matching the
+       * requested field is found, return NULL.
+       */
+      if (node->is_tail_sentinal())
+        return NULL;
+   }
+
+   return (ir_constant *) node;
+}
+
+
 ir_dereference_variable::ir_dereference_variable(ir_variable *var)
 {
    this->var = var;
diff --git a/ir.h b/ir.h
index 86beb2d7ce6712169cbd822e263ed9dff5d1ff33..718c495fb3089da3c54ff1061953704f5efc3d77 100644 (file)
--- a/ir.h
+++ b/ir.h
@@ -1071,6 +1071,8 @@ public:
    unsigned get_uint_component(unsigned i) const;
    /*@}*/
 
+   ir_constant *get_record_field(const char *name);
+
    /**
     * Value of the constant.
     *