Skip to content

Commit c446433

Browse files
authored
Merge branch 'master' into odin_leak_assignment_alias_right
2 parents 44e389d + 264e954 commit c446433

26 files changed

+860
-194
lines changed

ODIN_II/SRC/ast_util.cpp

Lines changed: 245 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -373,8 +373,8 @@ void make_concat_into_list_of_strings(ast_node_t *concat_top, char *instance_nam
373373
else if (((ast_node_t*)local_symbol_table_sc->data[sc_spot])->children[3] == NULL)
374374
{
375375
/* reverse thorugh the range since highest bit in index will be lower in the string indx */
376-
rnode[1] = resolve_node(NULL, instance_name_prefix, ((ast_node_t*)local_symbol_table_sc->data[sc_spot])->children[1]);
377-
rnode[2] = resolve_node(NULL, instance_name_prefix, ((ast_node_t*)local_symbol_table_sc->data[sc_spot])->children[2]);
376+
rnode[1] = resolve_node(NULL, instance_name_prefix, ((ast_node_t*)local_symbol_table_sc->data[sc_spot])->children[1], NULL, 0);
377+
rnode[2] = resolve_node(NULL, instance_name_prefix, ((ast_node_t*)local_symbol_table_sc->data[sc_spot])->children[2], NULL, 0);
378378
oassert(rnode[1]->type == NUMBERS && rnode[2]->type == NUMBERS);
379379

380380
///TODO WHats this?? compareo bit string but uses value ??? value is honestly not the right thing to look for...
@@ -404,8 +404,8 @@ void make_concat_into_list_of_strings(ast_node_t *concat_top, char *instance_nam
404404
}
405405
else if (concat_top->children[i]->type == RANGE_REF)
406406
{
407-
rnode[1] = resolve_node(NULL, instance_name_prefix, concat_top->children[i]->children[1]);
408-
rnode[2] = resolve_node(NULL, instance_name_prefix, concat_top->children[i]->children[2]);
407+
rnode[1] = resolve_node(NULL, instance_name_prefix, concat_top->children[i]->children[1], NULL, 0);
408+
rnode[2] = resolve_node(NULL, instance_name_prefix, concat_top->children[i]->children[2], NULL, 0);
409409
oassert(rnode[1]->type == NUMBERS && rnode[2]->type == NUMBERS);
410410
oassert(rnode[1]->types.vnumber->get_value() >= rnode[2]->types.vnumber->get_value());
411411
int width = abs(rnode[1]->types.vnumber->get_value() - rnode[2]->types.vnumber->get_value()) + 1;
@@ -448,7 +448,8 @@ void make_concat_into_list_of_strings(ast_node_t *concat_top, char *instance_nam
448448
concat_top->types.concat.bit_strings[concat_top->types.concat.num_bit_strings-1] = get_name_of_pin_at_bit(concat_top->children[i], j, instance_name_prefix);
449449
}
450450
}
451-
else {
451+
else
452+
{
452453
error_message(NETLIST_ERROR, concat_top->line_number, concat_top->file_number, "%s", "Unsupported operation within a concatenation.\n");
453454
}
454455
}
@@ -513,7 +514,7 @@ char *get_name_of_pin_at_bit(ast_node_t *var_node, int bit, char *instance_name_
513514

514515
if (var_node->type == ARRAY_REF)
515516
{
516-
var_node->children[1] = resolve_node(NULL, instance_name_prefix, var_node->children[1]);
517+
var_node->children[1] = resolve_node(NULL, instance_name_prefix, var_node->children[1], NULL, 0);
517518
oassert(var_node->children[0]->type == IDENTIFIERS);
518519
oassert(var_node->children[1]->type == NUMBERS);
519520
return_string = make_full_ref_name(NULL, NULL, NULL, var_node->children[0]->types.identifier, (int)var_node->children[1]->types.vnumber->get_value());
@@ -522,8 +523,8 @@ char *get_name_of_pin_at_bit(ast_node_t *var_node, int bit, char *instance_name_
522523
{
523524
oassert(bit >= 0);
524525

525-
rnode[1] = resolve_node(NULL, instance_name_prefix, var_node->children[1]);
526-
rnode[2] = resolve_node(NULL, instance_name_prefix, var_node->children[2]);
526+
rnode[1] = resolve_node(NULL, instance_name_prefix, var_node->children[1], NULL, 0);
527+
rnode[2] = resolve_node(NULL, instance_name_prefix, var_node->children[2], NULL, 0);
527528
oassert(var_node->children[0]->type == IDENTIFIERS);
528529
oassert(rnode[1]->type == NUMBERS);
529530
oassert(rnode[2]->type == NUMBERS);
@@ -575,6 +576,7 @@ char *get_name_of_pin_at_bit(ast_node_t *var_node, int bit, char *instance_name_
575576
if (var_node->types.concat.num_bit_strings == -1)
576577
{
577578
/* If this hasn't been made into a string list then do it */
579+
var_node = resolve_node(NULL, instance_name_prefix, var_node, NULL, 0);
578580
make_concat_into_list_of_strings(var_node, instance_name_prefix);
579581
}
580582

@@ -646,16 +648,16 @@ char_list_t *get_name_of_pins(ast_node_t *var_node, char *instance_name_prefix)
646648
{
647649
width = 1;
648650
return_string = (char**)vtr::malloc(sizeof(char*));
649-
rnode[1] = resolve_node(NULL, instance_name_prefix, var_node->children[1]);
651+
rnode[1] = resolve_node(NULL, instance_name_prefix, var_node->children[1], NULL, 0);
650652
oassert(rnode[1] && rnode[1]->type == NUMBERS);
651653
oassert(var_node->children[0]->type == IDENTIFIERS);
652654
return_string[0] = make_full_ref_name(NULL, NULL, NULL, var_node->children[0]->types.identifier, rnode[1]->types.vnumber->get_value());
653655
}
654656
else if (var_node->type == RANGE_REF)
655657
{
656-
rnode[0] = resolve_node(NULL, instance_name_prefix, var_node->children[0]);
657-
rnode[1] = resolve_node(NULL, instance_name_prefix, var_node->children[1]);
658-
rnode[2] = resolve_node(NULL, instance_name_prefix, var_node->children[2]);
658+
rnode[0] = resolve_node(NULL, instance_name_prefix, var_node->children[0], NULL, 0);
659+
rnode[1] = resolve_node(NULL, instance_name_prefix, var_node->children[1], NULL, 0);
660+
rnode[2] = resolve_node(NULL, instance_name_prefix, var_node->children[2], NULL, 0);
659661
oassert(rnode[1]->type == NUMBERS && rnode[2]->type == NUMBERS);
660662
width = abs(rnode[1]->types.vnumber->get_value() - rnode[2]->types.vnumber->get_value()) + 1;
661663
if (rnode[0]->type == IDENTIFIERS)
@@ -677,7 +679,7 @@ char_list_t *get_name_of_pins(ast_node_t *var_node, char *instance_name_prefix)
677679
ast_node_t *sym_node;
678680

679681
// try and resolve var_node
680-
sym_node = resolve_node(NULL, instance_name_prefix, var_node);
682+
sym_node = resolve_node(NULL, instance_name_prefix, var_node, NULL, 0);
681683

682684
if (sym_node == var_node)
683685
{
@@ -707,8 +709,8 @@ char_list_t *get_name_of_pins(ast_node_t *var_node, char *instance_name_prefix)
707709
else if (sym_node->children[3] == NULL)
708710
{
709711
int index = 0;
710-
rnode[1] = resolve_node(NULL, instance_name_prefix, sym_node->children[1]);
711-
rnode[2] = resolve_node(NULL, instance_name_prefix, sym_node->children[2]);
712+
rnode[1] = resolve_node(NULL, instance_name_prefix, sym_node->children[1], NULL, 0);
713+
rnode[2] = resolve_node(NULL, instance_name_prefix, sym_node->children[2], NULL, 0);
712714
oassert(rnode[1]->type == NUMBERS && rnode[2]->type == NUMBERS);
713715
width = (rnode[1]->types.vnumber->get_value() - rnode[2]->types.vnumber->get_value() + 1);
714716
return_string = (char**)vtr::malloc(sizeof(char*)*width);
@@ -747,6 +749,7 @@ char_list_t *get_name_of_pins(ast_node_t *var_node, char *instance_name_prefix)
747749
if (var_node->types.concat.num_bit_strings == -1)
748750
{
749751
/* If this hasn't been made into a string list then do it */
752+
var_node = resolve_node(NULL, instance_name_prefix, var_node, NULL, 0);
750753
make_concat_into_list_of_strings(var_node, instance_name_prefix);
751754
}
752755

@@ -793,6 +796,89 @@ char_list_t *get_name_of_pins_with_prefix(ast_node_t *var_node, char *instance_n
793796
return return_list;
794797
}
795798

799+
/*----------------------------------------------------------------------------
800+
* (function: get_size_of_variable)
801+
*--------------------------------------------------------------------------*/
802+
long get_size_of_variable(ast_node_t *node, char *instance_name_prefix, STRING_CACHE *local_sym_table_sc, STRING_CACHE *function_local_sym_table_sc)
803+
{
804+
long assignment_size = 0;
805+
long sc_spot = 0;
806+
ast_node_t *var_declare = NULL;
807+
808+
switch(node->type)
809+
{
810+
case IDENTIFIERS:
811+
{
812+
sc_spot = sc_lookup_string(local_sym_table_sc, node->types.identifier);
813+
if (sc_spot > -1)
814+
{
815+
var_declare = (ast_node_t *)local_sym_table_sc->data[sc_spot];
816+
break;
817+
}
818+
819+
sc_spot = sc_lookup_string(function_local_sym_table_sc, node->types.identifier);
820+
if (sc_spot > -1)
821+
{
822+
var_declare = (ast_node_t *)function_local_sym_table_sc->data[sc_spot];
823+
break;
824+
}
825+
826+
error_message(NETLIST_ERROR, node->line_number, node->file_number, "Missing declaration of this symbol %s\n", node->types.identifier);
827+
828+
}
829+
break;
830+
831+
case ARRAY_REF:
832+
{
833+
sc_spot = sc_lookup_string(local_sym_table_sc, node->children[0]->types.identifier);
834+
if (sc_spot > -1)
835+
{
836+
var_declare = (ast_node_t *)local_sym_table_sc->data[sc_spot];
837+
break;
838+
}
839+
840+
error_message(NETLIST_ERROR, node->children[0]->line_number, node->children[0]->file_number, "Missing declaration of this symbol %s\n", node->children[0]->types.identifier);
841+
}
842+
break;
843+
844+
case RANGE_REF:
845+
{
846+
var_declare = node;
847+
}
848+
break;
849+
850+
case CONCATENATE:
851+
{
852+
assignment_size = resolve_concat_sizes(node, instance_name_prefix, local_sym_table_sc, function_local_sym_table_sc);
853+
return assignment_size;
854+
}
855+
856+
default:
857+
oassert(false);
858+
break;
859+
}
860+
861+
862+
if (var_declare && !(var_declare->children[1]))
863+
{
864+
assignment_size = 1;
865+
}
866+
else if (var_declare && var_declare->children[1] && var_declare->children[2])
867+
{
868+
ast_node_t *node_max = resolve_node(NULL, instance_name_prefix, var_declare->children[1], NULL, 0);
869+
ast_node_t *node_min = resolve_node(NULL, instance_name_prefix, var_declare->children[2], NULL, 0);
870+
871+
oassert(node_min->type == NUMBERS && node_max->type == NUMBERS);
872+
long range_max = node_max->types.vnumber->get_value();
873+
long range_min = node_min->types.vnumber->get_value();
874+
875+
assignment_size = (range_max - range_min) + 1;
876+
}
877+
878+
oassert(assignment_size != 0);
879+
return assignment_size;
880+
}
881+
796882
/*----------------------------------------------------------------------------
797883
* (function: resolve_node)
798884
*--------------------------------------------------------------------------*/
@@ -802,8 +888,14 @@ char_list_t *get_name_of_pins_with_prefix(ast_node_t *var_node, char *instance_n
802888
* Also try and fold any BINARY_OPERATIONs now that an IDENTIFIER has been
803889
* resolved
804890
*/
805-
ast_node_t *resolve_node(STRING_CACHE *local_param_table_sc, char *module_name, ast_node_t *node)
891+
ast_node_t *resolve_node(STRING_CACHE *local_param_table_sc, char *module_name, ast_node_t *node, long *max_size, long assignment_size)
806892
{
893+
long my_max = 0;
894+
if(max_size == NULL)
895+
{
896+
max_size = &my_max;
897+
}
898+
807899
long sc_spot = -1;
808900

809901
// Not sure this should even be used.
@@ -824,12 +916,12 @@ ast_node_t *resolve_node(STRING_CACHE *local_param_table_sc, char *module_name,
824916
long i;
825917
for (i = 0; i < node->num_children; i++)
826918
{
827-
node->children[i] = resolve_node(local_param_table_sc, module_name, node->children[i]);
919+
node->children[i] = resolve_node(local_param_table_sc, module_name, node->children[i], max_size, assignment_size);
828920
}
829921

830922
ast_node_t *newNode = NULL;
831-
switch (node->type){
832-
923+
switch (node->type)
924+
{
833925
case IDENTIFIERS:
834926
{
835927
if(local_param_table_sc != NULL && node->types.identifier)
@@ -856,6 +948,18 @@ ast_node_t *resolve_node(STRING_CACHE *local_param_table_sc, char *module_name,
856948
case BINARY_OPERATION:
857949
newNode = fold_binary(&node);
858950
break;
951+
952+
case REPLICATE:
953+
oassert(node_is_constant(node->children[0])); // should be taken care of in parse
954+
newNode = create_node_w_type(CONCATENATE, node->line_number, node->file_number); // ????
955+
for (i = 0; i < node->children[0]->types.vnumber->get_value(); i++)
956+
{
957+
add_child_to_node(newNode, ast_node_deep_copy(node->children[1]));
958+
}
959+
// node = free_whole_tree(node); // this might free stuff we don't want to free?
960+
node = newNode;
961+
break;
962+
859963

860964
default:
861965
break;
@@ -864,6 +968,19 @@ ast_node_t *resolve_node(STRING_CACHE *local_param_table_sc, char *module_name,
864968
if (node_is_constant(newNode)){
865969
newNode->shared_node = node->shared_node;
866970

971+
/* resize as needed */
972+
if (assignment_size != 0)
973+
{
974+
VNumber *temp_num = new VNumber(*(newNode->types.vnumber), assignment_size);
975+
delete newNode->types.vnumber;
976+
newNode->types.vnumber = temp_num;
977+
}
978+
979+
if (newNode->types.vnumber->size() > *max_size)
980+
{
981+
*max_size = newNode->types.vnumber->size();
982+
}
983+
867984
// /* clean up */
868985
// if (node->type != IDENTIFIERS) {
869986
// node = free_whole_tree(node);
@@ -1340,6 +1457,47 @@ ast_node_t * fold_binary(ast_node_t **node)
13401457
return NULL;
13411458
}
13421459

1460+
/*---------------------------------------------------------------------------------------------
1461+
* (function: calculate_ternary)
1462+
*-------------------------------------------------------------------------------------------*/
1463+
ast_node_t * fold_conditional(ast_node_t **node)
1464+
{
1465+
if(!node || !(*node))
1466+
return NULL;
1467+
1468+
operation_list op_id = (*node)->types.operation.op;
1469+
ast_node_t *to_return = NULL;
1470+
1471+
switch (op_id)
1472+
{
1473+
case IF_Q:
1474+
{
1475+
ast_node_t *child_condition = (*node)->children[0];
1476+
if(node_is_constant(child_condition))
1477+
{
1478+
VNumber condition = *(child_condition->types.vnumber);
1479+
1480+
if(V_TRUE(condition))
1481+
{
1482+
to_return = ast_node_deep_copy((*node)->children[1]);
1483+
}
1484+
else if(V_FALSE(condition))
1485+
{
1486+
to_return = ast_node_deep_copy((*node)->children[2]);
1487+
}
1488+
// otherwise we keep it as is to build the circuitry
1489+
}
1490+
break;
1491+
}
1492+
default:
1493+
{
1494+
break;
1495+
}
1496+
}
1497+
1498+
return to_return;
1499+
}
1500+
13431501
/*---------------------------------------------------------------------------------------------
13441502
* (function: node_is_constant)
13451503
*-------------------------------------------------------------------------------------------*/
@@ -1399,4 +1557,72 @@ long clog2(long value_in, int length)
13991557
}
14001558

14011559
return result;
1560+
}
1561+
1562+
/*---------------------------------------------------------------------------
1563+
* (function: resolve_concat_sizes)
1564+
*-------------------------------------------------------------------------*/
1565+
long resolve_concat_sizes(ast_node_t *node_top, char *instance_name_prefix, STRING_CACHE *local_sym_table_sc, STRING_CACHE *function_local_sym_table_sc)
1566+
{
1567+
long concatenation_size = 0;
1568+
1569+
switch (node_top->type)
1570+
{
1571+
case CONCATENATE:
1572+
{
1573+
for (int i = 0; i < node_top->num_children; i++)
1574+
{
1575+
concatenation_size += resolve_concat_sizes(node_top->children[i], instance_name_prefix, local_sym_table_sc, function_local_sym_table_sc);
1576+
}
1577+
}
1578+
break;
1579+
1580+
case IDENTIFIERS:
1581+
case ARRAY_REF:
1582+
case RANGE_REF:
1583+
{
1584+
concatenation_size += get_size_of_variable(node_top, instance_name_prefix, local_sym_table_sc, function_local_sym_table_sc);
1585+
}
1586+
break;
1587+
1588+
case BINARY_OPERATION:
1589+
case UNARY_OPERATION:
1590+
{
1591+
long max_size = 0;
1592+
for (int i = 0; i < node_top->num_children; i++)
1593+
{
1594+
long this_size = resolve_concat_sizes(node_top->children[i], instance_name_prefix, local_sym_table_sc, function_local_sym_table_sc);
1595+
if (this_size > max_size) max_size = this_size;
1596+
}
1597+
concatenation_size += max_size;
1598+
}
1599+
break;
1600+
1601+
case IF_Q:
1602+
{
1603+
/* check true/false expressions */
1604+
long true_length = resolve_concat_sizes(node_top->children[1], instance_name_prefix, local_sym_table_sc, function_local_sym_table_sc);
1605+
long false_length = resolve_concat_sizes(node_top->children[2], instance_name_prefix, local_sym_table_sc, function_local_sym_table_sc);
1606+
concatenation_size += (true_length > false_length) ? true_length : false_length;
1607+
}
1608+
break;
1609+
1610+
case NUMBERS:
1611+
{
1612+
/* verify that the number that this represents is sized */
1613+
if (!(node_top->types.vnumber->is_defined_size()))
1614+
{
1615+
error_message(NETLIST_ERROR, node_top->line_number, node_top->file_number, "%s", "Unsized constants cannot be concatenated.\n");
1616+
}
1617+
concatenation_size += node_top->types.vnumber->size();
1618+
}
1619+
break;
1620+
1621+
default:
1622+
{
1623+
error_message(NETLIST_ERROR, node_top->line_number, node_top->file_number, "%s", "Unsupported operation within a concatenation.\n");
1624+
}
1625+
}
1626+
1627+
return concatenation_size;
14021628
}

ODIN_II/SRC/enum_str.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ const char *ids_STR []=
184184
"ARRAY_REF",
185185
"RANGE_REF",
186186
"CONCATENATE",
187+
"REPLICATE",
187188
/* basic identifiers */
188189
"IDENTIFIERS",
189190
"NUMBERS",

0 commit comments

Comments
 (0)