ir_variable: Add method to get string representing interpolation qualifier
[mesa.git] / ast.h
diff --git a/ast.h b/ast.h
index fa84a915749c0dcf09b937c76f59696fffd7c6b4..1cf80af9144fc0af39ba9c902bfd3ebef55af6ac 100644 (file)
--- a/ast.h
+++ b/ast.h
@@ -1,3 +1,4 @@
+/* -*- c++ -*- */
 /*
  * Copyright © 2009 Intel Corporation
  *
@@ -25,7 +26,6 @@
 #ifndef AST_H
 #define AST_H
 
-#include "main/simple_list.h"
 #include "list.h"
 #include "glsl_parser_extras.h"
 
@@ -34,12 +34,12 @@ struct _mesa_glsl_parse_state;
 
 struct YYLTYPE;
 
-class ast_node : public simple_node {
+class ast_node {
 public:
    virtual ~ast_node();
    virtual void print(void) const;
-   virtual ir_instruction *hir(exec_list *instructions,
-                              struct _mesa_glsl_parse_state *state);
+   virtual ir_rvalue *hir(exec_list *instructions,
+                         struct _mesa_glsl_parse_state *state);
 
    /**
     * Retrieve the source location of an AST node
@@ -67,22 +67,21 @@ public:
     *
     * \sa ast_node::get_location
     */
-   void set_location(const struct YYLTYPE *locp)
+   void set_location(const struct YYLTYPE &locp)
    {
-      this->location.source = locp->source;
-      this->location.line = locp->first_line;
-      this->location.column = locp->first_column;
+      this->location.source = locp.source;
+      this->location.line = locp.first_line;
+      this->location.column = locp.first_column;
    }
 
-
-   int  type;
-
    struct {
       unsigned source;
       unsigned line;
       unsigned column;
    } location;
 
+   exec_node link;
+
 protected:
    ast_node(void);
 };
@@ -150,10 +149,19 @@ public:
    ast_expression(int oper, ast_expression *,
                  ast_expression *, ast_expression *);
 
+   ast_expression(const char *identifier) :
+      oper(ast_identifier)
+   {
+      subexpressions[0] = NULL;
+      subexpressions[1] = NULL;
+      subexpressions[2] = NULL;
+      primary_expression.identifier = (char *) identifier;
+   }
+
    static const char *operator_string(enum ast_operators op);
 
-   virtual ir_instruction *hir(exec_list *instructions,
-                              struct _mesa_glsl_parse_state *state);
+   virtual ir_rvalue *hir(exec_list *instructions,
+                         struct _mesa_glsl_parse_state *state);
 
    virtual void print(void) const;
 
@@ -171,9 +179,10 @@ public:
 
 
    /**
-    * List of expressions for an \c ast_sequence.
+    * List of expressions for an \c ast_sequence or parameters for an
+    * \c ast_function_call
     */
-   struct simple_node expressions;
+   exec_list expressions;
 };
 
 class ast_expression_bin : public ast_expression {
@@ -183,6 +192,42 @@ public:
    virtual void print(void) const;
 };
 
+/**
+ * Subclass of expressions for function calls
+ */
+class ast_function_expression : public ast_expression {
+public:
+   ast_function_expression(ast_expression *callee)
+      : ast_expression(ast_function_call, callee,
+                      NULL, NULL),
+       cons(false)
+   {
+      /* empty */
+   }
+
+   ast_function_expression(class ast_type_specifier *type)
+      : ast_expression(ast_function_call, (ast_expression *) type,
+                      NULL, NULL),
+       cons(true)
+   {
+      /* empty */
+   }
+
+   bool is_constructor() const
+   {
+      return cons;
+   }
+
+   virtual ir_rvalue *hir(exec_list *instructions,
+                         struct _mesa_glsl_parse_state *state);
+
+private:
+   /**
+    * Is this function call actually a constructor?
+    */
+   bool cons;
+};
+
 
 /**
  * Number of possible operators for an ast_expression
@@ -199,11 +244,11 @@ public:
    ast_compound_statement(int new_scope, ast_node *statements);
    virtual void print(void) const;
 
-   virtual ir_instruction *hir(exec_list *instructions,
-                              struct _mesa_glsl_parse_state *state);
+   virtual ir_rvalue *hir(exec_list *instructions,
+                         struct _mesa_glsl_parse_state *state);
 
    int new_scope;
-   struct simple_node statements;
+   exec_list statements;
 };
 
 class ast_declaration : public ast_node {
@@ -246,8 +291,11 @@ public:
    ast_struct_specifier(char *identifier, ast_node *declarator_list);
    virtual void print(void) const;
 
+   virtual ir_rvalue *hir(exec_list *instructions,
+                         struct _mesa_glsl_parse_state *state);
+
    char *name;
-   struct simple_node declarations;
+   exec_list declarations;
 };
 
 
@@ -280,10 +328,12 @@ enum ast_types {
    ast_mat4,
    ast_sampler1d,
    ast_sampler2d,
+   ast_sampler2drect,
    ast_sampler3d,
    ast_samplercube,
    ast_sampler1dshadow,
    ast_sampler2dshadow,
+   ast_sampler2drectshadow,
    ast_samplercubeshadow,
    ast_sampler1darray,
    ast_sampler2darray,
@@ -311,11 +361,33 @@ class ast_type_specifier : public ast_node {
 public:
    ast_type_specifier(int specifier);
 
+   /** 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)
+   {
+      /* empty */
+   }
+
+   /** 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)
+   {
+      /* empty */
+   }
+
+   const struct glsl_type *glsl_type(const char **name,
+                                    struct _mesa_glsl_parse_state *state)
+      const;
+
    virtual void print(void) const;
 
+   ir_rvalue *hir(exec_list *, struct _mesa_glsl_parse_state *);
+
    enum ast_types type_specifier;
 
-   char *type_name;
+   const char *type_name;
    ast_struct_specifier *structure;
 
    int is_array;
@@ -339,11 +411,11 @@ public:
    ast_declarator_list(ast_fully_specified_type *);
    virtual void print(void) const;
 
-   virtual ir_instruction *hir(exec_list *instructions,
-                              struct _mesa_glsl_parse_state *state);
+   virtual ir_rvalue *hir(exec_list *instructions,
+                         struct _mesa_glsl_parse_state *state);
 
    ast_fully_specified_type *type;
-   struct simple_node declarations;
+   exec_list declarations;
 
    /**
     * Special flag for vertex shader "invariant" declarations.
@@ -360,13 +432,28 @@ class ast_parameter_declarator : public ast_node {
 public:
    virtual void print(void) const;
 
-   virtual ir_instruction *hir(exec_list *instructions,
-                              struct _mesa_glsl_parse_state *state);
+   virtual ir_rvalue *hir(exec_list *instructions,
+                         struct _mesa_glsl_parse_state *state);
 
    ast_fully_specified_type *type;
    char *identifier;
    int is_array;
    ast_expression *array_size;
+
+   static void parameters_to_hir(exec_list *ast_parameters,
+                                bool formal, exec_list *ir_parameters,
+                                struct _mesa_glsl_parse_state *state);
+
+private:
+   /** Is this parameter declaration part of a formal parameter list? */
+   bool formal_parameter;
+
+   /**
+    * Is this parameter 'void' type?
+    *
+    * This field is set by \c ::hir.
+    */
+   bool is_void;
 };
 
 
@@ -376,10 +463,36 @@ public:
 
    virtual void print(void) const;
 
+   virtual ir_rvalue *hir(exec_list *instructions,
+                         struct _mesa_glsl_parse_state *state);
+
    ast_fully_specified_type *return_type;
    char *identifier;
 
-   struct simple_node parameters;
+   exec_list parameters;
+
+private:
+   /**
+    * Is this prototype part of the function definition?
+    *
+    * Used by ast_function_definition::hir to process the parameters, etc.
+    * of the function.
+    *
+    * \sa ::hir
+    */
+   bool is_definition;
+
+   /**
+    * Function signature corresponding to this function prototype instance
+    *
+    * Used by ast_function_definition::hir to process the parameters, etc.
+    * of the function.
+    *
+    * \sa ::hir
+    */
+   class ir_function_signature *signature;
+
+   friend class ast_function_definition;
 };
 
 
@@ -407,8 +520,8 @@ public:
    ast_expression_statement(ast_expression *);
    virtual void print(void) const;
 
-   virtual ir_instruction *hir(exec_list *instructions,
-                              struct _mesa_glsl_parse_state *state);
+   virtual ir_rvalue *hir(exec_list *instructions,
+                         struct _mesa_glsl_parse_state *state);
 
    ast_expression *expression;
 };
@@ -430,6 +543,9 @@ public:
                           ast_node *else_statement);
    virtual void print(void) const;
 
+   virtual ir_rvalue *hir(exec_list *instructions,
+                         struct _mesa_glsl_parse_state *state);
+
    ast_expression *condition;
    ast_node *then_statement;
    ast_node *else_statement;
@@ -439,7 +555,7 @@ public:
 class ast_switch_statement : public ast_node {
 public:
    ast_expression *expression;
-   struct simple_node statements;
+   exec_list statements;
 };
 
 class ast_iteration_statement : public ast_node {
@@ -449,6 +565,8 @@ public:
 
    virtual void print(void) const;
 
+   virtual ir_rvalue *hir(exec_list *, struct _mesa_glsl_parse_state *);
+
    enum ast_iteration_modes {
       ast_for,
       ast_while,
@@ -461,6 +579,15 @@ public:
    ast_expression *rest_expression;
 
    ast_node *body;
+
+private:
+   /**
+    * Generate IR from the condition of a loop
+    *
+    * This is factored out of ::hir because some loops have the condition
+    * test at the top (for and while), and others have it at the end (do-while).
+    */
+   void condition_to_hir(class ir_loop *, struct _mesa_glsl_parse_state *);
 };
 
 
@@ -469,6 +596,9 @@ public:
    ast_jump_statement(int mode, ast_expression *return_value);
    virtual void print(void) const;
 
+   virtual ir_rvalue *hir(exec_list *instructions,
+                         struct _mesa_glsl_parse_state *state);
+
    enum ast_jump_modes {
       ast_continue,
       ast_break,
@@ -484,15 +614,18 @@ class ast_function_definition : public ast_node {
 public:
    virtual void print(void) const;
 
-   virtual ir_instruction *hir(exec_list *instructions,
-                              struct _mesa_glsl_parse_state *state);
+   virtual ir_rvalue *hir(exec_list *instructions,
+                         struct _mesa_glsl_parse_state *state);
 
    ast_function *prototype;
    ast_compound_statement *body;
 };
 
 
-extern struct ir_instruction *
+extern void
+_mesa_ast_to_hir(exec_list *instructions, struct _mesa_glsl_parse_state *state);
+
+extern struct ir_rvalue *
 _mesa_ast_field_selection_to_hir(const struct ast_expression *expr,
                                 exec_list *instructions,
                                 struct _mesa_glsl_parse_state *state);