Skip to content

Commit 841f555

Browse files
committed
Update tasks and functions
1 parent bbb32ee commit 841f555

File tree

10 files changed

+110
-51
lines changed

10 files changed

+110
-51
lines changed

ODIN_II/SRC/ast_elaborate.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,7 @@ ast_node_t *finalize_ast(ast_node_t *node, ast_node_t *parent, STRING_CACHE_LIST
527527
{
528528
break;
529529
}
530+
case STATEMENT: //fallthrough
530531
case ALWAYS: // fallthrough
531532
case INITIALS:
532533
{
@@ -1171,6 +1172,7 @@ ast_node_t *finalize_ast(ast_node_t *node, ast_node_t *parent, STRING_CACHE_LIST
11711172
if (node->num_children == 3) convert_2D_to_1D_array_ref(&node, local_string_cache_list);
11721173
break;
11731174
}
1175+
case STATEMENT: //fallthrough
11741176
case ALWAYS: // fallthrough
11751177
case INITIALS:
11761178
{

ODIN_II/SRC/enum_str.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,8 @@ const char *ids_STR []=
134134
"FUNCTION",
135135
/* OTHER FUNCTION ITEMS */
136136
"FUNCTION_ITEMS",
137+
"TASK",
138+
"TASK_ITEMS",
137139
/* primitives */
138140
"GATE",
139141
"GATE_INSTANCE",
@@ -150,12 +152,16 @@ const char *ids_STR []=
150152
/* Function instances*/
151153
"FUNCTION_NAMED_INSTANCE",
152154
"FUNCTION_INSTANCE",
155+
156+
"TASK_NAMED_INSTANCE",
157+
"TASK_INSTANCE",
153158
/* Specify Items */
154159
"SPECIFY_ITEMS",
155160
"SPECIFY_PARAMETER",
156161
"SPECIFY_PAL_CONNECTION_STATEMENT",
157162
"SPECIFY_PAL_CONNECT_LIST",
158163
/* statements */
164+
"STATEMENT",
159165
"BLOCK",
160166
"NON_BLOCKING_STATEMENT",
161167
"BLOCKING_STATEMENT",

ODIN_II/SRC/include/odin_types.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,7 @@ enum ids
298298
SPECIFY_PAL_CONNECTION_STATEMENT,
299299
SPECIFY_PAL_CONNECT_LIST,
300300
/* statements */
301+
STATEMENT,
301302
BLOCK,
302303
NON_BLOCKING_STATEMENT,
303304
BLOCKING_STATEMENT,

ODIN_II/SRC/include/parse_making_ast.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ ast_node_t *newIf(ast_node_t *compare_expression, ast_node_t *true_expression, a
5151
ast_node_t *newIfQuestion(ast_node_t *compare_expression, ast_node_t *true_expression, ast_node_t *false_expression, int line_number);
5252
ast_node_t *newCase(ast_node_t *compare_expression, ast_node_t *case_list, int line_number);
5353
ast_node_t *newAlways(ast_node_t *delay_control, ast_node_t *statements, int line_number);
54+
ast_node_t *newStatement(ast_node_t *statement, int line_number);
5455
ast_node_t *newFor(ast_node_t *initial, ast_node_t *compare_expression, ast_node_t *terminal, ast_node_t *statement, int line_number);
5556
ast_node_t *newWhile(ast_node_t *compare_expression, ast_node_t *statement, int line_number);
5657

ODIN_II/SRC/netlist_create_from_ast.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -741,6 +741,9 @@ signal_list_t *netlist_expand_ast_of_module(ast_node_t** node_ref, char *instanc
741741
terminate_continuous_assignment(node, children_signal_list[i], instance_name_prefix);
742742
}
743743
break;
744+
case STATEMENT:
745+
terminate_continuous_assignment(node, children_signal_list[0], instance_name_prefix);
746+
break;
744747
case ALWAYS:
745748
/* attach the drivers to the driver nets */
746749
switch(circuit_edge)
@@ -824,6 +827,7 @@ signal_list_t *netlist_expand_ast_of_module(ast_node_t** node_ref, char *instanc
824827
&& node->type != VAR_DECLARE_LIST
825828
&& node->type != ASSIGN
826829
&& node->type != ALWAYS
830+
&& node->type != STATEMENT
827831
&& node->type != CONCATENATE)
828832
{
829833
free_signal_list(children_signal_list[i]);

ODIN_II/SRC/parse_making_ast.cpp

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,11 @@ ast_node_t **function_instantiations_instance;
6363
int size_function_instantiations;
6464
ast_node_t **function_instantiations_instance_by_module;
6565
int size_function_instantiations_by_module;
66-
ast_node_t **function_instantiations_instance_by_task;
67-
int size_function_instantiations_by_task;
6866

6967
ast_node_t **task_instantiations_instance;
7068
int size_task_instantiations;
7169
ast_node_t **task_instantiations_instance_by_module;
7270
int size_task_instantiations_by_module;
73-
ast_node_t **task_instantiations_instance_by_task;
74-
int size_task_instantiations_by_task;
7571

7672
long num_modules;
7773
ast_node_t **ast_modules;
@@ -154,10 +150,9 @@ void init_parser()
154150
size_function_instantiations = 0;
155151
function_instantiations_instance_by_module = NULL;
156152
size_function_instantiations_by_module = 0;
157-
size_function_instantiations_by_task = 0;
158153
size_task_instantiations = 0;
159154
size_task_instantiations_by_module = 0;
160-
size_task_instantiations_by_task = 0;
155+
161156

162157
/* keeps track of all the ast roots */
163158
all_file_items_list = NULL;
@@ -1235,6 +1230,17 @@ ast_node_t *newAlways(ast_node_t *delay_control, ast_node_t *statement, int line
12351230

12361231
return new_node;
12371232
}
1233+
1234+
ast_node_t *newStatement(ast_node_t *statement, int line_number)
1235+
{
1236+
/* create a node for this array reference */
1237+
ast_node_t* new_node = create_node_w_type(STATEMENT, line_number, current_parse_file);
1238+
/* allocate child nodes to this node */
1239+
allocate_children_to_node(new_node, { statement });
1240+
1241+
return new_node;
1242+
}
1243+
12381244
/*---------------------------------------------------------------------------------------------
12391245
* (function: newModuleConnection)
12401246
*-------------------------------------------------------------------------------------------*/
@@ -1323,7 +1329,7 @@ ast_node_t *newFunctionNamedInstance(ast_node_t *module_connect_list, ast_node_t
13231329
ast_node_t *newTaskNamedInstance(ast_node_t *module_connect_list, int line_number)
13241330
{
13251331
std::string buffer("task_instance_");
1326-
buffer += std::to_string(size_task_instantiations_by_module + size_task_instantiations_by_task);
1332+
buffer += std::to_string(size_task_instantiations_by_module);
13271333

13281334
char *unique_name = vtr::strdup(buffer.c_str());
13291335

@@ -1355,10 +1361,6 @@ ast_node_t *newTaskInstance(char *task_name, ast_node_t *task_named_instace, ast
13551361
task_instantiations_instance_by_module[size_task_instantiations_by_module] = new_node;
13561362
size_task_instantiations_by_module++;
13571363

1358-
// task_instantiations_instance_by_task = (ast_node_t **)vtr::realloc(task_instantiations_instance_by_task, sizeof(ast_node_t*)*(size_task_instantiations_by_task+1));
1359-
// task_instantiations_instance_by_task[size_task_instantiations_by_task] = new_node;
1360-
// size_task_instantiations_by_task++;
1361-
13621364
return new_node;
13631365
}
13641366

ODIN_II/SRC/verilog_bison.y

Lines changed: 71 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ int yylex(void);
5454
%token vALWAYS vAUTOMATIC vINITIAL vSPECIFY vAND vASSIGN vBEGIN vCASE vDEFAULT vDEFINE vELSE vEND vENDCASE
5555
%token vENDMODULE vENDSPECIFY vENDGENERATE vENDFUNCTION vENDTASK vIF vINOUT vINPUT vMODULE vGENERATE vFUNCTION vTASK
5656
%token vOUTPUT vPARAMETER vLOCALPARAM vPOSEDGE vXNOR vXOR vDEFPARAM voANDAND vNAND vNEGEDGE vNOR vNOT vOR vFOR
57-
5857
%token voOROR voLTE voGTE voPAL voSLEFT voSRIGHT voASRIGHT voEQUAL voNOTEQUAL voCASEEQUAL
5958
%token voCASENOTEQUAL voXNOR voNAND voNOR vWHILE vINTEGER vCLOG2 vGENVAR
6059
%token vPLUS_COLON vMINUS_COLON vSPECPARAM voUNSIGNED voSIGNED vSIGNED vCFUNC
@@ -105,14 +104,14 @@ int yylex(void);
105104
%type <node> io_declaration variable_list function_output_variable function_id_and_output_variable
106105
%type <node> integer_type_variable_list variable integer_type_variable
107106
%type <node> net_declaration integer_declaration function_instantiation task_instantiation genvar_declaration
108-
%type <node> continuous_assign multiple_inputs_gate_instance list_of_single_input_gate_declaration_instance
107+
%type <node> procedural_continuous_assignment multiple_inputs_gate_instance list_of_single_input_gate_declaration_instance
109108
%type <node> list_of_multiple_inputs_gate_declaration_instance list_of_module_instance
110109
%type <node> gate_declaration single_input_gate_instance
111110
%type <node> module_instantiation module_instance function_instance task_instance list_of_module_connections list_of_function_connections list_of_task_connections
112111
%type <node> list_of_multiple_inputs_gate_connections
113-
%type <node> module_connection always statement function_statement task_statement blocking_assignment
114-
%type <node> non_blocking_assignment conditional_statement case_statement case_item_list case_items seq_block
115-
%type <node> stmt_list delay_control event_expression_list event_expression loop_statement
112+
%type <node> module_connection always statement function_statement function_statement_items task_statement blocking_assignment
113+
%type <node> non_blocking_assignment conditional_statement function_conditional_statement case_statement function_case_statement case_item_list function_case_item_list case_items function_case_items seq_block function_seq_block
114+
%type <node> stmt_list function_stmt_list delay_control event_expression_list event_expression loop_statement function_loop_statement
116115
%type <node> expression primary expression_list module_parameter
117116
%type <node> list_of_module_parameters localparam_declaration
118117
%type <node> specify_block list_of_specify_items
@@ -199,23 +198,22 @@ list_of_generate_items:
199198
;
200199

201200
generate_item:
202-
localparam_declaration {$$ = $1;}
203-
| net_declaration {$$ = $1;}
204-
| genvar_declaration {$$ = $1;}
205-
| integer_declaration {$$ = $1;}
206-
| continuous_assign {$$ = $1;}
207-
| gate_declaration {$$ = $1;}
208-
| module_instantiation {$$ = $1;}
209-
| function_declaration {$$ = $1;}
210-
| task_declaration {$$ = $1;}
211-
| initial_block {$$ = $1;}
212-
| task_instantiation {$$ = $1;}
213-
| always {$$ = $1;}
214-
| defparam_declaration {$$ = $1;}
215-
| c_function ';' {$$ = $1;}
216-
| if_generate_construct {$$ = $1;}
217-
| case_generate_construct {$$ = $1;}
218-
| loop_generate_construct {$$ = $1;}
201+
localparam_declaration {$$ = $1;}
202+
| net_declaration {$$ = $1;}
203+
| genvar_declaration {$$ = $1;}
204+
| integer_declaration {$$ = $1;}
205+
| procedural_continuous_assignment {$$ = $1;}
206+
| gate_declaration {$$ = $1;}
207+
| module_instantiation {$$ = $1;}
208+
| function_declaration {$$ = $1;}
209+
| task_declaration {$$ = $1;}
210+
| initial_block {$$ = $1;}
211+
| always {$$ = $1;}
212+
| defparam_declaration {$$ = $1;}
213+
| c_function ';' {$$ = $1;}
214+
| if_generate_construct {$$ = $1;}
215+
| case_generate_construct {$$ = $1;}
216+
| loop_generate_construct {$$ = $1;}
219217
;
220218

221219
function_declaration:
@@ -285,9 +283,8 @@ function_item:
285283
| function_input_declaration {$$ = $1;}
286284
| net_declaration {$$ = $1;}
287285
| integer_declaration {$$ = $1;}
288-
| continuous_assign {$$ = $1;}
289286
| defparam_declaration {$$ = $1;}
290-
| function_statement {$$ = $1;} //TODO It`s temporary
287+
| function_statement {$$ = $1;}
291288
| error ';' {$$ = NULL;}
292289
;
293290

@@ -298,9 +295,8 @@ task_item:
298295
| task_inout_declaration {$$ = $1;}
299296
| net_declaration {$$ = $1;}
300297
| integer_declaration {$$ = $1;}
301-
| continuous_assign {$$ = $1;}
302298
| defparam_declaration {$$ = $1;}
303-
| task_statement {$$ = $1;} //TODO It`s temporary
299+
| task_statement {$$ = $1;}
304300
;
305301

306302
function_input_declaration:
@@ -382,7 +378,7 @@ integer_type_variable:
382378
| vSYMBOL_ID '=' primary {$$ = newIntegerTypeVarDeclare($1, NULL, NULL, NULL, NULL, $3, my_yylineno);} // ONLY FOR PARAMETER
383379
;
384380

385-
continuous_assign:
381+
procedural_continuous_assignment:
386382
vASSIGN list_of_blocking_assignment ';' {$$ = $2;}
387383
;
388384

@@ -533,11 +529,11 @@ generate_block:
533529
;
534530

535531
function_statement:
536-
statement {$$ = newAlways(NULL, $1, my_yylineno);}
532+
function_statement_items {$$ = newStatement($1, my_yylineno);}
537533
;
538534

539535
task_statement:
540-
statement {$$ = newAlways(NULL, $1, my_yylineno);}
536+
statement {$$ = newStatement($1, my_yylineno);}
541537
;
542538

543539
statement:
@@ -546,12 +542,38 @@ statement:
546542
| c_function ';' {$$ = $1;}
547543
| blocking_assignment ';' {$$ = $1;}
548544
| non_blocking_assignment ';' {$$ = $1;}
545+
| procedural_continuous_assignment {$$ = $1;}
549546
| conditional_statement {$$ = $1;}
550547
| case_statement {$$ = $1;}
551548
| loop_statement {$$ = newList(BLOCK, $1, my_yylineno);}
552549
| ';' {$$ = NULL;}
553550
;
554551

552+
function_statement_items:
553+
function_seq_block {$$ = $1;}
554+
| c_function ';' {$$ = $1;}
555+
| blocking_assignment ';' {$$ = $1;}
556+
| function_conditional_statement {$$ = $1;}
557+
| function_case_statement {$$ = $1;}
558+
| function_loop_statement {$$ = newList(BLOCK, $1, my_yylineno);}
559+
| ';' {$$ = NULL;}
560+
;
561+
562+
function_seq_block:
563+
vBEGIN function_stmt_list vEND {$$ = $2;}
564+
| vBEGIN ':' vSYMBOL_ID function_stmt_list vEND {free($3); $$ = $4;}
565+
;
566+
567+
function_stmt_list:
568+
function_stmt_list function_statement_items {$$ = newList_entry($1, $2);}
569+
| function_statement_items {$$ = newList(BLOCK, $1, my_yylineno);}
570+
;
571+
572+
function_loop_statement:
573+
vFOR '(' blocking_assignment ';' expression ';' blocking_assignment ')' function_statement_items {$$ = newFor($3, $5, $7, $9, my_yylineno);}
574+
| vWHILE '(' expression ')' function_statement_items {$$ = newWhile($3, $5, my_yylineno);}
575+
;
576+
555577
loop_statement:
556578
vFOR '(' blocking_assignment ';' expression ';' blocking_assignment ')' statement {$$ = newFor($3, $5, $7, $9, my_yylineno);}
557579
| vWHILE '(' expression ')' statement {$$ = newWhile($3, $5, my_yylineno);}
@@ -561,6 +583,15 @@ case_statement:
561583
vCASE '(' expression ')' case_item_list vENDCASE {$$ = newCase($3, $5, my_yylineno);}
562584
;
563585

586+
function_case_statement:
587+
vCASE '(' expression ')' function_case_item_list vENDCASE {$$ = newCase($3, $5, my_yylineno);}
588+
;
589+
590+
function_conditional_statement:
591+
vIF '(' expression ')' function_statement_items %prec LOWER_THAN_ELSE {$$ = newIf($3, $5, NULL, my_yylineno);}
592+
| vIF '(' expression ')' function_statement_items vELSE function_statement_items {$$ = newIf($3, $5, $7, my_yylineno);}
593+
;
594+
564595
conditional_statement:
565596
vIF '(' expression ')' statement %prec LOWER_THAN_ELSE {$$ = newIf($3, $5, NULL, my_yylineno);}
566597
| vIF '(' expression ')' statement vELSE statement {$$ = newIf($3, $5, $7, my_yylineno);}
@@ -582,11 +613,21 @@ case_item_list:
582613
| case_items {$$ = newList(CASE_LIST, $1, my_yylineno);}
583614
;
584615

616+
function_case_item_list:
617+
function_case_item_list function_case_items {$$ = newList_entry($1, $2);}
618+
| function_case_items {$$ = newList(CASE_LIST, $1, my_yylineno);}
619+
;
620+
621+
function_case_items:
622+
expression ':' function_statement_items {$$ = newCaseItem($1, $3, my_yylineno);}
623+
| vDEFAULT ':' function_statement_items {$$ = newDefaultCase($3, my_yylineno);}
624+
;
625+
585626
case_items:
586627
expression ':' statement {$$ = newCaseItem($1, $3, my_yylineno);}
587628
| vDEFAULT ':' statement {$$ = newDefaultCase($3, my_yylineno);}
588629
;
589-
630+
590631
seq_block:
591632
vBEGIN stmt_list vEND {$$ = $2;}
592633
| vBEGIN ':' vSYMBOL_ID stmt_list vEND {free($3); $$ = $4;}

ODIN_II/regression_test/benchmark/verilog/syntax/function_automatic.v

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ input [1:0] x, y;
2626
input rst;
2727

2828
case(rst)
29-
1'b0: func_out <= x + y;
30-
default: func_out <= 1'b0;
29+
1'b0: func_out = x + y;
30+
default: func_out = 1'b0;
3131
endcase
3232

3333
endfunction

ODIN_II/regression_test/benchmark/verilog/syntax/simple_function.v

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ input [1:0] x, y;
2626
input rst;
2727

2828
case(rst)
29-
1'b0: func_out <= x + y;
30-
default: func_out <= 1'b0;
29+
1'b0: func_out = x + y;
30+
default: func_out = 1'b0;
3131
endcase
3232

3333
endfunction

ODIN_II/regression_test/benchmark/verilog/syntax/simple_task.v

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,15 @@ task my_task;
2525
input [1:0] x,y;
2626
input rst;
2727
output [2:0] z;
28-
29-
case(rst)
30-
1'b0: z <= x + y;
31-
default: z <= 1'b0;
32-
endcase
33-
28+
29+
begin
30+
case(rst)
31+
1'b0: z <= x + y;
32+
default: z <= 1'b0;
33+
endcase
34+
end
3435
endtask
3536

37+
3638
endmodule
3739

0 commit comments

Comments
 (0)