~ubuntu-branches/ubuntu/quantal/mesa/quantal

« back to all changes in this revision

Viewing changes to src/mesa/shader/slang/slang_assemble_assignment.c

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2007-02-21 12:44:07 UTC
  • mfrom: (1.2.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 22.
  • Revision ID: james.westby@ubuntu.com-20070221124407-rgcacs32mycrtadl
ImportĀ upstreamĀ versionĀ 6.5.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
 * Mesa 3-D graphics library
3
 
 * Version:  6.5
 
3
 * Version:  6.5.2
4
4
 *
5
5
 * Copyright (C) 2005-2006  Brian Paul   All Rights Reserved.
6
6
 *
53
53
 *      +------------------+
54
54
 */
55
55
 
 
56
 
 
57
 
56
58
static GLboolean
57
 
assign_basic (slang_assemble_ctx *A, slang_storage_type type, GLuint *index, GLuint size)
 
59
assign_basic(slang_assemble_ctx * A, slang_storage_type type, GLuint * index,
 
60
             GLuint size)
58
61
{
59
62
   GLuint dst_offset, dst_addr_loc;
60
63
   slang_assembly_type ty;
85
88
      ty = slang_asm_none;
86
89
   }
87
90
 
88
 
  /* Calculate the distance from top of the stack to the destination address. As the
89
 
   * copy operation progresses, components of the source are being successively popped
90
 
   * off the stack by the amount of *index increase step.
91
 
   */
 
91
   /* Calculate the distance from top of the stack to the destination
 
92
    * address. As the copy operation progresses, components of the
 
93
    * source are being successively popped off the stack by the amount
 
94
    * of *index increase step.
 
95
    */
92
96
   dst_addr_loc = size - *index;
93
97
 
94
 
   if (!slang_assembly_file_push_label2 (A->file, ty, dst_addr_loc, dst_offset))
 
98
   if (!slang_assembly_file_push_label2
 
99
       (A->file, ty, dst_addr_loc, dst_offset))
95
100
      return GL_FALSE;
96
 
   *index += _slang_sizeof_type (type);
 
101
   *index += _slang_sizeof_type(type);
97
102
 
98
103
   return GL_TRUE;
99
104
}
100
105
 
 
106
 
101
107
static GLboolean
102
 
assign_aggregate (slang_assemble_ctx *A, const slang_storage_aggregate *agg, GLuint *index,
103
 
                  GLuint size)
 
108
assign_aggregate(slang_assemble_ctx * A, const slang_storage_aggregate * agg,
 
109
                 GLuint * index, GLuint size)
104
110
{
105
111
   GLuint i;
106
112
 
110
116
 
111
117
      for (j = 0; j < arr->length; j++) {
112
118
         if (arr->type == slang_stor_aggregate) {
113
 
            if (!assign_aggregate (A, arr->aggregate, index, size))
 
119
            if (!assign_aggregate(A, arr->aggregate, index, size))
114
120
               return GL_FALSE;
115
121
         }
116
122
         else {
117
 
            /* When the destination is swizzled, we are forced to do float_copy, even if
118
 
             * vec4 extension is enabled with vec4_copy operation.
 
123
            /* When the destination is swizzled, we are forced to do
 
124
             * float_copy, even if vec4 extension is enabled with
 
125
             * vec4_copy operation.
119
126
             */
120
127
            if (A->swz.num_components != 0 && arr->type == slang_stor_vec4) {
121
 
               if (!assign_basic (A, slang_stor_float, index, size))
122
 
                  return GL_FALSE;
123
 
               if (!assign_basic (A, slang_stor_float, index, size))
124
 
                  return GL_FALSE;
125
 
               if (!assign_basic (A, slang_stor_float, index, size))
126
 
                  return GL_FALSE;
127
 
               if (!assign_basic (A, slang_stor_float, index, size))
 
128
               if (!assign_basic(A, slang_stor_float, index, size))
 
129
                  return GL_FALSE;
 
130
               if (!assign_basic(A, slang_stor_float, index, size))
 
131
                  return GL_FALSE;
 
132
               if (!assign_basic(A, slang_stor_float, index, size))
 
133
                  return GL_FALSE;
 
134
               if (!assign_basic(A, slang_stor_float, index, size))
128
135
                  return GL_FALSE;
129
136
            }
130
137
            else {
131
 
               if (!assign_basic (A, arr->type, index, size))
 
138
               if (!assign_basic(A, arr->type, index, size))
132
139
                  return GL_FALSE;
133
140
            }
134
141
         }
138
145
   return GL_TRUE;
139
146
}
140
147
 
141
 
GLboolean _slang_assemble_assignment (slang_assemble_ctx *A, slang_operation *op)
 
148
 
 
149
GLboolean
 
150
_slang_assemble_assignment(slang_assemble_ctx * A, const slang_operation * op)
142
151
{
143
 
        slang_assembly_typeinfo ti;
144
 
        GLboolean result = GL_FALSE;
145
 
        slang_storage_aggregate agg;
146
 
        GLuint index, size;
147
 
 
148
 
        if (!slang_assembly_typeinfo_construct (&ti))
149
 
                return GL_FALSE;
150
 
        if (!_slang_typeof_operation (A, op, &ti))
151
 
                goto end1;
152
 
 
153
 
        if (!slang_storage_aggregate_construct (&agg))
154
 
                goto end1;
155
 
        if (!_slang_aggregate_variable (&agg, &ti.spec, 0, A->space.funcs, A->space.structs,
156
 
                        A->space.vars, A->mach, A->file, A->atoms))
157
 
                goto end;
158
 
 
159
 
        index = 0;
160
 
        size = _slang_sizeof_aggregate (&agg);
161
 
        result = assign_aggregate (A, &agg, &index, size);
162
 
 
163
 
end1:
164
 
        slang_storage_aggregate_destruct (&agg);
165
 
end:
166
 
        slang_assembly_typeinfo_destruct (&ti);
167
 
        return result;
 
152
   slang_assembly_typeinfo ti;
 
153
   GLboolean result = GL_FALSE;
 
154
   slang_storage_aggregate agg;
 
155
   GLuint index, size;
 
156
 
 
157
   if (!slang_assembly_typeinfo_construct(&ti))
 
158
      return GL_FALSE;
 
159
   if (!_slang_typeof_operation(A, op, &ti))
 
160
      goto end1;
 
161
 
 
162
   if (!slang_storage_aggregate_construct(&agg))
 
163
      goto end1;
 
164
   if (!_slang_aggregate_variable(&agg, &ti.spec, 0, A->space.funcs,
 
165
                                  A->space.structs, A->space.vars,
 
166
                                  A->mach, A->file, A->atoms))
 
167
      goto end;
 
168
 
 
169
   index = 0;
 
170
   size = _slang_sizeof_aggregate(&agg);
 
171
   result = assign_aggregate(A, &agg, &index, size);
 
172
 
 
173
 end1:
 
174
   slang_storage_aggregate_destruct(&agg);
 
175
 end:
 
176
   slang_assembly_typeinfo_destruct(&ti);
 
177
   return result;
168
178
}
169
179
 
170
 
/*
171
 
 * _slang_assemble_assign()
172
 
 *
173
 
 * Performs unary (pre ++ and --) or binary (=, +=, -=, *=, /=) assignment on the operation's
174
 
 * children.
 
180
 
 
181
/**
 
182
 * Performs unary (pre ++ and --) or binary (=, +=, -=, *=, /=)
 
183
 * assignment on the operation's children.
175
184
 */
176
 
 
177
 
GLboolean _slang_assemble_assign (slang_assemble_ctx *A, slang_operation *op, const char *oper,
178
 
        slang_ref_type ref)
 
185
GLboolean
 
186
_slang_assemble_assign(slang_assemble_ctx * A, slang_operation * op,
 
187
                       const char *oper, slang_ref_type ref)
179
188
{
180
 
        slang_swizzle swz;
181
 
 
182
 
        if (ref == slang_ref_forbid)
183
 
        {
184
 
                if (!slang_assembly_file_push_label2 (A->file, slang_asm_local_addr, A->local.addr_tmp, 4))
185
 
                        return GL_FALSE;
186
 
        }
187
 
 
188
 
        if (slang_string_compare ("=", oper) == 0)
189
 
        {
190
 
                if (!_slang_assemble_operation (A, &op->children[0], slang_ref_force))
191
 
                        return GL_FALSE;
192
 
                swz = A->swz;
193
 
                if (!_slang_assemble_operation (A, &op->children[1], slang_ref_forbid))
194
 
                        return GL_FALSE;
195
 
                A->swz = swz;
196
 
                if (!_slang_assemble_assignment (A, op->children))
197
 
                        return GL_FALSE;
198
 
        }
199
 
        else
200
 
        {
201
 
                if (!_slang_assemble_function_call_name (A, oper, op->children, op->num_children, GL_TRUE))
202
 
                        return GL_FALSE;
203
 
        }
204
 
 
205
 
        if (ref == slang_ref_forbid)
206
 
        {
207
 
                if (!slang_assembly_file_push (A->file, slang_asm_addr_copy))
208
 
                        return GL_FALSE;
209
 
                if (!slang_assembly_file_push_label (A->file, slang_asm_local_free, 4))
210
 
                        return GL_FALSE;
211
 
                if (!_slang_dereference (A, op->children))
212
 
                        return GL_FALSE;
213
 
        }
214
 
 
215
 
        return GL_TRUE;
 
189
   slang_swizzle swz;
 
190
 
 
191
   if (ref == slang_ref_forbid) {
 
192
      if (!slang_assembly_file_push_label2
 
193
          (A->file, slang_asm_local_addr, A->local.addr_tmp, 4))
 
194
         return GL_FALSE;
 
195
   }
 
196
 
 
197
   if (slang_string_compare("=", oper) == 0) {
 
198
      if (!_slang_assemble_operation(A, &op->children[0], slang_ref_force))
 
199
         return GL_FALSE;
 
200
      swz = A->swz;
 
201
      if (!_slang_assemble_operation(A, &op->children[1], slang_ref_forbid))
 
202
         return GL_FALSE;
 
203
      A->swz = swz;
 
204
      if (!_slang_assemble_assignment(A, op->children))
 
205
         return GL_FALSE;
 
206
   }
 
207
   else {
 
208
      if (!_slang_assemble_function_call_name
 
209
          (A, oper, op->children, op->num_children, GL_TRUE))
 
210
         return GL_FALSE;
 
211
   }
 
212
 
 
213
   if (ref == slang_ref_forbid) {
 
214
      if (!slang_assembly_file_push(A->file, slang_asm_addr_copy))
 
215
         return GL_FALSE;
 
216
      if (!slang_assembly_file_push_label(A->file, slang_asm_local_free, 4))
 
217
         return GL_FALSE;
 
218
      if (!_slang_dereference(A, op->children))
 
219
         return GL_FALSE;
 
220
   }
 
221
 
 
222
   return GL_TRUE;
216
223
}
217