ir_variable: Add method to get string representing interpolation qualifier
[mesa.git] / ir.h
diff --git a/ir.h b/ir.h
index a286e7b9324c987c1ce1df4121723dcfd4d5f3c9..04ecb582e482268f3f18a85ab1210b5974e4f707 100644 (file)
--- a/ir.h
+++ b/ir.h
@@ -26,6 +26,9 @@
 #ifndef IR_H
 #define IR_H
 
+#include <cstdio>
+#include <cstdlib>
+
 #include "list.h"
 #include "ir_visitor.h"
 #include "ir_hierarchical_visitor.h"
@@ -42,6 +45,10 @@ public:
    const struct glsl_type *type;
 
    class ir_constant *constant_expression_value();
+
+   /** ir_print_visitor helper for debugging. */
+   void print(void);
+
    virtual void accept(ir_visitor *) = 0;
    virtual ir_visitor_status accept(ir_hierarchical_visitor *) = 0;
 
@@ -170,6 +177,16 @@ public:
       return var;
    }
 
+   /**
+    * Get the string value for the interpolation qualifier
+    *
+    * \return
+    * If none of \c shader_in or \c shader_out is set, an empty string will
+    * be returned.  Otherwise the string that would be used in a shader to
+    * specify \c mode will be returned.
+    */
+   const char *interpolation_string() const;
+
    const char *name;
 
    /**
@@ -494,6 +511,14 @@ enum ir_expression_operation {
    ir_unop_cos,
    /*@}*/
 
+   /**
+    * \name Partial derivatives.
+    */
+   /*@{*/
+   ir_unop_dFdx,
+   ir_unop_dFdy,
+   /*@}*/
+
    ir_binop_add,
    ir_binop_sub,
    ir_binop_mul,
@@ -770,7 +795,7 @@ enum ir_texture_opcode {
 class ir_texture : public ir_rvalue {
 public:
    ir_texture(enum ir_texture_opcode op)
-      : op(op)
+      : op(op), projector(NULL), shadow_comparitor(NULL)
    {
       /* empty */
    }
@@ -787,6 +812,9 @@ public:
     */
    const char *opcode_string();
 
+   /** Set the sampler and infer the type. */
+   void set_sampler(ir_dereference *sampler);
+
    /**
     * Do a reverse-lookup to translate a string into an ir_texture_opcode.
     */
@@ -1007,14 +1035,42 @@ public:
 };
 
 
+/**
+ * Data stored in an ir_constant
+ */
+union ir_constant_data {
+      unsigned u[16];
+      int i[16];
+      float f[16];
+      bool b[16];
+};
+
+
 class ir_constant : public ir_rvalue {
 public:
-   ir_constant(const struct glsl_type *type, const void *data);
+   ir_constant(const struct glsl_type *type, const ir_constant_data *data);
    ir_constant(bool b);
    ir_constant(unsigned int u);
    ir_constant(int i);
    ir_constant(float f);
 
+   /**
+    * Construct an ir_constant from a list of ir_constant values
+    */
+   ir_constant(const struct glsl_type *type, exec_list *values);
+
+   /**
+    * Construct an ir_constant from a scalar component of another ir_constant
+    *
+    * The new \c ir_constant inherits the type of the component from the
+    * source constant.
+    *
+    * \note
+    * In the case of a matrix constant, the new constant is a scalar, \b not
+    * a vector.
+    */
+   ir_constant(const ir_constant *c, unsigned i);
+
    virtual ir_constant *as_constant()
    {
       return this;
@@ -1027,10 +1083,28 @@ public:
 
    virtual ir_visitor_status accept(ir_hierarchical_visitor *);
 
-   ir_constant *clone()
-   {
-      return new ir_constant(this->type, &this->value);
-   }
+   ir_constant *clone();
+
+   /**
+    * Get a particular component of a constant as a specific type
+    *
+    * This is useful, for example, to get a value from an integer constant
+    * as a float or bool.  This appears frequently when constructors are
+    * called with all constant parameters.
+    */
+   /*@{*/
+   bool get_bool_component(unsigned i) const;
+   float get_float_component(unsigned i) const;
+   int get_int_component(unsigned i) const;
+   unsigned get_uint_component(unsigned i) const;
+   /*@}*/
+
+   ir_constant *get_record_field(const char *name);
+
+   /**
+    * Determine whether a constant has the same value as another constant
+    */
+   bool has_value(const ir_constant *) const;
 
    /**
     * Value of the constant.
@@ -1039,17 +1113,22 @@ public:
     * by the type associated with the \c ir_instruction.  Constants may be
     * scalars, vectors, or matrices.
     */
-   union {
-      unsigned u[16];
-      int i[16];
-      float f[16];
-      bool b[16];
-   } value;
+   union ir_constant_data value;
+
+   exec_list components;
+
+private:
+   /**
+    * Parameterless constructor only used by the clone method
+    */
+   ir_constant(void);
 };
 
 void
 visit_exec_list(exec_list *list, ir_visitor *visitor);
 
+void validate_ir_tree(exec_list *instructions);
+
 extern void
 _mesa_glsl_initialize_variables(exec_list *instructions,
                                struct _mesa_glsl_parse_state *state);