Skip to content

Commit d9abcfc

Browse files
author
vincelasal
committed
Modified the handling of assignments when declaring registers.
ARM_CORE.v now works, also blif file is printing proper values on latches.
1 parent c5dad5f commit d9abcfc

File tree

1 file changed

+50
-38
lines changed

1 file changed

+50
-38
lines changed

ODIN_II/SRC/netlist_create_from_ast.c

Lines changed: 50 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ OTHER DEALINGS IN THE SOFTWARE.
2323
#include <string.h>
2424
#include <stdio.h>
2525
#include <stdlib.h>
26+
#include <string.h>
2627
#include "types.h"
2728
#include "globals.h"
2829
#include "errors.h"
@@ -476,7 +477,8 @@ void convert_ast_to_netlist_recursing_via_modules(ast_node_t* current_module, ch
476477
signal_list_t *list = NULL;
477478

478479
/* BASE CASE is when there are no other instantiations of modules in this module */
479-
if (current_module->types.module.size_module_instantiations == 0 && current_module->types.function.size_function_instantiations == 0)
480+
if (current_module->types.module.size_module_instantiations == 0 &&
481+
current_module->types.function.size_function_instantiations == 0)
480482
{
481483
list = netlist_expand_ast_of_module(current_module, instance_name);
482484
}
@@ -734,7 +736,7 @@ signal_list_t *netlist_expand_ast_of_module(ast_node_t* node, char *instance_nam
734736
break;
735737
case INITIALS:
736738
/* define initial value of latchs */
737-
define_latchs_initial_value_inside_initial_statement(node->children[0],instance_name_prefix);
739+
define_latchs_initial_value_inside_initial_statement(node->children[0], instance_name_prefix);
738740
skip_children = TRUE;
739741
break;
740742
case FUNCTION_INSTANCE:
@@ -1345,8 +1347,7 @@ nnet_t* define_nets_with_driver(ast_node_t* var_declare, char *instance_name_pre
13451347
if(var_declare->types.variable.is_initialized){
13461348
initial_value = var_declare->types.variable.initial_value;
13471349
}
1348-
1349-
1350+
13501351
/* This register declaration is a range as opposed to a single bit so we need to define each element */
13511352
/* assume digit 1 is largest */
13521353
for (i = node_min->types.number.value; i <= node_max->types.number.value; i++)
@@ -2836,8 +2837,12 @@ signal_list_t *assignment_alias(ast_node_t* assignment, char *instance_name_pref
28362837
if(assignment->type == VAR_DECLARE){
28372838
left = assignment->children[0];
28382839
right = assignment->children[5];
2840+
2841+
/*we don't create signal list on declaration.*/
2842+
return init_signal_list();
28392843
}
2840-
else{
2844+
else
2845+
{
28412846
left = assignment->children[0];
28422847
right = assignment->children[1];
28432848
}
@@ -2927,7 +2932,7 @@ signal_list_t *assignment_alias(ast_node_t* assignment, char *instance_name_pref
29272932
if (!is_valid_implicit_memory_reference_ast(instance_name_prefix, left))
29282933
error_message(NETLIST_ERROR, assignment->line_number, assignment->file_number,
29292934
"Invalid addressing mode for implicit memory %s.\n", left_memory->name);
2930-
2935+
29312936
// A memory can only be written from a clocked sequential block.
29322937
if (type_of_circuit != SEQUENTIAL)
29332938
{
@@ -3026,7 +3031,8 @@ signal_list_t *assignment_alias(ast_node_t* assignment, char *instance_name_pref
30263031
}
30273032
free_signal_list(in_1);
30283033
}
3029-
else{
3034+
else
3035+
{
30303036
if (output_size < in_1->count)
30313037
{
30323038
/* need to shrink the output list */
@@ -3091,47 +3097,52 @@ signal_list_t *assignment_alias(ast_node_t* assignment, char *instance_name_pref
30913097
return return_list;
30923098
}
30933099

3094-
void define_latchs_initial_value_inside_initial_statement(ast_node_t *initial_node, char *instance_name_prefix){
3100+
void define_latchs_initial_value_inside_initial_statement(ast_node_t *initial_node, char *instance_name_prefix)
3101+
{
30953102
int i;
30963103
long sc_spot;
3097-
ast_node_t *left;
3098-
ast_node_t *right;
3104+
ast_node_t *assignee;
3105+
ast_node_t *value;
30993106
char *word_to_set_latch_initial_value;
3100-
for(i = 0; i < initial_node->num_children; i++){
3101-
if((initial_node->children[i]->type == BLOCKING_STATEMENT || initial_node->children[i]->type == NON_BLOCKING_STATEMENT) && initial_node->children[i]->children[1]->type == NUMBERS){
3107+
for(i = 0; i < initial_node->num_children; i++)
3108+
{
3109+
/*check to see if, for each member of the initial block, if the assignment to a given variable is a number and not
3110+
a complex statement*/
3111+
if((initial_node->children[i]->type == BLOCKING_STATEMENT || initial_node->children[i]->type == NON_BLOCKING_STATEMENT)
3112+
&& initial_node->children[i]->children[1]->type == NUMBERS)
3113+
{
3114+
//Assignee
3115+
assignee = initial_node->children[i]->children[0];
31023116

3103-
left = initial_node->children[i]->children[0];
3104-
right = initial_node->children[i]->children[1];
3105-
3106-
word_to_set_latch_initial_value = (char *)calloc(strlen(left->types.identifier)+40,sizeof(char));
3117+
//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));
31073122
strcpy(word_to_set_latch_initial_value,instance_name_prefix);
31083123
strcat(word_to_set_latch_initial_value,"^");
3109-
3110-
strcat(word_to_set_latch_initial_value,left->types.identifier);
3124+
strcat(word_to_set_latch_initial_value,assignee->types.identifier);
31113125
strcat(word_to_set_latch_initial_value,"_latch_initial_value");
3112-
31133126
sc_spot = sc_lookup_string(local_symbol_table_sc, word_to_set_latch_initial_value);
31143127

3115-
if (sc_spot != -1){
3116-
((nnode_t *)(local_symbol_table_sc->data[sc_spot]))->has_initial_value = 1;
3117-
if(right->types.number.value > 1)
3118-
((nnode_t *)(local_symbol_table_sc->data[sc_spot]))->initial_value = 0;
3119-
else ((nnode_t *)(local_symbol_table_sc->data[sc_spot]))->initial_value = right->types.number.value;
3120-
free(word_to_set_latch_initial_value);
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);
31213138
}
3122-
else{
3139+
else
3140+
{
3141+
/*could not find entry, so add it then update the node*/
31233142
sc_spot = sc_add_string(local_symbol_table_sc, word_to_set_latch_initial_value);
3124-
if(right->types.number.value > 1) {
3125-
local_symbol_table_sc->data[sc_spot] = (char *)calloc(2,sizeof(char));
3126-
((char *)(local_symbol_table_sc->data[sc_spot]))[0] = '0';//local_symbol_table_sc->data[sc_spot] = "0";
3127-
//strcpy((char *)(local_symbol_table_sc->data[sc_spot]),"0");
3128-
}
3129-
else{
3130-
local_symbol_table_sc->data[sc_spot] = (char *)calloc(2,sizeof(char));
3131-
((char *)(local_symbol_table_sc->data[sc_spot]))[0] = right->types.number.value;
3132-
//strcpy((char *)(local_symbol_table_sc->data[sc_spot]),right->types.number.value);
3133-
//strcpy(local_symbol_table_sc->data[sc_spot],right->types.number.value);
3134-
}
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;
31353146
}
31363147
}
31373148
}
@@ -3302,7 +3313,7 @@ void terminate_registered_assignment(ast_node_t *always_node, signal_list_t* ass
33023313

33033314
for(j = i-1; j >= 0; j--){
33043315

3305-
if(list_dependence_pin[j]->net->driver_pin &&
3316+
if(list_dependence_pin[j] && list_dependence_pin[j]->net->driver_pin &&
33063317
list_dependence_type[j] && list_dependence_type[j] == BLOCKING_STATEMENT &&
33073318
strcmp(ref_string,assignment->pins[j]->node->name) == 0){
33083319

@@ -5480,3 +5491,4 @@ signal_list_t *create_hard_block(ast_node_t* block, char *instance_name_prefix)
54805491
return return_list;
54815492
}
54825493
#endif
5494+

0 commit comments

Comments
 (0)