Skip to content

Commit efdb610

Browse files
emacdo12jeanlego
emacdo12
authored andcommitted
Odin_II: added two functions called in create_netlist that parse tree and resolve parameters in the top module (because they can't be overriden) solving issue1369
1 parent bd5378b commit efdb610

File tree

10 files changed

+274
-29
lines changed

10 files changed

+274
-29
lines changed

ODIN_II/SRC/ast_elaborate.cpp

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,8 @@ ast_node_t* finalize_ast(ast_node_t* node, ast_node_t* parent, sc_hierarchy* loc
133133
ast_node_t* reduce_expressions(ast_node_t* node, sc_hierarchy* local_ref, long* max_size, long assignment_size);
134134

135135
void update_string_caches(sc_hierarchy* local_ref);
136-
void update_instance_parameter_table(ast_node_t* instance, STRING_CACHE* instance_param_table_sc);
136+
void update_instance_parameter_table_direct_instances(ast_node_t* instance, STRING_CACHE* instance_param_table_sc);
137+
void update_instance_parameter_table_defparams(ast_node_t* instance, STRING_CACHE* instance_param_table_sc);
137138
void override_parameters_for_all_instances(ast_node_t* module, sc_hierarchy* local_ref);
138139

139140
void convert_2D_to_1D_array(ast_node_t** var_declare);
@@ -959,7 +960,8 @@ ast_node_t* build_hierarchy(ast_node_t* node, ast_node_t* parent, int index, sc_
959960
if (data->pass == 2) {
960961
/* make sure parameters are updated */
961962
/* TODO apply remaining defparams and check for conflicts */
962-
update_instance_parameter_table(temp_instance, module_sc_hierarchy->local_param_table_sc);
963+
update_instance_parameter_table_direct_instances(temp_instance, module_sc_hierarchy->local_param_table_sc);
964+
update_instance_parameter_table_defparams(temp_instance, module_sc_hierarchy->local_param_table_sc);
963965
}
964966
instance = build_hierarchy(instance, NULL, -1, module_sc_hierarchy, true, true, data);
965967

@@ -1475,7 +1477,8 @@ ast_node_t* finalize_ast(ast_node_t* node, ast_node_t* parent, sc_hierarchy* loc
14751477

14761478
/* update the parameter table for the instantiated module */
14771479
STRING_CACHE* instance_param_table_sc = module_sc_hierarchy->local_param_table_sc;
1478-
update_instance_parameter_table(temp_instance, instance_param_table_sc);
1480+
update_instance_parameter_table_direct_instances(temp_instance, instance_param_table_sc);
1481+
update_instance_parameter_table_defparams(temp_instance, instance_param_table_sc);
14791482

14801483
/* elaboration */
14811484
update_string_caches(module_sc_hierarchy);
@@ -1506,7 +1509,8 @@ ast_node_t* finalize_ast(ast_node_t* node, ast_node_t* parent, sc_hierarchy* loc
15061509

15071510
/* update the parameter table for the instantiated module */
15081511
STRING_CACHE* instance_param_table_sc = function_sc_hierarchy->local_param_table_sc;
1509-
update_instance_parameter_table(temp_instance, instance_param_table_sc);
1512+
update_instance_parameter_table_direct_instances(temp_instance, instance_param_table_sc);
1513+
update_instance_parameter_table_defparams(temp_instance, instance_param_table_sc);
15101514

15111515
/* elaboration */
15121516
update_string_caches(function_sc_hierarchy);
@@ -1538,7 +1542,8 @@ ast_node_t* finalize_ast(ast_node_t* node, ast_node_t* parent, sc_hierarchy* loc
15381542

15391543
/* update the parameter table for the instantiated module */
15401544
STRING_CACHE* instance_param_table_sc = task_sc_hierarchy->local_param_table_sc;
1541-
update_instance_parameter_table(temp_instance, instance_param_table_sc);
1545+
update_instance_parameter_table_direct_instances(temp_instance, instance_param_table_sc);
1546+
update_instance_parameter_table_defparams(temp_instance, instance_param_table_sc);
15421547

15431548
/* elaboration */
15441549
update_string_caches(task_sc_hierarchy);
@@ -2157,7 +2162,7 @@ void update_string_caches(sc_hierarchy* local_ref) {
21572162
}
21582163
}
21592164

2160-
void update_instance_parameter_table(ast_node_t* instance, STRING_CACHE* instance_param_table_sc) {
2165+
void update_instance_parameter_table_direct_instances(ast_node_t* instance, STRING_CACHE* instance_param_table_sc) {
21612166
if (instance->children[1]->children[2] && instance->children[1]->children[2]->num_children > 0) {
21622167
long sc_spot;
21632168
ast_node_t* parameter_override_list = instance->children[1]->children[2];
@@ -2206,6 +2211,13 @@ void update_instance_parameter_table(ast_node_t* instance, STRING_CACHE* instanc
22062211
"There are more parameters (%d) passed into %s than there are specified in the module (%ld)!",
22072212
param_count, instance->children[1]->children[0]->types.identifier, instance_param_table_sc->free);
22082213
}
2214+
}
2215+
}
2216+
2217+
void update_instance_parameter_table_defparams(ast_node_t* instance, STRING_CACHE* instance_param_table_sc) {
2218+
if (instance->children[1]->children[2] && instance->children[1]->children[2]->num_children > 0) {
2219+
long sc_spot;
2220+
ast_node_t* parameter_override_list = instance->children[1]->children[2];
22092221

22102222
/* fill out the overrides */
22112223
for (int j = (parameter_override_list->num_children - 1); j >= 0; j--) {
@@ -2273,8 +2285,8 @@ void override_parameters_for_all_instances(ast_node_t* module, sc_hierarchy* loc
22732285

22742286
/* update the parameter table for the instantiated module */
22752287
STRING_CACHE* instance_param_table_sc = module_sc_hierarchy->local_param_table_sc;
2276-
update_instance_parameter_table(temp_instance, instance_param_table_sc);
2277-
2288+
update_instance_parameter_table_direct_instances(temp_instance, instance_param_table_sc);
2289+
update_instance_parameter_table_defparams(temp_instance, instance_param_table_sc);
22782290
/* go through this instance's children */
22792291
override_parameters_for_all_instances(instance, module_sc_hierarchy);
22802292
}

ODIN_II/SRC/netlist_create_from_ast.cpp

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656

5757
#define INSTANTIATE_DRIVERS 1
5858
#define ALIAS_INPUTS 2
59+
#define RECURSIVE_LIMIT 256
5960

6061
STRING_CACHE* output_nets_sc;
6162
STRING_CACHE* input_nets_sc;
@@ -84,6 +85,8 @@ void create_top_driver_nets(ast_node_t* module, char* instance_name_prefix, sc_h
8485
void create_top_output_nodes(ast_node_t* module, char* instance_name_prefix, sc_hierarchy* local_ref);
8586
nnet_t* define_nets_with_driver(ast_node_t* var_declare, char* instance_name_prefix);
8687
nnet_t* define_nodes_and_nets_with_driver(ast_node_t* var_declare, char* instance_name_prefix);
88+
ast_node_t* resolve_top_module_parameters(ast_node_t* node, sc_hierarchy* top_sc_list);
89+
ast_node_t* resolve_top_parameters_defined_by_parameters(ast_node_t* node, sc_hierarchy* top_sc_list, int count);
8790

8891
void connect_hard_block_and_alias(ast_node_t* hb_instance, char* instance_name_prefix, int outport_size, sc_hierarchy* local_ref);
8992
void connect_module_instantiation_and_alias(short PASS, ast_node_t* module_instance, char* instance_name_prefix, sc_hierarchy* local_ref);
@@ -175,6 +178,7 @@ void create_netlist(ast_t* ast) {
175178
top_sc_list->scope_id = vtr::strdup(top_module->children[0]->types.identifier);
176179
verilog_netlist->identifier = vtr::strdup(top_module->children[0]->types.identifier);
177180
/* elaboration */
181+
resolve_top_module_parameters(top_module, top_sc_list);
178182
simplify_ast_module(&top_module, top_sc_list);
179183

180184
/* now recursively parse the modules by going through the tree of modules starting at top */
@@ -5143,4 +5147,70 @@ void reorder_connections_from_name(ast_node_t* instance_node_list, ast_node_t* i
51435147
}
51445148

51455149
delete[] arr_index;
5150+
}
5151+
/*--------------------------------------------------------------------------
5152+
* Resolves top module parameters and defparams defined by it's own parameters as those parameters cannot be overriden
5153+
* Technically the top module parameters can be overriden by defparams in a seperate module however that cannot be supported until
5154+
* Odin has full hierarchy support. Even Quartus doesn't allow defparams to override the top module parameters but the Verilog Standard 2005
5155+
* doesn't say its not allowed. It's not good practice to override top module parameters and Odin could choose not to allow it.
5156+
*-------------------------------------------------------------------------*/
5157+
5158+
ast_node_t* resolve_top_module_parameters(ast_node_t* node, sc_hierarchy* top_sc_list) {
5159+
if (node->type == MODULE_PARAMETER) {
5160+
ast_node_t* child = node->children[5];
5161+
if (child->type != NUMBERS) {
5162+
node->children[5] = resolve_top_parameters_defined_by_parameters(child, top_sc_list, 0);
5163+
}
5164+
return (node);
5165+
}
5166+
5167+
int i = 0;
5168+
5169+
while (node->num_children > i) {
5170+
ast_node_t* new_child = node->children[i];
5171+
if (new_child != NULL) {
5172+
node->children[i] = resolve_top_module_parameters(new_child, top_sc_list);
5173+
}
5174+
i++;
5175+
}
5176+
return (node);
5177+
}
5178+
5179+
ast_node_t* resolve_top_parameters_defined_by_parameters(ast_node_t* node, sc_hierarchy* top_sc_list, int count) {
5180+
STRING_CACHE* local_param_table_sc = top_sc_list->local_param_table_sc;
5181+
STRING_CACHE* local_symbol_table_sc = top_sc_list->local_symbol_table_sc;
5182+
5183+
count++;
5184+
5185+
if (count > RECURSIVE_LIMIT) {
5186+
error_message(NETLIST, node->loc, "Exceeds recursion count limit of %s", RECURSIVE_LIMIT);
5187+
}
5188+
5189+
if (node->type == IDENTIFIERS) {
5190+
const char* string = node->types.identifier;
5191+
long sc_spot = sc_lookup_string(local_param_table_sc, string);
5192+
long sc_spot_symbol = sc_lookup_string(local_symbol_table_sc, string);
5193+
5194+
if ((sc_spot == -1) && (sc_spot_symbol == -1)) {
5195+
error_message(NETLIST, node->loc, "%s is not a valid parameter", string);
5196+
} else if (sc_spot_symbol != -1) {
5197+
return (node);
5198+
} else {
5199+
ast_node_t* newNode = ast_node_deep_copy((ast_node_t*)local_param_table_sc->data[sc_spot]);
5200+
if (newNode->type != NUMBERS) {
5201+
newNode = resolve_top_parameters_defined_by_parameters(newNode, top_sc_list, count);
5202+
}
5203+
node = free_whole_tree(node);
5204+
node = newNode;
5205+
}
5206+
}
5207+
if (node->type == BINARY_OPERATION) {
5208+
for (int i = 0; i < 2; i++) {
5209+
ast_node_t* child = node->children[i];
5210+
if (child->type != NUMBERS) {
5211+
node->children[i] = resolve_top_parameters_defined_by_parameters(node->children[i], top_sc_list, count);
5212+
}
5213+
}
5214+
}
5215+
return (node);
51465216
}

ODIN_II/regression_test/benchmark/task/keywords/defparam/simulation_result.json

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -57,21 +57,6 @@
5757
"Estimated LUTs": 1,
5858
"Total Node": 3
5959
},
60-
"defparam/defparam_depth_1/no_arch": {
61-
"test_name": "defparam/defparam_depth_1/no_arch",
62-
"blif": "defparam_depth_1.blif",
63-
"max_rss(MiB)": 30,
64-
"exec_time(ms)": 5.1,
65-
"simulation_time(ms)": 1.7,
66-
"test_coverage(%)": 100,
67-
"Pi": 10,
68-
"Po": 10,
69-
"logic element": 10,
70-
"Longest Path": 3,
71-
"Average Path": 3,
72-
"Estimated LUTs": 10,
73-
"Total Node": 10
74-
},
7560
"defparam/defparam_depth_1_failure/no_arch": {
7661
"test_name": "defparam/defparam_depth_1_failure/no_arch",
7762
"blif": "defparam_depth_1_failure.blif",
@@ -100,6 +85,36 @@
10085
"Estimated LUTs": 3,
10186
"Total Node": 3
10287
},
88+
"defparam/defparam_depth_1/no_arch": {
89+
"test_name": "defparam/defparam_depth_1/no_arch",
90+
"blif": "defparam_depth_1.blif",
91+
"max_rss(MiB)": 35.5,
92+
"exec_time(ms)": 7.2,
93+
"simulation_time(ms)": 2.5,
94+
"test_coverage(%)": 100,
95+
"Pi": 10,
96+
"Po": 10,
97+
"logic element": 10,
98+
"Longest Path": 3,
99+
"Average Path": 3,
100+
"Estimated LUTs": 10,
101+
"Total Node": 10
102+
},
103+
"defparam/override_same_param_name/no_arch": {
104+
"test_name": "defparam/override_same_param_name/no_arch",
105+
"blif": "override_same_param_name.blif",
106+
"max_rss(MiB)": 35.6,
107+
"exec_time(ms)": 6.4,
108+
"simulation_time(ms)": 2.3,
109+
"test_coverage(%)": 100,
110+
"Pi": 10,
111+
"Po": 7,
112+
"logic element": 12,
113+
"Longest Path": 6,
114+
"Average Path": 4,
115+
"Estimated LUTs": 12,
116+
"Total Node": 12
117+
},
103118
"DEFAULT": {
104119
"test_name": "n/a",
105120
"architecture": "n/a",

ODIN_II/regression_test/benchmark/task/keywords/defparam/synthesis_result.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,17 @@
107107
"Longest Path": 2,
108108
"Average Path": 2
109109
},
110+
"defparam/override_same_param_name/no_arch": {
111+
"test_name": "defparam/override_same_param_name/no_arch",
112+
"verilog": "override_same_param_name.v",
113+
"Pi": 10,
114+
"Po": 7,
115+
"logic element": 5,
116+
"Longest Path": 5,
117+
"Average Path": 3,
118+
"Estimated LUTs": 5,
119+
"Total Node": 5
120+
},
110121
"DEFAULT": {
111122
"test_name": "n/a",
112123
"architecture": "n/a",

ODIN_II/regression_test/benchmark/task/keywords/parameter/simulation_result.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,21 @@
2828
"Estimated LUTs": 4,
2929
"Total Node": 4
3030
},
31+
"parameter/parameter_override/no_arch": {
32+
"test_name": "parameter/parameter_override/no_arch",
33+
"blif": "parameter_override.blif",
34+
"max_rss(MiB)": 35.2,
35+
"exec_time(ms)": 4.4,
36+
"simulation_time(ms)": 0.6,
37+
"test_coverage(%)": 100,
38+
"Pi": 10,
39+
"Po": 7,
40+
"logic element": 12,
41+
"Longest Path": 6,
42+
"Average Path": 4,
43+
"Estimated LUTs": 12,
44+
"Total Node": 12
45+
},
3146
"DEFAULT": {
3247
"test_name": "n/a",
3348
"architecture": "n/a",

ODIN_II/regression_test/benchmark/task/keywords/parameter/synthesis_result.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,13 @@
2727
"parameter/parameter_override/no_arch": {
2828
"test_name": "parameter/parameter_override/no_arch",
2929
"verilog": "parameter_override.v",
30-
"exit": 1
30+
"Pi": 10,
31+
"Po": 7,
32+
"logic element": 5,
33+
"Longest Path": 5,
34+
"Average Path": 3,
35+
"Estimated LUTs": 5,
36+
"Total Node": 5
3137
},
3238
"DEFAULT": {
3339
"test_name": "n/a",

ODIN_II/regression_test/benchmark/verilog/keywords/defparam/defparam_depth_1.v

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
module simple_op(in1,in2,out1,out2);
2-
parameter width1 = 2;
2+
parameter width = 2;
33
parameter width2 = 8;
44

5-
input [width1-1:0] in1;
5+
input [width-1:0] in1;
66
input [width2-1:0] in2;
7-
output [width1-1:0] out1;
7+
output [width-1:0] out1;
88
output [width2-1:0] out2;
99

10-
defparam m1.width = 2;
11-
defparam m2.width = 8;
10+
defparam m1.width = width;
11+
defparam m2.width = width2;
1212

1313
assg m1 (in1,out1);
1414
assg m2 (in2,out2);
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
module simple_op(in1,in2,in3,out1,out2);
2+
parameter msb1 = 3;
3+
parameter msb2 = 2;
4+
parameter lsb = 0;
5+
6+
input [msb1:lsb] in1;
7+
input [msb2:lsb] in2;
8+
input [msb2:lsb] in3;
9+
output [msb1:lsb] out1;
10+
output [msb2:lsb] out2;
11+
12+
assg #(.msb(msb1),.lsb(lsb)) assg(in1,out1);
13+
14+
addi #(.msb(msb2),.lsb(lsb)) addi(in2,in3,out2);
15+
16+
endmodule
17+
18+
19+
module assg(in,out);
20+
parameter msb = 8;
21+
parameter lsb = 1;
22+
23+
input [msb:lsb] in;
24+
output [msb:lsb] out;
25+
26+
assign out = in;
27+
endmodule
28+
29+
module addi(in1,in2,out);
30+
parameter msb = 4;
31+
parameter lsb = 2;
32+
33+
input [msb:lsb] in1;
34+
input [msb:lsb] in2;
35+
output [msb:lsb] out;
36+
37+
assign out = in1 + in2;
38+
endmodule
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
GLOBAL_SIM_BASE_CLK in1 in2 in3
2+
1 0Xe 0X1 0X3
3+
0 0X6 0X0 0X2
4+
1 0X1 0X7 0X1
5+
0 0X7 0X5 0X7
6+
1 0X9 0X2 0X1
7+
0 0X8 0X3 0X5
8+
1 0X7 0X5 0X2
9+
0 0X5 0X0 0X6
10+
1 0X1 0X2 0X0
11+
0 0X1 0X7 0X2
12+
1 0X2 0X7 0X2
13+
0 0Xf 0X7 0X3
14+
1 0X5 0X3 0X2
15+
0 0X3 0X2 0X5
16+
1 0Xd 0X3 0X4
17+
0 0X1 0X4 0X6
18+
1 0X3 0X3 0X3
19+
0 0Xe 0X3 0X6
20+
1 0X9 0X3 0X0
21+
0 0Xc 0X1 0X5
22+
1 0X5 0X6 0X4
23+
0 0Xc 0X1 0X1
24+
1 0X1 0X2 0X7
25+
0 0X2 0X0 0X1
26+
1 0X4 0X0 0X6
27+
0 0Xe 0X5 0X4
28+
1 0Xb 0X3 0X2
29+
0 0X0 0X0 0X3
30+
1 0X2 0X6 0X0
31+
0 0X6 0X7 0X3
32+
1 0Xd 0X2 0X0
33+
0 0Xa 0X0 0X0
34+
1 0X5 0X4 0X0
35+
0 0X7 0X2 0X6
36+
1 0X4 0X2 0X7
37+
0 0X6 0X2 0X0
38+
1 0X1 0X1 0X0
39+
0 0Xd 0X1 0X2

0 commit comments

Comments
 (0)