Skip to content

Commit 802dada

Browse files
author
vincelasal
committed
Added logic to handle register assignments inside initial block.
1 parent dcd980e commit 802dada

File tree

1 file changed

+32
-31
lines changed

1 file changed

+32
-31
lines changed

ODIN_II/SRC/netlist_create_from_ast.c

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -661,6 +661,15 @@ signal_list_t *netlist_expand_ast_of_module(ast_node_t* node, char *instance_nam
661661
create_symbol_table_for_module(node, instance_name_prefix);
662662
local_clock_found = FALSE;
663663

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+
664673
/* create all the driven nets based on the "reg" registers */
665674
create_all_driver_nets_in_this_module(instance_name_prefix);
666675

@@ -736,7 +745,7 @@ signal_list_t *netlist_expand_ast_of_module(ast_node_t* node, char *instance_nam
736745
break;
737746
case INITIALS:
738747
/* 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);
740749
skip_children = TRUE;
741750
break;
742751
case FUNCTION_INSTANCE:
@@ -3097,9 +3106,11 @@ signal_list_t *assignment_alias(ast_node_t* assignment, char *instance_name_pref
30973106
return return_list;
30983107
}
30993108

3109+
3110+
31003111
void define_latchs_initial_value_inside_initial_statement(ast_node_t *initial_node, char *instance_name_prefix)
31013112
{
3102-
int i;
3113+
int i, q;
31033114
long sc_spot;
31043115
ast_node_t *assignee;
31053116
ast_node_t *value;
@@ -3115,38 +3126,27 @@ void define_latchs_initial_value_inside_initial_statement(ast_node_t *initial_no
31153126
assignee = initial_node->children[i]->children[0];
31163127

31173128
//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+
}
31473146
}
31483147
}
31493148
}
3149+
31503150
/*---------------------------------------------------------------------------------------------
31513151
* (function: terminate_registered_assignment)
31523152
*-------------------------------------------------------------------------------------------*/
@@ -5492,3 +5492,4 @@ signal_list_t *create_hard_block(ast_node_t* block, char *instance_name_prefix)
54925492
}
54935493
#endif
54945494

5495+

0 commit comments

Comments
 (0)