6
6
#include " odin_globals.h"
7
7
#include " odin_types.h"
8
8
#include " ast_util.h"
9
+ #include " ast_elaborate.h"
9
10
#include " parse_making_ast.h"
10
11
#include " odin_util.h"
11
12
#include " vtr_memory.h"
@@ -20,12 +21,12 @@ long find_module_instance(ast_node_t *ast_module, char *instance_name, ast_node_
20
21
/*
21
22
* (function: unroll_loops)
22
23
*/
23
- void unroll_loops (ast_node_t **ast_module)
24
+ void unroll_loops (ast_node_t **ast_module, STRING_CACHE_LIST *local_string_cache_list )
24
25
{
25
26
ast_node_t **removed_instances = NULL ;
26
27
int num_removed = 0 ;
27
28
28
- ast_node_t * module = for_preprocessor ((*ast_module), (*ast_module), &removed_instances, &num_removed);
29
+ ast_node_t * module = for_preprocessor ((*ast_module), (*ast_module), local_string_cache_list, &removed_instances, &num_removed);
29
30
30
31
for (int i = 0 ; i < num_removed; i++)
31
32
{
@@ -52,7 +53,7 @@ void update_module_instantiations(ast_node_t *ast_module, ast_node_t ****new_ins
52
53
if ((idx = find_module_instance (ast_module, instance_name, module_instantiations, module_instantiations_size)) != -1 )
53
54
{
54
55
(*removed_instances) = (ast_node_t **)vtr::realloc ((*removed_instances), sizeof (ast_node_t *)*((*num_removed)+1 ));
55
- (*removed_instances)[*num_removed] = ( *module_instantiations)[idx];
56
+ (*removed_instances)[*num_removed] = ast_node_deep_copy (( *module_instantiations)[idx]) ;
56
57
(*num_removed)++;
57
58
58
59
(*module_instantiations) = expand_node_list_at (*module_instantiations, *module_instantiations_size, (*num_unrolled) - 1 , idx + 1 );
@@ -142,7 +143,7 @@ long find_module_instance(ast_node_t *ast_module, char *instance_name, ast_node_
142
143
/*
143
144
* (function: for_preprocessor)
144
145
*/
145
- ast_node_t * for_preprocessor (ast_node_t *ast_module, ast_node_t * node, ast_node_t ***removed_instances, int *num_removed)
146
+ ast_node_t * for_preprocessor (ast_node_t *ast_module, ast_node_t * node, STRING_CACHE_LIST *local_string_cache_list, ast_node_t ***removed_instances, int *num_removed)
146
147
{
147
148
if (!node)
148
149
return nullptr ;
@@ -158,7 +159,7 @@ ast_node_t* for_preprocessor(ast_node_t *ast_module, ast_node_t* node, ast_node_
158
159
ast_node_t * new_node = NULL ;
159
160
if (for_loops)
160
161
{
161
- new_node = replace_fors (ast_module, node, removed_instances, num_removed);
162
+ new_node = replace_fors (ast_module, node, local_string_cache_list, removed_instances, num_removed);
162
163
}
163
164
else
164
165
{
@@ -169,7 +170,7 @@ ast_node_t* for_preprocessor(ast_node_t *ast_module, ast_node_t* node, ast_node_
169
170
{
170
171
/* Run this function recursively on the children */
171
172
for (int i=0 ; i<new_node->num_children ; i++){
172
- ast_node_t * new_child = for_preprocessor (ast_module, new_node->children [i], removed_instances, num_removed);
173
+ ast_node_t * new_child = for_preprocessor (ast_module, new_node->children [i], local_string_cache_list, removed_instances, num_removed);
173
174
174
175
/* Cleanup replaced child */
175
176
if (new_node->children [i] != new_child){
@@ -185,7 +186,7 @@ ast_node_t* for_preprocessor(ast_node_t *ast_module, ast_node_t* node, ast_node_
185
186
/*
186
187
* (function: replace_fors)
187
188
*/
188
- ast_node_t * replace_fors (ast_node_t *ast_module, ast_node_t * node, ast_node_t ***removed_instances, int *num_removed)
189
+ ast_node_t * replace_fors (ast_node_t *ast_module, ast_node_t * node, STRING_CACHE_LIST *local_string_cache_list, ast_node_t ***removed_instances, int *num_removed)
189
190
{
190
191
oassert (!is_for_node (node));
191
192
oassert (node != nullptr );
@@ -204,7 +205,7 @@ ast_node_t* replace_fors(ast_node_t *ast_module, ast_node_t* node, ast_node_t **
204
205
int num_unrolled_module_instances = 0 ;
205
206
int num_original_module_instances = 0 ;
206
207
207
- ast_node_t * unrolled_for = resolve_for (ast_module, new_node->children [i], &unrolled_module_instances, &num_unrolled_module_instances, &num_original_module_instances);
208
+ ast_node_t * unrolled_for = resolve_for (ast_module, new_node->children [i], local_string_cache_list, &unrolled_module_instances, &num_unrolled_module_instances, &num_original_module_instances);
208
209
oassert (unrolled_for != nullptr );
209
210
free_whole_tree (new_node->children [i]);
210
211
new_node->children [i] = unrolled_for;
@@ -231,7 +232,7 @@ ast_node_t* replace_fors(ast_node_t *ast_module, ast_node_t* node, ast_node_t **
231
232
/*
232
233
* (function: resolve_for)
233
234
*/
234
- ast_node_t * resolve_for (ast_node_t *ast_module, ast_node_t * node, ast_node_t ****instances, int *num_unrolled, int *num_original)
235
+ ast_node_t * resolve_for (ast_node_t *ast_module, ast_node_t * node, STRING_CACHE_LIST *local_string_cache_list, ast_node_t ****instances, int *num_unrolled, int *num_original)
235
236
{
236
237
oassert (is_for_node (node));
237
238
oassert (node != nullptr );
@@ -285,6 +286,8 @@ ast_node_t* resolve_for(ast_node_t *ast_module, ast_node_t* node, ast_node_t ***
285
286
}
286
287
287
288
free_whole_tree (value);
289
+
290
+ body_parent = reduce_expressions (body_parent, local_string_cache_list, NULL , 0 );
288
291
return body_parent;
289
292
}
290
293
0 commit comments