i965 gen6: Implement rasterizer discard.
[mesa.git] / src / glsl / ast.h
index a77b522705cce5b237ffe6294621d212a0afe462..d899bc62a81dffe5d638121ab05a455cd0d77155 100644 (file)
@@ -49,23 +49,23 @@ struct YYLTYPE;
  */
 class ast_node {
 public:
-   /* Callers of this talloc-based new need not call delete. It's
-    * easier to just talloc_free 'ctx' (or any of its ancestors). */
+   /* Callers of this ralloc-based new need not call delete. It's
+    * easier to just ralloc_free 'ctx' (or any of its ancestors). */
    static void* operator new(size_t size, void *ctx)
    {
       void *node;
 
-      node = talloc_zero_size(ctx, size);
+      node = rzalloc_size(ctx, size);
       assert(node != NULL);
 
       return node;
    }
 
    /* If the user *does* call delete, that's OK, we will just
-    * talloc_free in that case. */
+    * ralloc_free in that case. */
    static void operator delete(void *table)
    {
-      talloc_free(table);
+      ralloc_free(table);
    }
 
    /**
@@ -318,7 +318,8 @@ public:
 
 
 enum {
-   ast_precision_high = 0, /**< Default precision. */
+   ast_precision_none = 0, /**< Absence of precision qualifier. */
+   ast_precision_high,
    ast_precision_medium,
    ast_precision_low
 };
@@ -349,7 +350,19 @@ struct ast_type_qualifier {
          * qualifier is used.
          */
         unsigned explicit_location:1;
-      } q;
+
+         /** \name Layout qualifiers for GL_AMD_conservative_depth */
+         /** \{ */
+         unsigned depth_any:1;
+         unsigned depth_greater:1;
+         unsigned depth_less:1;
+         unsigned depth_unchanged:1;
+         /** \} */
+      }
+      /** \brief Set of flags, accessed by name. */
+      q;
+
+      /** \brief Set of flags, accessed as a bitmask. */
       unsigned i;
    } flags;
 
@@ -359,7 +372,24 @@ struct ast_type_qualifier {
     * \note
     * This field is only valid if \c explicit_location is set.
     */
-   unsigned location;
+   int location;
+
+   /**
+    * Return true if and only if an interpolation qualifier is present.
+    */
+   bool has_interpolation() const;
+
+   /**
+    * \brief Return string representation of interpolation qualifier.
+    *
+    * If an interpolation qualifier is present, then return that qualifier's
+    * string representation. Otherwise, return null. For example, if the
+    * noperspective bit is set, then this returns "noperspective".
+    *
+    * If multiple interpolation qualifiers are somehow present, then the
+    * returned string is undefined but not null.
+    */
+   const char *interpolation_string() const;
 };
 
 class ast_struct_specifier : public ast_node {
@@ -407,6 +437,7 @@ enum ast_types {
    ast_sampler2drect,
    ast_sampler3d,
    ast_samplercube,
+   ast_samplerexternaloes,
    ast_sampler1dshadow,
    ast_sampler2dshadow,
    ast_sampler2drectshadow,
@@ -440,7 +471,8 @@ public:
    /** Construct a type specifier from a type name */
    ast_type_specifier(const char *name) 
       : type_specifier(ast_type_name), type_name(name), structure(NULL),
-       is_array(false), array_size(NULL), precision(ast_precision_high)
+       is_array(false), array_size(NULL), precision(ast_precision_none),
+       is_precision_statement(false)
    {
       /* empty */
    }
@@ -448,7 +480,8 @@ public:
    /** Construct a type specifier from a structure definition */
    ast_type_specifier(ast_struct_specifier *s)
       : type_specifier(ast_struct), type_name(s->name), structure(s),
-       is_array(false), array_size(NULL), precision(ast_precision_high)
+       is_array(false), array_size(NULL), precision(ast_precision_none),
+       is_precision_statement(false)
    {
       /* empty */
    }
@@ -470,6 +503,8 @@ public:
    ast_expression *array_size;
 
    unsigned precision:2;
+
+   bool is_precision_statement;
 };
 
 
@@ -580,46 +615,92 @@ private:
 };
 
 
-class ast_declaration_statement : public ast_node {
+class ast_expression_statement : public ast_node {
 public:
-   ast_declaration_statement(void);
+   ast_expression_statement(ast_expression *);
+   virtual void print(void) const;
 
-   enum {
-      ast_function,
-      ast_declaration,
-      ast_precision
-   } mode;
+   virtual ir_rvalue *hir(exec_list *instructions,
+                         struct _mesa_glsl_parse_state *state);
 
-   union {
-      class ast_function *function;
-      ast_declarator_list *declarator;
-      ast_type_specifier *type;
-      ast_node *node;
-   } declaration;
+   ast_expression *expression;
 };
 
 
-class ast_expression_statement : public ast_node {
+class ast_case_label : public ast_node {
 public:
-   ast_expression_statement(ast_expression *);
+   ast_case_label(ast_expression *test_value);
    virtual void print(void) const;
 
    virtual ir_rvalue *hir(exec_list *instructions,
                          struct _mesa_glsl_parse_state *state);
 
-   ast_expression *expression;
+   /**
+    * An test value of NULL means 'default'.
+    */
+   ast_expression *test_value;
 };
 
 
-class ast_case_label : public ast_node {
+class ast_case_label_list : public ast_node {
 public:
+   ast_case_label_list(void);
+   virtual void print(void) const;
+
+   virtual ir_rvalue *hir(exec_list *instructions,
+                         struct _mesa_glsl_parse_state *state);
 
    /**
-    * An expression of NULL means 'default'.
+    * A list of case labels.
     */
-   ast_expression *expression;
+   exec_list labels;
 };
 
+
+class ast_case_statement : public ast_node {
+public:
+   ast_case_statement(ast_case_label_list *labels);
+   virtual void print(void) const;
+
+   virtual ir_rvalue *hir(exec_list *instructions,
+                         struct _mesa_glsl_parse_state *state);
+
+   ast_case_label_list *labels;
+
+   /**
+    * A list of statements.
+    */
+   exec_list stmts;
+};
+
+
+class ast_case_statement_list : public ast_node {
+public:
+   ast_case_statement_list(void);
+   virtual void print(void) const;
+
+   virtual ir_rvalue *hir(exec_list *instructions,
+                         struct _mesa_glsl_parse_state *state);
+
+   /**
+    * A list of cases.
+    */
+   exec_list cases;
+};
+
+
+class ast_switch_body : public ast_node {
+public:
+   ast_switch_body(ast_case_statement_list *stmts);
+   virtual void print(void) const;
+
+   virtual ir_rvalue *hir(exec_list *instructions,
+                         struct _mesa_glsl_parse_state *state);
+
+   ast_case_statement_list *stmts;
+};
+
+
 class ast_selection_statement : public ast_node {
 public:
    ast_selection_statement(ast_expression *condition,
@@ -638,8 +719,18 @@ public:
 
 class ast_switch_statement : public ast_node {
 public:
-   ast_expression *expression;
-   exec_list statements;
+   ast_switch_statement(ast_expression *test_expression,
+                       ast_node *body);
+   virtual void print(void) const;
+
+   virtual ir_rvalue *hir(exec_list *instructions,
+                         struct _mesa_glsl_parse_state *state);
+
+   ast_expression *test_expression;
+   ast_node *body;
+
+protected:
+   void test_to_hir(exec_list *, struct _mesa_glsl_parse_state *);
 };
 
 class ast_iteration_statement : public ast_node {
@@ -715,7 +806,6 @@ _mesa_ast_field_selection_to_hir(const ast_expression *expr,
                                 struct _mesa_glsl_parse_state *state);
 
 void
-emit_function(_mesa_glsl_parse_state *state, exec_list *instructions,
-             ir_function *f);
+emit_function(_mesa_glsl_parse_state *state, ir_function *f);
 
 #endif /* AST_H */