Default function parameters to 'in' instead of auto
[mesa.git] / ast_to_hir.cpp
index 3342eae8c30231376f9d113d10f2dba2f185a0ec..c791aec3e243f1ff017369cc4655985b0775adc3 100644 (file)
 #include "ir.h"
 
 void
-_mesa_generate_hir_from_ast(struct _mesa_glsl_parse_state *state)
+_mesa_ast_to_hir(exec_list *instructions, struct _mesa_glsl_parse_state *state)
 {
    struct simple_node *ptr;
 
+   _mesa_glsl_initialize_variables(instructions, state);
+
    foreach (ptr, & state->translation_unit) {
-      if (1) {
-      }
+      ((ast_node *)ptr)->hir(instructions, state);
    }
 }
 
@@ -122,7 +123,7 @@ arithmetic_result_type(const struct glsl_type *type_a,
     *    * The two operands are scalars. In this case the operation is
     *      applied, resulting in a scalar."
     */
-   if (is_glsl_type_scalar(type_a) && is_glsl_type_scalar(type_b))
+   if (type_a->is_scalar() && type_b->is_scalar())
       return type_a;
 
    /*   "* One operand is a scalar, and the other is a vector or matrix.
@@ -130,10 +131,10 @@ arithmetic_result_type(const struct glsl_type *type_a,
     *      component of the vector or matrix, resulting in the same size
     *      vector or matrix."
     */
-   if (is_glsl_type_scalar(type_a)) {
-      if (!is_glsl_type_scalar(type_b))
+   if (type_a->is_scalar()) {
+      if (!type_b->is_scalar())
         return type_b;
-   } else if (is_glsl_type_scalar(type_b)) {
+   } else if (type_b->is_scalar()) {
       return type_a;
    }
 
@@ -148,7 +149,7 @@ arithmetic_result_type(const struct glsl_type *type_a,
     *      operation is done component-wise resulting in the same size
     *      vector."
     */
-   if (is_glsl_type_vector(type_a) && is_glsl_type_vector(type_b)) {
+   if (type_a->is_vector() && type_b->is_vector()) {
       if (type_a->vector_elements == type_b->vector_elements)
         return type_a;
       else
@@ -181,14 +182,14 @@ arithmetic_result_type(const struct glsl_type *type_a,
     *      more detail how vectors and matrices are operated on."
     */
    if (! multiply) {
-      if (is_glsl_type_matrix(type_a) && is_glsl_type_matrix(type_b)
+      if (type_a->is_matrix() && type_b->is_matrix()
          && (type_a->vector_elements == type_b->vector_elements)
          && (type_a->matrix_rows == type_b->matrix_rows))
         return type_a;
       else
         return glsl_error_type;
    } else {
-      if (is_glsl_type_matrix(type_a) && is_glsl_type_matrix(type_b)) {
+      if (type_a->is_matrix() && type_b->is_matrix()) {
         if (type_a->vector_elements == type_b->matrix_rows) {
            char type_name[7];
            const struct glsl_type *t;
@@ -211,14 +212,14 @@ arithmetic_result_type(const struct glsl_type *type_a,
               _mesa_symbol_table_find_symbol(state->symbols, 0, type_name);
            return (t != NULL) ? t : glsl_error_type;
         }
-      } else if (is_glsl_type_matrix(type_a)) {
+      } else if (type_a->is_matrix()) {
         /* A is a matrix and B is a column vector.  Columns of A must match
          * rows of B.
          */
         if (type_a->vector_elements == type_b->vector_elements)
            return type_b;
       } else {
-        assert(is_glsl_type_matrix(type_b));
+        assert(type_b->is_matrix());
 
         /* A is a row vector and B is a matrix.  Columns of A must match
          * rows of B.
@@ -273,8 +274,8 @@ modulus_result_type(const struct glsl_type *type_a,
     *    wise to the vector, resulting in the same type as the vector. If both
     *    are vectors of the same size, the result is computed component-wise."
     */
-   if (is_glsl_type_vector(type_a)) {
-      if (!is_glsl_type_vector(type_b)
+   if (type_a->is_vector()) {
+      if (!type_b->is_vector()
          || (type_a->vector_elements == type_b->vector_elements))
         return type_a;
    } else
@@ -299,8 +300,8 @@ relational_result_type(const struct glsl_type *type_a,
     */
    if (! is_numeric_base_type(type_a->base_type)
        || ! is_numeric_base_type(type_b->base_type)
-       || ! is_glsl_type_scalar(type_a) 
-       || ! is_glsl_type_scalar(type_b))
+       || !type_a->is_scalar()
+       || !type_b->is_scalar())
       return glsl_error_type;
 
    /*    "Either the operands' types must match, or the conversions from
@@ -410,7 +411,7 @@ ast_expression::hir(exec_list *instructions,
    make_empty_list(& op_list);
 
    switch (this->oper) {
-   case ast_assign:
+   case ast_assign: {
       op[0] = this->subexpressions[0]->hir(instructions, state);
       op[1] = this->subexpressions[1]->hir(instructions, state);
 
@@ -449,8 +450,12 @@ ast_expression::hir(exec_list *instructions,
       /* FINISHME: Check that the LHS and RHS have matching types. */
       /* FINISHME: For GLSL 1.10, check that the types are not arrays. */
 
-      result = new ir_assignment(op[0], op[1], NULL);
+      ir_instruction *tmp = new ir_assignment(op[0], op[1], NULL);
+      instructions->push_tail(tmp);
+
+      result = op[0];
       break;
+   }
 
    case ast_plus:
       op[0] = this->subexpressions[0]->hir(instructions, state);
@@ -525,7 +530,7 @@ ast_expression::hir(exec_list *instructions,
        */
       assert((type == glsl_error_type)
             || ((type->base_type == GLSL_TYPE_BOOL)
-                && is_glsl_type_scalar(type)));
+                && type->is_scalar()));
 
       result = new ir_expression(operations[this->oper], type,
                                 op[0], op[1]);
@@ -625,21 +630,10 @@ ast_expression::hir(exec_list *instructions,
       break;
 
    case ast_function_call:
-      /* There are three sorts of function calls.
-       *
-       * 1. contstructors - The first subexpression is an ast_type_specifier.
-       * 2. methods - Only the .length() method of array types.
-       * 3. functions - Calls to regular old functions.
-       *
-       * Method calls are actually detected when the ast_field_selection
-       * expression is handled.
+      /* Should *NEVER* get here.  ast_function_call should always be handled
+       * by ast_function_expression::hir.
        */
-#if 0
-      result = _mesa_ast_function_call_to_hir(this->subexpressions[0],
-                                             this->subexpressions[1],
-                                             state);
-      type = result->type;
-#endif
+      assert(0);
       break;
 
    case ast_identifier: {
@@ -716,6 +710,24 @@ ast_expression::hir(exec_list *instructions,
 }
 
 
+ir_instruction *
+ast_function_expression::hir(exec_list *instructions,
+                            struct _mesa_glsl_parse_state *state)
+{
+   /* There are three sorts of function calls.
+    *
+    * 1. contstructors - The first subexpression is an ast_type_specifier.
+    * 2. methods - Only the .length() method of array types.
+    * 3. functions - Calls to regular old functions.
+    *
+    * Method calls are actually detected when the ast_field_selection
+    * expression is handled.
+    */
+   (void) instructions;
+   (void) state;
+   return ir_call::get_error_instruction();
+}
+
 ir_instruction *
 ast_expression_statement::hir(exec_list *instructions,
                              struct _mesa_glsl_parse_state *state)
@@ -863,7 +875,7 @@ apply_type_qualifier_to_variable(const struct ast_type_qualifier *qual,
    else if (qual->attribute || qual->in
            || (qual->varying && (state->target == fragment_shader)))
       var->mode = ir_var_in;
-   else if (qual->out)
+   else if (qual->out || (qual->varying && (state->target == vertex_shader)))
       var->mode = ir_var_out;
    else if (qual->uniform)
       var->mode = ir_var_uniform;
@@ -995,7 +1007,12 @@ ast_parameter_declarator::hir(exec_list *instructions,
     * FINISHME: complete handling of constant expressions.
     */
 
+   /* Apply any specified qualifiers to the parameter declaration.  Note that
+    * for function parameters the default mode is 'in'.
+    */
    apply_type_qualifier_to_variable(& this->type->qualifier, var, state);
+   if (var->mode == ir_var_auto)
+      var->mode = ir_var_in;
 
    instructions->push_tail(var);
 
@@ -1143,7 +1160,7 @@ ast_function_definition::hir(exec_list *instructions,
    foreach_iter(exec_list_iterator, iter, parameters) {
       ir_variable *const var = (ir_variable *) iter.get();
 
-      assert(var->mode == ir_op_var_decl);
+      assert(((ir_instruction *)var)->mode == ir_op_var_decl);
 
       iter.remove();
       instructions->push_tail(var);