@@ -661,6 +661,15 @@ signal_list_t *netlist_expand_ast_of_module(ast_node_t* node, char *instance_nam
661
661
create_symbol_table_for_module (node , instance_name_prefix );
662
662
local_clock_found = FALSE;
663
663
664
+ /* check for initial register values set in initial block.*/
665
+ for (i = 0 ; i < node -> num_children ; i ++ )
666
+ {
667
+ if (node -> children [i ]-> type == INITIALS )
668
+ {
669
+ define_latchs_initial_value_inside_initial_statement (node -> children [i ]-> children [0 ], instance_name_prefix );
670
+ }
671
+ }
672
+
664
673
/* create all the driven nets based on the "reg" registers */
665
674
create_all_driver_nets_in_this_module (instance_name_prefix );
666
675
@@ -736,7 +745,7 @@ signal_list_t *netlist_expand_ast_of_module(ast_node_t* node, char *instance_nam
736
745
break ;
737
746
case INITIALS :
738
747
/* define initial value of latchs */
739
- define_latchs_initial_value_inside_initial_statement (node -> children [0 ], instance_name_prefix );
748
+ // define_latchs_initial_value_inside_initial_statement(node->children[0], instance_name_prefix);
740
749
skip_children = TRUE;
741
750
break ;
742
751
case FUNCTION_INSTANCE :
@@ -3097,9 +3106,11 @@ signal_list_t *assignment_alias(ast_node_t* assignment, char *instance_name_pref
3097
3106
return return_list ;
3098
3107
}
3099
3108
3109
+
3110
+
3100
3111
void define_latchs_initial_value_inside_initial_statement (ast_node_t * initial_node , char * instance_name_prefix )
3101
3112
{
3102
- int i ;
3113
+ int i , q ;
3103
3114
long sc_spot ;
3104
3115
ast_node_t * assignee ;
3105
3116
ast_node_t * value ;
@@ -3115,38 +3126,27 @@ void define_latchs_initial_value_inside_initial_statement(ast_node_t *initial_no
3115
3126
assignee = initial_node -> children [i ]-> children [0 ];
3116
3127
3117
3128
//Value
3118
- value = initial_node -> children [i ]-> children [1 ];
3119
-
3120
- //Create out string.
3121
- word_to_set_latch_initial_value = (char * )calloc (strlen (assignee -> types .identifier )+ 40 , sizeof (char ));
3122
- strcpy (word_to_set_latch_initial_value ,instance_name_prefix );
3123
- strcat (word_to_set_latch_initial_value ,"^" );
3124
- strcat (word_to_set_latch_initial_value ,assignee -> types .identifier );
3125
- strcat (word_to_set_latch_initial_value ,"_latch_initial_value" );
3126
- sc_spot = sc_lookup_string (local_symbol_table_sc , word_to_set_latch_initial_value );
3127
-
3128
- if (sc_spot != -1 )
3129
- {
3130
- /*found the entry so simply udpdate node info*/
3131
-
3132
- /*here, I think we can have a check for if the ast ndoe is marked as alread being initialized, then we can assume
3133
- that someone has placed an assignment for that node before our initial block, so we just die and tell them they are
3134
- stupid.*/
3135
- ((ast_node_t * )(local_symbol_table_sc -> data [sc_spot ]))-> types .variable .is_initialized = TRUE;
3136
- ((ast_node_t * )(local_symbol_table_sc -> data [sc_spot ]))-> types .variable .initial_value = value -> types .number .value ;
3137
- //free(word_to_set_latch_initial_value);
3138
- }
3139
- else
3140
- {
3141
- /*could not find entry, so add it then update the node*/
3142
- sc_spot = sc_add_string (local_symbol_table_sc , word_to_set_latch_initial_value );
3143
- local_symbol_table_sc -> data [sc_spot ] = assignee ;
3144
- ((ast_node_t * )(local_symbol_table_sc -> data [sc_spot ]))-> types .variable .is_initialized = TRUE;
3145
- ((ast_node_t * )(local_symbol_table_sc -> data [sc_spot ]))-> types .variable .initial_value = value -> types .number .value ;
3146
- }
3129
+ int number = initial_node -> children [i ]-> children [1 ]-> types .number .value ;
3130
+
3131
+ //Find corresponding register, set it's members to reflect initialization.
3132
+ if (initial_node -> children [i ])
3133
+ {
3134
+ /*if the identifier we found in the table matches the identifier of our blocking statement*/
3135
+ sc_spot = sc_lookup_string (local_symbol_table_sc , initial_node -> children [i ]-> children [0 ]-> types .identifier );
3136
+ if (sc_spot == -1 )
3137
+ {
3138
+ printf ("** Register [%s] used in initial block is not declared.\n" , initial_node -> children [i ]-> children [0 ]-> types .identifier );
3139
+ }
3140
+ else
3141
+ {
3142
+ local_symbol_table [sc_spot ]-> types .variable .is_initialized = 1 ;
3143
+ local_symbol_table [sc_spot ]-> types .variable .initial_value = number ;
3144
+ }
3145
+ }
3147
3146
}
3148
3147
}
3149
3148
}
3149
+
3150
3150
/*---------------------------------------------------------------------------------------------
3151
3151
* (function: terminate_registered_assignment)
3152
3152
*-------------------------------------------------------------------------------------------*/
@@ -5492,3 +5492,4 @@ signal_list_t *create_hard_block(ast_node_t* block, char *instance_name_prefix)
5492
5492
}
5493
5493
#endif
5494
5494
5495
+
0 commit comments