2 * Mesa 3-D graphics library
5 * Copyright (C) 2005 Brian Paul All Rights Reserved.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 * \file slang_assemble_assignment.c
27 * slang assignment expressions assembler
32 #include "slang_assemble_assignment.h"
33 #include "slang_assemble_typeinfo.h"
34 #include "slang_storage.h"
35 #include "slang_utility.h"
38 _slang_assemble_assignment()
40 copies values on the stack (<component 0> to <component N-1>) to a memory
41 location pointed by <addr of variable>;
57 /* TODO: add support for swizzle mask */
58 static int assign_aggregate (slang_assembly_file
*file
, const slang_storage_aggregate
*agg
,
59 unsigned int *index
, unsigned int size
, slang_assembly_local_info
*info
)
63 for (i
= 0; i
< agg
->count
; i
++)
65 const slang_storage_array
*arr
= agg
->arrays
+ i
;
68 for (j
= 0; j
< arr
->length
; j
++)
70 if (arr
->type
== slang_stor_aggregate
)
72 if (!assign_aggregate (file
, arr
->aggregate
, index
, size
, info
))
77 slang_assembly_type ty
;
82 ty
= slang_asm_bool_copy
;
85 ty
= slang_asm_int_copy
;
87 case slang_stor_float
:
88 ty
= slang_asm_float_copy
;
93 if (!slang_assembly_file_push_label2 (file
, ty
, size
- *index
, *index
))
102 int _slang_assemble_assignment (slang_assembly_file
*file
, slang_operation
*op
,
103 slang_assembly_name_space
*space
, slang_assembly_local_info
*info
)
105 slang_assembly_typeinfo ti
;
107 slang_storage_aggregate agg
;
108 unsigned int index
, size
;
110 slang_assembly_typeinfo_construct (&ti
);
111 if (!_slang_typeof_operation (op
, space
, &ti
))
113 slang_assembly_typeinfo_destruct (&ti
);
117 slang_storage_aggregate_construct (&agg
);
118 if (!_slang_aggregate_variable (&agg
, &ti
.spec
, NULL
, space
->funcs
, space
->structs
))
120 slang_storage_aggregate_destruct (&agg
);
121 slang_assembly_typeinfo_destruct (&ti
);
126 size
= _slang_sizeof_aggregate (&agg
);
127 result
= assign_aggregate (file
, &agg
, &index
, size
, info
);
129 slang_storage_aggregate_destruct (&agg
);
130 slang_assembly_typeinfo_destruct (&ti
);
135 _slang_assemble_assign()
137 performs unary (pre ++ and --) or binary (=, +=, -=, *=, /=) assignment on the operation's
141 int dereference (slang_assembly_file
*file
, slang_operation
*op
,
142 slang_assembly_name_space
*space
, slang_assembly_local_info
*info
);
144 int call_function_name (slang_assembly_file
*file
, const char *name
, slang_operation
*params
,
145 unsigned int param_count
, int assignment
, slang_assembly_name_space
*space
,
146 slang_assembly_local_info
*info
);
148 int _slang_assemble_assign (slang_assembly_file
*file
, slang_operation
*op
, const char *oper
,
149 int ref
, slang_assembly_name_space
*space
, slang_assembly_local_info
*info
)
151 slang_assembly_stack_info stk
;
152 slang_assembly_flow_control flow
;
156 if (!slang_assembly_file_push_label2 (file
, slang_asm_local_addr
, info
->addr_tmp
, 4))
160 if (slang_string_compare ("=", oper
) == 0)
162 if (!_slang_assemble_operation (file
, op
->children
, 1, &flow
, space
, info
, &stk
))
164 if (!_slang_assemble_operation (file
, op
->children
+ 1, 0, &flow
, space
, info
, &stk
))
166 if (!_slang_assemble_assignment (file
, op
->children
, space
, info
))
171 if (!call_function_name (file
, oper
, op
->children
, op
->num_children
, 1, space
, info
))
177 if (!slang_assembly_file_push (file
, slang_asm_addr_copy
))
179 if (!slang_assembly_file_push_label (file
, slang_asm_local_free
, 4))
181 if (!dereference (file
, op
->children
, space
, info
))