@@ -373,8 +373,8 @@ void make_concat_into_list_of_strings(ast_node_t *concat_top, char *instance_nam
373
373
else if (((ast_node_t *)local_symbol_table_sc->data [sc_spot])->children [3 ] == NULL )
374
374
{
375
375
/* 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 );
378
378
oassert (rnode[1 ]->type == NUMBERS && rnode[2 ]->type == NUMBERS);
379
379
380
380
// /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
404
404
}
405
405
else if (concat_top->children [i]->type == RANGE_REF)
406
406
{
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 );
409
409
oassert (rnode[1 ]->type == NUMBERS && rnode[2 ]->type == NUMBERS);
410
410
oassert (rnode[1 ]->types .vnumber ->get_value () >= rnode[2 ]->types .vnumber ->get_value ());
411
411
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
448
448
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);
449
449
}
450
450
}
451
- else {
451
+ else
452
+ {
452
453
error_message (NETLIST_ERROR, concat_top->line_number , concat_top->file_number , " %s" , " Unsupported operation within a concatenation.\n " );
453
454
}
454
455
}
@@ -513,7 +514,7 @@ char *get_name_of_pin_at_bit(ast_node_t *var_node, int bit, char *instance_name_
513
514
514
515
if (var_node->type == ARRAY_REF)
515
516
{
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 );
517
518
oassert (var_node->children [0 ]->type == IDENTIFIERS);
518
519
oassert (var_node->children [1 ]->type == NUMBERS);
519
520
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_
522
523
{
523
524
oassert (bit >= 0 );
524
525
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 );
527
528
oassert (var_node->children [0 ]->type == IDENTIFIERS);
528
529
oassert (rnode[1 ]->type == NUMBERS);
529
530
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_
575
576
if (var_node->types .concat .num_bit_strings == -1 )
576
577
{
577
578
/* 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 );
578
580
make_concat_into_list_of_strings (var_node, instance_name_prefix);
579
581
}
580
582
@@ -646,16 +648,16 @@ char_list_t *get_name_of_pins(ast_node_t *var_node, char *instance_name_prefix)
646
648
{
647
649
width = 1 ;
648
650
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 );
650
652
oassert (rnode[1 ] && rnode[1 ]->type == NUMBERS);
651
653
oassert (var_node->children [0 ]->type == IDENTIFIERS);
652
654
return_string[0 ] = make_full_ref_name (NULL , NULL , NULL , var_node->children [0 ]->types .identifier , rnode[1 ]->types .vnumber ->get_value ());
653
655
}
654
656
else if (var_node->type == RANGE_REF)
655
657
{
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 );
659
661
oassert (rnode[1 ]->type == NUMBERS && rnode[2 ]->type == NUMBERS);
660
662
width = abs (rnode[1 ]->types .vnumber ->get_value () - rnode[2 ]->types .vnumber ->get_value ()) + 1 ;
661
663
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)
677
679
ast_node_t *sym_node;
678
680
679
681
// 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 );
681
683
682
684
if (sym_node == var_node)
683
685
{
@@ -707,8 +709,8 @@ char_list_t *get_name_of_pins(ast_node_t *var_node, char *instance_name_prefix)
707
709
else if (sym_node->children [3 ] == NULL )
708
710
{
709
711
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 );
712
714
oassert (rnode[1 ]->type == NUMBERS && rnode[2 ]->type == NUMBERS);
713
715
width = (rnode[1 ]->types .vnumber ->get_value () - rnode[2 ]->types .vnumber ->get_value () + 1 );
714
716
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)
747
749
if (var_node->types .concat .num_bit_strings == -1 )
748
750
{
749
751
/* 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 );
750
753
make_concat_into_list_of_strings (var_node, instance_name_prefix);
751
754
}
752
755
@@ -793,6 +796,89 @@ char_list_t *get_name_of_pins_with_prefix(ast_node_t *var_node, char *instance_n
793
796
return return_list;
794
797
}
795
798
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
+
796
882
/* ----------------------------------------------------------------------------
797
883
* (function: resolve_node)
798
884
*--------------------------------------------------------------------------*/
@@ -802,8 +888,14 @@ char_list_t *get_name_of_pins_with_prefix(ast_node_t *var_node, char *instance_n
802
888
* Also try and fold any BINARY_OPERATIONs now that an IDENTIFIER has been
803
889
* resolved
804
890
*/
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 )
806
892
{
893
+ long my_max = 0 ;
894
+ if (max_size == NULL )
895
+ {
896
+ max_size = &my_max;
897
+ }
898
+
807
899
long sc_spot = -1 ;
808
900
809
901
// 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,
824
916
long i;
825
917
for (i = 0 ; i < node->num_children ; i++)
826
918
{
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 );
828
920
}
829
921
830
922
ast_node_t *newNode = NULL ;
831
- switch (node->type ){
832
-
923
+ switch (node->type )
924
+ {
833
925
case IDENTIFIERS:
834
926
{
835
927
if (local_param_table_sc != NULL && node->types .identifier )
@@ -856,19 +948,39 @@ ast_node_t *resolve_node(STRING_CACHE *local_param_table_sc, char *module_name,
856
948
case BINARY_OPERATION:
857
949
newNode = fold_binary (&node);
858
950
break ;
859
-
860
- case IF_Q:
861
- {
862
- newNode = fold_conditional (&node);
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;
863
961
break ;
864
- }
962
+
963
+
865
964
default :
866
965
break ;
867
966
}
868
967
869
968
if (node_is_constant (newNode)){
870
969
newNode->shared_node = node->shared_node ;
871
970
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
+
872
984
// /* clean up */
873
985
// if (node->type != IDENTIFIERS) {
874
986
// node = free_whole_tree(node);
@@ -1445,4 +1557,72 @@ long clog2(long value_in, int length)
1445
1557
}
1446
1558
1447
1559
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;
1448
1628
}
0 commit comments