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 "kernel/log.h"
45 using namespace VERILOG_FRONTEND;
48 namespace VERILOG_FRONTEND {
50 std::map<std::string, int> port_stubs;
51 std::map<std::string, AstNode*> *attr_list, default_attr_list;
52 std::stack<std::map<std::string, AstNode*> *> attr_list_stack;
53 std::map<std::string, AstNode*> *albuf;
54 std::vector<AstNode*> ast_stack;
55 struct AstNode *astbuf1, *astbuf2, *astbuf3;
56 struct AstNode *current_function_or_task;
57 struct AstNode *current_ast, *current_ast_mod;
58 int current_function_or_task_port_id;
59 std::vector<char> case_type_stack;
60 bool do_not_require_port_stubs;
61 bool default_nettype_wire;
62 bool sv_mode, formal_mode, lib_mode, specify_mode;
63 bool noassert_mode, noassume_mode, norestrict_mode;
64 bool assume_asserts_mode, assert_assumes_mode;
65 bool current_wire_rand, current_wire_const;
66 bool current_modport_input, current_modport_output;
71 static void append_attr(AstNode *ast, std::map<std::string, AstNode*> *al)
73 for (auto &it : *al) {
74 if (ast->attributes.count(it.first) > 0)
75 delete ast->attributes[it.first];
76 ast->attributes[it.first] = it.second;
81 static void append_attr_clone(AstNode *ast, std::map<std::string, AstNode*> *al)
83 for (auto &it : *al) {
84 if (ast->attributes.count(it.first) > 0)
85 delete ast->attributes[it.first];
86 ast->attributes[it.first] = it.second->clone();
90 static void free_attr(std::map<std::string, AstNode*> *al)
97 struct specify_target {
102 struct specify_triple {
103 AstNode *t_min, *t_avg, *t_max;
106 struct specify_rise_fall {
113 %define api.prefix {frontend_verilog_yy}
115 /* The union is defined in the header, so we need to provide all the
116 * includes it requires
121 #include "frontends/verilog/verilog_frontend.h"
126 struct YOSYS_NAMESPACE_PREFIX AST::AstNode *ast;
127 std::map<std::string, YOSYS_NAMESPACE_PREFIX AST::AstNode*> *al;
128 struct specify_target *specify_target_ptr;
129 struct specify_triple *specify_triple_ptr;
130 struct specify_rise_fall *specify_rise_fall_ptr;
135 %token <string> TOK_STRING TOK_ID TOK_CONSTVAL TOK_REALVAL TOK_PRIMITIVE
136 %token <string> TOK_SVA_LABEL TOK_SPECIFY_OPER TOK_MSG_TASKS
137 %token TOK_ASSERT TOK_ASSUME TOK_RESTRICT TOK_COVER TOK_FINAL
138 %token ATTR_BEGIN ATTR_END DEFATTR_BEGIN DEFATTR_END
139 %token TOK_MODULE TOK_ENDMODULE TOK_PARAMETER TOK_LOCALPARAM TOK_DEFPARAM
140 %token TOK_PACKAGE TOK_ENDPACKAGE TOK_PACKAGESEP
141 %token TOK_INTERFACE TOK_ENDINTERFACE TOK_MODPORT TOK_VAR
142 %token TOK_INPUT TOK_OUTPUT TOK_INOUT TOK_WIRE TOK_WAND TOK_WOR TOK_REG TOK_LOGIC
143 %token TOK_INTEGER TOK_SIGNED TOK_ASSIGN TOK_ALWAYS TOK_INITIAL
144 %token TOK_ALWAYS_FF TOK_ALWAYS_COMB TOK_ALWAYS_LATCH
145 %token TOK_BEGIN TOK_END TOK_IF TOK_ELSE TOK_FOR TOK_WHILE TOK_REPEAT
146 %token TOK_DPI_FUNCTION TOK_POSEDGE TOK_NEGEDGE TOK_OR TOK_AUTOMATIC
147 %token TOK_CASE TOK_CASEX TOK_CASEZ TOK_ENDCASE TOK_DEFAULT
148 %token TOK_FUNCTION TOK_ENDFUNCTION TOK_TASK TOK_ENDTASK TOK_SPECIFY
149 %token TOK_IGNORED_SPECIFY TOK_ENDSPECIFY TOK_SPECPARAM TOK_SPECIFY_AND
150 %token TOK_GENERATE TOK_ENDGENERATE TOK_GENVAR TOK_REAL
151 %token TOK_SYNOPSYS_FULL_CASE TOK_SYNOPSYS_PARALLEL_CASE
152 %token TOK_SUPPLY0 TOK_SUPPLY1 TOK_TO_SIGNED TOK_TO_UNSIGNED
153 %token TOK_POS_INDEXED TOK_NEG_INDEXED TOK_PROPERTY TOK_ENUM TOK_TYPEDEF
154 %token TOK_RAND TOK_CONST TOK_CHECKER TOK_ENDCHECKER TOK_EVENTUALLY
155 %token TOK_INCREMENT TOK_DECREMENT TOK_UNIQUE TOK_PRIORITY
157 %type <ast> range range_or_multirange non_opt_range non_opt_multirange range_or_signed_int
158 %type <ast> wire_type expr basic_expr concat_list rvalue lvalue lvalue_concat_list
159 %type <string> opt_label opt_sva_label tok_prim_wrapper hierarchical_id hierarchical_type_id
160 %type <boolean> opt_signed opt_property unique_case_attr always_comb_or_latch always_or_always_ff
161 %type <al> attr case_attr
163 %type <specify_target_ptr> specify_target
164 %type <specify_triple_ptr> specify_triple
165 %type <specify_rise_fall_ptr> specify_rise_fall
166 %type <ast> specify_if specify_condition specify_opt_arg
167 %type <ch> specify_edge
169 // operator precedence from low to high
175 %left OP_EQ OP_NE OP_EQX OP_NEX
176 %left '<' OP_LE OP_GE '>'
177 %left OP_SHL OP_SHR OP_SSHL OP_SSHR
183 %define parse.error verbose
184 %define parse.lac full
195 ast_stack.push_back(current_ast);
197 ast_stack.pop_back();
198 log_assert(GetSize(ast_stack) == 0);
199 for (auto &it : default_attr_list)
201 default_attr_list.clear();
207 task_func_decl design |
209 localparam_decl design |
210 typedef_decl design |
217 if (attr_list != nullptr)
218 attr_list_stack.push(attr_list);
219 attr_list = new std::map<std::string, AstNode*>;
220 for (auto &it : default_attr_list)
221 (*attr_list)[it.first] = it.second->clone();
224 if (!attr_list_stack.empty()) {
225 attr_list = attr_list_stack.top();
226 attr_list_stack.pop();
232 attr_opt ATTR_BEGIN opt_attr_list ATTR_END |
237 if (attr_list != nullptr)
238 attr_list_stack.push(attr_list);
239 attr_list = new std::map<std::string, AstNode*>;
240 for (auto &it : default_attr_list)
242 default_attr_list.clear();
244 attr_list->swap(default_attr_list);
246 if (!attr_list_stack.empty()) {
247 attr_list = attr_list_stack.top();
248 attr_list_stack.pop();
254 attr_list | /* empty */;
258 attr_list ',' attr_assign;
262 if (attr_list->count(*$1) != 0)
263 delete (*attr_list)[*$1];
264 (*attr_list)[*$1] = AstNode::mkconst_int(1, false);
267 hierarchical_id '=' expr {
268 if (attr_list->count(*$1) != 0)
269 delete (*attr_list)[*$1];
270 (*attr_list)[*$1] = $3;
278 hierarchical_id TOK_PACKAGESEP TOK_ID {
279 if ($3->compare(0, 1, "\\") == 0)
280 *$1 += "::" + $3->substr(1);
286 hierarchical_id '.' TOK_ID {
287 if ($3->compare(0, 1, "\\") == 0)
288 *$1 += "." + $3->substr(1);
295 hierarchical_type_id:
296 '(' hierarchical_id ')' { $$ = $2; };
299 attr TOK_MODULE TOK_ID {
300 do_not_require_port_stubs = false;
301 AstNode *mod = new AstNode(AST_MODULE);
302 ast_stack.back()->children.push_back(mod);
303 ast_stack.push_back(mod);
304 current_ast_mod = mod;
308 append_attr(mod, $1);
310 } module_para_opt module_args_opt ';' module_body TOK_ENDMODULE {
311 if (port_stubs.size() != 0)
312 frontend_verilog_yyerror("Missing details for module port `%s'.",
313 port_stubs.begin()->first.c_str());
314 ast_stack.pop_back();
315 log_assert(ast_stack.size() == 1);
316 current_ast_mod = NULL;
320 '#' '(' { astbuf1 = nullptr; } module_para_list { if (astbuf1) delete astbuf1; } ')' | /* empty */;
323 single_module_para | module_para_list ',' single_module_para;
328 if (astbuf1) delete astbuf1;
329 astbuf1 = new AstNode(AST_PARAMETER);
330 astbuf1->children.push_back(AstNode::mkconst_int(0, true));
331 append_attr(astbuf1, $1);
332 } param_type single_param_decl |
333 attr TOK_LOCALPARAM {
334 if (astbuf1) delete astbuf1;
335 astbuf1 = new AstNode(AST_LOCALPARAM);
336 astbuf1->children.push_back(AstNode::mkconst_int(0, true));
337 append_attr(astbuf1, $1);
338 } param_type single_param_decl |
342 '(' ')' | /* empty */ | '(' module_args optional_comma ')';
345 module_arg | module_args ',' module_arg;
350 module_arg_opt_assignment:
352 if (ast_stack.back()->children.size() > 0 && ast_stack.back()->children.back()->type == AST_WIRE) {
353 AstNode *wire = new AstNode(AST_IDENTIFIER);
354 wire->str = ast_stack.back()->children.back()->str;
355 if (ast_stack.back()->children.back()->is_input) {
356 AstNode *n = ast_stack.back()->children.back();
357 if (n->attributes.count("\\defaultvalue"))
358 delete n->attributes.at("\\defaultvalue");
359 n->attributes["\\defaultvalue"] = $2;
361 if (ast_stack.back()->children.back()->is_reg || ast_stack.back()->children.back()->is_logic)
362 ast_stack.back()->children.push_back(new AstNode(AST_INITIAL, new AstNode(AST_BLOCK, new AstNode(AST_ASSIGN_LE, wire, $2))));
364 ast_stack.back()->children.push_back(new AstNode(AST_ASSIGN, wire, $2));
366 frontend_verilog_yyerror("SystemVerilog interface in module port list cannot have a default value.");
372 if (ast_stack.back()->children.size() > 0 && ast_stack.back()->children.back()->type == AST_WIRE) {
373 AstNode *node = ast_stack.back()->children.back()->clone();
375 node->port_id = ++port_counter;
376 ast_stack.back()->children.push_back(node);
378 if (port_stubs.count(*$1) != 0)
379 frontend_verilog_yyerror("Duplicate module port `%s'.", $1->c_str());
380 port_stubs[*$1] = ++port_counter;
383 } module_arg_opt_assignment |
385 astbuf1 = new AstNode(AST_INTERFACEPORT);
386 astbuf1->children.push_back(new AstNode(AST_INTERFACEPORTTYPE));
387 astbuf1->children[0]->str = *$1;
389 } TOK_ID { /* SV interfaces */
391 frontend_verilog_yyerror("Interface found in port list (%s). This is not supported unless read_verilog is called with -sv!", $3->c_str());
392 astbuf2 = astbuf1->clone(); // really only needed if multiple instances of same type.
395 astbuf2->port_id = ++port_counter;
396 ast_stack.back()->children.push_back(astbuf2);
397 delete astbuf1; // really only needed if multiple instances of same type.
398 } module_arg_opt_assignment |
399 attr wire_type range TOK_ID {
402 node->port_id = ++port_counter;
404 node->children.push_back($3);
405 if (!node->is_input && !node->is_output)
406 frontend_verilog_yyerror("Module port `%s' is neither input nor output.", $4->c_str());
407 if (node->is_reg && node->is_input && !node->is_output && !sv_mode)
408 frontend_verilog_yyerror("Input port `%s' is declared as register.", $4->c_str());
409 ast_stack.back()->children.push_back(node);
410 append_attr(node, $1);
412 } module_arg_opt_assignment |
414 do_not_require_port_stubs = true;
418 attr TOK_PACKAGE TOK_ID {
419 AstNode *mod = new AstNode(AST_PACKAGE);
420 ast_stack.back()->children.push_back(mod);
421 ast_stack.push_back(mod);
422 current_ast_mod = mod;
424 append_attr(mod, $1);
425 } ';' package_body TOK_ENDPACKAGE {
426 ast_stack.pop_back();
427 current_ast_mod = NULL;
431 package_body package_body_stmt |;
438 TOK_INTERFACE TOK_ID {
439 do_not_require_port_stubs = false;
440 AstNode *intf = new AstNode(AST_INTERFACE);
441 ast_stack.back()->children.push_back(intf);
442 ast_stack.push_back(intf);
443 current_ast_mod = intf;
448 } module_para_opt module_args_opt ';' interface_body TOK_ENDINTERFACE {
449 if (port_stubs.size() != 0)
450 frontend_verilog_yyerror("Missing details for module port `%s'.",
451 port_stubs.begin()->first.c_str());
452 ast_stack.pop_back();
453 log_assert(ast_stack.size() == 1);
454 current_ast_mod = NULL;
458 interface_body interface_body_stmt |;
461 param_decl | localparam_decl | typedef_decl | defparam_decl | wire_decl | always_stmt | assign_stmt |
465 '#' TOK_ID { delete $2; } |
466 '#' TOK_CONSTVAL { delete $2; } |
467 '#' TOK_REALVAL { delete $2; } |
468 '#' '(' expr ')' { delete $3; } |
469 '#' '(' expr ':' expr ':' expr ')' { delete $3; delete $5; delete $7; };
472 non_opt_delay | /* empty */;
476 astbuf3 = new AstNode(AST_WIRE);
477 current_wire_rand = false;
478 current_wire_const = false;
479 } wire_type_token_list {
483 wire_type_token_list:
485 wire_type_token_list wire_type_token |
487 hierarchical_type_id {
488 astbuf3->is_custom_type = true;
489 astbuf3->children.push_back(new AstNode(AST_WIRETYPE));
490 astbuf3->children.back()->str = *$1;
495 astbuf3->is_input = true;
498 astbuf3->is_output = true;
501 astbuf3->is_input = true;
502 astbuf3->is_output = true;
509 astbuf3->is_wor = true;
512 astbuf3->is_wand = true;
515 astbuf3->is_reg = true;
518 astbuf3->is_logic = true;
521 astbuf3->is_logic = true;
524 astbuf3->is_reg = true;
525 astbuf3->range_left = 31;
526 astbuf3->range_right = 0;
527 astbuf3->is_signed = true;
530 astbuf3->type = AST_GENVAR;
531 astbuf3->is_reg = true;
532 astbuf3->is_signed = true;
533 astbuf3->range_left = 31;
534 astbuf3->range_right = 0;
537 astbuf3->is_signed = true;
540 current_wire_rand = true;
543 current_wire_const = true;
547 '[' expr ':' expr ']' {
548 $$ = new AstNode(AST_RANGE);
549 $$->children.push_back($2);
550 $$->children.push_back($4);
552 '[' expr TOK_POS_INDEXED expr ']' {
553 $$ = new AstNode(AST_RANGE);
554 $$->children.push_back(new AstNode(AST_SUB, new AstNode(AST_ADD, $2->clone(), $4), AstNode::mkconst_int(1, true)));
555 $$->children.push_back(new AstNode(AST_ADD, $2, AstNode::mkconst_int(0, true)));
557 '[' expr TOK_NEG_INDEXED expr ']' {
558 $$ = new AstNode(AST_RANGE);
559 $$->children.push_back(new AstNode(AST_ADD, $2, AstNode::mkconst_int(0, true)));
560 $$->children.push_back(new AstNode(AST_SUB, new AstNode(AST_ADD, $2->clone(), AstNode::mkconst_int(1, true)), $4));
563 $$ = new AstNode(AST_RANGE);
564 $$->children.push_back($2);
568 non_opt_range non_opt_range {
569 $$ = new AstNode(AST_MULTIRANGE, $1, $2);
571 non_opt_multirange non_opt_range {
573 $$->children.push_back($2);
586 non_opt_multirange { $$ = $1; };
593 $$ = new AstNode(AST_RANGE);
594 $$->children.push_back(AstNode::mkconst_int(31, true));
595 $$->children.push_back(AstNode::mkconst_int(0, true));
596 $$->is_signed = true;
600 module_body module_body_stmt |
601 /* the following line makes the generate..endgenrate keywords optional */
602 module_body gen_stmt |
606 task_func_decl | specify_block | param_decl | localparam_decl | typedef_decl | defparam_decl | specparam_declaration | wire_decl | assign_stmt | cell_stmt |
607 always_stmt | TOK_GENERATE module_gen_body TOK_ENDGENERATE | defattr | assert_property | checker_decl | ignored_specify_block;
610 TOK_CHECKER TOK_ID ';' {
611 AstNode *node = new AstNode(AST_GENBLOCK);
613 ast_stack.back()->children.push_back(node);
614 ast_stack.push_back(node);
615 } module_body TOK_ENDCHECKER {
617 ast_stack.pop_back();
621 attr TOK_DPI_FUNCTION TOK_ID TOK_ID {
622 current_function_or_task = new AstNode(AST_DPI_FUNCTION, AstNode::mkconst_str(*$3), AstNode::mkconst_str(*$4));
623 current_function_or_task->str = *$4;
624 append_attr(current_function_or_task, $1);
625 ast_stack.back()->children.push_back(current_function_or_task);
628 } opt_dpi_function_args ';' {
629 current_function_or_task = NULL;
631 attr TOK_DPI_FUNCTION TOK_ID '=' TOK_ID TOK_ID {
632 current_function_or_task = new AstNode(AST_DPI_FUNCTION, AstNode::mkconst_str(*$5), AstNode::mkconst_str(*$3));
633 current_function_or_task->str = *$6;
634 append_attr(current_function_or_task, $1);
635 ast_stack.back()->children.push_back(current_function_or_task);
639 } opt_dpi_function_args ';' {
640 current_function_or_task = NULL;
642 attr TOK_DPI_FUNCTION TOK_ID ':' TOK_ID '=' TOK_ID TOK_ID {
643 current_function_or_task = new AstNode(AST_DPI_FUNCTION, AstNode::mkconst_str(*$7), AstNode::mkconst_str(*$3 + ":" + RTLIL::unescape_id(*$5)));
644 current_function_or_task->str = *$8;
645 append_attr(current_function_or_task, $1);
646 ast_stack.back()->children.push_back(current_function_or_task);
651 } opt_dpi_function_args ';' {
652 current_function_or_task = NULL;
654 attr TOK_TASK opt_automatic TOK_ID {
655 current_function_or_task = new AstNode(AST_TASK);
656 current_function_or_task->str = *$4;
657 append_attr(current_function_or_task, $1);
658 ast_stack.back()->children.push_back(current_function_or_task);
659 ast_stack.push_back(current_function_or_task);
660 current_function_or_task_port_id = 1;
662 } task_func_args_opt ';' task_func_body TOK_ENDTASK {
663 current_function_or_task = NULL;
664 ast_stack.pop_back();
666 attr TOK_FUNCTION opt_automatic opt_signed range_or_signed_int TOK_ID {
667 current_function_or_task = new AstNode(AST_FUNCTION);
668 current_function_or_task->str = *$6;
669 append_attr(current_function_or_task, $1);
670 ast_stack.back()->children.push_back(current_function_or_task);
671 ast_stack.push_back(current_function_or_task);
672 AstNode *outreg = new AstNode(AST_WIRE);
674 outreg->is_signed = $4;
675 outreg->is_reg = true;
677 outreg->children.push_back($5);
678 outreg->is_signed = $4 || $5->is_signed;
679 $5->is_signed = false;
681 current_function_or_task->children.push_back(outreg);
682 current_function_or_task_port_id = 1;
684 } task_func_args_opt ';' task_func_body TOK_ENDFUNCTION {
685 current_function_or_task = NULL;
686 ast_stack.pop_back();
691 current_function_or_task->children.push_back(AstNode::mkconst_str(*$1));
696 current_function_or_task->children.push_back(AstNode::mkconst_str(*$1));
700 opt_dpi_function_args:
701 '(' dpi_function_args ')' |
705 dpi_function_args ',' dpi_function_arg |
706 dpi_function_args ',' |
723 '(' ')' | /* empty */ | '(' {
727 } task_func_args optional_comma {
735 task_func_port | task_func_args ',' task_func_port;
738 attr wire_type range {
748 if (astbuf1->range_left >= 0 && astbuf1->range_right >= 0) {
750 frontend_verilog_yyerror("integer/genvar types cannot have packed dimensions (task/function arguments)");
752 astbuf2 = new AstNode(AST_RANGE);
753 astbuf2->children.push_back(AstNode::mkconst_int(astbuf1->range_left, true));
754 astbuf2->children.push_back(AstNode::mkconst_int(astbuf1->range_right, true));
757 if (astbuf2 && astbuf2->children.size() != 2)
758 frontend_verilog_yyerror("task/function argument range must be of the form: [<expr>:<expr>], [<expr>+:<expr>], or [<expr>-:<expr>]");
759 } wire_name | wire_name;
762 task_func_body behavioral_stmt |
765 /*************************** specify parser ***************************/
768 TOK_SPECIFY specify_item_list TOK_ENDSPECIFY;
771 specify_item specify_item_list |
775 specify_if '(' specify_edge expr TOK_SPECIFY_OPER specify_target ')' '=' specify_rise_fall ';' {
776 AstNode *en_expr = $1;
777 char specify_edge = $3;
778 AstNode *src_expr = $4;
780 specify_target *target = $6;
781 specify_rise_fall *timing = $9;
783 if (specify_edge != 0 && target->dat == nullptr)
784 frontend_verilog_yyerror("Found specify edge but no data spec.\n");
786 AstNode *cell = new AstNode(AST_CELL);
787 ast_stack.back()->children.push_back(cell);
788 cell->str = stringf("$specify$%d", autoidx++);
789 cell->children.push_back(new AstNode(AST_CELLTYPE));
790 cell->children.back()->str = target->dat ? "$specify3" : "$specify2";
792 char oper_polarity = 0;
793 char oper_type = oper->at(0);
795 if (oper->size() == 3) {
796 oper_polarity = oper->at(0);
797 oper_type = oper->at(1);
800 cell->children.push_back(new AstNode(AST_PARASET, AstNode::mkconst_int(oper_type == '*', false, 1)));
801 cell->children.back()->str = "\\FULL";
803 cell->children.push_back(new AstNode(AST_PARASET, AstNode::mkconst_int(oper_polarity != 0, false, 1)));
804 cell->children.back()->str = "\\SRC_DST_PEN";
806 cell->children.push_back(new AstNode(AST_PARASET, AstNode::mkconst_int(oper_polarity == '+', false, 1)));
807 cell->children.back()->str = "\\SRC_DST_POL";
809 cell->children.push_back(new AstNode(AST_PARASET, timing->rise.t_min));
810 cell->children.back()->str = "\\T_RISE_MIN";
812 cell->children.push_back(new AstNode(AST_PARASET, timing->rise.t_avg));
813 cell->children.back()->str = "\\T_RISE_TYP";
815 cell->children.push_back(new AstNode(AST_PARASET, timing->rise.t_max));
816 cell->children.back()->str = "\\T_RISE_MAX";
818 cell->children.push_back(new AstNode(AST_PARASET, timing->fall.t_min));
819 cell->children.back()->str = "\\T_FALL_MIN";
821 cell->children.push_back(new AstNode(AST_PARASET, timing->fall.t_avg));
822 cell->children.back()->str = "\\T_FALL_TYP";
824 cell->children.push_back(new AstNode(AST_PARASET, timing->fall.t_max));
825 cell->children.back()->str = "\\T_FALL_MAX";
827 cell->children.push_back(new AstNode(AST_ARGUMENT, en_expr ? en_expr : AstNode::mkconst_int(1, false, 1)));
828 cell->children.back()->str = "\\EN";
830 cell->children.push_back(new AstNode(AST_ARGUMENT, src_expr));
831 cell->children.back()->str = "\\SRC";
833 cell->children.push_back(new AstNode(AST_ARGUMENT, target->dst));
834 cell->children.back()->str = "\\DST";
838 cell->children.push_back(new AstNode(AST_PARASET, AstNode::mkconst_int(specify_edge != 0, false, 1)));
839 cell->children.back()->str = "\\EDGE_EN";
841 cell->children.push_back(new AstNode(AST_PARASET, AstNode::mkconst_int(specify_edge == 'p', false, 1)));
842 cell->children.back()->str = "\\EDGE_POL";
844 cell->children.push_back(new AstNode(AST_PARASET, AstNode::mkconst_int(target->polarity_op != 0, false, 1)));
845 cell->children.back()->str = "\\DAT_DST_PEN";
847 cell->children.push_back(new AstNode(AST_PARASET, AstNode::mkconst_int(target->polarity_op == '+', false, 1)));
848 cell->children.back()->str = "\\DAT_DST_POL";
850 cell->children.push_back(new AstNode(AST_ARGUMENT, target->dat));
851 cell->children.back()->str = "\\DAT";
858 TOK_ID '(' specify_edge expr specify_condition ',' specify_edge expr specify_condition ',' expr specify_opt_arg ')' ';' {
859 if (*$1 != "$setup" && *$1 != "$hold" && *$1 != "$setuphold" && *$1 != "$removal" && *$1 != "$recovery" &&
860 *$1 != "$recrem" && *$1 != "$skew" && *$1 != "$timeskew" && *$1 != "$fullskew" && *$1 != "$nochange")
861 frontend_verilog_yyerror("Unsupported specify rule type: %s\n", $1->c_str());
863 AstNode *src_pen = AstNode::mkconst_int($3 != 0, false, 1);
864 AstNode *src_pol = AstNode::mkconst_int($3 == 'p', false, 1);
865 AstNode *src_expr = $4, *src_en = $5 ? $5 : AstNode::mkconst_int(1, false, 1);
867 AstNode *dst_pen = AstNode::mkconst_int($7 != 0, false, 1);
868 AstNode *dst_pol = AstNode::mkconst_int($7 == 'p', false, 1);
869 AstNode *dst_expr = $8, *dst_en = $9 ? $9 : AstNode::mkconst_int(1, false, 1);
871 AstNode *limit = $11;
872 AstNode *limit2 = $12;
874 AstNode *cell = new AstNode(AST_CELL);
875 ast_stack.back()->children.push_back(cell);
876 cell->str = stringf("$specify$%d", autoidx++);
877 cell->children.push_back(new AstNode(AST_CELLTYPE));
878 cell->children.back()->str = "$specrule";
880 cell->children.push_back(new AstNode(AST_PARASET, AstNode::mkconst_str(*$1)));
881 cell->children.back()->str = "\\TYPE";
883 cell->children.push_back(new AstNode(AST_PARASET, limit));
884 cell->children.back()->str = "\\T_LIMIT";
886 cell->children.push_back(new AstNode(AST_PARASET, limit2 ? limit2 : AstNode::mkconst_int(0, true)));
887 cell->children.back()->str = "\\T_LIMIT2";
889 cell->children.push_back(new AstNode(AST_PARASET, src_pen));
890 cell->children.back()->str = "\\SRC_PEN";
892 cell->children.push_back(new AstNode(AST_PARASET, src_pol));
893 cell->children.back()->str = "\\SRC_POL";
895 cell->children.push_back(new AstNode(AST_PARASET, dst_pen));
896 cell->children.back()->str = "\\DST_PEN";
898 cell->children.push_back(new AstNode(AST_PARASET, dst_pol));
899 cell->children.back()->str = "\\DST_POL";
901 cell->children.push_back(new AstNode(AST_ARGUMENT, src_en));
902 cell->children.back()->str = "\\SRC_EN";
904 cell->children.push_back(new AstNode(AST_ARGUMENT, src_expr));
905 cell->children.back()->str = "\\SRC";
907 cell->children.push_back(new AstNode(AST_ARGUMENT, dst_en));
908 cell->children.back()->str = "\\DST_EN";
910 cell->children.push_back(new AstNode(AST_ARGUMENT, dst_expr));
911 cell->children.back()->str = "\\DST";
925 TOK_IF '(' expr ')' {
933 TOK_SPECIFY_AND expr {
942 $$ = new specify_target;
947 '(' expr ':' expr ')'{
948 $$ = new specify_target;
953 '(' expr TOK_NEG_INDEXED expr ')'{
954 $$ = new specify_target;
955 $$->polarity_op = '-';
959 '(' expr TOK_POS_INDEXED expr ')'{
960 $$ = new specify_target;
961 $$->polarity_op = '+';
967 TOK_POSEDGE { $$ = 'p'; } |
968 TOK_NEGEDGE { $$ = 'n'; } |
973 $$ = new specify_rise_fall;
975 $$->fall.t_min = $1->t_min->clone();
976 $$->fall.t_avg = $1->t_avg->clone();
977 $$->fall.t_max = $1->t_max->clone();
980 '(' specify_triple ',' specify_triple ')' {
981 $$ = new specify_rise_fall;
990 $$ = new specify_triple;
992 $$->t_avg = $1->clone();
993 $$->t_max = $1->clone();
995 expr ':' expr ':' expr {
996 $$ = new specify_triple;
1002 /******************** ignored specify parser **************************/
1004 ignored_specify_block:
1005 TOK_IGNORED_SPECIFY ignored_specify_item_opt TOK_ENDSPECIFY |
1006 TOK_IGNORED_SPECIFY TOK_ENDSPECIFY ;
1008 ignored_specify_item_opt:
1009 ignored_specify_item_opt ignored_specify_item |
1010 ignored_specify_item ;
1012 ignored_specify_item:
1013 specparam_declaration
1014 // | pulsestyle_declaration
1015 // | showcancelled_declaration
1017 | system_timing_declaration
1020 specparam_declaration:
1021 TOK_SPECPARAM list_of_specparam_assignments ';' |
1022 TOK_SPECPARAM specparam_range list_of_specparam_assignments ';' ;
1024 // IEEE 1364-2005 calls this sinmply 'range' but the current 'range' rule allows empty match
1025 // and the 'non_opt_range' rule allows index ranges not allowed by 1364-2005
1026 // exxxxtending this for SV specparam would change this anyhow
1028 '[' ignspec_constant_expression ':' ignspec_constant_expression ']' ;
1030 list_of_specparam_assignments:
1031 specparam_assignment | list_of_specparam_assignments ',' specparam_assignment;
1033 specparam_assignment:
1034 ignspec_id '=' constant_mintypmax_expression ;
1037 TOK_IF '(' ignspec_expr ')' | /* empty */;
1040 simple_path_declaration ';'
1041 // | edge_sensitive_path_declaration
1042 // | state_dependent_path_declaration
1045 simple_path_declaration :
1046 ignspec_opt_cond parallel_path_description '=' path_delay_value |
1047 ignspec_opt_cond full_path_description '=' path_delay_value
1051 '(' path_delay_expression list_of_path_delay_extra_expressions ')'
1052 | path_delay_expression
1053 | path_delay_expression list_of_path_delay_extra_expressions
1056 list_of_path_delay_extra_expressions :
1057 ',' path_delay_expression | ',' path_delay_expression list_of_path_delay_extra_expressions;
1059 specify_edge_identifier :
1060 TOK_POSEDGE | TOK_NEGEDGE ;
1062 parallel_path_description :
1063 '(' specify_input_terminal_descriptor opt_polarity_operator '=' '>' specify_output_terminal_descriptor ')' |
1064 '(' specify_edge_identifier specify_input_terminal_descriptor '=' '>' '(' specify_output_terminal_descriptor opt_polarity_operator ':' ignspec_expr ')' ')' |
1065 '(' specify_edge_identifier specify_input_terminal_descriptor '=' '>' '(' specify_output_terminal_descriptor TOK_POS_INDEXED ignspec_expr ')' ')' ;
1067 full_path_description :
1068 '(' list_of_path_inputs '*' '>' list_of_path_outputs ')' |
1069 '(' specify_edge_identifier list_of_path_inputs '*' '>' '(' list_of_path_outputs opt_polarity_operator ':' ignspec_expr ')' ')' |
1070 '(' specify_edge_identifier list_of_path_inputs '*' '>' '(' list_of_path_outputs TOK_POS_INDEXED ignspec_expr ')' ')' ;
1072 // This was broken into 2 rules to solve shift/reduce conflicts
1073 list_of_path_inputs :
1074 specify_input_terminal_descriptor opt_polarity_operator |
1075 specify_input_terminal_descriptor more_path_inputs opt_polarity_operator ;
1078 ',' specify_input_terminal_descriptor |
1079 more_path_inputs ',' specify_input_terminal_descriptor ;
1081 list_of_path_outputs :
1082 specify_output_terminal_descriptor |
1083 list_of_path_outputs ',' specify_output_terminal_descriptor ;
1085 opt_polarity_operator :
1090 // Good enough for the time being
1091 specify_input_terminal_descriptor :
1094 // Good enough for the time being
1095 specify_output_terminal_descriptor :
1098 system_timing_declaration :
1099 ignspec_id '(' system_timing_args ')' ';' ;
1102 TOK_POSEDGE ignspec_id |
1103 TOK_NEGEDGE ignspec_id |
1106 system_timing_args :
1108 system_timing_args ',' system_timing_arg ;
1110 path_delay_expression :
1111 ignspec_constant_expression;
1113 constant_mintypmax_expression :
1114 ignspec_constant_expression
1115 | ignspec_constant_expression ':' ignspec_constant_expression ':' ignspec_constant_expression
1118 // for the time being this is OK, but we may write our own expr here.
1119 // as I'm not sure it is legal to use a full expr here (probably not)
1120 // On the other hand, other rules requiring constant expressions also use 'expr'
1121 // (such as param assignment), so we may leave this as-is, perhaps adding runtime checks for constant-ness
1122 ignspec_constant_expression:
1123 expr { delete $1; };
1126 expr { delete $1; };
1129 TOK_ID { delete $1; };
1131 /**********************************************************************/
1135 astbuf1->is_signed = true;
1140 if (astbuf1->children.size() != 1)
1141 frontend_verilog_yyerror("Internal error in param_integer - should not happen?");
1142 astbuf1->children.push_back(new AstNode(AST_RANGE));
1143 astbuf1->children.back()->children.push_back(AstNode::mkconst_int(31, true));
1144 astbuf1->children.back()->children.push_back(AstNode::mkconst_int(0, true));
1145 astbuf1->is_signed = true;
1150 if (astbuf1->children.size() != 1)
1151 frontend_verilog_yyerror("Parameter already declared as integer, cannot set to real.");
1152 astbuf1->children.push_back(new AstNode(AST_REALVALUE));
1158 if (astbuf1->children.size() != 1)
1159 frontend_verilog_yyerror("integer/real parameters should not have a range.");
1160 astbuf1->children.push_back($1);
1165 param_signed param_integer param_real param_range |
1166 hierarchical_type_id {
1167 astbuf1->is_custom_type = true;
1168 astbuf1->children.push_back(new AstNode(AST_WIRETYPE));
1169 astbuf1->children.back()->str = *$1;
1173 attr TOK_PARAMETER {
1174 astbuf1 = new AstNode(AST_PARAMETER);
1175 astbuf1->children.push_back(AstNode::mkconst_int(0, true));
1176 append_attr(astbuf1, $1);
1177 } param_type param_decl_list ';' {
1182 attr TOK_LOCALPARAM {
1183 astbuf1 = new AstNode(AST_LOCALPARAM);
1184 astbuf1->children.push_back(AstNode::mkconst_int(0, true));
1185 append_attr(astbuf1, $1);
1186 } param_type param_decl_list ';' {
1191 single_param_decl | param_decl_list ',' single_param_decl;
1196 if (astbuf1 == nullptr) {
1198 frontend_verilog_yyerror("In pure Verilog (not SystemVerilog), parameter/localparam with an initializer must use the parameter/localparam keyword");
1199 node = new AstNode(AST_PARAMETER);
1200 node->children.push_back(AstNode::mkconst_int(0, true));
1202 node = astbuf1->clone();
1205 delete node->children[0];
1206 node->children[0] = $3;
1207 ast_stack.back()->children.push_back(node);
1212 TOK_DEFPARAM defparam_decl_list ';';
1215 single_defparam_decl | defparam_decl_list ',' single_defparam_decl;
1217 single_defparam_decl:
1218 range rvalue '=' expr {
1219 AstNode *node = new AstNode(AST_DEFPARAM);
1220 node->children.push_back($2);
1221 node->children.push_back($4);
1223 node->children.push_back($1);
1224 ast_stack.back()->children.push_back(node);
1228 attr wire_type range {
1232 if (astbuf1->range_left >= 0 && astbuf1->range_right >= 0) {
1234 frontend_verilog_yyerror("integer/genvar types cannot have packed dimensions.");
1236 astbuf2 = new AstNode(AST_RANGE);
1237 astbuf2->children.push_back(AstNode::mkconst_int(astbuf1->range_left, true));
1238 astbuf2->children.push_back(AstNode::mkconst_int(astbuf1->range_right, true));
1241 if (astbuf2 && astbuf2->children.size() != 2)
1242 frontend_verilog_yyerror("wire/reg/logic packed dimension must be of the form: [<expr>:<expr>], [<expr>+:<expr>], or [<expr>-:<expr>]");
1243 } delay wire_name_list {
1245 if (astbuf2 != NULL)
1249 attr TOK_SUPPLY0 TOK_ID {
1250 ast_stack.back()->children.push_back(new AstNode(AST_WIRE));
1251 ast_stack.back()->children.back()->str = *$3;
1252 append_attr(ast_stack.back()->children.back(), $1);
1253 ast_stack.back()->children.push_back(new AstNode(AST_ASSIGN, new AstNode(AST_IDENTIFIER), AstNode::mkconst_int(0, false, 1)));
1254 ast_stack.back()->children.back()->children[0]->str = *$3;
1256 } opt_supply_wires ';' |
1257 attr TOK_SUPPLY1 TOK_ID {
1258 ast_stack.back()->children.push_back(new AstNode(AST_WIRE));
1259 ast_stack.back()->children.back()->str = *$3;
1260 append_attr(ast_stack.back()->children.back(), $1);
1261 ast_stack.back()->children.push_back(new AstNode(AST_ASSIGN, new AstNode(AST_IDENTIFIER), AstNode::mkconst_int(1, false, 1)));
1262 ast_stack.back()->children.back()->children[0]->str = *$3;
1264 } opt_supply_wires ';';
1268 opt_supply_wires ',' TOK_ID {
1269 AstNode *wire_node = ast_stack.back()->children.at(GetSize(ast_stack.back()->children)-2)->clone();
1270 AstNode *assign_node = ast_stack.back()->children.at(GetSize(ast_stack.back()->children)-1)->clone();
1271 wire_node->str = *$3;
1272 assign_node->children[0]->str = *$3;
1273 ast_stack.back()->children.push_back(wire_node);
1274 ast_stack.back()->children.push_back(assign_node);
1279 wire_name_and_opt_assign | wire_name_list ',' wire_name_and_opt_assign;
1281 wire_name_and_opt_assign:
1283 bool attr_anyconst = false;
1284 bool attr_anyseq = false;
1285 bool attr_allconst = false;
1286 bool attr_allseq = false;
1287 if (ast_stack.back()->children.back()->get_bool_attribute("\\anyconst")) {
1288 delete ast_stack.back()->children.back()->attributes.at("\\anyconst");
1289 ast_stack.back()->children.back()->attributes.erase("\\anyconst");
1290 attr_anyconst = true;
1292 if (ast_stack.back()->children.back()->get_bool_attribute("\\anyseq")) {
1293 delete ast_stack.back()->children.back()->attributes.at("\\anyseq");
1294 ast_stack.back()->children.back()->attributes.erase("\\anyseq");
1297 if (ast_stack.back()->children.back()->get_bool_attribute("\\allconst")) {
1298 delete ast_stack.back()->children.back()->attributes.at("\\allconst");
1299 ast_stack.back()->children.back()->attributes.erase("\\allconst");
1300 attr_allconst = true;
1302 if (ast_stack.back()->children.back()->get_bool_attribute("\\allseq")) {
1303 delete ast_stack.back()->children.back()->attributes.at("\\allseq");
1304 ast_stack.back()->children.back()->attributes.erase("\\allseq");
1307 if (current_wire_rand || attr_anyconst || attr_anyseq || attr_allconst || attr_allseq) {
1308 AstNode *wire = new AstNode(AST_IDENTIFIER);
1309 AstNode *fcall = new AstNode(AST_FCALL);
1310 wire->str = ast_stack.back()->children.back()->str;
1311 fcall->str = current_wire_const ? "\\$anyconst" : "\\$anyseq";
1313 fcall->str = "\\$anyconst";
1315 fcall->str = "\\$anyseq";
1317 fcall->str = "\\$allconst";
1319 fcall->str = "\\$allseq";
1320 fcall->attributes["\\reg"] = AstNode::mkconst_str(RTLIL::unescape_id(wire->str));
1321 ast_stack.back()->children.push_back(new AstNode(AST_ASSIGN, wire, fcall));
1324 wire_name '=' expr {
1325 AstNode *wire = new AstNode(AST_IDENTIFIER);
1326 wire->str = ast_stack.back()->children.back()->str;
1327 if (astbuf1->is_input) {
1328 if (astbuf1->attributes.count("\\defaultvalue"))
1329 delete astbuf1->attributes.at("\\defaultvalue");
1330 astbuf1->attributes["\\defaultvalue"] = $3;
1332 if (astbuf1->is_reg || astbuf1->is_logic)
1333 ast_stack.back()->children.push_back(new AstNode(AST_INITIAL, new AstNode(AST_BLOCK, new AstNode(AST_ASSIGN_LE, wire, $3))));
1335 ast_stack.back()->children.push_back(new AstNode(AST_ASSIGN, wire, $3));
1339 TOK_ID range_or_multirange {
1340 if (astbuf1 == nullptr)
1341 frontend_verilog_yyerror("Internal error - should not happen - no AST_WIRE node.");
1342 AstNode *node = astbuf1->clone();
1344 append_attr_clone(node, albuf);
1345 if (astbuf2 != NULL)
1346 node->children.push_back(astbuf2->clone());
1348 if (node->is_input || node->is_output)
1349 frontend_verilog_yyerror("input/output/inout ports cannot have unpacked dimensions.");
1350 if (!astbuf2 && !node->is_custom_type) {
1351 AstNode *rng = new AstNode(AST_RANGE);
1352 rng->children.push_back(AstNode::mkconst_int(0, true));
1353 rng->children.push_back(AstNode::mkconst_int(0, true));
1354 node->children.push_back(rng);
1356 node->type = AST_MEMORY;
1357 auto *rangeNode = $2;
1358 if (rangeNode->type == AST_RANGE && rangeNode->children.size() == 1) {
1359 // SV array size [n], rewrite as [n-1:0]
1360 rangeNode->children[0] = new AstNode(AST_SUB, rangeNode->children[0], AstNode::mkconst_int(1, true));
1361 rangeNode->children.push_back(AstNode::mkconst_int(0, false));
1363 node->children.push_back(rangeNode);
1365 if (current_function_or_task == NULL) {
1366 if (do_not_require_port_stubs && (node->is_input || node->is_output) && port_stubs.count(*$1) == 0) {
1367 port_stubs[*$1] = ++port_counter;
1369 if (port_stubs.count(*$1) != 0) {
1370 if (!node->is_input && !node->is_output)
1371 frontend_verilog_yyerror("Module port `%s' is neither input nor output.", $1->c_str());
1372 if (node->is_reg && node->is_input && !node->is_output && !sv_mode)
1373 frontend_verilog_yyerror("Input port `%s' is declared as register.", $1->c_str());
1374 node->port_id = port_stubs[*$1];
1375 port_stubs.erase(*$1);
1377 if (node->is_input || node->is_output)
1378 frontend_verilog_yyerror("Module port `%s' is not declared in module header.", $1->c_str());
1381 if (node->is_input || node->is_output)
1382 node->port_id = current_function_or_task_port_id++;
1384 ast_stack.back()->children.push_back(node);
1390 TOK_ASSIGN delay assign_expr_list ';';
1393 assign_expr | assign_expr_list ',' assign_expr;
1397 ast_stack.back()->children.push_back(new AstNode(AST_ASSIGN, $1, $3));
1401 TOK_TYPEDEF wire_type range TOK_ID range_or_multirange ';' {
1404 if (astbuf1->range_left >= 0 && astbuf1->range_right >= 0) {
1406 frontend_verilog_yyerror("integer/genvar types cannot have packed dimensions.");
1408 astbuf2 = new AstNode(AST_RANGE);
1409 astbuf2->children.push_back(AstNode::mkconst_int(astbuf1->range_left, true));
1410 astbuf2->children.push_back(AstNode::mkconst_int(astbuf1->range_right, true));
1413 if (astbuf2 && astbuf2->children.size() != 2)
1414 frontend_verilog_yyerror("wire/reg/logic packed dimension must be of the form: [<expr>:<expr>], [<expr>+:<expr>], or [<expr>-:<expr>]");
1416 astbuf1->children.push_back(astbuf2);
1420 AstNode *rng = new AstNode(AST_RANGE);
1421 rng->children.push_back(AstNode::mkconst_int(0, true));
1422 rng->children.push_back(AstNode::mkconst_int(0, true));
1423 astbuf1->children.push_back(rng);
1425 astbuf1->type = AST_MEMORY;
1426 auto *rangeNode = $5;
1427 if (rangeNode->type == AST_RANGE && rangeNode->children.size() == 1) {
1428 // SV array size [n], rewrite as [n-1:0]
1429 rangeNode->children[0] = new AstNode(AST_SUB, rangeNode->children[0], AstNode::mkconst_int(1, true));
1430 rangeNode->children.push_back(AstNode::mkconst_int(0, false));
1432 astbuf1->children.push_back(rangeNode);
1435 ast_stack.back()->children.push_back(new AstNode(AST_TYPEDEF, astbuf1));
1436 ast_stack.back()->children.back()->str = *$4;
1441 astbuf1 = new AstNode(AST_CELL);
1442 append_attr(astbuf1, $1);
1443 astbuf1->children.push_back(new AstNode(AST_CELLTYPE));
1444 astbuf1->children[0]->str = *$2;
1446 } cell_parameter_list_opt cell_list ';' {
1449 attr tok_prim_wrapper delay {
1450 astbuf1 = new AstNode(AST_PRIMITIVE);
1452 append_attr(astbuf1, $1);
1463 $$ = new std::string("or");
1468 cell_list ',' single_cell;
1472 astbuf2 = astbuf1->clone();
1473 if (astbuf2->type != AST_PRIMITIVE)
1476 ast_stack.back()->children.push_back(astbuf2);
1477 } '(' cell_port_list ')' |
1478 TOK_ID non_opt_range {
1479 astbuf2 = astbuf1->clone();
1480 if (astbuf2->type != AST_PRIMITIVE)
1483 ast_stack.back()->children.push_back(new AstNode(AST_CELLARRAY, $2, astbuf2));
1484 } '(' cell_port_list ')';
1488 prim_list ',' single_prim;
1493 astbuf2 = astbuf1->clone();
1494 ast_stack.back()->children.push_back(astbuf2);
1495 } '(' cell_port_list ')';
1497 cell_parameter_list_opt:
1498 '#' '(' cell_parameter_list ')' | /* empty */;
1500 cell_parameter_list:
1501 cell_parameter | cell_parameter_list ',' cell_parameter;
1506 AstNode *node = new AstNode(AST_PARASET);
1507 astbuf1->children.push_back(node);
1508 node->children.push_back($1);
1510 '.' TOK_ID '(' expr ')' {
1511 AstNode *node = new AstNode(AST_PARASET);
1513 astbuf1->children.push_back(node);
1514 node->children.push_back($4);
1519 cell_port_list_rules {
1520 // remove empty args from end of list
1521 while (!astbuf2->children.empty()) {
1522 AstNode *node = astbuf2->children.back();
1523 if (node->type != AST_ARGUMENT) break;
1524 if (!node->children.empty()) break;
1525 if (!node->str.empty()) break;
1526 astbuf2->children.pop_back();
1531 bool has_positional_args = false;
1532 bool has_named_args = false;
1533 for (auto node : astbuf2->children) {
1534 if (node->type != AST_ARGUMENT) continue;
1535 if (node->str.empty())
1536 has_positional_args = true;
1538 has_named_args = true;
1541 if (has_positional_args && has_named_args)
1542 frontend_verilog_yyerror("Mix of positional and named cell ports.");
1545 cell_port_list_rules:
1546 cell_port | cell_port_list_rules ',' cell_port;
1550 AstNode *node = new AstNode(AST_ARGUMENT);
1551 astbuf2->children.push_back(node);
1555 AstNode *node = new AstNode(AST_ARGUMENT);
1556 astbuf2->children.push_back(node);
1557 node->children.push_back($2);
1560 attr '.' TOK_ID '(' expr ')' {
1561 AstNode *node = new AstNode(AST_ARGUMENT);
1563 astbuf2->children.push_back(node);
1564 node->children.push_back($5);
1568 attr '.' TOK_ID '(' ')' {
1569 AstNode *node = new AstNode(AST_ARGUMENT);
1571 astbuf2->children.push_back(node);
1576 AstNode *node = new AstNode(AST_ARGUMENT);
1578 astbuf2->children.push_back(node);
1579 node->children.push_back(new AstNode(AST_IDENTIFIER));
1580 node->children.back()->str = *$3;
1585 always_comb_or_latch:
1593 always_or_always_ff:
1602 attr always_or_always_ff {
1603 AstNode *node = new AstNode(AST_ALWAYS);
1604 append_attr(node, $1);
1606 node->attributes[ID(always_ff)] = AstNode::mkconst_int(1, false);
1607 ast_stack.back()->children.push_back(node);
1608 ast_stack.push_back(node);
1610 AstNode *block = new AstNode(AST_BLOCK);
1611 ast_stack.back()->children.push_back(block);
1612 ast_stack.push_back(block);
1614 ast_stack.pop_back();
1615 ast_stack.pop_back();
1617 attr always_comb_or_latch {
1618 AstNode *node = new AstNode(AST_ALWAYS);
1619 append_attr(node, $1);
1621 node->attributes[ID(always_latch)] = AstNode::mkconst_int(1, false);
1623 node->attributes[ID(always_comb)] = AstNode::mkconst_int(1, false);
1624 ast_stack.back()->children.push_back(node);
1625 ast_stack.push_back(node);
1626 AstNode *block = new AstNode(AST_BLOCK);
1627 ast_stack.back()->children.push_back(block);
1628 ast_stack.push_back(block);
1630 ast_stack.pop_back();
1631 ast_stack.pop_back();
1634 AstNode *node = new AstNode(AST_INITIAL);
1635 append_attr(node, $1);
1636 ast_stack.back()->children.push_back(node);
1637 ast_stack.push_back(node);
1638 AstNode *block = new AstNode(AST_BLOCK);
1639 ast_stack.back()->children.push_back(block);
1640 ast_stack.push_back(block);
1642 ast_stack.pop_back();
1643 ast_stack.pop_back();
1647 '@' '(' always_events ')' |
1649 '@' ATTR_BEGIN ')' |
1656 always_events TOK_OR always_event |
1657 always_events ',' always_event;
1661 AstNode *node = new AstNode(AST_POSEDGE);
1662 ast_stack.back()->children.push_back(node);
1663 node->children.push_back($2);
1666 AstNode *node = new AstNode(AST_NEGEDGE);
1667 ast_stack.back()->children.push_back(node);
1668 node->children.push_back($2);
1671 AstNode *node = new AstNode(AST_EDGE);
1672 ast_stack.back()->children.push_back(node);
1673 node->children.push_back($1);
1704 TOK_MODPORT TOK_ID {
1705 AstNode *modport = new AstNode(AST_MODPORT);
1706 ast_stack.back()->children.push_back(modport);
1707 ast_stack.push_back(modport);
1710 } modport_args_opt {
1711 ast_stack.pop_back();
1712 log_assert(ast_stack.size() == 2);
1716 '(' ')' | '(' modport_args optional_comma ')';
1719 modport_arg | modport_args ',' modport_arg;
1722 modport_type_token modport_member |
1727 AstNode *modport_member = new AstNode(AST_MODPORTMEMBER);
1728 ast_stack.back()->children.push_back(modport_member);
1729 modport_member->str = *$1;
1730 modport_member->is_input = current_modport_input;
1731 modport_member->is_output = current_modport_output;
1736 TOK_INPUT {current_modport_input = 1; current_modport_output = 0;} | TOK_OUTPUT {current_modport_input = 0; current_modport_output = 1;}
1739 opt_sva_label TOK_ASSERT opt_property '(' expr ')' ';' {
1740 if (noassert_mode) {
1743 AstNode *node = new AstNode(assume_asserts_mode ? AST_ASSUME : AST_ASSERT, $5);
1746 ast_stack.back()->children.push_back(node);
1751 opt_sva_label TOK_ASSUME opt_property '(' expr ')' ';' {
1752 if (noassume_mode) {
1755 AstNode *node = new AstNode(assert_assumes_mode ? AST_ASSERT : AST_ASSUME, $5);
1758 ast_stack.back()->children.push_back(node);
1763 opt_sva_label TOK_ASSERT opt_property '(' TOK_EVENTUALLY expr ')' ';' {
1764 if (noassert_mode) {
1767 AstNode *node = new AstNode(assume_asserts_mode ? AST_FAIR : AST_LIVE, $6);
1770 ast_stack.back()->children.push_back(node);
1775 opt_sva_label TOK_ASSUME opt_property '(' TOK_EVENTUALLY expr ')' ';' {
1776 if (noassume_mode) {
1779 AstNode *node = new AstNode(assert_assumes_mode ? AST_LIVE : AST_FAIR, $6);
1782 ast_stack.back()->children.push_back(node);
1787 opt_sva_label TOK_COVER opt_property '(' expr ')' ';' {
1788 AstNode *node = new AstNode(AST_COVER, $5);
1789 if ($1 != nullptr) {
1793 ast_stack.back()->children.push_back(node);
1795 opt_sva_label TOK_COVER opt_property '(' ')' ';' {
1796 AstNode *node = new AstNode(AST_COVER, AstNode::mkconst_int(1, false));
1797 if ($1 != nullptr) {
1801 ast_stack.back()->children.push_back(node);
1803 opt_sva_label TOK_COVER ';' {
1804 AstNode *node = new AstNode(AST_COVER, AstNode::mkconst_int(1, false));
1805 if ($1 != nullptr) {
1809 ast_stack.back()->children.push_back(node);
1811 opt_sva_label TOK_RESTRICT opt_property '(' expr ')' ';' {
1812 if (norestrict_mode) {
1815 AstNode *node = new AstNode(AST_ASSUME, $5);
1818 ast_stack.back()->children.push_back(node);
1821 log_file_warning(current_filename, get_line_num(), "SystemVerilog does not allow \"restrict\" without \"property\".\n");
1825 opt_sva_label TOK_RESTRICT opt_property '(' TOK_EVENTUALLY expr ')' ';' {
1826 if (norestrict_mode) {
1829 AstNode *node = new AstNode(AST_FAIR, $6);
1832 ast_stack.back()->children.push_back(node);
1835 log_file_warning(current_filename, get_line_num(), "SystemVerilog does not allow \"restrict\" without \"property\".\n");
1841 opt_sva_label TOK_ASSERT TOK_PROPERTY '(' expr ')' ';' {
1842 ast_stack.back()->children.push_back(new AstNode(assume_asserts_mode ? AST_ASSUME : AST_ASSERT, $5));
1843 if ($1 != nullptr) {
1844 ast_stack.back()->children.back()->str = *$1;
1848 opt_sva_label TOK_ASSUME TOK_PROPERTY '(' expr ')' ';' {
1849 ast_stack.back()->children.push_back(new AstNode(AST_ASSUME, $5));
1850 if ($1 != nullptr) {
1851 ast_stack.back()->children.back()->str = *$1;
1855 opt_sva_label TOK_ASSERT TOK_PROPERTY '(' TOK_EVENTUALLY expr ')' ';' {
1856 ast_stack.back()->children.push_back(new AstNode(assume_asserts_mode ? AST_FAIR : AST_LIVE, $6));
1857 if ($1 != nullptr) {
1858 ast_stack.back()->children.back()->str = *$1;
1862 opt_sva_label TOK_ASSUME TOK_PROPERTY '(' TOK_EVENTUALLY expr ')' ';' {
1863 ast_stack.back()->children.push_back(new AstNode(AST_FAIR, $6));
1864 if ($1 != nullptr) {
1865 ast_stack.back()->children.back()->str = *$1;
1869 opt_sva_label TOK_COVER TOK_PROPERTY '(' expr ')' ';' {
1870 ast_stack.back()->children.push_back(new AstNode(AST_COVER, $5));
1871 if ($1 != nullptr) {
1872 ast_stack.back()->children.back()->str = *$1;
1876 opt_sva_label TOK_RESTRICT TOK_PROPERTY '(' expr ')' ';' {
1877 if (norestrict_mode) {
1880 ast_stack.back()->children.push_back(new AstNode(AST_ASSUME, $5));
1881 if ($1 != nullptr) {
1882 ast_stack.back()->children.back()->str = *$1;
1887 opt_sva_label TOK_RESTRICT TOK_PROPERTY '(' TOK_EVENTUALLY expr ')' ';' {
1888 if (norestrict_mode) {
1891 ast_stack.back()->children.push_back(new AstNode(AST_FAIR, $6));
1892 if ($1 != nullptr) {
1893 ast_stack.back()->children.back()->str = *$1;
1899 simple_behavioral_stmt:
1900 lvalue '=' delay expr {
1901 AstNode *node = new AstNode(AST_ASSIGN_EQ, $1, $4);
1902 ast_stack.back()->children.push_back(node);
1904 lvalue TOK_INCREMENT {
1905 AstNode *node = new AstNode(AST_ASSIGN_EQ, $1, new AstNode(AST_ADD, $1->clone(), AstNode::mkconst_int(1, true)));
1906 ast_stack.back()->children.push_back(node);
1908 lvalue TOK_DECREMENT {
1909 AstNode *node = new AstNode(AST_ASSIGN_EQ, $1, new AstNode(AST_SUB, $1->clone(), AstNode::mkconst_int(1, true)));
1910 ast_stack.back()->children.push_back(node);
1912 lvalue OP_LE delay expr {
1913 AstNode *node = new AstNode(AST_ASSIGN_LE, $1, $4);
1914 ast_stack.back()->children.push_back(node);
1917 // this production creates the obligatory if-else shift/reduce conflict
1919 defattr | assert | wire_decl | param_decl | localparam_decl | typedef_decl |
1920 non_opt_delay behavioral_stmt |
1921 simple_behavioral_stmt ';' | ';' |
1922 hierarchical_id attr {
1923 AstNode *node = new AstNode(AST_TCALL);
1926 ast_stack.back()->children.push_back(node);
1927 ast_stack.push_back(node);
1928 append_attr(node, $2);
1930 ast_stack.pop_back();
1932 TOK_MSG_TASKS attr {
1933 AstNode *node = new AstNode(AST_TCALL);
1936 ast_stack.back()->children.push_back(node);
1937 ast_stack.push_back(node);
1938 append_attr(node, $2);
1940 ast_stack.pop_back();
1942 attr TOK_BEGIN opt_label {
1943 AstNode *node = new AstNode(AST_BLOCK);
1944 ast_stack.back()->children.push_back(node);
1945 ast_stack.push_back(node);
1946 append_attr(node, $1);
1949 } behavioral_stmt_list TOK_END opt_label {
1950 if ($3 != NULL && $7 != NULL && *$3 != *$7)
1951 frontend_verilog_yyerror("Begin label (%s) and end label (%s) don't match.", $3->c_str()+1, $7->c_str()+1);
1956 ast_stack.pop_back();
1959 AstNode *node = new AstNode(AST_FOR);
1960 ast_stack.back()->children.push_back(node);
1961 ast_stack.push_back(node);
1962 append_attr(node, $1);
1963 } simple_behavioral_stmt ';' expr {
1964 ast_stack.back()->children.push_back($7);
1965 } ';' simple_behavioral_stmt ')' {
1966 AstNode *block = new AstNode(AST_BLOCK);
1967 ast_stack.back()->children.push_back(block);
1968 ast_stack.push_back(block);
1970 ast_stack.pop_back();
1971 ast_stack.pop_back();
1973 attr TOK_WHILE '(' expr ')' {
1974 AstNode *node = new AstNode(AST_WHILE);
1975 ast_stack.back()->children.push_back(node);
1976 ast_stack.push_back(node);
1977 append_attr(node, $1);
1978 AstNode *block = new AstNode(AST_BLOCK);
1979 ast_stack.back()->children.push_back($4);
1980 ast_stack.back()->children.push_back(block);
1981 ast_stack.push_back(block);
1983 ast_stack.pop_back();
1984 ast_stack.pop_back();
1986 attr TOK_REPEAT '(' expr ')' {
1987 AstNode *node = new AstNode(AST_REPEAT);
1988 ast_stack.back()->children.push_back(node);
1989 ast_stack.push_back(node);
1990 append_attr(node, $1);
1991 AstNode *block = new AstNode(AST_BLOCK);
1992 ast_stack.back()->children.push_back($4);
1993 ast_stack.back()->children.push_back(block);
1994 ast_stack.push_back(block);
1996 ast_stack.pop_back();
1997 ast_stack.pop_back();
1999 attr TOK_IF '(' expr ')' {
2000 AstNode *node = new AstNode(AST_CASE);
2001 AstNode *block = new AstNode(AST_BLOCK);
2002 AstNode *cond = new AstNode(AST_COND, AstNode::mkconst_int(1, false, 1), block);
2003 ast_stack.back()->children.push_back(node);
2004 node->children.push_back(new AstNode(AST_REDUCE_BOOL, $4));
2005 node->children.push_back(cond);
2006 ast_stack.push_back(node);
2007 ast_stack.push_back(block);
2008 append_attr(node, $1);
2009 } behavioral_stmt optional_else {
2010 ast_stack.pop_back();
2011 ast_stack.pop_back();
2013 case_attr case_type '(' expr ')' {
2014 AstNode *node = new AstNode(AST_CASE, $4);
2015 ast_stack.back()->children.push_back(node);
2016 ast_stack.push_back(node);
2017 append_attr(node, $1);
2018 } opt_synopsys_attr case_body TOK_ENDCASE {
2019 case_type_stack.pop_back();
2020 ast_stack.pop_back();
2027 TOK_PRIORITY case_attr {
2030 TOK_UNIQUE case_attr {
2035 attr unique_case_attr {
2036 if ($2) (*$1)["\\parallel_case"] = AstNode::mkconst_int(1, false);
2042 case_type_stack.push_back(0);
2045 case_type_stack.push_back('x');
2048 case_type_stack.push_back('z');
2052 opt_synopsys_attr TOK_SYNOPSYS_FULL_CASE {
2053 if (ast_stack.back()->attributes.count("\\full_case") == 0)
2054 ast_stack.back()->attributes["\\full_case"] = AstNode::mkconst_int(1, false);
2056 opt_synopsys_attr TOK_SYNOPSYS_PARALLEL_CASE {
2057 if (ast_stack.back()->attributes.count("\\parallel_case") == 0)
2058 ast_stack.back()->attributes["\\parallel_case"] = AstNode::mkconst_int(1, false);
2062 behavioral_stmt_list:
2063 behavioral_stmt_list behavioral_stmt |
2068 AstNode *block = new AstNode(AST_BLOCK);
2069 AstNode *cond = new AstNode(AST_COND, new AstNode(AST_DEFAULT), block);
2070 ast_stack.pop_back();
2071 ast_stack.back()->children.push_back(cond);
2072 ast_stack.push_back(block);
2074 /* empty */ %prec FAKE_THEN;
2077 case_body case_item |
2082 AstNode *node = new AstNode(
2083 case_type_stack.size() && case_type_stack.back() == 'x' ? AST_CONDX :
2084 case_type_stack.size() && case_type_stack.back() == 'z' ? AST_CONDZ : AST_COND);
2085 ast_stack.back()->children.push_back(node);
2086 ast_stack.push_back(node);
2088 AstNode *block = new AstNode(AST_BLOCK);
2089 ast_stack.back()->children.push_back(block);
2090 ast_stack.push_back(block);
2091 case_type_stack.push_back(0);
2093 case_type_stack.pop_back();
2094 ast_stack.pop_back();
2095 ast_stack.pop_back();
2099 gen_case_body gen_case_item |
2104 AstNode *node = new AstNode(
2105 case_type_stack.size() && case_type_stack.back() == 'x' ? AST_CONDX :
2106 case_type_stack.size() && case_type_stack.back() == 'z' ? AST_CONDZ : AST_COND);
2107 ast_stack.back()->children.push_back(node);
2108 ast_stack.push_back(node);
2110 case_type_stack.push_back(0);
2111 } gen_stmt_or_null {
2112 case_type_stack.pop_back();
2113 ast_stack.pop_back();
2117 case_expr_list ':' |
2122 ast_stack.back()->children.push_back(new AstNode(AST_DEFAULT));
2125 ast_stack.back()->children.push_back(new AstNode(AST_IDENTIFIER));
2126 ast_stack.back()->children.back()->str = *$1;
2130 ast_stack.back()->children.push_back($1);
2132 case_expr_list ',' expr {
2133 ast_stack.back()->children.push_back($3);
2137 hierarchical_id '[' expr ']' '.' rvalue {
2138 $$ = new AstNode(AST_PREFIX, $3, $6);
2142 hierarchical_id range {
2143 $$ = new AstNode(AST_IDENTIFIER, $2);
2146 if ($2 == nullptr && ($$->str == "\\$initstate" ||
2147 $$->str == "\\$anyconst" || $$->str == "\\$anyseq" ||
2148 $$->str == "\\$allconst" || $$->str == "\\$allseq"))
2149 $$->type = AST_FCALL;
2151 hierarchical_id non_opt_multirange {
2152 $$ = new AstNode(AST_IDENTIFIER, $2);
2161 '{' lvalue_concat_list '}' {
2167 $$ = new AstNode(AST_CONCAT);
2168 $$->children.push_back($1);
2170 expr ',' lvalue_concat_list {
2172 $$->children.push_back($1);
2176 '(' arg_list optional_comma ')' |
2185 arg_list ',' single_arg;
2189 ast_stack.back()->children.push_back($1);
2193 module_gen_body gen_stmt_or_module_body_stmt |
2196 gen_stmt_or_module_body_stmt:
2197 gen_stmt | module_body_stmt;
2199 // this production creates the obligatory if-else shift/reduce conflict
2202 AstNode *node = new AstNode(AST_GENFOR);
2203 ast_stack.back()->children.push_back(node);
2204 ast_stack.push_back(node);
2205 } simple_behavioral_stmt ';' expr {
2206 ast_stack.back()->children.push_back($6);
2207 } ';' simple_behavioral_stmt ')' gen_stmt_block {
2208 ast_stack.pop_back();
2210 TOK_IF '(' expr ')' {
2211 AstNode *node = new AstNode(AST_GENIF);
2212 ast_stack.back()->children.push_back(node);
2213 ast_stack.push_back(node);
2214 ast_stack.back()->children.push_back($3);
2215 } gen_stmt_block opt_gen_else {
2216 ast_stack.pop_back();
2218 case_type '(' expr ')' {
2219 AstNode *node = new AstNode(AST_GENCASE, $3);
2220 ast_stack.back()->children.push_back(node);
2221 ast_stack.push_back(node);
2222 } gen_case_body TOK_ENDCASE {
2223 case_type_stack.pop_back();
2224 ast_stack.pop_back();
2226 TOK_BEGIN opt_label {
2227 AstNode *node = new AstNode(AST_GENBLOCK);
2228 node->str = $2 ? *$2 : std::string();
2229 ast_stack.back()->children.push_back(node);
2230 ast_stack.push_back(node);
2231 } module_gen_body TOK_END opt_label {
2236 ast_stack.pop_back();
2239 AstNode *node = new AstNode(AST_TECALL);
2242 ast_stack.back()->children.push_back(node);
2243 ast_stack.push_back(node);
2245 ast_stack.pop_back();
2250 AstNode *node = new AstNode(AST_GENBLOCK);
2251 ast_stack.back()->children.push_back(node);
2252 ast_stack.push_back(node);
2253 } gen_stmt_or_module_body_stmt {
2254 ast_stack.pop_back();
2258 gen_stmt_block | ';';
2261 TOK_ELSE gen_stmt_or_null | /* empty */ %prec FAKE_THEN;
2267 basic_expr '?' attr expr ':' expr {
2268 $$ = new AstNode(AST_TERNARY);
2269 $$->children.push_back($1);
2270 $$->children.push_back($4);
2271 $$->children.push_back($6);
2272 append_attr($$, $3);
2279 '(' expr ')' TOK_CONSTVAL {
2280 if ($4->compare(0, 1, "'") != 0)
2281 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());
2283 AstNode *val = const2ast(*$4, case_type_stack.size() == 0 ? 0 : case_type_stack.back(), !lib_mode);
2285 log_error("Value conversion failed: `%s'\n", $4->c_str());
2286 $$ = new AstNode(AST_TO_BITS, bits, val);
2289 hierarchical_id TOK_CONSTVAL {
2290 if ($2->compare(0, 1, "'") != 0)
2291 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());
2292 AstNode *bits = new AstNode(AST_IDENTIFIER);
2294 AstNode *val = const2ast(*$2, case_type_stack.size() == 0 ? 0 : case_type_stack.back(), !lib_mode);
2296 log_error("Value conversion failed: `%s'\n", $2->c_str());
2297 $$ = new AstNode(AST_TO_BITS, bits, val);
2301 TOK_CONSTVAL TOK_CONSTVAL {
2302 $$ = const2ast(*$1 + *$2, case_type_stack.size() == 0 ? 0 : case_type_stack.back(), !lib_mode);
2303 if ($$ == NULL || (*$2)[0] != '\'')
2304 log_error("Value conversion failed: `%s%s'\n", $1->c_str(), $2->c_str());
2309 $$ = const2ast(*$1, case_type_stack.size() == 0 ? 0 : case_type_stack.back(), !lib_mode);
2311 log_error("Value conversion failed: `%s'\n", $1->c_str());
2315 $$ = new AstNode(AST_REALVALUE);
2316 char *p = (char*)malloc(GetSize(*$1) + 1), *q;
2317 for (int i = 0, j = 0; j < GetSize(*$1); j++)
2318 if ((*$1)[j] != '_')
2319 p[i++] = (*$1)[j], p[i] = 0;
2320 $$->realvalue = strtod(p, &q);
2321 log_assert(*q == 0);
2326 $$ = AstNode::mkconst_str(*$1);
2329 hierarchical_id attr {
2330 AstNode *node = new AstNode(AST_FCALL);
2333 ast_stack.push_back(node);
2334 append_attr(node, $2);
2335 } '(' arg_list optional_comma ')' {
2336 $$ = ast_stack.back();
2337 ast_stack.pop_back();
2339 TOK_TO_SIGNED attr '(' expr ')' {
2340 $$ = new AstNode(AST_TO_SIGNED, $4);
2341 append_attr($$, $2);
2343 TOK_TO_UNSIGNED attr '(' expr ')' {
2344 $$ = new AstNode(AST_TO_UNSIGNED, $4);
2345 append_attr($$, $2);
2350 '(' expr ':' expr ':' expr ')' {
2355 '{' concat_list '}' {
2358 '{' expr '{' concat_list '}' '}' {
2359 $$ = new AstNode(AST_REPLICATE, $2, $4);
2361 '~' attr basic_expr %prec UNARY_OPS {
2362 $$ = new AstNode(AST_BIT_NOT, $3);
2363 append_attr($$, $2);
2365 basic_expr '&' attr basic_expr {
2366 $$ = new AstNode(AST_BIT_AND, $1, $4);
2367 append_attr($$, $3);
2369 basic_expr OP_NAND attr basic_expr {
2370 $$ = new AstNode(AST_BIT_NOT, new AstNode(AST_BIT_AND, $1, $4));
2371 append_attr($$, $3);
2373 basic_expr '|' attr basic_expr {
2374 $$ = new AstNode(AST_BIT_OR, $1, $4);
2375 append_attr($$, $3);
2377 basic_expr OP_NOR attr basic_expr {
2378 $$ = new AstNode(AST_BIT_NOT, new AstNode(AST_BIT_OR, $1, $4));
2379 append_attr($$, $3);
2381 basic_expr '^' attr basic_expr {
2382 $$ = new AstNode(AST_BIT_XOR, $1, $4);
2383 append_attr($$, $3);
2385 basic_expr OP_XNOR attr basic_expr {
2386 $$ = new AstNode(AST_BIT_XNOR, $1, $4);
2387 append_attr($$, $3);
2389 '&' attr basic_expr %prec UNARY_OPS {
2390 $$ = new AstNode(AST_REDUCE_AND, $3);
2391 append_attr($$, $2);
2393 OP_NAND attr basic_expr %prec UNARY_OPS {
2394 $$ = new AstNode(AST_REDUCE_AND, $3);
2395 append_attr($$, $2);
2396 $$ = new AstNode(AST_LOGIC_NOT, $$);
2398 '|' attr basic_expr %prec UNARY_OPS {
2399 $$ = new AstNode(AST_REDUCE_OR, $3);
2400 append_attr($$, $2);
2402 OP_NOR attr basic_expr %prec UNARY_OPS {
2403 $$ = new AstNode(AST_REDUCE_OR, $3);
2404 append_attr($$, $2);
2405 $$ = new AstNode(AST_LOGIC_NOT, $$);
2407 '^' attr basic_expr %prec UNARY_OPS {
2408 $$ = new AstNode(AST_REDUCE_XOR, $3);
2409 append_attr($$, $2);
2411 OP_XNOR attr basic_expr %prec UNARY_OPS {
2412 $$ = new AstNode(AST_REDUCE_XNOR, $3);
2413 append_attr($$, $2);
2415 basic_expr OP_SHL attr basic_expr {
2416 $$ = new AstNode(AST_SHIFT_LEFT, $1, new AstNode(AST_TO_UNSIGNED, $4));
2417 append_attr($$, $3);
2419 basic_expr OP_SHR attr basic_expr {
2420 $$ = new AstNode(AST_SHIFT_RIGHT, $1, new AstNode(AST_TO_UNSIGNED, $4));
2421 append_attr($$, $3);
2423 basic_expr OP_SSHL attr basic_expr {
2424 $$ = new AstNode(AST_SHIFT_SLEFT, $1, new AstNode(AST_TO_UNSIGNED, $4));
2425 append_attr($$, $3);
2427 basic_expr OP_SSHR attr basic_expr {
2428 $$ = new AstNode(AST_SHIFT_SRIGHT, $1, new AstNode(AST_TO_UNSIGNED, $4));
2429 append_attr($$, $3);
2431 basic_expr '<' attr basic_expr {
2432 $$ = new AstNode(AST_LT, $1, $4);
2433 append_attr($$, $3);
2435 basic_expr OP_LE attr basic_expr {
2436 $$ = new AstNode(AST_LE, $1, $4);
2437 append_attr($$, $3);
2439 basic_expr OP_EQ attr basic_expr {
2440 $$ = new AstNode(AST_EQ, $1, $4);
2441 append_attr($$, $3);
2443 basic_expr OP_NE attr basic_expr {
2444 $$ = new AstNode(AST_NE, $1, $4);
2445 append_attr($$, $3);
2447 basic_expr OP_EQX attr basic_expr {
2448 $$ = new AstNode(AST_EQX, $1, $4);
2449 append_attr($$, $3);
2451 basic_expr OP_NEX attr basic_expr {
2452 $$ = new AstNode(AST_NEX, $1, $4);
2453 append_attr($$, $3);
2455 basic_expr OP_GE attr basic_expr {
2456 $$ = new AstNode(AST_GE, $1, $4);
2457 append_attr($$, $3);
2459 basic_expr '>' attr basic_expr {
2460 $$ = new AstNode(AST_GT, $1, $4);
2461 append_attr($$, $3);
2463 basic_expr '+' attr basic_expr {
2464 $$ = new AstNode(AST_ADD, $1, $4);
2465 append_attr($$, $3);
2467 basic_expr '-' attr basic_expr {
2468 $$ = new AstNode(AST_SUB, $1, $4);
2469 append_attr($$, $3);
2471 basic_expr '*' attr basic_expr {
2472 $$ = new AstNode(AST_MUL, $1, $4);
2473 append_attr($$, $3);
2475 basic_expr '/' attr basic_expr {
2476 $$ = new AstNode(AST_DIV, $1, $4);
2477 append_attr($$, $3);
2479 basic_expr '%' attr basic_expr {
2480 $$ = new AstNode(AST_MOD, $1, $4);
2481 append_attr($$, $3);
2483 basic_expr OP_POW attr basic_expr {
2484 $$ = new AstNode(AST_POW, $1, $4);
2485 append_attr($$, $3);
2487 '+' attr basic_expr %prec UNARY_OPS {
2488 $$ = new AstNode(AST_POS, $3);
2489 append_attr($$, $2);
2491 '-' attr basic_expr %prec UNARY_OPS {
2492 $$ = new AstNode(AST_NEG, $3);
2493 append_attr($$, $2);
2495 basic_expr OP_LAND attr basic_expr {
2496 $$ = new AstNode(AST_LOGIC_AND, $1, $4);
2497 append_attr($$, $3);
2499 basic_expr OP_LOR attr basic_expr {
2500 $$ = new AstNode(AST_LOGIC_OR, $1, $4);
2501 append_attr($$, $3);
2503 '!' attr basic_expr %prec UNARY_OPS {
2504 $$ = new AstNode(AST_LOGIC_NOT, $3);
2505 append_attr($$, $2);
2510 $$ = new AstNode(AST_CONCAT, $1);
2512 expr ',' concat_list {
2514 $$->children.push_back($1);