Skip to content

Commit 9f7e882

Browse files
authored
Merge pull request #819 from CAS-Atlantic/move_resolve_node
ODIN II: initial AST elaboration refactoring
2 parents 2c07068 + d7c462c commit 9f7e882

File tree

8 files changed

+594
-514
lines changed

8 files changed

+594
-514
lines changed

ODIN_II/SRC/ast_elaborate.cpp

Lines changed: 418 additions & 6 deletions
Large diffs are not rendered by default.

ODIN_II/SRC/ast_loop_unroll.cpp

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "odin_globals.h"
77
#include "odin_types.h"
88
#include "ast_util.h"
9+
#include "ast_elaborate.h"
910
#include "parse_making_ast.h"
1011
#include "odin_util.h"
1112
#include "vtr_memory.h"
@@ -20,12 +21,12 @@ long find_module_instance(ast_node_t *ast_module, char *instance_name, ast_node_
2021
/*
2122
* (function: unroll_loops)
2223
*/
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)
2425
{
2526
ast_node_t **removed_instances = NULL;
2627
int num_removed = 0;
2728

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);
2930

3031
for (int i = 0; i < num_removed; i++)
3132
{
@@ -52,7 +53,7 @@ void update_module_instantiations(ast_node_t *ast_module, ast_node_t ****new_ins
5253
if ((idx = find_module_instance(ast_module, instance_name, module_instantiations, module_instantiations_size)) != -1)
5354
{
5455
(*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]);
5657
(*num_removed)++;
5758

5859
(*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_
142143
/*
143144
* (function: for_preprocessor)
144145
*/
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)
146147
{
147148
if(!node)
148149
return nullptr;
@@ -158,7 +159,7 @@ ast_node_t* for_preprocessor(ast_node_t *ast_module, ast_node_t* node, ast_node_
158159
ast_node_t* new_node = NULL;
159160
if(for_loops)
160161
{
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);
162163
}
163164
else
164165
{
@@ -169,7 +170,7 @@ ast_node_t* for_preprocessor(ast_node_t *ast_module, ast_node_t* node, ast_node_
169170
{
170171
/* Run this function recursively on the children */
171172
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);
173174

174175
/* Cleanup replaced child */
175176
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_
185186
/*
186187
* (function: replace_fors)
187188
*/
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)
189190
{
190191
oassert(!is_for_node(node));
191192
oassert(node != nullptr);
@@ -204,7 +205,7 @@ ast_node_t* replace_fors(ast_node_t *ast_module, ast_node_t* node, ast_node_t **
204205
int num_unrolled_module_instances = 0;
205206
int num_original_module_instances = 0;
206207

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);
208209
oassert(unrolled_for != nullptr);
209210
free_whole_tree(new_node->children[i]);
210211
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 **
231232
/*
232233
* (function: resolve_for)
233234
*/
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)
235236
{
236237
oassert(is_for_node(node));
237238
oassert(node != nullptr);
@@ -285,6 +286,8 @@ ast_node_t* resolve_for(ast_node_t *ast_module, ast_node_t* node, ast_node_t ***
285286
}
286287

287288
free_whole_tree(value);
289+
290+
body_parent = reduce_expressions(body_parent, local_string_cache_list, NULL, 0);
288291
return body_parent;
289292
}
290293

0 commit comments

Comments
 (0)