Skip to content

Commit c02498a

Browse files
authored
Merge pull request verilog-to-routing#627 from verilog-to-routing/odin_merge_constant_fold
fix edge sensitivity
2 parents 1098f2a + f5780d5 commit c02498a

File tree

3 files changed

+66
-80
lines changed

3 files changed

+66
-80
lines changed

ODIN_II/SRC/include/odin_types.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,13 @@ typedef enum
209209
edge_type_e_END
210210
} edge_type_e;
211211

212+
typedef enum
213+
{
214+
COMBINATIONAL,
215+
SEQUENTIAL,
216+
circuit_type_e_END
217+
} circuit_type_e;
218+
212219
typedef enum
213220
{
214221
NO_OP,
@@ -532,6 +539,8 @@ struct npin_t_t
532539
int pin_node_idx; // pin on the node where we're located
533540
char *mapping; // name of mapped port from hard block
534541

542+
edge_type_e sensitivity;
543+
535544
////////////////////
536545
// For simulation
537546
std::shared_ptr<AtomicBuffer> values;

ODIN_II/SRC/netlist_create_from_ast.cpp

Lines changed: 56 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,6 @@ OTHER DEALINGS IN THE SOFTWARE.
5757
#define INSTANTIATE_DRIVERS 1
5858
#define ALIAS_INPUTS 2
5959

60-
#define COMBINATIONAL 1
61-
#define SEQUENTIAL 2
62-
6360
STRING_CACHE *output_nets_sc;
6461
STRING_CACHE *input_nets_sc;
6562

@@ -85,8 +82,8 @@ netlist_t *verilog_netlist;
8582

8683
int netlist_create_line_number = -2;
8784

88-
int type_of_circuit;
89-
85+
circuit_type_e type_of_circuit;
86+
edge_type_e circuit_edge;
9087

9188
/* PROTOTYPES */
9289
void create_param_table_for_module(ast_node_t* parent_parameter_list, ast_node_t *module_items, char *module_name, char *parent_module);
@@ -283,6 +280,13 @@ void create_param_table_for_module(ast_node_t* parent_parameter_list, ast_node_t
283280
{
284281
ast_node_t *var_declare = parent_parameter_list->children[i];
285282
sc_spot = sc_lookup_string(local_param_table_sc, temp_parameter_list[parameter_count]);
283+
if(sc_spot == -1)
284+
{
285+
error_message(NETLIST_ERROR, parent_parameter_list->line_number, parent_parameter_list->file_number,
286+
"Can't find parameter name %s in module %s\n",
287+
var_declare->children[0]->types.identifier,
288+
module_name);
289+
}
286290
local_param_table_sc->data[sc_spot] = (void *)var_declare->children[5];
287291
}
288292

@@ -330,12 +334,23 @@ void create_param_table_for_module(ast_node_t* parent_parameter_list, ast_node_t
330334
}
331335

332336
/* now that parameters are all updated, resolve them */
333-
for (i = 0; i < parameter_num; i++) {
337+
for (i = 0; i < parameter_num; i++)
338+
{
334339
sc_spot = sc_lookup_string(local_param_table_sc, temp_parameter_list[i]);
340+
if(sc_spot == -1)
341+
{
342+
error_message(NETLIST_ERROR, parent_parameter_list->line_number, parent_parameter_list->file_number,
343+
"Can't find parameter name %s in module %s\n",
344+
temp_parameter_list[i],
345+
module_name);
346+
}
335347
ast_node_t *node = (ast_node_t *)local_param_table_sc->data[sc_spot];
336348
oassert(node);
337349
node = resolve_node(NULL, module_name, node);
338-
if (node->type != NUMBERS) node = resolve_node(NULL, parent_module, node); // may contain parameters from parent
350+
if (node->type != NUMBERS)
351+
{
352+
node = resolve_node(NULL, parent_module, node); // may contain parameters from parent
353+
}
339354
oassert(node->type == NUMBERS);
340355
local_param_table_sc->data[sc_spot] = (void *)node;
341356
}
@@ -815,7 +830,8 @@ signal_list_t *netlist_expand_ast_of_module(ast_node_t* node, char *instance_nam
815830
break;
816831
case VAR_DECLARE:
817832
if(node->types.variable.is_parameter == 0 && node->children[5]){
818-
return_sig_list = assignment_alias(node, instance_name_prefix);
833+
/*we don't create signal list on declaration.*/
834+
return_sig_list = init_signal_list();
819835
}
820836
skip_children = TRUE;
821837
break;
@@ -885,22 +901,11 @@ signal_list_t *netlist_expand_ast_of_module(ast_node_t* node, char *instance_nam
885901
case ASSIGN:
886902
/* combinational path */
887903
type_of_circuit = COMBINATIONAL;
904+
circuit_edge = UNDEFINED_SENSITIVITY;
888905
break;
889906
case BLOCKING_STATEMENT:
890-
{
891-
/*if (type_of_circuit == SEQUENTIAL)
892-
error_message(NETLIST_ERROR, node->line_number, node->file_number,
893-
"ODIN doesn't handle blocking statements in Sequential blocks\n");*/
894-
895-
return_sig_list = assignment_alias(node, instance_name_prefix);
896-
skip_children = TRUE;
897-
break;
898-
}
899907
case NON_BLOCKING_STATEMENT:
900908
{
901-
/*if (type_of_circuit != SEQUENTIAL)
902-
error_message(NETLIST_ERROR, node->line_number, node->file_number,
903-
"ODIN doesn't handle non blocking statements in combinational blocks\n");*/
904909

905910
return_sig_list = assignment_alias(node, instance_name_prefix);
906911
skip_children = TRUE;
@@ -1013,13 +1018,9 @@ signal_list_t *netlist_expand_ast_of_module(ast_node_t* node, char *instance_nam
10131018
break;
10141019
case ALWAYS:
10151020
/* attach the drivers to the driver nets */
1016-
switch(type_of_circuit)
1021+
switch(circuit_edge)
10171022
{
1018-
case FALLING_EDGE_SENSITIVITY:
1019-
{
1020-
terminate_registered_assignment(node, children_signal_list[1], local_clock_list, instance_name_prefix);
1021-
break;
1022-
}
1023+
case FALLING_EDGE_SENSITIVITY: //fallthrough
10231024
case RISING_EDGE_SENSITIVITY:
10241025
{
10251026
terminate_registered_assignment(node, children_signal_list[1], local_clock_list, instance_name_prefix);
@@ -3237,18 +3238,8 @@ signal_list_t *assignment_alias(ast_node_t* assignment, char *instance_name_pref
32373238
{
32383239
ast_node_t *left;
32393240
ast_node_t *right;
3240-
if(assignment->type == VAR_DECLARE){
3241-
left = assignment->children[0];
3242-
right = assignment->children[5];
3243-
3244-
/*we don't create signal list on declaration.*/
3245-
return init_signal_list();
3246-
}
3247-
else
3248-
{
3249-
left = assignment->children[0];
3250-
right = assignment->children[1];
3251-
}
3241+
left = assignment->children[0];
3242+
right = assignment->children[1];
32523243

32533244
implicit_memory *left_memory = lookup_implicit_memory_reference_ast(instance_name_prefix, left);
32543245
implicit_memory *right_memory = lookup_implicit_memory_reference_ast(instance_name_prefix, right);
@@ -3361,7 +3352,7 @@ signal_list_t *assignment_alias(ast_node_t* assignment, char *instance_name_pref
33613352
"Invalid addressing mode for implicit memory %s.\n", left_memory->name);
33623353

33633354
// A memory can only be written from a clocked rising edge block.
3364-
if (type_of_circuit != RISING_EDGE_SENSITIVITY)
3355+
if (type_of_circuit != SEQUENTIAL)
33653356
{
33663357
out_list = NULL;
33673358
error_message(NETLIST_ERROR, assignment->line_number, assignment->file_number, "%s",
@@ -3714,6 +3705,7 @@ void terminate_registered_assignment(ast_node_t *always_node, signal_list_t* ass
37143705
ff_node->related_ast_node = always_node;
37153706

37163707
ff_node->type = FF_NODE;
3708+
ff_node->edge_type = potential_clocks->pins[local_clock_idx]->sensitivity;
37173709
/* create the unique name for this gate */
37183710
//ff_node->name = node_name(ff_node, instance_name_prefix);
37193711
/* Name the flipflop based on the name of its output pin */
@@ -4299,13 +4291,13 @@ signal_list_t *create_operation_node(ast_node_t *op, signal_list_t **input_lists
42994291
signal_list_t *evaluate_sensitivity_list(ast_node_t *delay_control, char *instance_name_prefix)
43004292
{
43014293
long i;
4302-
edge_type_e edge_type = UNDEFINED_SENSITIVITY;
4294+
circuit_edge = UNDEFINED_SENSITIVITY;
43034295
signal_list_t *return_sig_list = init_signal_list();
43044296

43054297
if (delay_control == NULL)
43064298
{
43074299
/* Assume always @* */
4308-
edge_type = ASYNCHRONOUS_SENSITIVITY;
4300+
circuit_edge = ASYNCHRONOUS_SENSITIVITY;
43094301
}
43104302
else
43114303
{
@@ -4328,26 +4320,26 @@ signal_list_t *evaluate_sensitivity_list(ast_node_t *delay_control, char *instan
43284320
break;
43294321
}
43304322

4331-
if(edge_type == UNDEFINED_SENSITIVITY)
4332-
edge_type = child_sensitivity;
4323+
if(circuit_edge == UNDEFINED_SENSITIVITY)
4324+
circuit_edge = child_sensitivity;
43334325

4334-
if( (edge_type != child_sensitivity)
4335-
&& ((edge_type == ASYNCHRONOUS_SENSITIVITY) || (child_sensitivity == ASYNCHRONOUS_SENSITIVITY)) )
4336-
error_message(NETLIST_ERROR, delay_control->line_number, delay_control->file_number, "%s",
4337-
"Sensitivity list switches between edge sensitive to asynchronous. You can't define something like always @(posedge clock or a).\n");
4338-
4339-
switch(edge_type)
4326+
if(circuit_edge != child_sensitivity)
4327+
{
4328+
if(circuit_edge == ASYNCHRONOUS_SENSITIVITY || child_sensitivity == ASYNCHRONOUS_SENSITIVITY)
4329+
{
4330+
error_message(NETLIST_ERROR, delay_control->line_number, delay_control->file_number, "%s",
4331+
"Sensitivity list switches between edge sensitive to asynchronous. You can't define something like always @(posedge clock or a).\n");
4332+
}
4333+
}
4334+
4335+
switch(child_sensitivity)
43404336
{
4341-
/**
4342-
* TODO: finish support for falling edge, this is left here for future work
4343-
*/
43444337
case FALLING_EDGE_SENSITIVITY: //falltrhough
4345-
edge_type = RISING_EDGE_SENSITIVITY; //fallthrough
43464338
case RISING_EDGE_SENSITIVITY:
43474339
{
43484340
signal_list_t *temp_list = create_pins(delay_control->children[i]->children[0], NULL, instance_name_prefix);
43494341
oassert(temp_list->count == 1);
4350-
4342+
temp_list->pins[0]->sensitivity = child_sensitivity;
43514343
add_pin_to_signal_list(return_sig_list, temp_list->pins[0]);
43524344
free_signal_list(temp_list);
43534345
break;
@@ -4358,16 +4350,20 @@ signal_list_t *evaluate_sensitivity_list(ast_node_t *delay_control, char *instan
43584350
}
43594351

43604352
/* update the analysis type of this block of statements */
4361-
if(edge_type == UNDEFINED_SENSITIVITY)
4353+
if(circuit_edge == UNDEFINED_SENSITIVITY)
4354+
{
4355+
// TODO: empty always block will probably appear here
43624356
error_message(NETLIST_ERROR, delay_control->line_number, delay_control->file_number, "%s", "Sensitivity list error...looks empty?\n");
4363-
4364-
else if(edge_type == ASYNCHRONOUS_SENSITIVITY)
4357+
}
4358+
else if(circuit_edge == ASYNCHRONOUS_SENSITIVITY)
43654359
{
4360+
/* @(*) or @* is here */
43664361
free_signal_list(return_sig_list);
43674362
return_sig_list = NULL;
43684363
}
43694364

4370-
type_of_circuit = edge_type;
4365+
type_of_circuit = SEQUENTIAL;
4366+
43714367
return return_sig_list;
43724368
}
43734369

@@ -4785,28 +4781,9 @@ signal_list_t *create_mux_statements(signal_list_t **statement_lists, nnode_t *m
47854781
/* Don't match, so this signal is an IMPLIED SIGNAL !!! */
47864782
npin_t *pin = combined_lists->pins[i];
47874783

4788-
switch(type_of_circuit)
4784+
switch(circuit_edge)
47894785
{
4790-
case RISING_EDGE_SENSITIVITY:
4791-
{
4792-
/* implied signal for mux */
4793-
if (lookup_implicit_memory_input(pin->name))
4794-
{
4795-
// If the mux feeds an implicit memory, imply zero.
4796-
add_input_pin_to_node(mux_node, get_zero_pin(verilog_netlist), pin_index);
4797-
}
4798-
else
4799-
{
4800-
/* lookup this driver name */
4801-
signal_list_t *this_pin_list = create_pins(NULL, pin->name, instance_name_prefix);
4802-
oassert(this_pin_list->count == 1);
4803-
//add_a_input_pin_to_node_spot_idx(mux_node, get_zero_pin(verilog_netlist), pin_index);
4804-
add_input_pin_to_node(mux_node, this_pin_list->pins[0], pin_index);
4805-
/* clean up */
4806-
free_signal_list(this_pin_list);
4807-
}
4808-
break;
4809-
}
4786+
case RISING_EDGE_SENSITIVITY: //fallthrough
48104787
case FALLING_EDGE_SENSITIVITY:
48114788
{
48124789
/* implied signal for mux */

ODIN_II/SRC/netlist_utils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ nnode_t* allocate_nnode() {
8181
new_node->num_undriven_pins = 0;
8282

8383
new_node->ratio = 1;
84-
new_node->edge_type = RISING_EDGE_SENSITIVITY;
84+
new_node->edge_type = UNDEFINED_SENSITIVITY;
8585

8686
new_node->has_initial_value = FALSE;
8787
new_node->initial_value = 0;

0 commit comments

Comments
 (0)