Skip to content

Commit 23fd3c6

Browse files
emacdo12jeanlego
authored andcommitted
Odin: moved identifier_node to a unique entry in ast_node_t
1 parent f34d28c commit 23fd3c6

15 files changed

+752
-708
lines changed

ODIN_II/SRC/adders.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1254,17 +1254,22 @@ void instantiate_add_w_carry_block(int* width, nnode_t* node, short mark, netlis
12541254
}
12551255
}
12561256

1257+
/*---------------------------------------------------------------------------------------------
1258+
* instance name = node->identifier_node
1259+
* instance list = instance->children[0]
1260+
* named port connections = connect list->children[n]->identifier_node
1261+
*-------------------------------------------------------------------------------------------*/
12571262
bool is_ast_adder(ast_node_t* node) {
12581263
bool is_adder;
1259-
ast_node_t* instance = node->children[1];
1260-
is_adder = (!strcmp(node->children[0]->types.identifier, "adder"))
1261-
&& (instance->children[1]->num_children == 5);
1264+
ast_node_t* instance = node->children[0];
1265+
is_adder = (!strcmp(node->identifier_node->types.identifier, "adder"))
1266+
&& (instance->children[0]->num_children == 4);
12621267

1263-
ast_node_t* connect_list = instance->children[1];
1264-
if (is_adder && connect_list->children[0]->children[0]) {
1268+
ast_node_t* connect_list = instance->children[0];
1269+
if (is_adder && connect_list->children[0]->identifier_node) {
12651270
/* port connections were passed by name; verify port names */
12661271
for (int i = 0; i < connect_list->num_children && is_adder; i++) {
1267-
char* id = connect_list->children[i]->children[0]->types.identifier;
1272+
char* id = connect_list->children[i]->identifier_node->types.identifier;
12681273

12691274
if ((strcmp(id, "a") != 0) && (strcmp(id, "b") != 0) && (strcmp(id, "cin") != 0) && (strcmp(id, "cout") != 0) && (strcmp(id, "sumout") != 0)) {
12701275
is_adder = false;

ODIN_II/SRC/ast_elaborate.cpp

Lines changed: 152 additions & 163 deletions
Large diffs are not rendered by default.

ODIN_II/SRC/ast_loop_unroll.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -370,8 +370,8 @@ ast_node_t* dup_and_fill_body(ast_node_t* body, ast_node_t* pre, ast_node_t** va
370370
}
371371
} else if (child->type == MODULE_INSTANCE && child->children[0]->type != MODULE_INSTANCE) {
372372
/* find and replace iteration symbol for port connections and parameters */
373-
ast_node_t* named_instance = child->children[1];
374-
copy->children[i]->children[1] = dup_and_fill_body(named_instance, pre, value, error_code);
373+
ast_node_t* named_instance = child->children[0];
374+
copy->children[i]->children[0] = dup_and_fill_body(named_instance, pre, value, error_code);
375375
free_whole_tree(named_instance);
376376

377377
is_unrolled = true;

ODIN_II/SRC/ast_util.cpp

Lines changed: 50 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ ast_node_t* create_node_w_type(ids id, loc_t loc) {
155155
new_node->types.identifier = NULL;
156156
new_node->types.hierarchy = NULL;
157157
new_node->chunk_size = 1;
158+
new_node->identifier_node = NULL;
158159
/* reset flags */
159160
new_node->types.variable.is_parameter = false;
160161
new_node->types.variable.is_string = false;
@@ -179,8 +180,12 @@ ast_node_t* create_node_w_type(ids id, loc_t loc) {
179180
*-------------------------------------------------------------------------*/
180181
void free_assignement_of_node_keep_tree(ast_node_t* node) {
181182
if (node) {
182-
int i;
183+
/* nuke the identifier node first */
184+
node->identifier_node = free_single_node(node->identifier_node);
185+
/* then free up the actual ID */
183186
vtr::free(node->types.identifier);
187+
node->types.identifier = NULL;
188+
/* check the typ and free acordingly afterwards*/
184189
switch (node->type) {
185190
case NUMBERS:
186191
if (node->types.vnumber != nullptr)
@@ -189,7 +194,7 @@ void free_assignement_of_node_keep_tree(ast_node_t* node) {
189194
break;
190195

191196
case CONCATENATE:
192-
for (i = 0; i < node->types.concat.num_bit_strings; i++) {
197+
for (int i = 0; i < node->types.concat.num_bit_strings; i++) {
193198
if (node->types.concat.bit_strings[i])
194199
vtr::free(node->types.concat.bit_strings[i]);
195200
}
@@ -422,14 +427,14 @@ void make_concat_into_list_of_strings(ast_node_t* concat_top, char* instance_nam
422427
if (var_declare == NULL) {
423428
error_message(AST, concat_top->loc, "Missing declaration of this symbol %s\n", temp_string);
424429
} else {
425-
if (var_declare->children[1] == NULL) {
430+
if (var_declare->children[0] == NULL) {
426431
concat_top->types.concat.num_bit_strings++;
427432
concat_top->types.concat.bit_strings = (char**)vtr::realloc(concat_top->types.concat.bit_strings, sizeof(char*) * (concat_top->types.concat.num_bit_strings));
428433
concat_top->types.concat.bit_strings[concat_top->types.concat.num_bit_strings - 1] = get_name_of_pin_at_bit(concat_top->children[i], -1, instance_name_prefix, local_ref);
429-
} else if (var_declare->children[3] == NULL) {
434+
} else if (var_declare->children[2] == NULL) {
430435
/* reverse thorugh the range since highest bit in index will be lower in the string indx */
431-
rnode[1] = var_declare->children[1];
432-
rnode[2] = var_declare->children[2];
436+
rnode[1] = var_declare->children[0];
437+
rnode[2] = var_declare->children[1];
433438
oassert(rnode[1]->type == NUMBERS && rnode[2]->type == NUMBERS);
434439

435440
for (j = rnode[1]->types.vnumber->get_value() - rnode[2]->types.vnumber->get_value(); j >= 0; j--) {
@@ -447,8 +452,8 @@ void make_concat_into_list_of_strings(ast_node_t* concat_top, char* instance_nam
447452
concat_top->types.concat.bit_strings = (char**)vtr::realloc(concat_top->types.concat.bit_strings, sizeof(char*) * (concat_top->types.concat.num_bit_strings));
448453
concat_top->types.concat.bit_strings[concat_top->types.concat.num_bit_strings - 1] = get_name_of_pin_at_bit(concat_top->children[i], 0, instance_name_prefix, local_ref);
449454
} else if (concat_top->children[i]->type == RANGE_REF) {
450-
rnode[1] = concat_top->children[i]->children[1];
451-
rnode[2] = concat_top->children[i]->children[2];
455+
rnode[1] = concat_top->children[i]->children[0];
456+
rnode[2] = concat_top->children[i]->children[1];
452457
oassert(rnode[1]->type == NUMBERS && rnode[2]->type == NUMBERS);
453458
oassert(rnode[1]->types.vnumber->get_value() >= rnode[2]->types.vnumber->get_value());
454459
int width = abs(rnode[1]->types.vnumber->get_value() - rnode[2]->types.vnumber->get_value()) + 1;
@@ -519,13 +524,13 @@ char* get_name_of_var_declare_at_bit(ast_node_t* var_declare, int bit) {
519524
char* return_string = NULL;
520525

521526
/* calculate the port details */
522-
if (var_declare->children[1] == NULL) {
527+
if (var_declare->children[0] == NULL) {
523528
oassert(bit == 0);
524-
return_string = make_full_ref_name(NULL, NULL, NULL, var_declare->children[0]->types.identifier, -1);
525-
} else if (var_declare->children[3] == NULL) {
526-
oassert(var_declare->children[2]->type == NUMBERS);
527-
return_string = make_full_ref_name(NULL, NULL, NULL, var_declare->children[0]->types.identifier, var_declare->children[2]->types.vnumber->get_value() + bit);
528-
} else if (var_declare->children[3] != NULL) {
529+
return_string = make_full_ref_name(NULL, NULL, NULL, var_declare->identifier_node->types.identifier, -1);
530+
} else if (var_declare->children[2] == NULL) {
531+
oassert(var_declare->children[1]->type == NUMBERS);
532+
return_string = make_full_ref_name(NULL, NULL, NULL, var_declare->identifier_node->types.identifier, var_declare->children[1]->types.vnumber->get_value() + bit);
533+
} else if (var_declare->children[2] != NULL) {
529534
/* MEMORY output */
530535
oassert(false);
531536
}
@@ -539,7 +544,7 @@ char* get_name_of_var_declare_at_bit(ast_node_t* var_declare, int bit) {
539544
*-------------------------------------------------------------------------------------------*/
540545
char* get_identifier(ast_node_t* node) {
541546
if (node->type == ARRAY_REF || node->type == RANGE_REF) {
542-
return node->children[0]->types.identifier;
547+
return node->identifier_node->types.identifier;
543548
} else {
544549
oassert(node->type == IDENTIFIERS);
545550
return node->types.identifier;
@@ -551,27 +556,29 @@ char* get_identifier(ast_node_t* node) {
551556
* Assume module connections can be one of: Array entry, Concat, Signal, Array range reference
552557
*-------------------------------------------------------------------------------------------*/
553558
char* get_name_of_pin_at_bit(ast_node_t* var_node, int bit, char* instance_name_prefix, sc_hierarchy* local_ref) {
559+
oassert(var_node);
560+
554561
char* return_string = NULL;
555562
ast_node_t* rnode[3] = {0};
556563

557564
// STRING_CACHE *local_symbol_table_sc = local_ref->local_symbol_table_sc;
558565

559566
if (var_node->type == ARRAY_REF) {
560-
oassert(var_node->children[0]->type == IDENTIFIERS);
561-
oassert(var_node->children[1]->type == NUMBERS);
562-
return_string = make_full_ref_name(NULL, NULL, NULL, var_node->children[0]->types.identifier, (int)var_node->children[1]->types.vnumber->get_value());
567+
oassert(var_node->identifier_node != NULL);
568+
oassert(var_node->children[0]->type == NUMBERS);
569+
return_string = make_full_ref_name(NULL, NULL, NULL, var_node->identifier_node->types.identifier, (int)var_node->children[0]->types.vnumber->get_value());
563570
} else if (var_node->type == RANGE_REF) {
564571
oassert(bit >= 0);
565572

566-
rnode[1] = var_node->children[1];
567-
rnode[2] = var_node->children[2];
573+
rnode[1] = var_node->children[0];
574+
rnode[2] = var_node->children[1];
568575

569-
oassert(var_node->children[0]->type == IDENTIFIERS);
576+
oassert(var_node->identifier_node != NULL);
570577
oassert(rnode[1]->type == NUMBERS);
571578
oassert(rnode[2]->type == NUMBERS);
572579
oassert(rnode[1]->types.vnumber->get_value() >= rnode[2]->types.vnumber->get_value() + bit);
573580

574-
return_string = make_full_ref_name(NULL, NULL, NULL, var_node->children[0]->types.identifier, rnode[2]->types.vnumber->get_value() + bit);
581+
return_string = make_full_ref_name(NULL, NULL, NULL, var_node->identifier_node->types.identifier, rnode[2]->types.vnumber->get_value() + bit);
575582
} else if ((var_node->type == IDENTIFIERS) && (bit == -1)) {
576583
return_string = make_full_ref_name(NULL, NULL, NULL, var_node->types.identifier, -1);
577584
} else if (var_node->type == IDENTIFIERS) {
@@ -582,11 +589,11 @@ char* get_name_of_pin_at_bit(ast_node_t* var_node, int bit, char* instance_name_
582589
error_message(AST, var_node->loc, "Missing declaration of this symbol %s\n", var_node->types.identifier);
583590
}
584591

585-
if (symbol_node->children[1] == NULL) {
592+
if (symbol_node->children[0] == NULL) {
586593
pin_index = bit;
587-
} else if (symbol_node->children[3] == NULL) {
588-
oassert(symbol_node->children[2]->type == NUMBERS);
589-
pin_index = symbol_node->children[2]->types.vnumber->get_value() + bit;
594+
} else if (symbol_node->children[2] == NULL) {
595+
oassert(symbol_node->children[1]->type == NUMBERS);
596+
pin_index = symbol_node->children[1]->types.vnumber->get_value() + bit;
590597
} else
591598
oassert(false);
592599

@@ -677,15 +684,15 @@ char_list_t* get_name_of_pins(ast_node_t* var_node, char* instance_name_prefix,
677684
width = 1;
678685
return_string = (char**)vtr::malloc(sizeof(char*));
679686

680-
rnode[1] = var_node->children[1];
687+
rnode[1] = var_node->children[0];
681688
oassert(rnode[1] && rnode[1]->type == NUMBERS);
682-
oassert(var_node->children[0]->type == IDENTIFIERS);
689+
oassert(var_node->identifier_node != NULL);
683690

684-
return_string[0] = make_full_ref_name(NULL, NULL, NULL, var_node->children[0]->types.identifier, rnode[1]->types.vnumber->get_value());
691+
return_string[0] = make_full_ref_name(NULL, NULL, NULL, var_node->identifier_node->types.identifier, rnode[1]->types.vnumber->get_value());
685692
} else if (var_node->type == RANGE_REF) {
686-
rnode[0] = var_node->children[0];
687-
rnode[1] = var_node->children[1];
688-
rnode[2] = var_node->children[2];
693+
rnode[0] = var_node->identifier_node;
694+
rnode[1] = var_node->children[0];
695+
rnode[2] = var_node->children[1];
689696

690697
oassert(rnode[1]->type == NUMBERS && rnode[2]->type == NUMBERS);
691698
width = abs(rnode[1]->types.vnumber->get_value() - rnode[2]->types.vnumber->get_value()) + 1;
@@ -710,15 +717,15 @@ char_list_t* get_name_of_pins(ast_node_t* var_node, char* instance_name_prefix,
710717
vtr::free(temp_string);
711718

712719
if (sym_node && sym_node->children && sym_node->type) {
713-
if (sym_node->children[1] == NULL || sym_node->type == BLOCKING_STATEMENT) {
720+
if (sym_node->children[0] == NULL || sym_node->type == BLOCKING_STATEMENT) {
714721
width = 1;
715722
return_string = (char**)vtr::malloc(sizeof(char*) * width);
716723
return_string[0] = make_full_ref_name(NULL, NULL, NULL, var_node->types.identifier, -1);
717-
} else if (sym_node->children[2] != NULL && sym_node->children[3] == NULL) {
724+
} else if (sym_node->children[1] != NULL && sym_node->children[2] == NULL) {
718725
int index = 0;
719726

720-
rnode[1] = sym_node->children[1];
721-
rnode[2] = sym_node->children[2];
727+
rnode[1] = sym_node->children[0];
728+
rnode[2] = sym_node->children[1];
722729
oassert(rnode[1]->type == NUMBERS && rnode[2]->type == NUMBERS);
723730

724731
width = (rnode[1]->types.vnumber->get_value() - rnode[2]->types.vnumber->get_value() + 1);
@@ -731,7 +738,7 @@ char_list_t* get_name_of_pins(ast_node_t* var_node, char* instance_name_prefix,
731738
}
732739
}
733740

734-
else if (sym_node->children[3] != NULL) {
741+
else if (sym_node->children[2] != NULL) {
735742
oassert(false);
736743
}
737744
}
@@ -821,13 +828,7 @@ long get_size_of_variable(ast_node_t* node, sc_hierarchy* local_ref) {
821828
} break;
822829

823830
case ARRAY_REF: {
824-
ast_node_t* sym_node = resolve_hierarchical_name_reference(local_ref, node->children[0]->types.identifier);
825-
if (sym_node != NULL) {
826-
var_declare = sym_node;
827-
break;
828-
}
829-
830-
error_message(AST, node->children[0]->loc, "Missing declaration of this symbol %s\n", node->children[0]->types.identifier);
831+
assignment_size = get_size_of_variable(node->identifier_node, local_ref);
831832
} break;
832833

833834
case RANGE_REF: {
@@ -844,11 +845,11 @@ long get_size_of_variable(ast_node_t* node, sc_hierarchy* local_ref) {
844845
break;
845846
}
846847

847-
if (var_declare && !(var_declare->children[1])) {
848+
if (var_declare && !(var_declare->children[0])) {
848849
assignment_size = 1;
849-
} else if (var_declare && var_declare->children[1] && var_declare->children[2]) {
850-
ast_node_t* node_max = var_declare->children[1];
851-
ast_node_t* node_min = var_declare->children[2];
850+
} else if (var_declare && var_declare->children[0] && var_declare->children[1]) {
851+
ast_node_t* node_max = var_declare->children[0];
852+
ast_node_t* node_min = var_declare->children[1];
852853

853854
oassert(node_min->type == NUMBERS && node_max->type == NUMBERS);
854855
long range_max = node_max->types.vnumber->get_value();
@@ -922,6 +923,7 @@ ast_node_t* ast_node_copy(ast_node_t* node) {
922923
node_copy->types.vnumber = new VNumber((*node->types.vnumber));
923924

924925
node_copy->types.identifier = vtr::strdup(node->types.identifier);
926+
node_copy->identifier_node = ast_node_deep_copy(node_copy->identifier_node);
925927
node_copy->children = NULL;
926928

927929
return node_copy;

ODIN_II/SRC/hard_blocks.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,12 +133,12 @@ void define_hard_block(nnode_t* node, FILE* out) {
133133
oassert(node->output_port_sizes[0] > 0);
134134

135135
//IF the hard_blocks is an adder or a multiplier, we ignore it.(Already print out in define_add_function and define_mult_function)
136-
if (strcmp(node->related_ast_node->children[0]->types.identifier, "multiply") == 0 || strcmp(node->related_ast_node->children[0]->types.identifier, "adder") == 0)
136+
if (strcmp(node->related_ast_node->identifier_node->types.identifier, "multiply") == 0 || strcmp(node->related_ast_node->identifier_node->types.identifier, "adder") == 0)
137137
return;
138138

139139
count = fprintf(out, "\n.subckt ");
140140
count--;
141-
count += fprintf(out, "%s", node->related_ast_node->children[0]->types.identifier);
141+
count += fprintf(out, "%s", node->related_ast_node->identifier_node->types.identifier);
142142

143143
/* print the input port mappings */
144144
port = index = 0;

ODIN_II/SRC/hierarchy_util.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ sc_hierarchy* copy_sc_hierarchy(sc_hierarchy* to_copy) {
5454
for (int i = 0; i < hierarchy->num_local_symbol_table; i++) {
5555
hierarchy->local_symbol_table[i] = ast_node_deep_copy(to_copy->local_symbol_table[i]);
5656

57-
char* identifier = hierarchy->local_symbol_table[i]->children[0]->types.identifier;
57+
char* identifier = hierarchy->local_symbol_table[i]->identifier_node->types.identifier;
5858
long sc_spot = sc_add_string(hierarchy->local_symbol_table_sc, identifier);
5959
hierarchy->local_symbol_table_sc->data[sc_spot] = (void*)hierarchy->local_symbol_table[i];
6060
}

0 commit comments

Comments
 (0)