2 * yosys -- Yosys Open SYnthesis Suite
4 * Copyright (C) 2012 Clifford Wolf <clifford@clifford.at>
6 * Permission to use, copy, modify, and/or distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20 * The Verilog frontend.
22 * This frontend is using the AST frontend library (see frontends/ast/).
23 * Thus this frontend does not generate RTLIL code directly but creates an
24 * AST directly from the Verilog parse tree and then passes this AST to
25 * the AST frontend library.
29 * This is the actual bison parser for Verilog code. The AST ist created directly
30 * from the bison reduce functions here. Note that this code uses a few global
31 * variables to hold the state of the AST generator and therefore this parser is
40 #include "frontends/verilog/verilog_frontend.h"
41 #include "frontends/verilog/verilog_parser.tab.hh"
42 #include "kernel/log.h"
44 #define YYLEX_PARAM &yylval, &yylloc
48 using namespace VERILOG_FRONTEND;
51 namespace VERILOG_FRONTEND {
53 std::map<std::string, int> port_stubs;
54 std::map<std::string, AstNode*> *attr_list, default_attr_list;
55 std::stack<std::map<std::string, AstNode*> *> attr_list_stack;
56 std::map<std::string, AstNode*> *albuf;
57 std::vector<UserTypeMap*> user_type_stack;
58 std::map<std::string, AstNode*> pkg_user_types;
59 std::vector<AstNode*> ast_stack;
60 struct AstNode *astbuf1, *astbuf2, *astbuf3;
61 struct AstNode *current_function_or_task;
62 struct AstNode *current_ast, *current_ast_mod;
63 int current_function_or_task_port_id;
64 std::vector<char> case_type_stack;
65 bool do_not_require_port_stubs;
66 bool default_nettype_wire;
67 bool sv_mode, formal_mode, lib_mode, specify_mode;
68 bool noassert_mode, noassume_mode, norestrict_mode;
69 bool assume_asserts_mode, assert_assumes_mode;
70 bool current_wire_rand, current_wire_const;
71 bool current_modport_input, current_modport_output;
76 #define SET_AST_NODE_LOC(WHICH, BEGIN, END) \
77 do { (WHICH)->location.first_line = (BEGIN).first_line; \
78 (WHICH)->location.first_column = (BEGIN).first_column; \
79 (WHICH)->location.last_line = (END).last_line; \
80 (WHICH)->location.last_column = (END).last_column; } while(0)
82 #define SET_RULE_LOC(LHS, BEGIN, END) \
83 do { (LHS).first_line = (BEGIN).first_line; \
84 (LHS).first_column = (BEGIN).first_column; \
85 (LHS).last_line = (END).last_line; \
86 (LHS).last_column = (END).last_column; } while(0)
88 int frontend_verilog_yylex(YYSTYPE *yylval_param, YYLTYPE *yyloc_param);
90 static void append_attr(AstNode *ast, std::map<std::string, AstNode*> *al)
92 for (auto &it : *al) {
93 if (ast->attributes.count(it.first) > 0)
94 delete ast->attributes[it.first];
95 ast->attributes[it.first] = it.second;
100 static void append_attr_clone(AstNode *ast, std::map<std::string, AstNode*> *al)
102 for (auto &it : *al) {
103 if (ast->attributes.count(it.first) > 0)
104 delete ast->attributes[it.first];
105 ast->attributes[it.first] = it.second->clone();
109 static void free_attr(std::map<std::string, AstNode*> *al)
116 struct specify_target {
121 struct specify_triple {
122 AstNode *t_min, *t_avg, *t_max;
125 struct specify_rise_fall {
130 static void addTypedefNode(std::string *name, AstNode *node)
133 auto *tnode = new AstNode(AST_TYPEDEF, node);
135 auto user_types = user_type_stack.back();
136 (*user_types)[*name] = tnode;
137 if (current_ast_mod && current_ast_mod->type == AST_PACKAGE) {
138 // typedef inside a package so we need the qualified name
139 auto qname = current_ast_mod->str + "::" + (*name).substr(1);
140 pkg_user_types[qname] = tnode;
143 ast_stack.back()->children.push_back(tnode);
146 static void enterTypeScope()
148 auto user_types = new UserTypeMap();
149 user_type_stack.push_back(user_types);
152 static void exitTypeScope()
154 user_type_stack.pop_back();
157 static bool isInLocalScope(const std::string *name)
159 // tests if a name was declared in the current block scope
160 auto user_types = user_type_stack.back();
161 return (user_types->count(*name) > 0);
164 static AstNode *makeRange(int msb = 31, int lsb = 0, bool isSigned = true)
166 auto range = new AstNode(AST_RANGE);
167 range->children.push_back(AstNode::mkconst_int(msb, true));
168 range->children.push_back(AstNode::mkconst_int(lsb, true));
169 range->is_signed = isSigned;
173 static void addRange(AstNode *parent, int msb = 31, int lsb = 0, bool isSigned = true)
175 auto range = makeRange(msb, lsb, isSigned);
176 parent->children.push_back(range);
180 %define api.prefix {frontend_verilog_yy}
183 /* The union is defined in the header, so we need to provide all the
184 * includes it requires
189 #include "frontends/verilog/verilog_frontend.h"
194 struct YOSYS_NAMESPACE_PREFIX AST::AstNode *ast;
195 std::map<std::string, YOSYS_NAMESPACE_PREFIX AST::AstNode*> *al;
196 struct specify_target *specify_target_ptr;
197 struct specify_triple *specify_triple_ptr;
198 struct specify_rise_fall *specify_rise_fall_ptr;
203 %token <string> TOK_STRING TOK_ID TOK_CONSTVAL TOK_REALVAL TOK_PRIMITIVE
204 %token <string> TOK_SVA_LABEL TOK_SPECIFY_OPER TOK_MSG_TASKS
205 %token <string> TOK_BASE TOK_BASED_CONSTVAL TOK_UNBASED_UNSIZED_CONSTVAL
206 %token <string> TOK_USER_TYPE TOK_PKG_USER_TYPE
207 %token TOK_ASSERT TOK_ASSUME TOK_RESTRICT TOK_COVER TOK_FINAL
208 %token ATTR_BEGIN ATTR_END DEFATTR_BEGIN DEFATTR_END
209 %token TOK_MODULE TOK_ENDMODULE TOK_PARAMETER TOK_LOCALPARAM TOK_DEFPARAM
210 %token TOK_PACKAGE TOK_ENDPACKAGE TOK_PACKAGESEP
211 %token TOK_INTERFACE TOK_ENDINTERFACE TOK_MODPORT TOK_VAR TOK_WILDCARD_CONNECT
212 %token TOK_INPUT TOK_OUTPUT TOK_INOUT TOK_WIRE TOK_WAND TOK_WOR TOK_REG TOK_LOGIC
213 %token TOK_INTEGER TOK_SIGNED TOK_ASSIGN TOK_ALWAYS TOK_INITIAL
214 %token TOK_ALWAYS_FF TOK_ALWAYS_COMB TOK_ALWAYS_LATCH
215 %token TOK_BEGIN TOK_END TOK_IF TOK_ELSE TOK_FOR TOK_WHILE TOK_REPEAT
216 %token TOK_DPI_FUNCTION TOK_POSEDGE TOK_NEGEDGE TOK_OR TOK_AUTOMATIC
217 %token TOK_CASE TOK_CASEX TOK_CASEZ TOK_ENDCASE TOK_DEFAULT
218 %token TOK_FUNCTION TOK_ENDFUNCTION TOK_TASK TOK_ENDTASK TOK_SPECIFY
219 %token TOK_IGNORED_SPECIFY TOK_ENDSPECIFY TOK_SPECPARAM TOK_SPECIFY_AND TOK_IGNORED_SPECIFY_AND
220 %token TOK_GENERATE TOK_ENDGENERATE TOK_GENVAR TOK_REAL
221 %token TOK_SYNOPSYS_FULL_CASE TOK_SYNOPSYS_PARALLEL_CASE
222 %token TOK_SUPPLY0 TOK_SUPPLY1 TOK_TO_SIGNED TOK_TO_UNSIGNED
223 %token TOK_POS_INDEXED TOK_NEG_INDEXED TOK_PROPERTY TOK_ENUM TOK_TYPEDEF
224 %token TOK_RAND TOK_CONST TOK_CHECKER TOK_ENDCHECKER TOK_EVENTUALLY
225 %token TOK_INCREMENT TOK_DECREMENT TOK_UNIQUE TOK_PRIORITY
227 %type <ast> range range_or_multirange non_opt_range non_opt_multirange range_or_signed_int
228 %type <ast> wire_type expr basic_expr concat_list rvalue lvalue lvalue_concat_list
229 %type <string> opt_label opt_sva_label tok_prim_wrapper hierarchical_id hierarchical_type_id integral_number
230 %type <string> type_name
231 %type <ast> opt_enum_init
232 %type <boolean> opt_signed opt_property unique_case_attr always_comb_or_latch always_or_always_ff
233 %type <al> attr case_attr
235 %type <specify_target_ptr> specify_target
236 %type <specify_triple_ptr> specify_triple specify_opt_triple
237 %type <specify_rise_fall_ptr> specify_rise_fall
238 %type <ast> specify_if specify_condition
239 %type <ch> specify_edge
241 // operator precedence from low to high
247 %left OP_EQ OP_NE OP_EQX OP_NEX
248 %left '<' OP_LE OP_GE '>'
249 %left OP_SHL OP_SHR OP_SSHL OP_SSHR
255 %define parse.error verbose
256 %define parse.lac full
268 ast_stack.push_back(current_ast);
270 ast_stack.pop_back();
271 log_assert(GetSize(ast_stack) == 0);
272 for (auto &it : default_attr_list)
274 default_attr_list.clear();
280 task_func_decl design |
282 localparam_decl design |
283 typedef_decl design |
290 if (attr_list != nullptr)
291 attr_list_stack.push(attr_list);
292 attr_list = new std::map<std::string, AstNode*>;
293 for (auto &it : default_attr_list)
294 (*attr_list)[it.first] = it.second->clone();
297 if (!attr_list_stack.empty()) {
298 attr_list = attr_list_stack.top();
299 attr_list_stack.pop();
305 attr_opt ATTR_BEGIN opt_attr_list ATTR_END {
306 SET_RULE_LOC(@$, @2, @$);
312 if (attr_list != nullptr)
313 attr_list_stack.push(attr_list);
314 attr_list = new std::map<std::string, AstNode*>;
315 for (auto &it : default_attr_list)
317 default_attr_list.clear();
319 attr_list->swap(default_attr_list);
321 if (!attr_list_stack.empty()) {
322 attr_list = attr_list_stack.top();
323 attr_list_stack.pop();
329 attr_list | /* empty */;
333 attr_list ',' attr_assign;
337 if (attr_list->count(*$1) != 0)
338 delete (*attr_list)[*$1];
339 (*attr_list)[*$1] = AstNode::mkconst_int(1, false);
342 hierarchical_id '=' expr {
343 if (attr_list->count(*$1) != 0)
344 delete (*attr_list)[*$1];
345 (*attr_list)[*$1] = $3;
353 hierarchical_id TOK_PACKAGESEP TOK_ID {
354 if ($3->compare(0, 1, "\\") == 0)
355 *$1 += "::" + $3->substr(1);
361 hierarchical_id '.' TOK_ID {
362 if ($3->compare(0, 1, "\\") == 0)
363 *$1 += "." + $3->substr(1);
370 hierarchical_type_id:
372 | TOK_PKG_USER_TYPE // package qualified type name
373 | '(' TOK_USER_TYPE ')' { $$ = $2; } // non-standard grammar
380 do_not_require_port_stubs = false;
381 AstNode *mod = new AstNode(AST_MODULE);
382 ast_stack.back()->children.push_back(mod);
383 ast_stack.push_back(mod);
384 current_ast_mod = mod;
388 append_attr(mod, $1);
390 } module_para_opt module_args_opt ';' module_body TOK_ENDMODULE {
391 if (port_stubs.size() != 0)
392 frontend_verilog_yyerror("Missing details for module port `%s'.",
393 port_stubs.begin()->first.c_str());
394 SET_AST_NODE_LOC(ast_stack.back(), @2, @$);
395 ast_stack.pop_back();
396 log_assert(ast_stack.size() == 1);
397 current_ast_mod = NULL;
402 '#' '(' { astbuf1 = nullptr; } module_para_list { if (astbuf1) delete astbuf1; } ')' | /* empty */;
405 single_module_para | module_para_list ',' single_module_para;
410 if (astbuf1) delete astbuf1;
411 astbuf1 = new AstNode(AST_PARAMETER);
412 astbuf1->children.push_back(AstNode::mkconst_int(0, true));
413 append_attr(astbuf1, $1);
414 } param_type single_param_decl |
415 attr TOK_LOCALPARAM {
416 if (astbuf1) delete astbuf1;
417 astbuf1 = new AstNode(AST_LOCALPARAM);
418 astbuf1->children.push_back(AstNode::mkconst_int(0, true));
419 append_attr(astbuf1, $1);
420 } param_type single_param_decl |
424 '(' ')' | /* empty */ | '(' module_args optional_comma ')';
427 module_arg | module_args ',' module_arg;
432 module_arg_opt_assignment:
434 if (ast_stack.back()->children.size() > 0 && ast_stack.back()->children.back()->type == AST_WIRE) {
435 AstNode *wire = new AstNode(AST_IDENTIFIER);
436 wire->str = ast_stack.back()->children.back()->str;
437 if (ast_stack.back()->children.back()->is_input) {
438 AstNode *n = ast_stack.back()->children.back();
439 if (n->attributes.count("\\defaultvalue"))
440 delete n->attributes.at("\\defaultvalue");
441 n->attributes["\\defaultvalue"] = $2;
443 if (ast_stack.back()->children.back()->is_reg || ast_stack.back()->children.back()->is_logic)
444 ast_stack.back()->children.push_back(new AstNode(AST_INITIAL, new AstNode(AST_BLOCK, new AstNode(AST_ASSIGN_LE, wire, $2))));
446 ast_stack.back()->children.push_back(new AstNode(AST_ASSIGN, wire, $2));
448 frontend_verilog_yyerror("SystemVerilog interface in module port list cannot have a default value.");
454 if (ast_stack.back()->children.size() > 0 && ast_stack.back()->children.back()->type == AST_WIRE) {
455 AstNode *node = ast_stack.back()->children.back()->clone();
457 node->port_id = ++port_counter;
458 ast_stack.back()->children.push_back(node);
459 SET_AST_NODE_LOC(node, @1, @1);
461 if (port_stubs.count(*$1) != 0)
462 frontend_verilog_yyerror("Duplicate module port `%s'.", $1->c_str());
463 port_stubs[*$1] = ++port_counter;
466 } module_arg_opt_assignment |
468 astbuf1 = new AstNode(AST_INTERFACEPORT);
469 astbuf1->children.push_back(new AstNode(AST_INTERFACEPORTTYPE));
470 astbuf1->children[0]->str = *$1;
472 } TOK_ID { /* SV interfaces */
474 frontend_verilog_yyerror("Interface found in port list (%s). This is not supported unless read_verilog is called with -sv!", $3->c_str());
475 astbuf2 = astbuf1->clone(); // really only needed if multiple instances of same type.
478 astbuf2->port_id = ++port_counter;
479 ast_stack.back()->children.push_back(astbuf2);
480 delete astbuf1; // really only needed if multiple instances of same type.
481 } module_arg_opt_assignment |
482 attr wire_type range TOK_ID {
485 SET_AST_NODE_LOC(node, @4, @4);
486 node->port_id = ++port_counter;
488 node->children.push_back($3);
489 if (!node->is_input && !node->is_output)
490 frontend_verilog_yyerror("Module port `%s' is neither input nor output.", $4->c_str());
491 if (node->is_reg && node->is_input && !node->is_output && !sv_mode)
492 frontend_verilog_yyerror("Input port `%s' is declared as register.", $4->c_str());
493 ast_stack.back()->children.push_back(node);
494 append_attr(node, $1);
496 } module_arg_opt_assignment |
498 do_not_require_port_stubs = true;
505 AstNode *mod = new AstNode(AST_PACKAGE);
506 ast_stack.back()->children.push_back(mod);
507 ast_stack.push_back(mod);
508 current_ast_mod = mod;
510 append_attr(mod, $1);
511 } ';' package_body TOK_ENDPACKAGE {
512 ast_stack.pop_back();
513 current_ast_mod = NULL;
518 package_body package_body_stmt
530 do_not_require_port_stubs = false;
531 AstNode *intf = new AstNode(AST_INTERFACE);
532 ast_stack.back()->children.push_back(intf);
533 ast_stack.push_back(intf);
534 current_ast_mod = intf;
539 } module_para_opt module_args_opt ';' interface_body TOK_ENDINTERFACE {
540 if (port_stubs.size() != 0)
541 frontend_verilog_yyerror("Missing details for module port `%s'.",
542 port_stubs.begin()->first.c_str());
543 ast_stack.pop_back();
544 log_assert(ast_stack.size() == 1);
545 current_ast_mod = NULL;
550 interface_body interface_body_stmt |;
553 param_decl | localparam_decl | typedef_decl | defparam_decl | wire_decl | always_stmt | assign_stmt |
557 '#' TOK_ID { delete $2; } |
558 '#' TOK_CONSTVAL { delete $2; } |
559 '#' TOK_REALVAL { delete $2; } |
560 '#' '(' expr ')' { delete $3; } |
561 '#' '(' expr ':' expr ':' expr ')' { delete $3; delete $5; delete $7; };
564 non_opt_delay | /* empty */;
568 astbuf3 = new AstNode(AST_WIRE);
569 current_wire_rand = false;
570 current_wire_const = false;
571 } wire_type_token_list {
573 SET_RULE_LOC(@$, @2, @$);
576 wire_type_token_list:
578 wire_type_token_list wire_type_token |
580 hierarchical_type_id {
581 astbuf3->is_custom_type = true;
582 astbuf3->children.push_back(new AstNode(AST_WIRETYPE));
583 astbuf3->children.back()->str = *$1;
588 astbuf3->is_input = true;
591 astbuf3->is_output = true;
594 astbuf3->is_input = true;
595 astbuf3->is_output = true;
602 astbuf3->is_wor = true;
605 astbuf3->is_wand = true;
608 astbuf3->is_reg = true;
611 astbuf3->is_logic = true;
614 astbuf3->is_logic = true;
617 astbuf3->is_reg = true;
618 astbuf3->range_left = 31;
619 astbuf3->range_right = 0;
620 astbuf3->is_signed = true;
623 astbuf3->type = AST_GENVAR;
624 astbuf3->is_reg = true;
625 astbuf3->is_signed = true;
626 astbuf3->range_left = 31;
627 astbuf3->range_right = 0;
630 astbuf3->is_signed = true;
633 current_wire_rand = true;
636 current_wire_const = true;
640 '[' expr ':' expr ']' {
641 $$ = new AstNode(AST_RANGE);
642 $$->children.push_back($2);
643 $$->children.push_back($4);
645 '[' expr TOK_POS_INDEXED expr ']' {
646 $$ = new AstNode(AST_RANGE);
647 AstNode *expr = new AstNode(AST_CONCAT, $2);
648 $$->children.push_back(new AstNode(AST_SUB, new AstNode(AST_ADD, expr->clone(), $4), AstNode::mkconst_int(1, true)));
649 $$->children.push_back(new AstNode(AST_ADD, expr, AstNode::mkconst_int(0, true)));
651 '[' expr TOK_NEG_INDEXED expr ']' {
652 $$ = new AstNode(AST_RANGE);
653 AstNode *expr = new AstNode(AST_CONCAT, $2);
654 $$->children.push_back(new AstNode(AST_ADD, expr, AstNode::mkconst_int(0, true)));
655 $$->children.push_back(new AstNode(AST_SUB, new AstNode(AST_ADD, expr->clone(), AstNode::mkconst_int(1, true)), $4));
658 $$ = new AstNode(AST_RANGE);
659 $$->children.push_back($2);
663 non_opt_range non_opt_range {
664 $$ = new AstNode(AST_MULTIRANGE, $1, $2);
666 non_opt_multirange non_opt_range {
668 $$->children.push_back($2);
681 non_opt_multirange { $$ = $1; };
688 $$ = new AstNode(AST_RANGE);
689 $$->children.push_back(AstNode::mkconst_int(31, true));
690 $$->children.push_back(AstNode::mkconst_int(0, true));
691 $$->is_signed = true;
695 module_body module_body_stmt |
696 /* the following line makes the generate..endgenrate keywords optional */
697 module_body gen_stmt |
701 task_func_decl | specify_block | param_decl | localparam_decl | typedef_decl | defparam_decl | specparam_declaration | wire_decl | assign_stmt | cell_stmt |
703 always_stmt | TOK_GENERATE module_gen_body TOK_ENDGENERATE | defattr | assert_property | checker_decl | ignored_specify_block;
706 TOK_CHECKER TOK_ID ';' {
707 AstNode *node = new AstNode(AST_GENBLOCK);
709 ast_stack.back()->children.push_back(node);
710 ast_stack.push_back(node);
711 } module_body TOK_ENDCHECKER {
713 ast_stack.pop_back();
717 attr TOK_DPI_FUNCTION TOK_ID TOK_ID {
718 current_function_or_task = new AstNode(AST_DPI_FUNCTION, AstNode::mkconst_str(*$3), AstNode::mkconst_str(*$4));
719 current_function_or_task->str = *$4;
720 append_attr(current_function_or_task, $1);
721 ast_stack.back()->children.push_back(current_function_or_task);
724 } opt_dpi_function_args ';' {
725 current_function_or_task = NULL;
727 attr TOK_DPI_FUNCTION TOK_ID '=' TOK_ID TOK_ID {
728 current_function_or_task = new AstNode(AST_DPI_FUNCTION, AstNode::mkconst_str(*$5), AstNode::mkconst_str(*$3));
729 current_function_or_task->str = *$6;
730 append_attr(current_function_or_task, $1);
731 ast_stack.back()->children.push_back(current_function_or_task);
735 } opt_dpi_function_args ';' {
736 current_function_or_task = NULL;
738 attr TOK_DPI_FUNCTION TOK_ID ':' TOK_ID '=' TOK_ID TOK_ID {
739 current_function_or_task = new AstNode(AST_DPI_FUNCTION, AstNode::mkconst_str(*$7), AstNode::mkconst_str(*$3 + ":" + RTLIL::unescape_id(*$5)));
740 current_function_or_task->str = *$8;
741 append_attr(current_function_or_task, $1);
742 ast_stack.back()->children.push_back(current_function_or_task);
747 } opt_dpi_function_args ';' {
748 current_function_or_task = NULL;
750 attr TOK_TASK opt_automatic TOK_ID {
751 current_function_or_task = new AstNode(AST_TASK);
752 current_function_or_task->str = *$4;
753 append_attr(current_function_or_task, $1);
754 ast_stack.back()->children.push_back(current_function_or_task);
755 ast_stack.push_back(current_function_or_task);
756 current_function_or_task_port_id = 1;
758 } task_func_args_opt ';' task_func_body TOK_ENDTASK {
759 current_function_or_task = NULL;
760 ast_stack.pop_back();
762 attr TOK_FUNCTION opt_automatic opt_signed range_or_signed_int TOK_ID {
763 current_function_or_task = new AstNode(AST_FUNCTION);
764 current_function_or_task->str = *$6;
765 append_attr(current_function_or_task, $1);
766 ast_stack.back()->children.push_back(current_function_or_task);
767 ast_stack.push_back(current_function_or_task);
768 AstNode *outreg = new AstNode(AST_WIRE);
770 outreg->is_signed = $4;
771 outreg->is_reg = true;
773 outreg->children.push_back($5);
774 outreg->is_signed = $4 || $5->is_signed;
775 $5->is_signed = false;
777 current_function_or_task->children.push_back(outreg);
778 current_function_or_task_port_id = 1;
780 } task_func_args_opt ';' task_func_body TOK_ENDFUNCTION {
781 current_function_or_task = NULL;
782 ast_stack.pop_back();
787 current_function_or_task->children.push_back(AstNode::mkconst_str(*$1));
792 current_function_or_task->children.push_back(AstNode::mkconst_str(*$1));
796 opt_dpi_function_args:
797 '(' dpi_function_args ')' |
801 dpi_function_args ',' dpi_function_arg |
802 dpi_function_args ',' |
819 '(' ')' | /* empty */ | '(' {
823 } task_func_args optional_comma {
831 task_func_port | task_func_args ',' task_func_port;
834 attr wire_type range {
844 if (astbuf1->range_left >= 0 && astbuf1->range_right >= 0) {
846 frontend_verilog_yyerror("integer/genvar types cannot have packed dimensions (task/function arguments)");
848 astbuf2 = new AstNode(AST_RANGE);
849 astbuf2->children.push_back(AstNode::mkconst_int(astbuf1->range_left, true));
850 astbuf2->children.push_back(AstNode::mkconst_int(astbuf1->range_right, true));
853 if (astbuf2 && astbuf2->children.size() != 2)
854 frontend_verilog_yyerror("task/function argument range must be of the form: [<expr>:<expr>], [<expr>+:<expr>], or [<expr>-:<expr>]");
855 } wire_name | wire_name;
858 task_func_body behavioral_stmt |
861 /*************************** specify parser ***************************/
864 TOK_SPECIFY specify_item_list TOK_ENDSPECIFY;
867 specify_item specify_item_list |
871 specify_if '(' specify_edge expr TOK_SPECIFY_OPER specify_target ')' '=' specify_rise_fall ';' {
872 AstNode *en_expr = $1;
873 char specify_edge = $3;
874 AstNode *src_expr = $4;
876 specify_target *target = $6;
877 specify_rise_fall *timing = $9;
879 if (specify_edge != 0 && target->dat == nullptr)
880 frontend_verilog_yyerror("Found specify edge but no data spec.\n");
882 AstNode *cell = new AstNode(AST_CELL);
883 ast_stack.back()->children.push_back(cell);
884 cell->str = stringf("$specify$%d", autoidx++);
885 cell->children.push_back(new AstNode(AST_CELLTYPE));
886 cell->children.back()->str = target->dat ? "$specify3" : "$specify2";
888 char oper_polarity = 0;
889 char oper_type = oper->at(0);
891 if (oper->size() == 3) {
892 oper_polarity = oper->at(0);
893 oper_type = oper->at(1);
896 cell->children.push_back(new AstNode(AST_PARASET, AstNode::mkconst_int(oper_type == '*', false, 1)));
897 cell->children.back()->str = "\\FULL";
899 cell->children.push_back(new AstNode(AST_PARASET, AstNode::mkconst_int(oper_polarity != 0, false, 1)));
900 cell->children.back()->str = "\\SRC_DST_PEN";
902 cell->children.push_back(new AstNode(AST_PARASET, AstNode::mkconst_int(oper_polarity == '+', false, 1)));
903 cell->children.back()->str = "\\SRC_DST_POL";
905 cell->children.push_back(new AstNode(AST_PARASET, timing->rise.t_min));
906 cell->children.back()->str = "\\T_RISE_MIN";
908 cell->children.push_back(new AstNode(AST_PARASET, timing->rise.t_avg));
909 cell->children.back()->str = "\\T_RISE_TYP";
911 cell->children.push_back(new AstNode(AST_PARASET, timing->rise.t_max));
912 cell->children.back()->str = "\\T_RISE_MAX";
914 cell->children.push_back(new AstNode(AST_PARASET, timing->fall.t_min));
915 cell->children.back()->str = "\\T_FALL_MIN";
917 cell->children.push_back(new AstNode(AST_PARASET, timing->fall.t_avg));
918 cell->children.back()->str = "\\T_FALL_TYP";
920 cell->children.push_back(new AstNode(AST_PARASET, timing->fall.t_max));
921 cell->children.back()->str = "\\T_FALL_MAX";
923 cell->children.push_back(new AstNode(AST_ARGUMENT, en_expr ? en_expr : AstNode::mkconst_int(1, false, 1)));
924 cell->children.back()->str = "\\EN";
926 cell->children.push_back(new AstNode(AST_ARGUMENT, src_expr));
927 cell->children.back()->str = "\\SRC";
929 cell->children.push_back(new AstNode(AST_ARGUMENT, target->dst));
930 cell->children.back()->str = "\\DST";
934 cell->children.push_back(new AstNode(AST_PARASET, AstNode::mkconst_int(specify_edge != 0, false, 1)));
935 cell->children.back()->str = "\\EDGE_EN";
937 cell->children.push_back(new AstNode(AST_PARASET, AstNode::mkconst_int(specify_edge == 'p', false, 1)));
938 cell->children.back()->str = "\\EDGE_POL";
940 cell->children.push_back(new AstNode(AST_PARASET, AstNode::mkconst_int(target->polarity_op != 0, false, 1)));
941 cell->children.back()->str = "\\DAT_DST_PEN";
943 cell->children.push_back(new AstNode(AST_PARASET, AstNode::mkconst_int(target->polarity_op == '+', false, 1)));
944 cell->children.back()->str = "\\DAT_DST_POL";
946 cell->children.push_back(new AstNode(AST_ARGUMENT, target->dat));
947 cell->children.back()->str = "\\DAT";
954 TOK_ID '(' specify_edge expr specify_condition ',' specify_edge expr specify_condition ',' specify_triple specify_opt_triple ')' ';' {
955 if (*$1 != "$setup" && *$1 != "$hold" && *$1 != "$setuphold" && *$1 != "$removal" && *$1 != "$recovery" &&
956 *$1 != "$recrem" && *$1 != "$skew" && *$1 != "$timeskew" && *$1 != "$fullskew" && *$1 != "$nochange")
957 frontend_verilog_yyerror("Unsupported specify rule type: %s\n", $1->c_str());
959 AstNode *src_pen = AstNode::mkconst_int($3 != 0, false, 1);
960 AstNode *src_pol = AstNode::mkconst_int($3 == 'p', false, 1);
961 AstNode *src_expr = $4, *src_en = $5 ? $5 : AstNode::mkconst_int(1, false, 1);
963 AstNode *dst_pen = AstNode::mkconst_int($7 != 0, false, 1);
964 AstNode *dst_pol = AstNode::mkconst_int($7 == 'p', false, 1);
965 AstNode *dst_expr = $8, *dst_en = $9 ? $9 : AstNode::mkconst_int(1, false, 1);
967 specify_triple *limit = $11;
968 specify_triple *limit2 = $12;
970 AstNode *cell = new AstNode(AST_CELL);
971 ast_stack.back()->children.push_back(cell);
972 cell->str = stringf("$specify$%d", autoidx++);
973 cell->children.push_back(new AstNode(AST_CELLTYPE));
974 cell->children.back()->str = "$specrule";
976 cell->children.push_back(new AstNode(AST_PARASET, AstNode::mkconst_str(*$1)));
977 cell->children.back()->str = "\\TYPE";
979 cell->children.push_back(new AstNode(AST_PARASET, limit->t_min));
980 cell->children.back()->str = "\\T_LIMIT_MIN";
982 cell->children.push_back(new AstNode(AST_PARASET, limit->t_avg));
983 cell->children.back()->str = "\\T_LIMIT_TYP";
985 cell->children.push_back(new AstNode(AST_PARASET, limit->t_max));
986 cell->children.back()->str = "\\T_LIMIT_MAX";
988 cell->children.push_back(new AstNode(AST_PARASET, limit2 ? limit2->t_min : AstNode::mkconst_int(0, true)));
989 cell->children.back()->str = "\\T_LIMIT2_MIN";
991 cell->children.push_back(new AstNode(AST_PARASET, limit2 ? limit2->t_avg : AstNode::mkconst_int(0, true)));
992 cell->children.back()->str = "\\T_LIMIT2_TYP";
994 cell->children.push_back(new AstNode(AST_PARASET, limit2 ? limit2->t_max : AstNode::mkconst_int(0, true)));
995 cell->children.back()->str = "\\T_LIMIT2_MAX";
997 cell->children.push_back(new AstNode(AST_PARASET, src_pen));
998 cell->children.back()->str = "\\SRC_PEN";
1000 cell->children.push_back(new AstNode(AST_PARASET, src_pol));
1001 cell->children.back()->str = "\\SRC_POL";
1003 cell->children.push_back(new AstNode(AST_PARASET, dst_pen));
1004 cell->children.back()->str = "\\DST_PEN";
1006 cell->children.push_back(new AstNode(AST_PARASET, dst_pol));
1007 cell->children.back()->str = "\\DST_POL";
1009 cell->children.push_back(new AstNode(AST_ARGUMENT, src_en));
1010 cell->children.back()->str = "\\SRC_EN";
1012 cell->children.push_back(new AstNode(AST_ARGUMENT, src_expr));
1013 cell->children.back()->str = "\\SRC";
1015 cell->children.push_back(new AstNode(AST_ARGUMENT, dst_en));
1016 cell->children.back()->str = "\\DST_EN";
1018 cell->children.push_back(new AstNode(AST_ARGUMENT, dst_expr));
1019 cell->children.back()->str = "\\DST";
1025 ',' specify_triple {
1033 TOK_IF '(' expr ')' {
1041 TOK_SPECIFY_AND expr {
1050 $$ = new specify_target;
1051 $$->polarity_op = 0;
1055 '(' expr ':' expr ')'{
1056 $$ = new specify_target;
1057 $$->polarity_op = 0;
1061 '(' expr TOK_NEG_INDEXED expr ')'{
1062 $$ = new specify_target;
1063 $$->polarity_op = '-';
1067 '(' expr TOK_POS_INDEXED expr ')'{
1068 $$ = new specify_target;
1069 $$->polarity_op = '+';
1075 TOK_POSEDGE { $$ = 'p'; } |
1076 TOK_NEGEDGE { $$ = 'n'; } |
1081 $$ = new specify_rise_fall;
1083 $$->fall.t_min = $1->t_min->clone();
1084 $$->fall.t_avg = $1->t_avg->clone();
1085 $$->fall.t_max = $1->t_max->clone();
1088 '(' specify_triple ',' specify_triple ')' {
1089 $$ = new specify_rise_fall;
1095 '(' specify_triple ',' specify_triple ',' specify_triple ')' {
1096 $$ = new specify_rise_fall;
1102 log_file_warning(current_filename, get_line_num(), "Path delay expressions beyond rise/fall not currently supported. Ignoring.\n");
1104 '(' specify_triple ',' specify_triple ',' specify_triple ',' specify_triple ',' specify_triple ',' specify_triple ')' {
1105 $$ = new specify_rise_fall;
1114 log_file_warning(current_filename, get_line_num(), "Path delay expressions beyond rise/fall not currently supported. Ignoring.\n");
1116 '(' specify_triple ',' specify_triple ',' specify_triple ',' specify_triple ',' specify_triple ',' specify_triple ',' specify_triple ',' specify_triple ',' specify_triple ',' specify_triple ',' specify_triple ',' specify_triple ')' {
1117 $$ = new specify_rise_fall;
1132 log_file_warning(current_filename, get_line_num(), "Path delay expressions beyond rise/fall not currently supported. Ignoring.\n");
1137 $$ = new specify_triple;
1139 $$->t_avg = $1->clone();
1140 $$->t_max = $1->clone();
1142 expr ':' expr ':' expr {
1143 $$ = new specify_triple;
1149 /******************** ignored specify parser **************************/
1151 ignored_specify_block:
1152 TOK_IGNORED_SPECIFY ignored_specify_item_opt TOK_ENDSPECIFY |
1153 TOK_IGNORED_SPECIFY TOK_ENDSPECIFY ;
1155 ignored_specify_item_opt:
1156 ignored_specify_item_opt ignored_specify_item |
1157 ignored_specify_item ;
1159 ignored_specify_item:
1160 specparam_declaration
1161 // | pulsestyle_declaration
1162 // | showcancelled_declaration
1164 | system_timing_declaration
1167 specparam_declaration:
1168 TOK_SPECPARAM list_of_specparam_assignments ';' |
1169 TOK_SPECPARAM specparam_range list_of_specparam_assignments ';' ;
1171 // IEEE 1364-2005 calls this sinmply 'range' but the current 'range' rule allows empty match
1172 // and the 'non_opt_range' rule allows index ranges not allowed by 1364-2005
1173 // exxxxtending this for SV specparam would change this anyhow
1175 '[' ignspec_constant_expression ':' ignspec_constant_expression ']' ;
1177 list_of_specparam_assignments:
1178 specparam_assignment | list_of_specparam_assignments ',' specparam_assignment;
1180 specparam_assignment:
1181 ignspec_id '=' ignspec_expr ;
1184 TOK_IF '(' ignspec_expr ')' | /* empty */;
1187 simple_path_declaration ';'
1188 // | edge_sensitive_path_declaration
1189 // | state_dependent_path_declaration
1192 simple_path_declaration :
1193 ignspec_opt_cond parallel_path_description '=' path_delay_value |
1194 ignspec_opt_cond full_path_description '=' path_delay_value
1198 '(' ignspec_expr list_of_path_delay_extra_expressions ')'
1200 | ignspec_expr list_of_path_delay_extra_expressions
1203 list_of_path_delay_extra_expressions :
1205 | ',' ignspec_expr list_of_path_delay_extra_expressions
1208 specify_edge_identifier :
1209 TOK_POSEDGE | TOK_NEGEDGE ;
1211 parallel_path_description :
1212 '(' specify_input_terminal_descriptor opt_polarity_operator '=' '>' specify_output_terminal_descriptor ')' |
1213 '(' specify_edge_identifier specify_input_terminal_descriptor '=' '>' '(' specify_output_terminal_descriptor opt_polarity_operator ':' ignspec_expr ')' ')' |
1214 '(' specify_edge_identifier specify_input_terminal_descriptor '=' '>' '(' specify_output_terminal_descriptor TOK_POS_INDEXED ignspec_expr ')' ')' ;
1216 full_path_description :
1217 '(' list_of_path_inputs '*' '>' list_of_path_outputs ')' |
1218 '(' specify_edge_identifier list_of_path_inputs '*' '>' '(' list_of_path_outputs opt_polarity_operator ':' ignspec_expr ')' ')' |
1219 '(' specify_edge_identifier list_of_path_inputs '*' '>' '(' list_of_path_outputs TOK_POS_INDEXED ignspec_expr ')' ')' ;
1221 // This was broken into 2 rules to solve shift/reduce conflicts
1222 list_of_path_inputs :
1223 specify_input_terminal_descriptor opt_polarity_operator |
1224 specify_input_terminal_descriptor more_path_inputs opt_polarity_operator ;
1227 ',' specify_input_terminal_descriptor |
1228 more_path_inputs ',' specify_input_terminal_descriptor ;
1230 list_of_path_outputs :
1231 specify_output_terminal_descriptor |
1232 list_of_path_outputs ',' specify_output_terminal_descriptor ;
1234 opt_polarity_operator :
1239 // Good enough for the time being
1240 specify_input_terminal_descriptor :
1243 // Good enough for the time being
1244 specify_output_terminal_descriptor :
1247 system_timing_declaration :
1248 ignspec_id '(' system_timing_args ')' ';' ;
1251 TOK_POSEDGE ignspec_id |
1252 TOK_NEGEDGE ignspec_id |
1255 system_timing_args :
1257 system_timing_args TOK_IGNORED_SPECIFY_AND system_timing_arg |
1258 system_timing_args ',' system_timing_arg ;
1260 // for the time being this is OK, but we may write our own expr here.
1261 // as I'm not sure it is legal to use a full expr here (probably not)
1262 // On the other hand, other rules requiring constant expressions also use 'expr'
1263 // (such as param assignment), so we may leave this as-is, perhaps adding runtime checks for constant-ness
1264 ignspec_constant_expression:
1265 expr { delete $1; };
1268 expr { delete $1; } |
1269 expr ':' expr ':' expr {
1276 TOK_ID { delete $1; }
1277 range_or_multirange { delete $3; };
1279 /**********************************************************************/
1283 astbuf1->is_signed = true;
1288 if (astbuf1->children.size() != 1)
1289 frontend_verilog_yyerror("Internal error in param_integer - should not happen?");
1290 astbuf1->children.push_back(new AstNode(AST_RANGE));
1291 astbuf1->children.back()->children.push_back(AstNode::mkconst_int(31, true));
1292 astbuf1->children.back()->children.push_back(AstNode::mkconst_int(0, true));
1293 astbuf1->is_signed = true;
1298 if (astbuf1->children.size() != 1)
1299 frontend_verilog_yyerror("Parameter already declared as integer, cannot set to real.");
1300 astbuf1->children.push_back(new AstNode(AST_REALVALUE));
1306 if (astbuf1->children.size() != 1)
1307 frontend_verilog_yyerror("integer/real parameters should not have a range.");
1308 astbuf1->children.push_back($1);
1313 param_signed param_integer param_real param_range |
1314 hierarchical_type_id {
1315 astbuf1->is_custom_type = true;
1316 astbuf1->children.push_back(new AstNode(AST_WIRETYPE));
1317 astbuf1->children.back()->str = *$1;
1321 attr TOK_PARAMETER {
1322 astbuf1 = new AstNode(AST_PARAMETER);
1323 astbuf1->children.push_back(AstNode::mkconst_int(0, true));
1324 append_attr(astbuf1, $1);
1325 } param_type param_decl_list ';' {
1330 attr TOK_LOCALPARAM {
1331 astbuf1 = new AstNode(AST_LOCALPARAM);
1332 astbuf1->children.push_back(AstNode::mkconst_int(0, true));
1333 append_attr(astbuf1, $1);
1334 } param_type param_decl_list ';' {
1339 single_param_decl | param_decl_list ',' single_param_decl;
1344 if (astbuf1 == nullptr) {
1346 frontend_verilog_yyerror("In pure Verilog (not SystemVerilog), parameter/localparam with an initializer must use the parameter/localparam keyword");
1347 node = new AstNode(AST_PARAMETER);
1348 node->children.push_back(AstNode::mkconst_int(0, true));
1350 node = astbuf1->clone();
1353 delete node->children[0];
1354 node->children[0] = $3;
1355 ast_stack.back()->children.push_back(node);
1360 TOK_DEFPARAM defparam_decl_list ';';
1363 single_defparam_decl | defparam_decl_list ',' single_defparam_decl;
1365 single_defparam_decl:
1366 range rvalue '=' expr {
1367 AstNode *node = new AstNode(AST_DEFPARAM);
1368 node->children.push_back($2);
1369 node->children.push_back($4);
1371 node->children.push_back($1);
1372 ast_stack.back()->children.push_back(node);
1375 enum_type: TOK_ENUM {
1376 static int enum_count;
1377 // create parent node for the enum
1378 astbuf2 = new AstNode(AST_ENUM);
1379 ast_stack.back()->children.push_back(astbuf2);
1380 astbuf2->str = std::string("$enum");
1381 astbuf2->str += std::to_string(enum_count++);
1382 // create the template for the names
1383 astbuf1 = new AstNode(AST_ENUM_ITEM);
1384 astbuf1->children.push_back(AstNode::mkconst_int(0, true));
1385 } param_signed enum_base_type '{' enum_name_list '}' { // create template for the enum vars
1386 auto tnode = astbuf1->clone();
1389 tnode->type = AST_WIRE;
1390 tnode->attributes["\\enum_type"] = AstNode::mkconst_str(astbuf2->str);
1391 // drop constant but keep any range
1392 delete tnode->children[0];
1393 tnode->children.erase(tnode->children.begin()); }
1396 enum_base_type: int_vec param_range
1398 | /* nothing */ {astbuf1->is_reg = true; addRange(astbuf1); }
1401 int_atom: TOK_INTEGER {astbuf1->is_reg=true; addRange(astbuf1); } // probably should do byte, range [7:0] here
1404 int_vec: TOK_REG {astbuf1->is_reg = true;}
1405 | TOK_LOGIC {astbuf1->is_logic = true;}
1410 | enum_name_list ',' enum_name_decl
1414 TOK_ID opt_enum_init {
1416 log_assert(astbuf1);
1417 log_assert(astbuf2);
1418 auto node = astbuf1->clone();
1421 delete node->children[0];
1422 node->children[0] = $2 ?: new AstNode(AST_NONE);
1423 astbuf2->children.push_back(node);
1428 '=' basic_expr { $$ = $2; } // TODO: restrict this
1429 | /* optional */ { $$ = NULL; }
1434 | enum_var_list ',' enum_var
1438 log_assert(astbuf1);
1439 log_assert(astbuf2);
1440 auto node = astbuf1->clone();
1441 ast_stack.back()->children.push_back(node);
1444 node->is_enum = true;
1448 enum_decl: enum_type enum_var_list ';' {
1449 //enum_type creates astbuf1 for use by typedef only
1455 attr wire_type range {
1459 if (astbuf1->range_left >= 0 && astbuf1->range_right >= 0) {
1461 frontend_verilog_yyerror("integer/genvar types cannot have packed dimensions.");
1463 astbuf2 = new AstNode(AST_RANGE);
1464 astbuf2->children.push_back(AstNode::mkconst_int(astbuf1->range_left, true));
1465 astbuf2->children.push_back(AstNode::mkconst_int(astbuf1->range_right, true));
1468 if (astbuf2 && astbuf2->children.size() != 2)
1469 frontend_verilog_yyerror("wire/reg/logic packed dimension must be of the form: [<expr>:<expr>], [<expr>+:<expr>], or [<expr>-:<expr>]");
1470 } delay wire_name_list {
1472 if (astbuf2 != NULL)
1476 attr TOK_SUPPLY0 TOK_ID {
1477 ast_stack.back()->children.push_back(new AstNode(AST_WIRE));
1478 ast_stack.back()->children.back()->str = *$3;
1479 append_attr(ast_stack.back()->children.back(), $1);
1480 ast_stack.back()->children.push_back(new AstNode(AST_ASSIGN, new AstNode(AST_IDENTIFIER), AstNode::mkconst_int(0, false, 1)));
1481 ast_stack.back()->children.back()->children[0]->str = *$3;
1483 } opt_supply_wires ';' |
1484 attr TOK_SUPPLY1 TOK_ID {
1485 ast_stack.back()->children.push_back(new AstNode(AST_WIRE));
1486 ast_stack.back()->children.back()->str = *$3;
1487 append_attr(ast_stack.back()->children.back(), $1);
1488 ast_stack.back()->children.push_back(new AstNode(AST_ASSIGN, new AstNode(AST_IDENTIFIER), AstNode::mkconst_int(1, false, 1)));
1489 ast_stack.back()->children.back()->children[0]->str = *$3;
1491 } opt_supply_wires ';';
1495 opt_supply_wires ',' TOK_ID {
1496 AstNode *wire_node = ast_stack.back()->children.at(GetSize(ast_stack.back()->children)-2)->clone();
1497 AstNode *assign_node = ast_stack.back()->children.at(GetSize(ast_stack.back()->children)-1)->clone();
1498 wire_node->str = *$3;
1499 assign_node->children[0]->str = *$3;
1500 ast_stack.back()->children.push_back(wire_node);
1501 ast_stack.back()->children.push_back(assign_node);
1506 wire_name_and_opt_assign | wire_name_list ',' wire_name_and_opt_assign;
1508 wire_name_and_opt_assign:
1510 bool attr_anyconst = false;
1511 bool attr_anyseq = false;
1512 bool attr_allconst = false;
1513 bool attr_allseq = false;
1514 if (ast_stack.back()->children.back()->get_bool_attribute("\\anyconst")) {
1515 delete ast_stack.back()->children.back()->attributes.at("\\anyconst");
1516 ast_stack.back()->children.back()->attributes.erase("\\anyconst");
1517 attr_anyconst = true;
1519 if (ast_stack.back()->children.back()->get_bool_attribute("\\anyseq")) {
1520 delete ast_stack.back()->children.back()->attributes.at("\\anyseq");
1521 ast_stack.back()->children.back()->attributes.erase("\\anyseq");
1524 if (ast_stack.back()->children.back()->get_bool_attribute("\\allconst")) {
1525 delete ast_stack.back()->children.back()->attributes.at("\\allconst");
1526 ast_stack.back()->children.back()->attributes.erase("\\allconst");
1527 attr_allconst = true;
1529 if (ast_stack.back()->children.back()->get_bool_attribute("\\allseq")) {
1530 delete ast_stack.back()->children.back()->attributes.at("\\allseq");
1531 ast_stack.back()->children.back()->attributes.erase("\\allseq");
1534 if (current_wire_rand || attr_anyconst || attr_anyseq || attr_allconst || attr_allseq) {
1535 AstNode *wire = new AstNode(AST_IDENTIFIER);
1536 AstNode *fcall = new AstNode(AST_FCALL);
1537 wire->str = ast_stack.back()->children.back()->str;
1538 fcall->str = current_wire_const ? "\\$anyconst" : "\\$anyseq";
1540 fcall->str = "\\$anyconst";
1542 fcall->str = "\\$anyseq";
1544 fcall->str = "\\$allconst";
1546 fcall->str = "\\$allseq";
1547 fcall->attributes["\\reg"] = AstNode::mkconst_str(RTLIL::unescape_id(wire->str));
1548 ast_stack.back()->children.push_back(new AstNode(AST_ASSIGN, wire, fcall));
1551 wire_name '=' expr {
1552 AstNode *wire = new AstNode(AST_IDENTIFIER);
1553 wire->str = ast_stack.back()->children.back()->str;
1554 if (astbuf1->is_input) {
1555 if (astbuf1->attributes.count("\\defaultvalue"))
1556 delete astbuf1->attributes.at("\\defaultvalue");
1557 astbuf1->attributes["\\defaultvalue"] = $3;
1559 else if (astbuf1->is_reg || astbuf1->is_logic){
1560 AstNode *assign = new AstNode(AST_ASSIGN_LE, wire, $3);
1561 AstNode *block = new AstNode(AST_BLOCK, assign);
1562 AstNode *init = new AstNode(AST_INITIAL, block);
1564 SET_AST_NODE_LOC(assign, @1, @3);
1565 SET_AST_NODE_LOC(block, @1, @3);
1566 SET_AST_NODE_LOC(init, @1, @3);
1568 ast_stack.back()->children.push_back(init);
1571 AstNode *assign = new AstNode(AST_ASSIGN, wire, $3);
1572 SET_AST_NODE_LOC(assign, @1, @3);
1573 ast_stack.back()->children.push_back(assign);
1579 TOK_ID range_or_multirange {
1580 if (astbuf1 == nullptr)
1581 frontend_verilog_yyerror("Internal error - should not happen - no AST_WIRE node.");
1582 AstNode *node = astbuf1->clone();
1584 append_attr_clone(node, albuf);
1585 if (astbuf2 != NULL)
1586 node->children.push_back(astbuf2->clone());
1588 if (node->is_input || node->is_output)
1589 frontend_verilog_yyerror("input/output/inout ports cannot have unpacked dimensions.");
1590 if (!astbuf2 && !node->is_custom_type) {
1591 AstNode *rng = new AstNode(AST_RANGE);
1592 rng->children.push_back(AstNode::mkconst_int(0, true));
1593 rng->children.push_back(AstNode::mkconst_int(0, true));
1594 node->children.push_back(rng);
1596 node->type = AST_MEMORY;
1597 auto *rangeNode = $2;
1598 if (rangeNode->type == AST_RANGE && rangeNode->children.size() == 1) {
1599 // SV array size [n], rewrite as [n-1:0]
1600 rangeNode->children[0] = new AstNode(AST_SUB, rangeNode->children[0], AstNode::mkconst_int(1, true));
1601 rangeNode->children.push_back(AstNode::mkconst_int(0, false));
1603 node->children.push_back(rangeNode);
1605 if (current_function_or_task == NULL) {
1606 if (do_not_require_port_stubs && (node->is_input || node->is_output) && port_stubs.count(*$1) == 0) {
1607 port_stubs[*$1] = ++port_counter;
1609 if (port_stubs.count(*$1) != 0) {
1610 if (!node->is_input && !node->is_output)
1611 frontend_verilog_yyerror("Module port `%s' is neither input nor output.", $1->c_str());
1612 if (node->is_reg && node->is_input && !node->is_output && !sv_mode)
1613 frontend_verilog_yyerror("Input port `%s' is declared as register.", $1->c_str());
1614 node->port_id = port_stubs[*$1];
1615 port_stubs.erase(*$1);
1617 if (node->is_input || node->is_output)
1618 frontend_verilog_yyerror("Module port `%s' is not declared in module header.", $1->c_str());
1621 if (node->is_input || node->is_output)
1622 node->port_id = current_function_or_task_port_id++;
1624 //FIXME: for some reason, TOK_ID has a location which always points to one column *after* the real last column...
1625 SET_AST_NODE_LOC(node, @1, @1);
1626 ast_stack.back()->children.push_back(node);
1632 TOK_ASSIGN delay assign_expr_list ';';
1635 assign_expr | assign_expr_list ',' assign_expr;
1639 AstNode *node = new AstNode(AST_ASSIGN, $1, $3);
1640 SET_AST_NODE_LOC(node, @$, @$);
1641 ast_stack.back()->children.push_back(node);
1644 type_name: TOK_ID // first time seen
1645 | TOK_USER_TYPE { if (isInLocalScope($1)) frontend_verilog_yyerror("Duplicate declaration of TYPEDEF '%s'", $1->c_str()+1); }
1649 TOK_TYPEDEF wire_type range type_name range_or_multirange ';' {
1652 if (astbuf1->range_left >= 0 && astbuf1->range_right >= 0) {
1654 frontend_verilog_yyerror("integer/genvar types cannot have packed dimensions.");
1656 astbuf2 = new AstNode(AST_RANGE);
1657 astbuf2->children.push_back(AstNode::mkconst_int(astbuf1->range_left, true));
1658 astbuf2->children.push_back(AstNode::mkconst_int(astbuf1->range_right, true));
1661 if (astbuf2 && astbuf2->children.size() != 2)
1662 frontend_verilog_yyerror("wire/reg/logic packed dimension must be of the form: [<expr>:<expr>], [<expr>+:<expr>], or [<expr>-:<expr>]");
1664 astbuf1->children.push_back(astbuf2);
1668 AstNode *rng = new AstNode(AST_RANGE);
1669 rng->children.push_back(AstNode::mkconst_int(0, true));
1670 rng->children.push_back(AstNode::mkconst_int(0, true));
1671 astbuf1->children.push_back(rng);
1673 astbuf1->type = AST_MEMORY;
1674 auto *rangeNode = $5;
1675 if (rangeNode->type == AST_RANGE && rangeNode->children.size() == 1) {
1676 // SV array size [n], rewrite as [n-1:0]
1677 rangeNode->children[0] = new AstNode(AST_SUB, rangeNode->children[0], AstNode::mkconst_int(1, true));
1678 rangeNode->children.push_back(AstNode::mkconst_int(0, false));
1680 astbuf1->children.push_back(rangeNode);
1682 addTypedefNode($4, astbuf1);
1684 TOK_TYPEDEF enum_type type_name ';' {
1685 addTypedefNode($3, astbuf1);
1691 astbuf1 = new AstNode(AST_CELL);
1692 append_attr(astbuf1, $1);
1693 astbuf1->children.push_back(new AstNode(AST_CELLTYPE));
1694 astbuf1->children[0]->str = *$2;
1696 } cell_parameter_list_opt cell_list ';' {
1699 attr tok_prim_wrapper delay {
1700 astbuf1 = new AstNode(AST_PRIMITIVE);
1702 append_attr(astbuf1, $1);
1713 $$ = new std::string("or");
1718 cell_list ',' single_cell;
1722 astbuf2 = astbuf1->clone();
1723 if (astbuf2->type != AST_PRIMITIVE)
1726 ast_stack.back()->children.push_back(astbuf2);
1727 } '(' cell_port_list ')' {
1728 SET_AST_NODE_LOC(astbuf2, @1, @$);
1730 TOK_ID non_opt_range {
1731 astbuf2 = astbuf1->clone();
1732 if (astbuf2->type != AST_PRIMITIVE)
1735 ast_stack.back()->children.push_back(new AstNode(AST_CELLARRAY, $2, astbuf2));
1736 } '(' cell_port_list ')'{
1737 SET_AST_NODE_LOC(astbuf2, @1, @$);
1738 SET_AST_NODE_LOC(astbuf3, @1, @$);
1743 prim_list ',' single_prim;
1748 astbuf2 = astbuf1->clone();
1749 ast_stack.back()->children.push_back(astbuf2);
1750 } '(' cell_port_list ')';
1752 cell_parameter_list_opt:
1753 '#' '(' cell_parameter_list ')' | /* empty */;
1755 cell_parameter_list:
1756 cell_parameter | cell_parameter_list ',' cell_parameter;
1761 AstNode *node = new AstNode(AST_PARASET);
1762 astbuf1->children.push_back(node);
1763 node->children.push_back($1);
1765 '.' TOK_ID '(' expr ')' {
1766 AstNode *node = new AstNode(AST_PARASET);
1768 astbuf1->children.push_back(node);
1769 node->children.push_back($4);
1774 cell_port_list_rules {
1775 // remove empty args from end of list
1776 while (!astbuf2->children.empty()) {
1777 AstNode *node = astbuf2->children.back();
1778 if (node->type != AST_ARGUMENT) break;
1779 if (!node->children.empty()) break;
1780 if (!node->str.empty()) break;
1781 astbuf2->children.pop_back();
1786 bool has_positional_args = false;
1787 bool has_named_args = false;
1788 for (auto node : astbuf2->children) {
1789 if (node->type != AST_ARGUMENT) continue;
1790 if (node->str.empty())
1791 has_positional_args = true;
1793 has_named_args = true;
1796 if (has_positional_args && has_named_args)
1797 frontend_verilog_yyerror("Mix of positional and named cell ports.");
1800 cell_port_list_rules:
1801 cell_port | cell_port_list_rules ',' cell_port;
1805 AstNode *node = new AstNode(AST_ARGUMENT);
1806 astbuf2->children.push_back(node);
1810 AstNode *node = new AstNode(AST_ARGUMENT);
1811 astbuf2->children.push_back(node);
1812 node->children.push_back($2);
1815 attr '.' TOK_ID '(' expr ')' {
1816 AstNode *node = new AstNode(AST_ARGUMENT);
1818 astbuf2->children.push_back(node);
1819 node->children.push_back($5);
1823 attr '.' TOK_ID '(' ')' {
1824 AstNode *node = new AstNode(AST_ARGUMENT);
1826 astbuf2->children.push_back(node);
1831 AstNode *node = new AstNode(AST_ARGUMENT);
1833 astbuf2->children.push_back(node);
1834 node->children.push_back(new AstNode(AST_IDENTIFIER));
1835 node->children.back()->str = *$3;
1839 attr TOK_WILDCARD_CONNECT {
1841 frontend_verilog_yyerror("Wildcard port connections are only supported in SystemVerilog mode.");
1842 astbuf2->attributes[ID(wildcard_port_conns)] = AstNode::mkconst_int(1, false);
1845 always_comb_or_latch:
1853 always_or_always_ff:
1862 attr always_or_always_ff {
1863 AstNode *node = new AstNode(AST_ALWAYS);
1864 append_attr(node, $1);
1866 node->attributes[ID(always_ff)] = AstNode::mkconst_int(1, false);
1867 ast_stack.back()->children.push_back(node);
1868 ast_stack.push_back(node);
1870 AstNode *block = new AstNode(AST_BLOCK);
1871 ast_stack.back()->children.push_back(block);
1872 ast_stack.push_back(block);
1874 SET_AST_NODE_LOC(ast_stack.back(), @6, @6);
1875 ast_stack.pop_back();
1877 SET_AST_NODE_LOC(ast_stack.back(), @2, @$);
1878 ast_stack.pop_back();
1880 SET_RULE_LOC(@$, @2, @$);
1882 attr always_comb_or_latch {
1883 AstNode *node = new AstNode(AST_ALWAYS);
1884 append_attr(node, $1);
1886 node->attributes[ID(always_latch)] = AstNode::mkconst_int(1, false);
1888 node->attributes[ID(always_comb)] = AstNode::mkconst_int(1, false);
1889 ast_stack.back()->children.push_back(node);
1890 ast_stack.push_back(node);
1891 AstNode *block = new AstNode(AST_BLOCK);
1892 ast_stack.back()->children.push_back(block);
1893 ast_stack.push_back(block);
1895 ast_stack.pop_back();
1896 ast_stack.pop_back();
1899 AstNode *node = new AstNode(AST_INITIAL);
1900 append_attr(node, $1);
1901 ast_stack.back()->children.push_back(node);
1902 ast_stack.push_back(node);
1903 AstNode *block = new AstNode(AST_BLOCK);
1904 ast_stack.back()->children.push_back(block);
1905 ast_stack.push_back(block);
1907 ast_stack.pop_back();
1908 ast_stack.pop_back();
1912 '@' '(' always_events ')' |
1914 '@' ATTR_BEGIN ')' |
1921 always_events TOK_OR always_event |
1922 always_events ',' always_event;
1926 AstNode *node = new AstNode(AST_POSEDGE);
1927 ast_stack.back()->children.push_back(node);
1928 node->children.push_back($2);
1931 AstNode *node = new AstNode(AST_NEGEDGE);
1932 ast_stack.back()->children.push_back(node);
1933 node->children.push_back($2);
1936 AstNode *node = new AstNode(AST_EDGE);
1937 ast_stack.back()->children.push_back(node);
1938 node->children.push_back($1);
1969 TOK_MODPORT TOK_ID {
1970 AstNode *modport = new AstNode(AST_MODPORT);
1971 ast_stack.back()->children.push_back(modport);
1972 ast_stack.push_back(modport);
1975 } modport_args_opt {
1976 ast_stack.pop_back();
1977 log_assert(ast_stack.size() == 2);
1981 '(' ')' | '(' modport_args optional_comma ')';
1984 modport_arg | modport_args ',' modport_arg;
1987 modport_type_token modport_member |
1992 AstNode *modport_member = new AstNode(AST_MODPORTMEMBER);
1993 ast_stack.back()->children.push_back(modport_member);
1994 modport_member->str = *$1;
1995 modport_member->is_input = current_modport_input;
1996 modport_member->is_output = current_modport_output;
2001 TOK_INPUT {current_modport_input = 1; current_modport_output = 0;} | TOK_OUTPUT {current_modport_input = 0; current_modport_output = 1;}
2004 opt_sva_label TOK_ASSERT opt_property '(' expr ')' ';' {
2005 if (noassert_mode) {
2008 AstNode *node = new AstNode(assume_asserts_mode ? AST_ASSUME : AST_ASSERT, $5);
2009 SET_AST_NODE_LOC(node, @1, @6);
2012 ast_stack.back()->children.push_back(node);
2017 opt_sva_label TOK_ASSUME opt_property '(' expr ')' ';' {
2018 if (noassume_mode) {
2021 AstNode *node = new AstNode(assert_assumes_mode ? AST_ASSERT : AST_ASSUME, $5);
2022 SET_AST_NODE_LOC(node, @1, @6);
2025 ast_stack.back()->children.push_back(node);
2030 opt_sva_label TOK_ASSERT opt_property '(' TOK_EVENTUALLY expr ')' ';' {
2031 if (noassert_mode) {
2034 AstNode *node = new AstNode(assume_asserts_mode ? AST_FAIR : AST_LIVE, $6);
2035 SET_AST_NODE_LOC(node, @1, @7);
2038 ast_stack.back()->children.push_back(node);
2043 opt_sva_label TOK_ASSUME opt_property '(' TOK_EVENTUALLY expr ')' ';' {
2044 if (noassume_mode) {
2047 AstNode *node = new AstNode(assert_assumes_mode ? AST_LIVE : AST_FAIR, $6);
2048 SET_AST_NODE_LOC(node, @1, @7);
2051 ast_stack.back()->children.push_back(node);
2056 opt_sva_label TOK_COVER opt_property '(' expr ')' ';' {
2057 AstNode *node = new AstNode(AST_COVER, $5);
2058 SET_AST_NODE_LOC(node, @1, @6);
2059 if ($1 != nullptr) {
2063 ast_stack.back()->children.push_back(node);
2065 opt_sva_label TOK_COVER opt_property '(' ')' ';' {
2066 AstNode *node = new AstNode(AST_COVER, AstNode::mkconst_int(1, false));
2067 SET_AST_NODE_LOC(node, @1, @5);
2068 if ($1 != nullptr) {
2072 ast_stack.back()->children.push_back(node);
2074 opt_sva_label TOK_COVER ';' {
2075 AstNode *node = new AstNode(AST_COVER, AstNode::mkconst_int(1, false));
2076 SET_AST_NODE_LOC(node, @1, @2);
2077 if ($1 != nullptr) {
2081 ast_stack.back()->children.push_back(node);
2083 opt_sva_label TOK_RESTRICT opt_property '(' expr ')' ';' {
2084 if (norestrict_mode) {
2087 AstNode *node = new AstNode(AST_ASSUME, $5);
2088 SET_AST_NODE_LOC(node, @1, @6);
2091 ast_stack.back()->children.push_back(node);
2094 log_file_warning(current_filename, get_line_num(), "SystemVerilog does not allow \"restrict\" without \"property\".\n");
2098 opt_sva_label TOK_RESTRICT opt_property '(' TOK_EVENTUALLY expr ')' ';' {
2099 if (norestrict_mode) {
2102 AstNode *node = new AstNode(AST_FAIR, $6);
2103 SET_AST_NODE_LOC(node, @1, @7);
2106 ast_stack.back()->children.push_back(node);
2109 log_file_warning(current_filename, get_line_num(), "SystemVerilog does not allow \"restrict\" without \"property\".\n");
2115 opt_sva_label TOK_ASSERT TOK_PROPERTY '(' expr ')' ';' {
2116 AstNode *node = new AstNode(assume_asserts_mode ? AST_ASSUME : AST_ASSERT, $5);
2117 SET_AST_NODE_LOC(node, @1, @6);
2118 ast_stack.back()->children.push_back(node);
2119 if ($1 != nullptr) {
2120 ast_stack.back()->children.back()->str = *$1;
2124 opt_sva_label TOK_ASSUME TOK_PROPERTY '(' expr ')' ';' {
2125 AstNode *node = new AstNode(AST_ASSUME, $5);
2126 SET_AST_NODE_LOC(node, @1, @6);
2127 ast_stack.back()->children.push_back(node);
2128 if ($1 != nullptr) {
2129 ast_stack.back()->children.back()->str = *$1;
2133 opt_sva_label TOK_ASSERT TOK_PROPERTY '(' TOK_EVENTUALLY expr ')' ';' {
2134 AstNode *node = new AstNode(assume_asserts_mode ? AST_FAIR : AST_LIVE, $6);
2135 SET_AST_NODE_LOC(node, @1, @7);
2136 ast_stack.back()->children.push_back(node);
2137 if ($1 != nullptr) {
2138 ast_stack.back()->children.back()->str = *$1;
2142 opt_sva_label TOK_ASSUME TOK_PROPERTY '(' TOK_EVENTUALLY expr ')' ';' {
2143 AstNode *node = new AstNode(AST_FAIR, $6);
2144 SET_AST_NODE_LOC(node, @1, @7);
2145 ast_stack.back()->children.push_back(node);
2146 if ($1 != nullptr) {
2147 ast_stack.back()->children.back()->str = *$1;
2151 opt_sva_label TOK_COVER TOK_PROPERTY '(' expr ')' ';' {
2152 AstNode *node = new AstNode(AST_COVER, $5);
2153 SET_AST_NODE_LOC(node, @1, @6);
2154 ast_stack.back()->children.push_back(node);
2155 if ($1 != nullptr) {
2156 ast_stack.back()->children.back()->str = *$1;
2160 opt_sva_label TOK_RESTRICT TOK_PROPERTY '(' expr ')' ';' {
2161 if (norestrict_mode) {
2164 AstNode *node = new AstNode(AST_ASSUME, $5);
2165 SET_AST_NODE_LOC(node, @1, @6);
2166 ast_stack.back()->children.push_back(node);
2167 if ($1 != nullptr) {
2168 ast_stack.back()->children.back()->str = *$1;
2173 opt_sva_label TOK_RESTRICT TOK_PROPERTY '(' TOK_EVENTUALLY expr ')' ';' {
2174 if (norestrict_mode) {
2177 AstNode *node = new AstNode(AST_FAIR, $6);
2178 SET_AST_NODE_LOC(node, @1, @7);
2179 ast_stack.back()->children.push_back(node);
2180 if ($1 != nullptr) {
2181 ast_stack.back()->children.back()->str = *$1;
2187 simple_behavioral_stmt:
2188 lvalue '=' delay expr {
2189 AstNode *node = new AstNode(AST_ASSIGN_EQ, $1, $4);
2190 ast_stack.back()->children.push_back(node);
2191 SET_AST_NODE_LOC(node, @1, @4);
2193 lvalue TOK_INCREMENT {
2194 AstNode *node = new AstNode(AST_ASSIGN_EQ, $1, new AstNode(AST_ADD, $1->clone(), AstNode::mkconst_int(1, true)));
2195 ast_stack.back()->children.push_back(node);
2196 SET_AST_NODE_LOC(node, @1, @2);
2198 lvalue TOK_DECREMENT {
2199 AstNode *node = new AstNode(AST_ASSIGN_EQ, $1, new AstNode(AST_SUB, $1->clone(), AstNode::mkconst_int(1, true)));
2200 ast_stack.back()->children.push_back(node);
2201 SET_AST_NODE_LOC(node, @1, @2);
2203 lvalue OP_LE delay expr {
2204 AstNode *node = new AstNode(AST_ASSIGN_LE, $1, $4);
2205 ast_stack.back()->children.push_back(node);
2206 SET_AST_NODE_LOC(node, @1, @4);
2209 // this production creates the obligatory if-else shift/reduce conflict
2211 defattr | assert | wire_decl | param_decl | localparam_decl | typedef_decl |
2212 non_opt_delay behavioral_stmt |
2213 simple_behavioral_stmt ';' | ';' |
2214 hierarchical_id attr {
2215 AstNode *node = new AstNode(AST_TCALL);
2218 ast_stack.back()->children.push_back(node);
2219 ast_stack.push_back(node);
2220 append_attr(node, $2);
2222 ast_stack.pop_back();
2224 TOK_MSG_TASKS attr {
2225 AstNode *node = new AstNode(AST_TCALL);
2228 ast_stack.back()->children.push_back(node);
2229 ast_stack.push_back(node);
2230 append_attr(node, $2);
2232 ast_stack.pop_back();
2237 AstNode *node = new AstNode(AST_BLOCK);
2238 ast_stack.back()->children.push_back(node);
2239 ast_stack.push_back(node);
2240 append_attr(node, $1);
2243 } behavioral_stmt_list TOK_END opt_label {
2245 if ($4 != NULL && $8 != NULL && *$4 != *$8)
2246 frontend_verilog_yyerror("Begin label (%s) and end label (%s) don't match.", $4->c_str()+1, $8->c_str()+1);
2249 ast_stack.pop_back();
2252 AstNode *node = new AstNode(AST_FOR);
2253 ast_stack.back()->children.push_back(node);
2254 ast_stack.push_back(node);
2255 append_attr(node, $1);
2256 } simple_behavioral_stmt ';' expr {
2257 ast_stack.back()->children.push_back($7);
2258 } ';' simple_behavioral_stmt ')' {
2259 AstNode *block = new AstNode(AST_BLOCK);
2260 ast_stack.back()->children.push_back(block);
2261 ast_stack.push_back(block);
2263 SET_AST_NODE_LOC(ast_stack.back(), @13, @13);
2264 ast_stack.pop_back();
2265 SET_AST_NODE_LOC(ast_stack.back(), @2, @13);
2266 ast_stack.pop_back();
2268 attr TOK_WHILE '(' expr ')' {
2269 AstNode *node = new AstNode(AST_WHILE);
2270 ast_stack.back()->children.push_back(node);
2271 ast_stack.push_back(node);
2272 append_attr(node, $1);
2273 AstNode *block = new AstNode(AST_BLOCK);
2274 ast_stack.back()->children.push_back($4);
2275 ast_stack.back()->children.push_back(block);
2276 ast_stack.push_back(block);
2278 SET_AST_NODE_LOC(ast_stack.back(), @7, @7);
2279 ast_stack.pop_back();
2280 ast_stack.pop_back();
2282 attr TOK_REPEAT '(' expr ')' {
2283 AstNode *node = new AstNode(AST_REPEAT);
2284 ast_stack.back()->children.push_back(node);
2285 ast_stack.push_back(node);
2286 append_attr(node, $1);
2287 AstNode *block = new AstNode(AST_BLOCK);
2288 ast_stack.back()->children.push_back($4);
2289 ast_stack.back()->children.push_back(block);
2290 ast_stack.push_back(block);
2292 SET_AST_NODE_LOC(ast_stack.back(), @7, @7);
2293 ast_stack.pop_back();
2294 ast_stack.pop_back();
2296 attr TOK_IF '(' expr ')' {
2297 AstNode *node = new AstNode(AST_CASE);
2298 AstNode *block = new AstNode(AST_BLOCK);
2299 AstNode *cond = new AstNode(AST_COND, AstNode::mkconst_int(1, false, 1), block);
2300 SET_AST_NODE_LOC(cond, @4, @4);
2301 ast_stack.back()->children.push_back(node);
2302 node->children.push_back(new AstNode(AST_REDUCE_BOOL, $4));
2303 node->children.push_back(cond);
2304 ast_stack.push_back(node);
2305 ast_stack.push_back(block);
2306 append_attr(node, $1);
2308 SET_AST_NODE_LOC(ast_stack.back(), @7, @7);
2310 ast_stack.pop_back();
2311 SET_AST_NODE_LOC(ast_stack.back(), @2, @9);
2312 ast_stack.pop_back();
2314 case_attr case_type '(' expr ')' {
2315 AstNode *node = new AstNode(AST_CASE, $4);
2316 ast_stack.back()->children.push_back(node);
2317 ast_stack.push_back(node);
2318 append_attr(node, $1);
2319 SET_AST_NODE_LOC(ast_stack.back(), @4, @4);
2320 } opt_synopsys_attr case_body TOK_ENDCASE {
2321 SET_AST_NODE_LOC(ast_stack.back(), @2, @9);
2322 case_type_stack.pop_back();
2323 ast_stack.pop_back();
2332 TOK_PRIORITY case_attr {
2335 TOK_UNIQUE case_attr {
2340 attr unique_case_attr {
2341 if ($2) (*$1)["\\parallel_case"] = AstNode::mkconst_int(1, false);
2347 case_type_stack.push_back(0);
2350 case_type_stack.push_back('x');
2353 case_type_stack.push_back('z');
2357 opt_synopsys_attr TOK_SYNOPSYS_FULL_CASE {
2358 if (ast_stack.back()->attributes.count("\\full_case") == 0)
2359 ast_stack.back()->attributes["\\full_case"] = AstNode::mkconst_int(1, false);
2361 opt_synopsys_attr TOK_SYNOPSYS_PARALLEL_CASE {
2362 if (ast_stack.back()->attributes.count("\\parallel_case") == 0)
2363 ast_stack.back()->attributes["\\parallel_case"] = AstNode::mkconst_int(1, false);
2367 behavioral_stmt_list:
2368 behavioral_stmt_list behavioral_stmt |
2373 AstNode *block = new AstNode(AST_BLOCK);
2374 AstNode *cond = new AstNode(AST_COND, new AstNode(AST_DEFAULT), block);
2375 SET_AST_NODE_LOC(cond, @1, @1);
2377 ast_stack.pop_back();
2378 ast_stack.back()->children.push_back(cond);
2379 ast_stack.push_back(block);
2381 SET_AST_NODE_LOC(ast_stack.back(), @3, @3);
2383 /* empty */ %prec FAKE_THEN;
2386 case_body case_item |
2391 AstNode *node = new AstNode(
2392 case_type_stack.size() && case_type_stack.back() == 'x' ? AST_CONDX :
2393 case_type_stack.size() && case_type_stack.back() == 'z' ? AST_CONDZ : AST_COND);
2394 ast_stack.back()->children.push_back(node);
2395 ast_stack.push_back(node);
2397 AstNode *block = new AstNode(AST_BLOCK);
2398 ast_stack.back()->children.push_back(block);
2399 ast_stack.push_back(block);
2400 case_type_stack.push_back(0);
2402 case_type_stack.pop_back();
2403 SET_AST_NODE_LOC(ast_stack.back(), @4, @4);
2404 ast_stack.pop_back();
2405 ast_stack.pop_back();
2409 gen_case_body gen_case_item |
2414 AstNode *node = new AstNode(
2415 case_type_stack.size() && case_type_stack.back() == 'x' ? AST_CONDX :
2416 case_type_stack.size() && case_type_stack.back() == 'z' ? AST_CONDZ : AST_COND);
2417 ast_stack.back()->children.push_back(node);
2418 ast_stack.push_back(node);
2420 case_type_stack.push_back(0);
2421 SET_AST_NODE_LOC(ast_stack.back(), @2, @2);
2422 } gen_stmt_or_null {
2423 case_type_stack.pop_back();
2424 ast_stack.pop_back();
2428 case_expr_list ':' |
2433 AstNode *node = new AstNode(AST_DEFAULT);
2434 SET_AST_NODE_LOC(node, @1, @1);
2435 ast_stack.back()->children.push_back(node);
2438 AstNode *node = new AstNode(AST_IDENTIFIER);
2439 SET_AST_NODE_LOC(node, @1, @1);
2440 ast_stack.back()->children.push_back(node);
2441 ast_stack.back()->children.back()->str = *$1;
2445 ast_stack.back()->children.push_back($1);
2447 case_expr_list ',' expr {
2448 ast_stack.back()->children.push_back($3);
2452 hierarchical_id '[' expr ']' '.' rvalue {
2453 $$ = new AstNode(AST_PREFIX, $3, $6);
2457 hierarchical_id range {
2458 $$ = new AstNode(AST_IDENTIFIER, $2);
2460 SET_AST_NODE_LOC($$, @1, @1);
2462 if ($2 == nullptr && ($$->str == "\\$initstate" ||
2463 $$->str == "\\$anyconst" || $$->str == "\\$anyseq" ||
2464 $$->str == "\\$allconst" || $$->str == "\\$allseq"))
2465 $$->type = AST_FCALL;
2467 hierarchical_id non_opt_multirange {
2468 $$ = new AstNode(AST_IDENTIFIER, $2);
2470 SET_AST_NODE_LOC($$, @1, @1);
2478 '{' lvalue_concat_list '}' {
2484 $$ = new AstNode(AST_CONCAT);
2485 $$->children.push_back($1);
2487 expr ',' lvalue_concat_list {
2489 $$->children.push_back($1);
2493 '(' arg_list optional_comma ')' |
2502 arg_list ',' single_arg;
2506 ast_stack.back()->children.push_back($1);
2510 module_gen_body gen_stmt_or_module_body_stmt |
2513 gen_stmt_or_module_body_stmt:
2514 gen_stmt | module_body_stmt;
2516 // this production creates the obligatory if-else shift/reduce conflict
2519 AstNode *node = new AstNode(AST_GENFOR);
2520 ast_stack.back()->children.push_back(node);
2521 ast_stack.push_back(node);
2522 } simple_behavioral_stmt ';' expr {
2523 ast_stack.back()->children.push_back($6);
2524 } ';' simple_behavioral_stmt ')' gen_stmt_block {
2525 SET_AST_NODE_LOC(ast_stack.back(), @1, @11);
2526 ast_stack.pop_back();
2528 TOK_IF '(' expr ')' {
2529 AstNode *node = new AstNode(AST_GENIF);
2530 ast_stack.back()->children.push_back(node);
2531 ast_stack.push_back(node);
2532 ast_stack.back()->children.push_back($3);
2533 } gen_stmt_block opt_gen_else {
2534 SET_AST_NODE_LOC(ast_stack.back(), @1, @7);
2535 ast_stack.pop_back();
2537 case_type '(' expr ')' {
2538 AstNode *node = new AstNode(AST_GENCASE, $3);
2539 ast_stack.back()->children.push_back(node);
2540 ast_stack.push_back(node);
2541 } gen_case_body TOK_ENDCASE {
2542 case_type_stack.pop_back();
2543 SET_AST_NODE_LOC(ast_stack.back(), @1, @7);
2544 ast_stack.pop_back();
2549 AstNode *node = new AstNode(AST_GENBLOCK);
2550 node->str = $3 ? *$3 : std::string();
2551 ast_stack.back()->children.push_back(node);
2552 ast_stack.push_back(node);
2553 } module_gen_body TOK_END opt_label {
2557 SET_AST_NODE_LOC(ast_stack.back(), @1, @7);
2558 ast_stack.pop_back();
2561 AstNode *node = new AstNode(AST_TECALL);
2564 ast_stack.back()->children.push_back(node);
2565 ast_stack.push_back(node);
2567 SET_AST_NODE_LOC(ast_stack.back(), @1, @3);
2568 ast_stack.pop_back();
2573 AstNode *node = new AstNode(AST_GENBLOCK);
2574 ast_stack.back()->children.push_back(node);
2575 ast_stack.push_back(node);
2576 } gen_stmt_or_module_body_stmt {
2577 SET_AST_NODE_LOC(ast_stack.back(), @2, @2);
2578 ast_stack.pop_back();
2582 gen_stmt_block | ';';
2585 TOK_ELSE gen_stmt_or_null | /* empty */ %prec FAKE_THEN;
2591 basic_expr '?' attr expr ':' expr {
2592 $$ = new AstNode(AST_TERNARY);
2593 $$->children.push_back($1);
2594 $$->children.push_back($4);
2595 $$->children.push_back($6);
2596 SET_AST_NODE_LOC($$, @1, @$);
2597 append_attr($$, $3);
2604 '(' expr ')' integral_number {
2605 if ($4->compare(0, 1, "'") != 0)
2606 frontend_verilog_yyerror("Cast operation must be applied on sized constants e.g. (<expr>)<constval> , while %s is not a sized constant.", $4->c_str());
2608 AstNode *val = const2ast(*$4, case_type_stack.size() == 0 ? 0 : case_type_stack.back(), !lib_mode);
2610 log_error("Value conversion failed: `%s'\n", $4->c_str());
2611 $$ = new AstNode(AST_TO_BITS, bits, val);
2614 hierarchical_id integral_number {
2615 if ($2->compare(0, 1, "'") != 0)
2616 frontend_verilog_yyerror("Cast operation must be applied on sized constants, e.g. <ID>\'d0, while %s is not a sized constant.", $2->c_str());
2617 AstNode *bits = new AstNode(AST_IDENTIFIER);
2619 SET_AST_NODE_LOC(bits, @1, @1);
2620 AstNode *val = const2ast(*$2, case_type_stack.size() == 0 ? 0 : case_type_stack.back(), !lib_mode);
2622 log_error("Value conversion failed: `%s'\n", $2->c_str());
2623 $$ = new AstNode(AST_TO_BITS, bits, val);
2628 $$ = const2ast(*$1, case_type_stack.size() == 0 ? 0 : case_type_stack.back(), !lib_mode);
2630 log_error("Value conversion failed: `%s'\n", $1->c_str());
2634 $$ = new AstNode(AST_REALVALUE);
2635 char *p = (char*)malloc(GetSize(*$1) + 1), *q;
2636 for (int i = 0, j = 0; j < GetSize(*$1); j++)
2637 if ((*$1)[j] != '_')
2638 p[i++] = (*$1)[j], p[i] = 0;
2639 $$->realvalue = strtod(p, &q);
2640 SET_AST_NODE_LOC($$, @1, @1);
2641 log_assert(*q == 0);
2646 $$ = AstNode::mkconst_str(*$1);
2649 hierarchical_id attr {
2650 AstNode *node = new AstNode(AST_FCALL);
2653 ast_stack.push_back(node);
2654 SET_AST_NODE_LOC(node, @1, @1);
2655 append_attr(node, $2);
2656 } '(' arg_list optional_comma ')' {
2657 $$ = ast_stack.back();
2658 ast_stack.pop_back();
2660 TOK_TO_SIGNED attr '(' expr ')' {
2661 $$ = new AstNode(AST_TO_SIGNED, $4);
2662 append_attr($$, $2);
2664 TOK_TO_UNSIGNED attr '(' expr ')' {
2665 $$ = new AstNode(AST_TO_UNSIGNED, $4);
2666 append_attr($$, $2);
2671 '(' expr ':' expr ':' expr ')' {
2676 '{' concat_list '}' {
2679 '{' expr '{' concat_list '}' '}' {
2680 $$ = new AstNode(AST_REPLICATE, $2, $4);
2682 '~' attr basic_expr %prec UNARY_OPS {
2683 $$ = new AstNode(AST_BIT_NOT, $3);
2684 SET_AST_NODE_LOC($$, @1, @3);
2685 append_attr($$, $2);
2687 basic_expr '&' attr basic_expr {
2688 $$ = new AstNode(AST_BIT_AND, $1, $4);
2689 SET_AST_NODE_LOC($$, @1, @4);
2690 append_attr($$, $3);
2692 basic_expr OP_NAND attr basic_expr {
2693 $$ = new AstNode(AST_BIT_NOT, new AstNode(AST_BIT_AND, $1, $4));
2694 SET_AST_NODE_LOC($$, @1, @4);
2695 append_attr($$, $3);
2697 basic_expr '|' attr basic_expr {
2698 $$ = new AstNode(AST_BIT_OR, $1, $4);
2699 SET_AST_NODE_LOC($$, @1, @4);
2700 append_attr($$, $3);
2702 basic_expr OP_NOR attr basic_expr {
2703 $$ = new AstNode(AST_BIT_NOT, new AstNode(AST_BIT_OR, $1, $4));
2704 SET_AST_NODE_LOC($$, @1, @4);
2705 append_attr($$, $3);
2707 basic_expr '^' attr basic_expr {
2708 $$ = new AstNode(AST_BIT_XOR, $1, $4);
2709 SET_AST_NODE_LOC($$, @1, @4);
2710 append_attr($$, $3);
2712 basic_expr OP_XNOR attr basic_expr {
2713 $$ = new AstNode(AST_BIT_XNOR, $1, $4);
2714 SET_AST_NODE_LOC($$, @1, @4);
2715 append_attr($$, $3);
2717 '&' attr basic_expr %prec UNARY_OPS {
2718 $$ = new AstNode(AST_REDUCE_AND, $3);
2719 SET_AST_NODE_LOC($$, @1, @3);
2720 append_attr($$, $2);
2722 OP_NAND attr basic_expr %prec UNARY_OPS {
2723 $$ = new AstNode(AST_REDUCE_AND, $3);
2724 SET_AST_NODE_LOC($$, @1, @3);
2725 append_attr($$, $2);
2726 $$ = new AstNode(AST_LOGIC_NOT, $$);
2728 '|' attr basic_expr %prec UNARY_OPS {
2729 $$ = new AstNode(AST_REDUCE_OR, $3);
2730 SET_AST_NODE_LOC($$, @1, @3);
2731 append_attr($$, $2);
2733 OP_NOR attr basic_expr %prec UNARY_OPS {
2734 $$ = new AstNode(AST_REDUCE_OR, $3);
2735 SET_AST_NODE_LOC($$, @1, @3);
2736 append_attr($$, $2);
2737 $$ = new AstNode(AST_LOGIC_NOT, $$);
2738 SET_AST_NODE_LOC($$, @1, @3);
2740 '^' attr basic_expr %prec UNARY_OPS {
2741 $$ = new AstNode(AST_REDUCE_XOR, $3);
2742 SET_AST_NODE_LOC($$, @1, @3);
2743 append_attr($$, $2);
2745 OP_XNOR attr basic_expr %prec UNARY_OPS {
2746 $$ = new AstNode(AST_REDUCE_XNOR, $3);
2747 SET_AST_NODE_LOC($$, @1, @3);
2748 append_attr($$, $2);
2750 basic_expr OP_SHL attr basic_expr {
2751 $$ = new AstNode(AST_SHIFT_LEFT, $1, new AstNode(AST_TO_UNSIGNED, $4));
2752 SET_AST_NODE_LOC($$, @1, @4);
2753 append_attr($$, $3);
2755 basic_expr OP_SHR attr basic_expr {
2756 $$ = new AstNode(AST_SHIFT_RIGHT, $1, new AstNode(AST_TO_UNSIGNED, $4));
2757 SET_AST_NODE_LOC($$, @1, @4);
2758 append_attr($$, $3);
2760 basic_expr OP_SSHL attr basic_expr {
2761 $$ = new AstNode(AST_SHIFT_SLEFT, $1, new AstNode(AST_TO_UNSIGNED, $4));
2762 SET_AST_NODE_LOC($$, @1, @4);
2763 append_attr($$, $3);
2765 basic_expr OP_SSHR attr basic_expr {
2766 $$ = new AstNode(AST_SHIFT_SRIGHT, $1, new AstNode(AST_TO_UNSIGNED, $4));
2767 SET_AST_NODE_LOC($$, @1, @4);
2768 append_attr($$, $3);
2770 basic_expr '<' attr basic_expr {
2771 $$ = new AstNode(AST_LT, $1, $4);
2772 SET_AST_NODE_LOC($$, @1, @4);
2773 append_attr($$, $3);
2775 basic_expr OP_LE attr basic_expr {
2776 $$ = new AstNode(AST_LE, $1, $4);
2777 SET_AST_NODE_LOC($$, @1, @4);
2778 append_attr($$, $3);
2780 basic_expr OP_EQ attr basic_expr {
2781 $$ = new AstNode(AST_EQ, $1, $4);
2782 SET_AST_NODE_LOC($$, @1, @4);
2783 append_attr($$, $3);
2785 basic_expr OP_NE attr basic_expr {
2786 $$ = new AstNode(AST_NE, $1, $4);
2787 SET_AST_NODE_LOC($$, @1, @4);
2788 append_attr($$, $3);
2790 basic_expr OP_EQX attr basic_expr {
2791 $$ = new AstNode(AST_EQX, $1, $4);
2792 SET_AST_NODE_LOC($$, @1, @4);
2793 append_attr($$, $3);
2795 basic_expr OP_NEX attr basic_expr {
2796 $$ = new AstNode(AST_NEX, $1, $4);
2797 SET_AST_NODE_LOC($$, @1, @4);
2798 append_attr($$, $3);
2800 basic_expr OP_GE attr basic_expr {
2801 $$ = new AstNode(AST_GE, $1, $4);
2802 SET_AST_NODE_LOC($$, @1, @4);
2803 append_attr($$, $3);
2805 basic_expr '>' attr basic_expr {
2806 $$ = new AstNode(AST_GT, $1, $4);
2807 SET_AST_NODE_LOC($$, @1, @4);
2808 append_attr($$, $3);
2810 basic_expr '+' attr basic_expr {
2811 $$ = new AstNode(AST_ADD, $1, $4);
2812 SET_AST_NODE_LOC($$, @1, @4);
2813 append_attr($$, $3);
2815 basic_expr '-' attr basic_expr {
2816 $$ = new AstNode(AST_SUB, $1, $4);
2817 SET_AST_NODE_LOC($$, @1, @4);
2818 append_attr($$, $3);
2820 basic_expr '*' attr basic_expr {
2821 $$ = new AstNode(AST_MUL, $1, $4);
2822 SET_AST_NODE_LOC($$, @1, @4);
2823 append_attr($$, $3);
2825 basic_expr '/' attr basic_expr {
2826 $$ = new AstNode(AST_DIV, $1, $4);
2827 SET_AST_NODE_LOC($$, @1, @4);
2828 append_attr($$, $3);
2830 basic_expr '%' attr basic_expr {
2831 $$ = new AstNode(AST_MOD, $1, $4);
2832 SET_AST_NODE_LOC($$, @1, @4);
2833 append_attr($$, $3);
2835 basic_expr OP_POW attr basic_expr {
2836 $$ = new AstNode(AST_POW, $1, $4);
2837 SET_AST_NODE_LOC($$, @1, @4);
2838 append_attr($$, $3);
2840 '+' attr basic_expr %prec UNARY_OPS {
2841 $$ = new AstNode(AST_POS, $3);
2842 SET_AST_NODE_LOC($$, @1, @3);
2843 append_attr($$, $2);
2845 '-' attr basic_expr %prec UNARY_OPS {
2846 $$ = new AstNode(AST_NEG, $3);
2847 SET_AST_NODE_LOC($$, @1, @3);
2848 append_attr($$, $2);
2850 basic_expr OP_LAND attr basic_expr {
2851 $$ = new AstNode(AST_LOGIC_AND, $1, $4);
2852 SET_AST_NODE_LOC($$, @1, @4);
2853 append_attr($$, $3);
2855 basic_expr OP_LOR attr basic_expr {
2856 $$ = new AstNode(AST_LOGIC_OR, $1, $4);
2857 SET_AST_NODE_LOC($$, @1, @4);
2858 append_attr($$, $3);
2860 '!' attr basic_expr %prec UNARY_OPS {
2861 $$ = new AstNode(AST_LOGIC_NOT, $3);
2862 SET_AST_NODE_LOC($$, @1, @3);
2863 append_attr($$, $2);
2868 $$ = new AstNode(AST_CONCAT, $1);
2870 expr ',' concat_list {
2872 $$->children.push_back($1);
2876 TOK_CONSTVAL { $$ = $1; } |
2877 TOK_UNBASED_UNSIZED_CONSTVAL { $$ = $1; } |
2878 TOK_BASE TOK_BASED_CONSTVAL {
2883 TOK_CONSTVAL TOK_BASE TOK_BASED_CONSTVAL {
2884 $1->append(*$2).append(*$3);