Skip to content

ODIN II: initial AST elaboration refactoring #819

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jul 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
424 changes: 418 additions & 6 deletions ODIN_II/SRC/ast_elaborate.cpp

Large diffs are not rendered by default.

21 changes: 12 additions & 9 deletions ODIN_II/SRC/ast_loop_unroll.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "odin_globals.h"
#include "odin_types.h"
#include "ast_util.h"
#include "ast_elaborate.h"
#include "parse_making_ast.h"
#include "odin_util.h"
#include "vtr_memory.h"
Expand All @@ -20,12 +21,12 @@ long find_module_instance(ast_node_t *ast_module, char *instance_name, ast_node_
/*
* (function: unroll_loops)
*/
void unroll_loops(ast_node_t **ast_module)
void unroll_loops(ast_node_t **ast_module, STRING_CACHE_LIST *local_string_cache_list)
{
ast_node_t **removed_instances = NULL;
int num_removed = 0;

ast_node_t* module = for_preprocessor((*ast_module), (*ast_module), &removed_instances, &num_removed);
ast_node_t* module = for_preprocessor((*ast_module), (*ast_module), local_string_cache_list, &removed_instances, &num_removed);

for (int i = 0; i < num_removed; i++)
{
Expand All @@ -52,7 +53,7 @@ void update_module_instantiations(ast_node_t *ast_module, ast_node_t ****new_ins
if ((idx = find_module_instance(ast_module, instance_name, module_instantiations, module_instantiations_size)) != -1)
{
(*removed_instances) = (ast_node_t **)vtr::realloc((*removed_instances), sizeof(ast_node_t*)*((*num_removed)+1));
(*removed_instances)[*num_removed] = (*module_instantiations)[idx];
(*removed_instances)[*num_removed] = ast_node_deep_copy((*module_instantiations)[idx]);
(*num_removed)++;

(*module_instantiations) = expand_node_list_at(*module_instantiations, *module_instantiations_size, (*num_unrolled) - 1, idx + 1);
Expand Down Expand Up @@ -142,7 +143,7 @@ long find_module_instance(ast_node_t *ast_module, char *instance_name, ast_node_
/*
* (function: for_preprocessor)
*/
ast_node_t* for_preprocessor(ast_node_t *ast_module, ast_node_t* node, ast_node_t ***removed_instances, int *num_removed)
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)
{
if(!node)
return nullptr;
Expand All @@ -158,7 +159,7 @@ ast_node_t* for_preprocessor(ast_node_t *ast_module, ast_node_t* node, ast_node_
ast_node_t* new_node = NULL;
if(for_loops)
{
new_node = replace_fors(ast_module, node, removed_instances, num_removed);
new_node = replace_fors(ast_module, node, local_string_cache_list, removed_instances, num_removed);
}
else
{
Expand All @@ -169,7 +170,7 @@ ast_node_t* for_preprocessor(ast_node_t *ast_module, ast_node_t* node, ast_node_
{
/* Run this function recursively on the children */
for(int i=0; i<new_node->num_children; i++){
ast_node_t* new_child = for_preprocessor(ast_module, new_node->children[i], removed_instances, num_removed);
ast_node_t* new_child = for_preprocessor(ast_module, new_node->children[i], local_string_cache_list, removed_instances, num_removed);

/* Cleanup replaced child */
if(new_node->children[i] != new_child){
Expand All @@ -185,7 +186,7 @@ ast_node_t* for_preprocessor(ast_node_t *ast_module, ast_node_t* node, ast_node_
/*
* (function: replace_fors)
*/
ast_node_t* replace_fors(ast_node_t *ast_module, ast_node_t* node, ast_node_t ***removed_instances, int *num_removed)
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)
{
oassert(!is_for_node(node));
oassert(node != nullptr);
Expand All @@ -204,7 +205,7 @@ ast_node_t* replace_fors(ast_node_t *ast_module, ast_node_t* node, ast_node_t **
int num_unrolled_module_instances = 0;
int num_original_module_instances = 0;

ast_node_t* unrolled_for = resolve_for(ast_module, new_node->children[i], &unrolled_module_instances, &num_unrolled_module_instances, &num_original_module_instances);
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);
oassert(unrolled_for != nullptr);
free_whole_tree(new_node->children[i]);
new_node->children[i] = unrolled_for;
Expand All @@ -231,7 +232,7 @@ ast_node_t* replace_fors(ast_node_t *ast_module, ast_node_t* node, ast_node_t **
/*
* (function: resolve_for)
*/
ast_node_t* resolve_for(ast_node_t *ast_module, ast_node_t* node, ast_node_t ****instances, int *num_unrolled, int *num_original)
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)
{
oassert(is_for_node(node));
oassert(node != nullptr);
Expand Down Expand Up @@ -285,6 +286,8 @@ ast_node_t* resolve_for(ast_node_t *ast_module, ast_node_t* node, ast_node_t ***
}

free_whole_tree(value);

body_parent = reduce_expressions(body_parent, local_string_cache_list, NULL, 0);
return body_parent;
}

Expand Down
Loading