Fix for pr1833776.
[iverilog.git] / parse.y
blobdfd6f39e5ff3f66cfba0eb9ef68bdabd9db65f02
2 %{
3 /*
4 * Copyright (c) 1998-2007 Stephen Williams (steve@icarus.com)
6 * This source code is free software; you can redistribute it
7 * and/or modify it in source code form under the terms of the GNU
8 * General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
10 * any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
21 #ifdef HAVE_CVS_IDENT
22 #ident "$Id: parse.y,v 1.239 2007/06/14 03:50:00 steve Exp $"
23 #endif
25 # include "config.h"
27 # include "parse_misc.h"
28 # include "compiler.h"
29 # include "pform.h"
30 # include "Statement.h"
31 # include "PSpec.h"
32 # include <sstream>
34 class PSpecPath;
36 extern void lex_start_table();
37 extern void lex_end_table();
39 static svector<PExpr*>* active_range = 0;
40 static bool active_signed = false;
42 /* Port declaration lists use this structure for context. */
43 static struct {
44 NetNet::Type port_net_type;
45 NetNet::PortType port_type;
46 bool sign_flag;
47 svector<PExpr*>* range;
48 } port_declaration_context;
50 /* Later version of bison (including 1.35) will not compile in stack
51 extension if the output is compiled with C++ and either the YYSTYPE
52 or YYLTYPE are provided by the source code. However, I can get the
53 old behavior back by defining these symbols. */
54 # define YYSTYPE_IS_TRIVIAL 1
55 # define YYLTYPE_IS_TRIVIAL 1
57 /* Recent version of bison expect that the user supply a
58 YYLLOC_DEFAULT macro that makes up a yylloc value from existing
59 values. I need to supply an explicit version to account for the
60 text field, that otherwise won't be copied. */
61 # define YYLLOC_DEFAULT(Current, Rhs, N) do { \
62 (Current).first_line = (Rhs)[1].first_line; \
63 (Current).first_column = (Rhs)[1].first_column; \
64 (Current).last_line = (Rhs)[N].last_line; \
65 (Current).last_column = (Rhs)[N].last_column; \
66 (Current).text = (Rhs)[1].text; } while (0)
69 * These are some common strength pairs that are used as defaults when
70 * the user is not otherwise specific.
72 const static struct str_pair_t pull_strength = { PGate::PULL, PGate::PULL };
73 const static struct str_pair_t str_strength = { PGate::STRONG, PGate::STRONG };
75 static list<perm_string>* list_from_identifier(char*id)
77 list<perm_string>*tmp = new list<perm_string>;
78 tmp->push_back(lex_strings.make(id));
79 delete id;
80 return tmp;
83 static list<perm_string>* list_from_identifier(list<perm_string>*tmp, char*id)
85 tmp->push_back(lex_strings.make(id));
86 delete id;
87 return tmp;
92 %union {
93 bool flag;
95 char letter;
97 /* text items are C strings allocated by the lexor using
98 strdup. They can be put into lists with the texts type. */
99 char*text;
100 list<perm_string>*perm_strings;
101 pform_name_t*pform_name;
103 hname_t*hier;
105 list<string>*strings;
107 struct str_pair_t drive;
109 PCase::Item*citem;
110 svector<PCase::Item*>*citems;
112 lgate*gate;
113 svector<lgate>*gates;
115 Module::port_t *mport;
116 svector<Module::port_t*>*mports;
118 named_pexpr_t*named_pexpr;
119 svector<named_pexpr_t*>*named_pexprs;
120 struct parmvalue_t*parmvalue;
122 PExpr*expr;
123 svector<PExpr*>*exprs;
125 svector<PEEvent*>*event_expr;
127 NetNet::Type nettype;
128 PGBuiltin::Type gatetype;
129 NetNet::PortType porttype;
130 ivl_variable_type_t datatype;
132 PWire*wire;
133 svector<PWire*>*wires;
135 PEventStatement*event_statement;
136 Statement*statement;
137 svector<Statement*>*statement_list;
139 PTaskFuncArg function_type;
141 net_decl_assign_t*net_decl_assign;
143 verinum* number;
145 verireal* realtime;
147 PSpecPath* specpath;
148 list<index_component_t> *dimensions;
151 %token <text> IDENTIFIER SYSTEM_IDENTIFIER STRING
152 %token <text> PATHPULSE_IDENTIFIER
153 %token <number> BASED_NUMBER DEC_NUMBER
154 %token <realtime> REALTIME
155 %token K_LE K_GE K_EG K_EQ K_NE K_CEQ K_CNE K_LS K_RS K_RSS K_SG
156 %token K_PO_POS K_PO_NEG K_POW
157 %token K_PSTAR K_STARP
158 %token K_LOR K_LAND K_NAND K_NOR K_NXOR K_TRIGGER
159 %token K_always K_and K_assign K_begin K_bool K_buf K_bufif0 K_bufif1 K_case
160 %token K_casex K_casez K_cmos K_deassign K_default K_defparam K_disable
161 %token K_edge K_edge_descriptor
162 %token K_else K_end K_endcase K_endfunction K_endgenerate K_endmodule
163 %token K_endprimitive K_endspecify K_endtable K_endtask K_event K_for
164 %token K_force K_forever K_fork K_function K_generate K_genvar
165 %token K_highz0 K_highz1 K_if K_ifnone
166 %token K_initial K_inout K_input K_integer K_join K_large K_localparam
167 %token K_logic K_macromodule
168 %token K_medium K_module K_nand K_negedge K_nmos K_nor K_not K_notif0
169 %token K_notif1 K_or K_output K_parameter K_pmos K_posedge K_primitive
170 %token K_pull0 K_pull1 K_pulldown K_pullup K_rcmos K_real K_realtime
171 %token K_reg K_release K_repeat
172 %token K_rnmos K_rpmos K_rtran K_rtranif0 K_rtranif1 K_scalared
173 %token K_signed K_small K_specify
174 %token K_specparam K_strong0 K_strong1 K_supply0 K_supply1 K_table K_task
175 %token K_time K_tran K_tranif0 K_tranif1 K_tri K_tri0 K_tri1 K_triand
176 %token K_trior K_trireg K_vectored K_wait K_wand K_weak0 K_weak1
177 %token K_while K_wire
178 %token K_wone K_wor K_xnor K_xor
179 %token K_Shold K_Speriod K_Srecovery K_Srecrem K_Ssetup K_Swidth K_Ssetuphold
181 %token KK_attribute
183 %type <number> number
184 %type <flag> signed_opt udp_reg_opt edge_operator
185 %type <drive> drive_strength drive_strength_opt dr_strength0 dr_strength1
186 %type <letter> udp_input_sym udp_output_sym
187 %type <text> udp_input_list udp_sequ_entry udp_comb_entry
188 %type <perm_strings> udp_input_declaration_list
189 %type <strings> udp_entry_list udp_comb_entry_list udp_sequ_entry_list
190 %type <strings> udp_body udp_port_list
191 %type <wires> udp_port_decl udp_port_decls
192 %type <statement> udp_initial udp_init_opt
193 %type <expr> udp_initial_expr_opt
195 %type <text> register_variable net_variable real_variable
196 %type <perm_strings> register_variable_list net_variable_list real_variable_list list_of_identifiers
198 %type <net_decl_assign> net_decl_assign net_decl_assigns
200 %type <mport> port port_opt port_reference port_reference_list
201 %type <mport> port_declaration
202 %type <mports> list_of_ports module_port_list_opt list_of_port_declarations
204 %type <wires> task_item task_item_list task_item_list_opt
205 %type <wires> task_port_item task_port_decl task_port_decl_list
206 %type <wires> function_item function_item_list
208 %type <named_pexpr> port_name parameter_value_byname
209 %type <named_pexprs> port_name_list parameter_value_byname_list
211 %type <named_pexpr> attribute
212 %type <named_pexprs> attribute_list attribute_list_opt
214 %type <citem> case_item
215 %type <citems> case_items
217 %type <gate> gate_instance
218 %type <gates> gate_instance_list
220 %type <pform_name> heirarchy_identifier
221 %type <expr> expression expr_primary expr_mintypmax
222 %type <expr> lpvalue
223 %type <expr> delay_value delay_value_simple
224 %type <exprs> delay1 delay3 delay3_opt delay_value_list
225 %type <exprs> expression_list_with_nuls expression_list_proper
226 %type <exprs> cont_assign cont_assign_list
228 %type <exprs> range range_opt
229 %type <dimensions> dimensions_opt dimensions
230 %type <nettype> net_type var_type net_type_opt
231 %type <gatetype> gatetype
232 %type <porttype> port_type
233 %type <datatype> primitive_type primitive_type_opt
234 %type <parmvalue> parameter_value_opt
236 %type <function_type> function_range_or_type_opt
237 %type <event_expr> event_expression_list
238 %type <event_expr> event_expression
239 %type <event_statement> event_control
240 %type <statement> statement statement_or_null
241 %type <statement_list> statement_list
243 %type <letter> spec_polarity
244 %type <perm_strings> specify_path_identifiers
246 %type <specpath> specify_simple_path specify_simple_path_decl
247 %type <specpath> specify_edge_path specify_edge_path_decl
249 %token K_TAND
250 %right '?' ':'
251 %left K_LOR
252 %left K_LAND
253 %left '|'
254 %left '^' K_NXOR K_NOR
255 %left '&' K_NAND
256 %left K_EQ K_NE K_CEQ K_CNE
257 %left K_GE K_LE '<' '>'
258 %left K_LS K_RS K_RSS
259 %left '+' '-'
260 %left '*' '/' '%'
261 %left K_POW
262 %left UNARY_PREC
264 /* to resolve dangling else ambiguity. */
265 %nonassoc less_than_K_else
266 %nonassoc K_else
270 /* A degenerate source file can be completely empty. */
271 main : source_file | ;
273 source_file
274 : description
275 | source_file description
278 number : BASED_NUMBER
279 { $$ = $1; based_size = 0;}
280 | DEC_NUMBER
281 { $$ = $1; based_size = 0;}
282 | DEC_NUMBER BASED_NUMBER
283 { $$ = pform_verinum_with_size($1,$2, @2.text, @2.first_line);
284 based_size = 0; }
287 /* Verilog-2001 supports attribute lists, which can be attached to a
288 variety of different objects. The syntax inside the (* *) is a
289 comma separated list of names or names with assigned values. */
290 attribute_list_opt
291 : K_PSTAR attribute_list K_STARP { $$ = $2; }
292 | K_PSTAR K_STARP { $$ = 0; }
293 | { $$ = 0; }
296 attribute_list
297 : attribute_list ',' attribute
298 { svector<named_pexpr_t*>*tmp =
299 new svector<named_pexpr_t*>(*$1,$3);
300 delete $1;
301 $$ = tmp;
303 | attribute
304 { svector<named_pexpr_t*>*tmp = new svector<named_pexpr_t*>(1);
305 (*tmp)[0] = $1;
306 $$ = tmp;
311 attribute
312 : IDENTIFIER
313 { named_pexpr_t*tmp = new named_pexpr_t;
314 tmp->name = lex_strings.make($1);
315 tmp->parm = 0;
316 delete $1;
317 $$ = tmp;
319 | IDENTIFIER '=' expression
320 { PExpr*tmp = $3;
321 if (!pform_expression_is_constant(tmp)) {
322 yyerror(@3, "error: attribute value "
323 "expression must be constant.");
324 delete tmp;
325 tmp = 0;
327 named_pexpr_t*tmp2 = new named_pexpr_t;
328 tmp2->name = lex_strings.make($1);
329 tmp2->parm = tmp;
330 delete $1;
331 $$ = tmp2;
336 /* The block_item_decl is used in function definitions, task
337 definitions, module definitions and named blocks. Wherever a new
338 scope is entered, the source may declare new registers and
339 integers. This rule matches those declarations. The containing
340 rule has presumably set up the scope. */
342 block_item_decl
343 : attribute_list_opt K_reg
344 primitive_type_opt signed_opt range
345 register_variable_list ';'
346 { ivl_variable_type_t dtype = $3;
347 if (dtype == IVL_VT_NO_TYPE)
348 dtype = IVL_VT_LOGIC;
349 pform_set_net_range($6, $5, $4, dtype);
350 if ($1) delete $1;
353 /* This differs from the above pattern only in the absence of the
354 range. This is the rule for a scalar. */
356 | attribute_list_opt K_reg
357 primitive_type_opt signed_opt
358 register_variable_list ';'
359 { ivl_variable_type_t dtype = $3;
360 if (dtype == IVL_VT_NO_TYPE)
361 dtype = IVL_VT_LOGIC;
362 pform_set_net_range($5, 0, $4, dtype);
363 if ($1) delete $1;
366 /* Integer declarations are simpler in that they do not have all the
367 trappings of a general variable declaration. All of that is
368 implicit in the "integer" of the declaratin. */
370 | attribute_list_opt K_integer register_variable_list ';'
371 { pform_set_reg_integer($3);
372 if ($1) delete $1;
375 | attribute_list_opt K_time register_variable_list ';'
376 { pform_set_reg_time($3);
379 /* real declarations are fairly simple as there is no range of
380 signed flag in the declaration. Create the real as a NetNet::REG
381 with real value. Note that real and realtime are interchangable
382 in this context. */
384 | attribute_list_opt K_real real_variable_list ';'
385 { delete $3; }
386 | attribute_list_opt K_realtime real_variable_list ';'
387 { delete $3; }
389 | K_parameter parameter_assign_decl ';'
390 | K_localparam localparam_assign_decl ';'
392 /* Recover from errors that happen within variable lists. Use the
393 trailing semi-colon to resync the parser. */
395 | attribute_list_opt K_reg error ';'
396 { yyerror(@2, "error: syntax error in reg variable list.");
397 yyerrok;
398 if ($1) delete $1;
400 | attribute_list_opt K_integer error ';'
401 { yyerror(@2, "error: syntax error in integer variable list.");
402 yyerrok;
403 if ($1) delete $1;
405 | attribute_list_opt K_time error ';'
406 { yyerror(@2, "error: syntax error in time variable list.");
407 yyerrok;
409 | attribute_list_opt K_real error ';'
410 { yyerror(@2, "error: syntax error in real variable list.");
411 yyerrok;
413 | attribute_list_opt K_realtime error ';'
414 { yyerror(@1, "error: syntax error in realtime variable list.");
415 yyerrok;
417 | K_parameter error ';'
418 { yyerror(@1, "error: syntax error in parameter list.");
419 yyerrok;
421 | K_localparam error ';'
422 { yyerror(@1, "error: syntax error localparam list.");
423 yyerrok;
427 block_item_decls
428 : block_item_decl
429 | block_item_decls block_item_decl
432 block_item_decls_opt
433 : block_item_decls
437 case_item
438 : expression_list_proper ':' statement_or_null
439 { PCase::Item*tmp = new PCase::Item;
440 tmp->expr = *$1;
441 tmp->stat = $3;
442 delete $1;
443 $$ = tmp;
445 | K_default ':' statement_or_null
446 { PCase::Item*tmp = new PCase::Item;
447 tmp->stat = $3;
448 $$ = tmp;
450 | K_default statement_or_null
451 { PCase::Item*tmp = new PCase::Item;
452 tmp->stat = $2;
453 $$ = tmp;
455 | error ':' statement_or_null
456 { yyerror(@1, "error: Incomprehensible case expression.");
457 yyerrok;
461 case_items
462 : case_items case_item
463 { svector<PCase::Item*>*tmp;
464 tmp = new svector<PCase::Item*>(*$1, $2);
465 delete $1;
466 $$ = tmp;
468 | case_item
469 { svector<PCase::Item*>*tmp = new svector<PCase::Item*>(1);
470 (*tmp)[0] = $1;
471 $$ = tmp;
475 charge_strength
476 : '(' K_small ')'
477 | '(' K_medium ')'
478 | '(' K_large ')'
481 charge_strength_opt
482 : charge_strength
486 defparam_assign
487 : heirarchy_identifier '=' expression
488 { PExpr*tmp = $3;
489 if (!pform_expression_is_constant(tmp)) {
490 yyerror(@3, "error: parameter value "
491 "must be constant.");
492 delete tmp;
493 tmp = 0;
495 pform_set_defparam(*$1, $3);
496 delete $1;
500 defparam_assign_list
501 : defparam_assign
502 | range defparam_assign
503 { yyerror(@1, "error: defparam may not include a range.");
504 delete $1;
506 | defparam_assign_list ',' defparam_assign
509 delay1
510 : '#' delay_value_simple
511 { svector<PExpr*>*tmp = new svector<PExpr*>(1);
512 (*tmp)[0] = $2;
513 $$ = tmp;
515 | '#' '(' delay_value ')'
516 { svector<PExpr*>*tmp = new svector<PExpr*>(1);
517 (*tmp)[0] = $3;
518 $$ = tmp;
522 delay3
523 : '#' delay_value_simple
524 { svector<PExpr*>*tmp = new svector<PExpr*>(1);
525 (*tmp)[0] = $2;
526 $$ = tmp;
528 | '#' '(' delay_value ')'
529 { svector<PExpr*>*tmp = new svector<PExpr*>(1);
530 (*tmp)[0] = $3;
531 $$ = tmp;
533 | '#' '(' delay_value ',' delay_value ')'
534 { svector<PExpr*>*tmp = new svector<PExpr*>(2);
535 (*tmp)[0] = $3;
536 (*tmp)[1] = $5;
537 $$ = tmp;
539 | '#' '(' delay_value ',' delay_value ',' delay_value ')'
540 { svector<PExpr*>*tmp = new svector<PExpr*>(3);
541 (*tmp)[0] = $3;
542 (*tmp)[1] = $5;
543 (*tmp)[2] = $7;
544 $$ = tmp;
548 delay3_opt
549 : delay3 { $$ = $1; }
550 | { $$ = 0; }
553 delay_value_list
554 : delay_value
555 { svector<PExpr*>*tmp = new svector<PExpr*>(1);
556 (*tmp)[0] = $1;
557 $$ = tmp;
559 | delay_value_list ',' delay_value
560 { svector<PExpr*>*tmp = new svector<PExpr*>(*$1, $3);
561 delete $1;
562 $$ = tmp;
566 delay_value
567 : expression
568 { PExpr*tmp = $1;
569 $$ = tmp;
571 | expression ':' expression ':' expression
572 { $$ = pform_select_mtm_expr($1, $3, $5); }
576 delay_value_simple
577 : DEC_NUMBER
578 { verinum*tmp = $1;
579 if (tmp == 0) {
580 yyerror(@1, "internal error: delay.");
581 $$ = 0;
582 } else {
583 $$ = new PENumber(tmp);
584 $$->set_file(@1.text);
585 $$->set_lineno(@1.first_line);
588 | REALTIME
589 { verireal*tmp = $1;
590 if (tmp == 0) {
591 yyerror(@1, "internal error: delay.");
592 $$ = 0;
593 } else {
594 $$ = new PEFNumber(tmp);
595 $$->set_file(@1.text);
596 $$->set_lineno(@1.first_line);
599 | IDENTIFIER
600 { PEIdent*tmp = new PEIdent(lex_strings.make($1));
601 tmp->set_file(@1.text);
602 tmp->set_lineno(@1.first_line);
603 $$ = tmp;
604 delete $1;
608 description
609 : module
610 | udp_primitive
611 | KK_attribute '(' IDENTIFIER ',' STRING ',' STRING ')'
612 { perm_string tmp3 = lex_strings.make($3);
613 pform_set_type_attrib(tmp3, $5, $7);
614 delete $3;
615 delete $5;
619 drive_strength
620 : '(' dr_strength0 ',' dr_strength1 ')'
621 { $$.str0 = $2.str0;
622 $$.str1 = $4.str1;
624 | '(' dr_strength1 ',' dr_strength0 ')'
625 { $$.str0 = $4.str0;
626 $$.str1 = $2.str1;
628 | '(' dr_strength0 ',' K_highz1 ')'
629 { $$.str0 = $2.str0;
630 $$.str1 = PGate::HIGHZ;
632 | '(' dr_strength1 ',' K_highz0 ')'
633 { $$.str0 = PGate::HIGHZ;
634 $$.str1 = $2.str1;
636 | '(' K_highz1 ',' dr_strength0 ')'
637 { $$.str0 = $4.str0;
638 $$.str1 = PGate::HIGHZ;
640 | '(' K_highz0 ',' dr_strength1 ')'
641 { $$.str0 = PGate::HIGHZ;
642 $$.str1 = $4.str1;
646 drive_strength_opt
647 : drive_strength { $$ = $1; }
648 | { $$.str0 = PGate::STRONG; $$.str1 = PGate::STRONG; }
651 dr_strength0
652 : K_supply0 { $$.str0 = PGate::SUPPLY; }
653 | K_strong0 { $$.str0 = PGate::STRONG; }
654 | K_pull0 { $$.str0 = PGate::PULL; }
655 | K_weak0 { $$.str0 = PGate::WEAK; }
658 dr_strength1
659 : K_supply1 { $$.str1 = PGate::SUPPLY; }
660 | K_strong1 { $$.str1 = PGate::STRONG; }
661 | K_pull1 { $$.str1 = PGate::PULL; }
662 | K_weak1 { $$.str1 = PGate::WEAK; }
665 event_control
666 : '@' heirarchy_identifier
667 { PEIdent*tmpi = new PEIdent(*$2);
668 PEEvent*tmpe = new PEEvent(PEEvent::ANYEDGE, tmpi);
669 PEventStatement*tmps = new PEventStatement(tmpe);
670 tmps->set_file(@1.text);
671 tmps->set_lineno(@1.first_line);
672 $$ = tmps;
673 delete $2;
675 | '@' '(' event_expression_list ')'
676 { PEventStatement*tmp = new PEventStatement(*$3);
677 tmp->set_file(@1.text);
678 tmp->set_lineno(@1.first_line);
679 delete $3;
680 $$ = tmp;
682 | '@' '(' error ')'
683 { yyerror(@1, "error: Malformed event control expression.");
684 $$ = 0;
688 event_expression_list
689 : event_expression
690 { $$ = $1; }
691 | event_expression_list K_or event_expression
692 { svector<PEEvent*>*tmp = new svector<PEEvent*>(*$1, *$3);
693 delete $1;
694 delete $3;
695 $$ = tmp;
697 | event_expression_list ',' event_expression
698 { svector<PEEvent*>*tmp = new svector<PEEvent*>(*$1, *$3);
699 delete $1;
700 delete $3;
701 $$ = tmp;
705 event_expression
706 : K_posedge expression
707 { PEEvent*tmp = new PEEvent(PEEvent::POSEDGE, $2);
708 tmp->set_file(@1.text);
709 tmp->set_lineno(@1.first_line);
710 svector<PEEvent*>*tl = new svector<PEEvent*>(1);
711 (*tl)[0] = tmp;
712 $$ = tl;
714 | K_negedge expression
715 { PEEvent*tmp = new PEEvent(PEEvent::NEGEDGE, $2);
716 tmp->set_file(@1.text);
717 tmp->set_lineno(@1.first_line);
718 svector<PEEvent*>*tl = new svector<PEEvent*>(1);
719 (*tl)[0] = tmp;
720 $$ = tl;
722 | expression
723 { PEEvent*tmp = new PEEvent(PEEvent::ANYEDGE, $1);
724 tmp->set_file(@1.text);
725 tmp->set_lineno(@1.first_line);
726 svector<PEEvent*>*tl = new svector<PEEvent*>(1);
727 (*tl)[0] = tmp;
728 $$ = tl;
732 expression
733 : expr_primary
734 { $$ = $1; }
735 | '+' expr_primary %prec UNARY_PREC
736 { $$ = $2; }
737 | '-' expr_primary %prec UNARY_PREC
738 { PEUnary*tmp = new PEUnary('-', $2);
739 tmp->set_file(@2.text);
740 tmp->set_lineno(@2.first_line);
741 $$ = tmp;
743 | '~' expr_primary %prec UNARY_PREC
744 { PEUnary*tmp = new PEUnary('~', $2);
745 tmp->set_file(@2.text);
746 tmp->set_lineno(@2.first_line);
747 $$ = tmp;
749 | '&' expr_primary %prec UNARY_PREC
750 { PEUnary*tmp = new PEUnary('&', $2);
751 tmp->set_file(@2.text);
752 tmp->set_lineno(@2.first_line);
753 $$ = tmp;
755 | '!' expr_primary %prec UNARY_PREC
756 { PEUnary*tmp = new PEUnary('!', $2);
757 tmp->set_file(@2.text);
758 tmp->set_lineno(@2.first_line);
759 $$ = tmp;
761 | '|' expr_primary %prec UNARY_PREC
762 { PEUnary*tmp = new PEUnary('|', $2);
763 tmp->set_file(@2.text);
764 tmp->set_lineno(@2.first_line);
765 $$ = tmp;
767 | '^' expr_primary %prec UNARY_PREC
768 { PEUnary*tmp = new PEUnary('^', $2);
769 tmp->set_file(@2.text);
770 tmp->set_lineno(@2.first_line);
771 $$ = tmp;
773 | K_NAND expr_primary %prec UNARY_PREC
774 { PEUnary*tmp = new PEUnary('A', $2);
775 tmp->set_file(@2.text);
776 tmp->set_lineno(@2.first_line);
777 $$ = tmp;
779 | K_NOR expr_primary %prec UNARY_PREC
780 { PEUnary*tmp = new PEUnary('N', $2);
781 tmp->set_file(@2.text);
782 tmp->set_lineno(@2.first_line);
783 $$ = tmp;
785 | K_NXOR expr_primary %prec UNARY_PREC
786 { PEUnary*tmp = new PEUnary('X', $2);
787 tmp->set_file(@2.text);
788 tmp->set_lineno(@2.first_line);
789 $$ = tmp;
791 | '!' error %prec UNARY_PREC
792 { yyerror(@1, "error: Operand of unary ! "
793 "is not a primary expression.");
794 $$ = 0;
796 | '^' error %prec UNARY_PREC
797 { yyerror(@1, "error: Operand of reduction ^ "
798 "is not a primary expression.");
799 $$ = 0;
801 | expression '^' expression
802 { PEBinary*tmp = new PEBinary('^', $1, $3);
803 tmp->set_file(@2.text);
804 tmp->set_lineno(@2.first_line);
805 $$ = tmp;
807 | expression K_POW expression
808 { PEBinary*tmp = new PEBinary('p', $1, $3);
809 tmp->set_file(@2.text);
810 tmp->set_lineno(@2.first_line);
811 $$ = tmp;
813 | expression '*' expression
814 { PEBinary*tmp = new PEBinary('*', $1, $3);
815 tmp->set_file(@2.text);
816 tmp->set_lineno(@2.first_line);
817 $$ = tmp;
819 | expression '/' expression
820 { PEBinary*tmp = new PEBinary('/', $1, $3);
821 tmp->set_file(@2.text);
822 tmp->set_lineno(@2.first_line);
823 $$ = tmp;
825 | expression '%' expression
826 { PEBinary*tmp = new PEBinary('%', $1, $3);
827 tmp->set_file(@2.text);
828 tmp->set_lineno(@2.first_line);
829 $$ = tmp;
831 | expression '+' expression
832 { PEBinary*tmp = new PEBinary('+', $1, $3);
833 tmp->set_file(@2.text);
834 tmp->set_lineno(@2.first_line);
835 $$ = tmp;
837 | expression '-' expression
838 { PEBinary*tmp = new PEBinary('-', $1, $3);
839 tmp->set_file(@2.text);
840 tmp->set_lineno(@2.first_line);
841 $$ = tmp;
843 | expression '&' expression
844 { PEBinary*tmp = new PEBinary('&', $1, $3);
845 tmp->set_file(@2.text);
846 tmp->set_lineno(@2.first_line);
847 $$ = tmp;
849 | expression '|' expression
850 { PEBinary*tmp = new PEBinary('|', $1, $3);
851 tmp->set_file(@2.text);
852 tmp->set_lineno(@2.first_line);
853 $$ = tmp;
855 | expression K_NAND expression
856 { PEBinary*tmp = new PEBinary('A', $1, $3);
857 tmp->set_file(@2.text);
858 tmp->set_lineno(@2.first_line);
859 $$ = tmp;
861 | expression K_NOR expression
862 { PEBinary*tmp = new PEBinary('O', $1, $3);
863 tmp->set_file(@2.text);
864 tmp->set_lineno(@2.first_line);
865 $$ = tmp;
867 | expression K_NXOR expression
868 { PEBinary*tmp = new PEBinary('X', $1, $3);
869 tmp->set_file(@2.text);
870 tmp->set_lineno(@2.first_line);
871 $$ = tmp;
873 | expression '<' expression
874 { PEBinary*tmp = new PEBComp('<', $1, $3);
875 tmp->set_file(@2.text);
876 tmp->set_lineno(@2.first_line);
877 $$ = tmp;
879 | expression '>' expression
880 { PEBinary*tmp = new PEBComp('>', $1, $3);
881 tmp->set_file(@2.text);
882 tmp->set_lineno(@2.first_line);
883 $$ = tmp;
885 | expression K_LS expression
886 { PEBinary*tmp = new PEBShift('l', $1, $3);
887 tmp->set_file(@2.text);
888 tmp->set_lineno(@2.first_line);
889 $$ = tmp;
891 | expression K_RS expression
892 { PEBinary*tmp = new PEBShift('r', $1, $3);
893 tmp->set_file(@2.text);
894 tmp->set_lineno(@2.first_line);
895 $$ = tmp;
897 | expression K_RSS expression
898 { PEBinary*tmp = new PEBShift('R', $1, $3);
899 tmp->set_file(@2.text);
900 tmp->set_lineno(@2.first_line);
901 $$ = tmp;
903 | expression K_EQ expression
904 { PEBinary*tmp = new PEBComp('e', $1, $3);
905 tmp->set_file(@2.text);
906 tmp->set_lineno(@2.first_line);
907 $$ = tmp;
909 | expression K_CEQ expression
910 { PEBinary*tmp = new PEBComp('E', $1, $3);
911 tmp->set_file(@2.text);
912 tmp->set_lineno(@2.first_line);
913 $$ = tmp;
915 | expression K_LE expression
916 { PEBinary*tmp = new PEBComp('L', $1, $3);
917 tmp->set_file(@2.text);
918 tmp->set_lineno(@2.first_line);
919 $$ = tmp;
921 | expression K_GE expression
922 { PEBinary*tmp = new PEBComp('G', $1, $3);
923 tmp->set_file(@2.text);
924 tmp->set_lineno(@2.first_line);
925 $$ = tmp;
927 | expression K_NE expression
928 { PEBinary*tmp = new PEBComp('n', $1, $3);
929 tmp->set_file(@2.text);
930 tmp->set_lineno(@2.first_line);
931 $$ = tmp;
933 | expression K_CNE expression
934 { PEBinary*tmp = new PEBComp('N', $1, $3);
935 tmp->set_file(@2.text);
936 tmp->set_lineno(@2.first_line);
937 $$ = tmp;
939 | expression K_LOR expression
940 { PEBinary*tmp = new PEBinary('o', $1, $3);
941 tmp->set_file(@2.text);
942 tmp->set_lineno(@2.first_line);
943 $$ = tmp;
945 | expression K_LAND expression
946 { PEBinary*tmp = new PEBinary('a', $1, $3);
947 tmp->set_file(@2.text);
948 tmp->set_lineno(@2.first_line);
949 $$ = tmp;
951 | expression '?' expression ':' expression
952 { PETernary*tmp = new PETernary($1, $3, $5);
953 tmp->set_file(@2.text);
954 tmp->set_lineno(@2.first_line);
955 $$ = tmp;
959 expr_mintypmax
960 : expression
961 { $$ = $1; }
962 | expression ':' expression ':' expression
963 { switch (min_typ_max_flag) {
964 case MIN:
965 $$ = $1;
966 delete $3;
967 delete $5;
968 break;
969 case TYP:
970 delete $1;
971 $$ = $3;
972 delete $5;
973 break;
974 case MAX:
975 delete $1;
976 delete $3;
977 $$ = $5;
978 break;
984 /* Many contexts take a comma separated list of expressions. Null
985 expressions can happen anywhere in the list, so there are two
986 extra rules in expression_list_with_nuls for parsing and
987 installing those nulls.
989 The expression_list_proper rules do not allow null items in the
990 expression list, so can be used where nul expressions are not allowed. */
992 expression_list_with_nuls
993 : expression_list_with_nuls ',' expression
994 { svector<PExpr*>*tmp = new svector<PExpr*>(*$1, $3);
995 delete $1;
996 $$ = tmp;
998 | expression
999 { svector<PExpr*>*tmp = new svector<PExpr*>(1);
1000 (*tmp)[0] = $1;
1001 $$ = tmp;
1004 { svector<PExpr*>*tmp = new svector<PExpr*>(1);
1005 (*tmp)[0] = 0;
1006 $$ = tmp;
1009 | expression_list_with_nuls ','
1010 { svector<PExpr*>*tmp = new svector<PExpr*>(*$1, 0);
1011 delete $1;
1012 $$ = tmp;
1016 expression_list_proper
1017 : expression_list_proper ',' expression
1018 { svector<PExpr*>*tmp = new svector<PExpr*>(*$1, $3);
1019 delete $1;
1020 $$ = tmp;
1022 | expression
1023 { svector<PExpr*>*tmp = new svector<PExpr*>(1);
1024 (*tmp)[0] = $1;
1025 $$ = tmp;
1029 expr_primary
1030 : number
1031 { assert($1);
1032 PENumber*tmp = new PENumber($1);
1033 tmp->set_file(@1.text);
1034 tmp->set_lineno(@1.first_line);
1035 $$ = tmp;
1037 | REALTIME
1038 { PEFNumber*tmp = new PEFNumber($1);
1039 tmp->set_file(@1.text);
1040 tmp->set_lineno(@1.first_line);
1041 $$ = tmp;
1043 | STRING
1044 { PEString*tmp = new PEString($1);
1045 tmp->set_file(@1.text);
1046 tmp->set_lineno(@1.first_line);
1047 $$ = tmp;
1049 | SYSTEM_IDENTIFIER
1050 { perm_string tn = lex_strings.make($1);
1051 PECallFunction*tmp = new PECallFunction(tn);
1052 tmp->set_file(@1.text);
1053 tmp->set_lineno(@1.first_line);
1054 $$ = tmp;
1055 delete $1;
1058 /* The heirarchy_identifier rule matches simple identifiers as well as
1059 indexed arrays and part selects */
1061 | heirarchy_identifier
1062 { PEIdent*tmp = new PEIdent(*$1);
1063 tmp->set_file(@1.text);
1064 tmp->set_lineno(@1.first_line);
1065 $$ = tmp;
1066 delete $1;
1069 /* An identifer followed by an expression list in parentheses is a
1070 function call. If a system identifier, then a system function
1071 call. */
1073 | heirarchy_identifier '(' expression_list_proper ')'
1074 { PECallFunction*tmp = new PECallFunction(*$1, *$3);
1075 tmp->set_file(@1.text);
1076 tmp->set_lineno(@1.first_line);
1077 delete $1;
1078 $$ = tmp;
1080 | SYSTEM_IDENTIFIER '(' expression_list_proper ')'
1081 { perm_string tn = lex_strings.make($1);
1082 PECallFunction*tmp = new PECallFunction(tn, *$3);
1083 tmp->set_file(@1.text);
1084 tmp->set_lineno(@1.first_line);
1085 $$ = tmp;
1088 /* Parenthesized expressions are primaries. */
1090 | '(' expr_mintypmax ')'
1091 { $$ = $2; }
1093 /* Various kinds of concatenation expressions. */
1095 | '{' expression_list_proper '}'
1096 { PEConcat*tmp = new PEConcat(*$2);
1097 tmp->set_file(@1.text);
1098 tmp->set_lineno(@1.first_line);
1099 delete $2;
1100 $$ = tmp;
1102 | '{' expression '{' expression_list_proper '}' '}'
1103 { PExpr*rep = $2;
1104 PEConcat*tmp = new PEConcat(*$4, rep);
1105 tmp->set_file(@1.text);
1106 tmp->set_lineno(@1.first_line);
1107 delete $4;
1108 $$ = tmp;
1110 | '{' expression '{' expression_list_proper '}' error '}'
1111 { PExpr*rep = $2;
1112 PEConcat*tmp = new PEConcat(*$4, rep);
1113 tmp->set_file(@1.text);
1114 tmp->set_lineno(@1.first_line);
1115 delete $4;
1116 $$ = tmp;
1117 yyerror(@5, "error: Syntax error between internal '}' "
1118 "and closing '}' of repeat concatenation.");
1119 yyerrok;
1123 /* A function_item is either a block item (i.e. a reg or integer
1124 declaration) or an input declaration. There are no output or
1125 inout ports. */
1126 function_item
1127 : K_input signed_opt range_opt list_of_identifiers ';'
1128 { svector<PWire*>*tmp
1129 = pform_make_task_ports(NetNet::PINPUT,
1130 IVL_VT_NO_TYPE, $2,
1131 $3, $4,
1132 @1.text, @1.first_line);
1133 $$ = tmp;
1135 | K_output signed_opt range_opt list_of_identifiers ';'
1136 { svector<PWire*>*tmp
1137 = pform_make_task_ports(NetNet::PINPUT,
1138 IVL_VT_NO_TYPE, $2,
1139 $3, $4,
1140 @1.text, @1.first_line);
1141 $$ = tmp;
1142 yyerror(@1, "Functions may not have output ports.");
1144 | K_inout signed_opt range_opt list_of_identifiers ';'
1145 { svector<PWire*>*tmp
1146 = pform_make_task_ports(NetNet::PINPUT,
1147 IVL_VT_NO_TYPE, $2,
1148 $3, $4,
1149 @1.text, @1.first_line);
1150 $$ = tmp;
1151 yyerror(@1, "Functions may not have inout ports.");
1154 /* When the port is an integer, infer a signed vector of the integer
1155 shape. Generate a range to make it work. */
1157 | K_input K_integer list_of_identifiers ';'
1158 { svector<PExpr*>*range_stub
1159 = new svector<PExpr*>(2);
1160 PExpr*re;
1161 re = new PENumber(new verinum(integer_width-1,
1162 integer_width));
1163 (*range_stub)[0] = re;
1164 re = new PENumber(new verinum((uint64_t)0, integer_width));
1165 (*range_stub)[1] = re;
1166 svector<PWire*>*tmp
1167 = pform_make_task_ports(NetNet::PINPUT,
1168 IVL_VT_LOGIC, true,
1169 range_stub, $3,
1170 @1.text, @1.first_line);
1171 $$ = tmp;
1174 /* Ports can be real. */
1176 | K_input K_real list_of_identifiers ';'
1177 { svector<PWire*>*tmp
1178 = pform_make_task_ports(NetNet::PINPUT,
1179 IVL_VT_REAL, false,
1180 0, $3,
1181 @1.text, @1.first_line);
1182 $$ = tmp;
1185 | block_item_decl
1186 { $$ = 0; }
1189 /* A function_item_list only lists the input/output/inout
1190 declarations. The integer and reg declarations are handled in
1191 place, so are not listed. The list builder needs to account for
1192 the possibility that the various parts may be NULL. */
1193 function_item_list
1194 : function_item
1195 { $$ = $1; }
1196 | function_item_list function_item
1197 { if ($1 && $2) {
1198 svector<PWire*>*tmp = new svector<PWire*>(*$1, *$2);
1199 delete $1;
1200 delete $2;
1201 $$ = tmp;
1202 } else if ($1) {
1203 $$ = $1;
1204 } else {
1205 $$ = $2;
1210 /* A gate_instance is a module instantiation or a built in part
1211 type. In any case, the gate has a set of connections to ports. */
1212 gate_instance
1213 : IDENTIFIER '(' expression_list_with_nuls ')'
1214 { lgate*tmp = new lgate;
1215 tmp->name = $1;
1216 tmp->parms = $3;
1217 tmp->file = @1.text;
1218 tmp->lineno = @1.first_line;
1219 delete $1;
1220 $$ = tmp;
1223 | IDENTIFIER range '(' expression_list_with_nuls ')'
1224 { lgate*tmp = new lgate;
1225 svector<PExpr*>*rng = $2;
1226 tmp->name = $1;
1227 tmp->parms = $4;
1228 tmp->range[0] = (*rng)[0];
1229 tmp->range[1] = (*rng)[1];
1230 tmp->file = @1.text;
1231 tmp->lineno = @1.first_line;
1232 delete $1;
1233 delete rng;
1234 $$ = tmp;
1236 | '(' expression_list_with_nuls ')'
1237 { lgate*tmp = new lgate;
1238 tmp->name = "";
1239 tmp->parms = $2;
1240 tmp->file = @1.text;
1241 tmp->lineno = @1.first_line;
1242 $$ = tmp;
1245 /* Degenerate modules can have no ports. */
1247 | IDENTIFIER range
1248 { lgate*tmp = new lgate;
1249 svector<PExpr*>*rng = $2;
1250 tmp->name = $1;
1251 tmp->parms = 0;
1252 tmp->parms_by_name = 0;
1253 tmp->range[0] = (*rng)[0];
1254 tmp->range[1] = (*rng)[1];
1255 tmp->file = @1.text;
1256 tmp->lineno = @1.first_line;
1257 delete $1;
1258 delete rng;
1259 $$ = tmp;
1262 /* Modules can also take ports by port-name expressions. */
1264 | IDENTIFIER '(' port_name_list ')'
1265 { lgate*tmp = new lgate;
1266 tmp->name = $1;
1267 tmp->parms = 0;
1268 tmp->parms_by_name = $3;
1269 tmp->file = @1.text;
1270 tmp->lineno = @1.first_line;
1271 delete $1;
1272 $$ = tmp;
1275 | IDENTIFIER range '(' port_name_list ')'
1276 { lgate*tmp = new lgate;
1277 svector<PExpr*>*rng = $2;
1278 tmp->name = $1;
1279 tmp->parms = 0;
1280 tmp->parms_by_name = $4;
1281 tmp->range[0] = (*rng)[0];
1282 tmp->range[1] = (*rng)[1];
1283 tmp->file = @1.text;
1284 tmp->lineno = @1.first_line;
1285 delete $1;
1286 delete rng;
1287 $$ = tmp;
1291 gate_instance_list
1292 : gate_instance_list ',' gate_instance
1293 { svector<lgate>*tmp1 = $1;
1294 lgate*tmp2 = $3;
1295 svector<lgate>*out = new svector<lgate> (*tmp1, *tmp2);
1296 delete tmp1;
1297 delete tmp2;
1298 $$ = out;
1300 | gate_instance
1301 { svector<lgate>*tmp = new svector<lgate>(1);
1302 (*tmp)[0] = *$1;
1303 delete $1;
1304 $$ = tmp;
1308 gatetype
1309 : K_and { $$ = PGBuiltin::AND; }
1310 | K_nand { $$ = PGBuiltin::NAND; }
1311 | K_or { $$ = PGBuiltin::OR; }
1312 | K_nor { $$ = PGBuiltin::NOR; }
1313 | K_xor { $$ = PGBuiltin::XOR; }
1314 | K_xnor { $$ = PGBuiltin::XNOR; }
1315 | K_buf { $$ = PGBuiltin::BUF; }
1316 | K_bufif0 { $$ = PGBuiltin::BUFIF0; }
1317 | K_bufif1 { $$ = PGBuiltin::BUFIF1; }
1318 | K_not { $$ = PGBuiltin::NOT; }
1319 | K_notif0 { $$ = PGBuiltin::NOTIF0; }
1320 | K_notif1 { $$ = PGBuiltin::NOTIF1; }
1321 | K_nmos { $$ = PGBuiltin::NMOS; }
1322 | K_rnmos { $$ = PGBuiltin::RNMOS; }
1323 | K_pmos { $$ = PGBuiltin::PMOS; }
1324 | K_rpmos { $$ = PGBuiltin::RPMOS; }
1325 | K_cmos { $$ = PGBuiltin::CMOS; }
1326 | K_rcmos { $$ = PGBuiltin::RCMOS; }
1327 | K_tran { $$ = PGBuiltin::TRAN; }
1328 | K_rtran { $$ = PGBuiltin::RTRAN; }
1329 | K_tranif0 { $$ = PGBuiltin::TRANIF0; }
1330 | K_tranif1 { $$ = PGBuiltin::TRANIF1; }
1331 | K_rtranif0 { $$ = PGBuiltin::RTRANIF0; }
1332 | K_rtranif1 { $$ = PGBuiltin::RTRANIF1; }
1336 /* A general identifier is a hierarchical name, with the right most
1337 name the base of the identifier. This rule builds up a
1338 hierarchical name from the left to the right, forming a list of
1339 names. */
1341 heirarchy_identifier
1342 : IDENTIFIER
1343 { $$ = new pform_name_t;
1344 $$->push_back(name_component_t(lex_strings.make($1)));
1345 delete $1;
1347 | heirarchy_identifier '.' IDENTIFIER
1348 { pform_name_t * tmp = $1;
1349 tmp->push_back(name_component_t(lex_strings.make($3)));
1350 delete $3;
1351 $$ = tmp;
1353 | heirarchy_identifier '[' expression ']'
1354 { pform_name_t * tmp = $1;
1355 name_component_t&tail = tmp->back();
1356 index_component_t itmp;
1357 itmp.sel = index_component_t::SEL_BIT;
1358 itmp.msb = $3;
1359 tail.index.push_back(itmp);
1360 $$ = tmp;
1362 | heirarchy_identifier '[' expression ':' expression ']'
1363 { pform_name_t * tmp = $1;
1364 name_component_t&tail = tmp->back();
1365 index_component_t itmp;
1366 itmp.sel = index_component_t::SEL_PART;
1367 itmp.msb = $3;
1368 itmp.lsb = $5;
1369 tail.index.push_back(itmp);
1370 $$ = tmp;
1372 | heirarchy_identifier '[' expression K_PO_POS expression ']'
1373 { pform_name_t * tmp = $1;
1374 name_component_t&tail = tmp->back();
1375 index_component_t itmp;
1376 itmp.sel = index_component_t::SEL_IDX_UP;
1377 itmp.msb = $3;
1378 itmp.lsb = $5;
1379 tail.index.push_back(itmp);
1380 $$ = tmp;
1382 | heirarchy_identifier '[' expression K_PO_NEG expression ']'
1383 { pform_name_t * tmp = $1;
1384 name_component_t&tail = tmp->back();
1385 index_component_t itmp;
1386 itmp.sel = index_component_t::SEL_IDX_DO;
1387 itmp.msb = $3;
1388 itmp.lsb = $5;
1389 tail.index.push_back(itmp);
1390 $$ = tmp;
1394 /* This is a list of identifiers. The result is a list of strings,
1395 each one of the identifiers in the list. These are simple,
1396 non-hierarchical names separated by ',' characters. */
1397 list_of_identifiers
1398 : IDENTIFIER
1399 { $$ = list_from_identifier($1); }
1400 | list_of_identifiers ',' IDENTIFIER
1401 { $$ = list_from_identifier($1, $3); }
1405 /* The list_of_ports and list_of_port_declarations rules are the
1406 port list formats for module ports. The list_of_ports_opt rule is
1407 only used by the module start rule.
1409 The first, the list_of_ports, is the 1364-1995 format, a list of
1410 port names, including .name() syntax.
1412 The list_of_port_declarations the 1364-2001 format, an in-line
1413 declaration of the ports.
1415 In both cases, the list_of_ports and list_of_port_declarations
1416 returns an array of Module::port_t* items that include the name
1417 of the port internally and externally. The actual creation of the
1418 nets/variables is done in the declaration, whether internal to
1419 the port list or in amongst the module items. */
1421 list_of_ports
1422 : port_opt
1423 { svector<Module::port_t*>*tmp
1424 = new svector<Module::port_t*>(1);
1425 (*tmp)[0] = $1;
1426 $$ = tmp;
1428 | list_of_ports ',' port_opt
1429 { svector<Module::port_t*>*tmp
1430 = new svector<Module::port_t*>(*$1, $3);
1431 delete $1;
1432 $$ = tmp;
1436 list_of_port_declarations
1437 : port_declaration
1438 { svector<Module::port_t*>*tmp
1439 = new svector<Module::port_t*>(1);
1440 (*tmp)[0] = $1;
1442 * Uncommenting this makes lopd always fully specified.
1443 * Some wanted an implicit net to not be fully defined.
1445 * pform_set_net_range($1[0].name);
1447 $$ = tmp;
1449 | list_of_port_declarations ',' port_declaration
1450 { svector<Module::port_t*>*tmp
1451 = new svector<Module::port_t*>(*$1, $3);
1452 delete $1;
1454 * Same as above.
1456 * pform_set_net_range($3[0].name);
1458 $$ = tmp;
1460 | list_of_port_declarations ',' IDENTIFIER
1461 { Module::port_t*ptmp;
1462 ptmp = pform_module_port_reference($3, @3.text,
1463 @3.first_line);
1464 svector<Module::port_t*>*tmp
1465 = new svector<Module::port_t*>(*$1, ptmp);
1467 /* Get the port declaration details, the port type
1468 and what not, from context data stored by the
1469 last port_declaration rule. */
1470 pform_module_define_port(@3, $3,
1471 port_declaration_context.port_type,
1472 port_declaration_context.port_net_type,
1473 port_declaration_context.sign_flag,
1474 port_declaration_context.range, 0);
1475 delete $1;
1477 * Same as above.
1479 * pform_set_net_range($3);
1481 $$ = tmp;
1485 port_declaration
1486 : attribute_list_opt
1487 K_input net_type_opt signed_opt range_opt IDENTIFIER
1488 { Module::port_t*ptmp;
1489 ptmp = pform_module_port_reference($6, @2.text,
1490 @2.first_line);
1491 pform_module_define_port(@2, $6, NetNet::PINPUT,
1492 $3, $4, $5, $1);
1493 port_declaration_context.port_type = NetNet::PINPUT;
1494 port_declaration_context.port_net_type = $3;
1495 port_declaration_context.sign_flag = $4;
1496 port_declaration_context.range = $5;
1497 delete $1;
1498 delete $6;
1499 $$ = ptmp;
1501 | attribute_list_opt
1502 K_inout net_type_opt signed_opt range_opt IDENTIFIER
1503 { Module::port_t*ptmp;
1504 ptmp = pform_module_port_reference($6, @2.text,
1505 @2.first_line);
1506 pform_module_define_port(@2, $6, NetNet::PINOUT,
1507 $3, $4, $5, $1);
1508 port_declaration_context.port_type = NetNet::PINOUT;
1509 port_declaration_context.port_net_type = $3;
1510 port_declaration_context.sign_flag = $4;
1511 port_declaration_context.range = $5;
1512 delete $1;
1513 delete $6;
1514 $$ = ptmp;
1516 | attribute_list_opt
1517 K_output net_type_opt signed_opt range_opt IDENTIFIER
1518 { Module::port_t*ptmp;
1519 ptmp = pform_module_port_reference($6, @2.text,
1520 @2.first_line);
1521 pform_module_define_port(@2, $6, NetNet::POUTPUT,
1522 $3, $4, $5, $1);
1523 port_declaration_context.port_type = NetNet::POUTPUT;
1524 port_declaration_context.port_net_type = $3;
1525 port_declaration_context.sign_flag = $4;
1526 port_declaration_context.range = $5;
1527 delete $1;
1528 delete $6;
1529 $$ = ptmp;
1531 | attribute_list_opt
1532 K_output var_type signed_opt range_opt IDENTIFIER
1533 { Module::port_t*ptmp;
1534 ptmp = pform_module_port_reference($6, @2.text,
1535 @2.first_line);
1536 pform_module_define_port(@2, $6, NetNet::POUTPUT,
1537 $3, $4, $5, $1);
1538 port_declaration_context.port_type = NetNet::POUTPUT;
1539 port_declaration_context.port_net_type = $3;
1540 port_declaration_context.sign_flag = $4;
1541 port_declaration_context.range = $5;
1542 delete $1;
1543 delete $6;
1544 $$ = ptmp;
1546 | attribute_list_opt
1547 K_output var_type signed_opt range_opt IDENTIFIER '=' expression
1548 { Module::port_t*ptmp;
1549 ptmp = pform_module_port_reference($6, @2.text,
1550 @2.first_line);
1551 pform_module_define_port(@2, $6, NetNet::POUTPUT,
1552 $3, $4, $5, $1);
1553 port_declaration_context.port_type = NetNet::POUTPUT;
1554 port_declaration_context.port_net_type = $3;
1555 port_declaration_context.sign_flag = $4;
1556 port_declaration_context.range = $5;
1558 if (! pform_expression_is_constant($8))
1559 yyerror(@8, "error: register declaration assignment"
1560 " value must be a constant expression.");
1561 pform_make_reginit(@6, $6, $8);
1563 delete $1;
1564 delete $6;
1565 $$ = ptmp;
1571 net_type_opt
1572 : net_type { $$ = $1; }
1573 | { $$ = NetNet::IMPLICIT; }
1576 signed_opt : K_signed { $$ = true; } | {$$ = false; } ;
1578 /* An lpvalue is the expression that can go on the left side of a
1579 procedural assignment. This rule handles only procedural
1580 assignments. It is more limited then the general expr_primary
1581 rule to reflect the rules for assignment l-values. */
1582 lpvalue
1583 : heirarchy_identifier
1584 { PEIdent*tmp = new PEIdent(*$1);
1585 tmp->set_file(@1.text);
1586 tmp->set_lineno(@1.first_line);
1587 $$ = tmp;
1588 delete $1;
1590 | '{' expression_list_proper '}'
1591 { PEConcat*tmp = new PEConcat(*$2);
1592 tmp->set_file(@1.text);
1593 tmp->set_lineno(@1.first_line);
1594 delete $2;
1595 $$ = tmp;
1600 /* Continuous assignments have a list of individual assignments. */
1602 cont_assign
1603 : lpvalue '=' expression
1604 { svector<PExpr*>*tmp = new svector<PExpr*>(2);
1605 (*tmp)[0] = $1;
1606 (*tmp)[1] = $3;
1607 $$ = tmp;
1611 cont_assign_list
1612 : cont_assign_list ',' cont_assign
1613 { svector<PExpr*>*tmp = new svector<PExpr*>(*$1, *$3);
1614 delete $1;
1615 delete $3;
1616 $$ = tmp;
1618 | cont_assign
1619 { $$ = $1; }
1623 /* This is the global structure of a module. A module in a start
1624 section, with optional ports, then an optional list of module
1625 items, and finally an end marker. */
1627 module : attribute_list_opt module_start IDENTIFIER
1628 { pform_startmodule($3, @2.text, @2.first_line, $1); }
1629 module_parameter_port_list_opt
1630 module_port_list_opt ';'
1631 { pform_module_set_ports($6); }
1632 module_item_list_opt
1633 K_endmodule
1634 { pform_endmodule($3);
1635 delete $3;
1640 module_start : K_module | K_macromodule ;
1642 module_port_list_opt
1643 : '(' list_of_ports ')' { $$ = $2; }
1644 | '(' list_of_port_declarations ')' { $$ = $2; }
1645 | { $$ = 0; }
1648 /* Module declarations include optional ANSII style module parameter
1649 ports. These are simply advance ways to declare parameters, so
1650 that the port declarations may use them. */
1651 module_parameter_port_list_opt
1653 | '#' '(' module_parameter_port_list ')'
1656 module_parameter_port_list
1657 : K_parameter parameter_assign
1658 | module_parameter_port_list ',' parameter_assign
1659 | module_parameter_port_list ',' K_parameter parameter_assign
1662 module_item
1664 /* This rule detects net declarations that possibly include a
1665 primitive type, an optional vector range and signed flag. This
1666 also includes an optional delay set. The values are then applied
1667 to a list of names. If the primitive type is not specified, then
1668 resort to the default type LOGIC. */
1670 : attribute_list_opt net_type
1671 primitive_type_opt signed_opt range_opt
1672 delay3_opt
1673 net_variable_list ';'
1675 { ivl_variable_type_t dtype = $3;
1676 if (dtype == IVL_VT_NO_TYPE)
1677 dtype = IVL_VT_LOGIC;
1678 pform_makewire(@2, $5, $4, $7, $2,
1679 NetNet::NOT_A_PORT, dtype, $1);
1680 if ($6 != 0) {
1681 yyerror(@6, "sorry: net delays not supported.");
1682 delete $6;
1684 if ($1) delete $1;
1687 /* Very similar to the rule above, but this takes a list of
1688 net_decl_assigns, which are <name> = <expr> assignment
1689 declarations. */
1691 | attribute_list_opt net_type
1692 primitive_type_opt signed_opt range_opt
1693 delay3_opt net_decl_assigns ';'
1695 { ivl_variable_type_t dtype = $3;
1696 if (dtype == IVL_VT_NO_TYPE)
1697 dtype = IVL_VT_LOGIC;
1698 pform_makewire(@2, $5, $4, $6,
1699 str_strength, $7, $2, dtype);
1700 if ($1) {
1701 yyerror(@2, "sorry: Attributes not supported "
1702 "on net declaration assignments.");
1703 delete $1;
1707 /* This form doesn't have the range, but does have strengths. This
1708 gives strength to the assignment drivers. */
1710 | attribute_list_opt net_type
1711 primitive_type_opt signed_opt
1712 drive_strength net_decl_assigns ';'
1714 { ivl_variable_type_t dtype = $3;
1715 if (dtype == IVL_VT_NO_TYPE)
1716 dtype = IVL_VT_LOGIC;
1717 pform_makewire(@2, 0, $4, 0, $5, $6, $2, dtype);
1718 if ($1) {
1719 yyerror(@2, "sorry: Attributes not supported "
1720 "on net declaration assignments.");
1721 delete $1;
1725 | K_trireg charge_strength_opt range_opt delay3_opt list_of_identifiers ';'
1726 { yyerror(@1, "sorry: trireg nets not supported.");
1727 delete $3;
1728 delete $4;
1731 | port_type signed_opt range_opt delay3_opt list_of_identifiers ';'
1732 { pform_set_port_type(@1, $5, $3, $2, $1);
1735 /* The next two rules handle Verilog 2001 statements of the form:
1736 input wire signed [h:l] <list>;
1737 This creates the wire and sets the port type all at once. */
1739 | port_type net_type signed_opt range_opt list_of_identifiers ';'
1740 { pform_makewire(@1, $4, $3, $5, $2, $1, IVL_VT_NO_TYPE, 0,
1741 SR_BOTH);
1744 | K_output var_type signed_opt range_opt list_of_identifiers ';'
1745 { pform_makewire(@1, $4, $3, $5, $2, NetNet::POUTPUT,
1746 IVL_VT_NO_TYPE, 0, SR_BOTH);
1749 /* var_type declaration (reg variables) cannot be input or output,
1750 because the port declaration implies an external driver, which
1751 cannot be attached to a reg. These rules catch that error early. */
1753 | K_input var_type signed_opt range_opt list_of_identifiers ';'
1754 { pform_makewire(@1, $4, $3, $5, $2, NetNet::PINPUT,
1755 IVL_VT_NO_TYPE, 0);
1756 yyerror(@2, "error: reg variables cannot be inputs.");
1759 | K_inout var_type signed_opt range_opt list_of_identifiers ';'
1760 { pform_makewire(@1, $4, $3, $5, $2, NetNet::PINOUT,
1761 IVL_VT_NO_TYPE, 0);
1762 yyerror(@2, "error: reg variables cannot be inouts.");
1765 | port_type signed_opt range_opt delay3_opt error ';'
1766 { yyerror(@1, "error: Invalid variable list"
1767 " in port declaration.");
1768 if ($3) delete $3;
1769 if ($4) delete $4;
1770 yyerrok;
1773 /* block_item_decl rule is shared with task blocks and named
1774 begin/end. */
1776 | block_item_decl
1778 /* */
1780 | K_defparam defparam_assign_list ';'
1781 | K_event list_of_identifiers ';'
1782 { pform_make_events($2, @1.text, @1.first_line);
1785 /* Most gate types have an optional drive strength and optional
1786 three-value delay. These rules handle the different cases. */
1788 | attribute_list_opt gatetype gate_instance_list ';'
1789 { pform_makegates($2, str_strength, 0, $3, $1);
1792 | attribute_list_opt gatetype delay3 gate_instance_list ';'
1793 { pform_makegates($2, str_strength, $3, $4, $1);
1796 | attribute_list_opt gatetype drive_strength gate_instance_list ';'
1797 { pform_makegates($2, $3, 0, $4, $1);
1800 | attribute_list_opt gatetype drive_strength delay3 gate_instance_list ';'
1801 { pform_makegates($2, $3, $4, $5, $1);
1804 /* Pullup and pulldown devices cannot have delays, and their
1805 strengths are limited. */
1807 | K_pullup gate_instance_list ';'
1808 { pform_makegates(PGBuiltin::PULLUP, pull_strength, 0,
1809 $2, 0);
1811 | K_pulldown gate_instance_list ';'
1812 { pform_makegates(PGBuiltin::PULLDOWN, pull_strength,
1813 0, $2, 0);
1816 | K_pullup '(' dr_strength1 ')' gate_instance_list ';'
1817 { pform_makegates(PGBuiltin::PULLUP, $3, 0, $5, 0);
1820 | K_pulldown '(' dr_strength0 ')' gate_instance_list ';'
1821 { pform_makegates(PGBuiltin::PULLDOWN, $3, 0, $5, 0);
1824 /* This rule handles instantiations of modules and user defined
1825 primitives. These devices to not have delay lists or strengths,
1826 but then can have parameter lists. */
1828 | attribute_list_opt
1829 IDENTIFIER parameter_value_opt gate_instance_list ';'
1830 { perm_string tmp1 = lex_strings.make($2);
1831 pform_make_modgates(tmp1, $3, $4);
1832 delete $2;
1833 if ($1) delete $1;
1836 | attribute_list_opt
1837 IDENTIFIER parameter_value_opt error ';'
1838 { yyerror(@2, "error: Invalid module instantiation");
1839 if ($1) delete $1;
1842 /* Continuous assignment can have an optional drive strength, then
1843 an optional delay3 that applies to all the assignments in the
1844 cont_assign_list. */
1846 | K_assign drive_strength_opt delay3_opt cont_assign_list ';'
1847 { pform_make_pgassign_list($4, $3, $2, @1.text, @1.first_line); }
1849 /* Always and initial items are behavioral processes. */
1851 | attribute_list_opt K_always statement
1852 { PProcess*tmp = pform_make_behavior(PProcess::PR_ALWAYS,
1853 $3, $1);
1854 tmp->set_file(@2.text);
1855 tmp->set_lineno(@2.first_line);
1857 | attribute_list_opt K_initial statement
1858 { PProcess*tmp = pform_make_behavior(PProcess::PR_INITIAL,
1859 $3, $1);
1860 tmp->set_file(@2.text);
1861 tmp->set_lineno(@2.first_line);
1864 /* The task declaration rule matches the task declaration
1865 header, then pushes the function scope. This causes the
1866 definitions in the task_body to take on the scope of the task
1867 instead of the module. Note that these runs accept for the task
1868 body statement_or_null, although the standard does not allow null
1869 statements in the task body. But we continue to accept it as an
1870 extension. */
1872 | K_task IDENTIFIER ';'
1873 { pform_push_scope($2); }
1874 task_item_list_opt
1875 statement_or_null
1876 K_endtask
1877 { PTask*tmp = new PTask;
1878 perm_string tmp2 = lex_strings.make($2);
1879 tmp->set_file(@1.text);
1880 tmp->set_lineno(@1.first_line);
1881 tmp->set_ports($5);
1882 tmp->set_statement($6);
1883 pform_set_task(tmp2, tmp);
1884 pform_pop_scope();
1885 delete $2;
1888 | K_task IDENTIFIER
1889 { pform_push_scope($2); }
1890 '(' task_port_decl_list ')' ';'
1891 task_item_list_opt
1892 statement_or_null
1893 K_endtask
1894 { PTask*tmp = new PTask;
1895 perm_string tmp2 = lex_strings.make($2);
1896 tmp->set_file(@1.text);
1897 tmp->set_lineno(@1.first_line);
1898 tmp->set_ports($5);
1899 tmp->set_statement($9);
1900 pform_set_task(tmp2, tmp);
1901 pform_pop_scope();
1902 delete $2;
1905 /* The function declaration rule matches the function declaration
1906 header, then pushes the function scope. This causes the
1907 definitions in the func_body to take on the scope of the function
1908 instead of the module. */
1910 | K_function function_range_or_type_opt IDENTIFIER ';'
1911 { pform_push_scope($3); }
1912 function_item_list statement
1913 K_endfunction
1914 { perm_string name = lex_strings.make($3);
1915 PFunction *tmp = new PFunction(name);
1916 tmp->set_file(@1.text);
1917 tmp->set_lineno(@1.first_line);
1918 tmp->set_ports($6);
1919 tmp->set_statement($7);
1920 tmp->set_return($2);
1921 pform_set_function(name, tmp);
1922 pform_pop_scope();
1923 delete $3;
1926 /* A generate region can contain further module items. Actually, it
1927 is supposed to be limited to certain kinds of module items, but
1928 the semantic tests will check that for us. */
1930 | K_generate module_item_list_opt K_endgenerate
1932 | K_genvar list_of_identifiers ';'
1933 { pform_genvars($2); }
1935 | K_for '(' IDENTIFIER '=' expression ';'
1936 expression ';'
1937 IDENTIFIER '=' expression ')'
1938 { pform_start_generate_for(@1, $3, $5, $7, $9, $11); }
1939 generate_block
1940 { pform_endgenerate(); }
1942 | generate_if
1943 generate_block_opt
1944 K_else
1945 { pform_start_generate_else(@1); }
1946 generate_block
1947 { pform_endgenerate(); }
1949 | generate_if
1950 generate_block_opt %prec less_than_K_else
1951 { pform_endgenerate(); }
1953 /* specify blocks are parsed but ignored. */
1955 | K_specify K_endspecify
1956 { /* empty lists are legal syntax. */ }
1958 | K_specify specify_item_list K_endspecify
1962 | K_specify error K_endspecify
1963 { yyerror(@1, "error: syntax error in specify block");
1964 yyerrok;
1967 /* These rules match various errors that the user can type into
1968 module items. These rules try to catch them at a point where a
1969 reasonable error message can be produced. */
1971 | K_module error ';'
1972 { yyerror(@2, "error: missing endmodule or attempt to "
1973 "nest modules.");
1974 pform_error_nested_modules();
1975 yyerrok;
1978 | error ';'
1979 { yyerror(@2, "error: invalid module item.");
1980 yyerrok;
1983 | K_assign error '=' expression ';'
1984 { yyerror(@1, "error: syntax error in left side "
1985 "of continuous assignment.");
1986 yyerrok;
1989 | K_assign error ';'
1990 { yyerror(@1, "error: syntax error in "
1991 "continuous assignment");
1992 yyerrok;
1995 | K_function error K_endfunction
1996 { yyerror(@1, "error: I give up on this "
1997 "function definition.");
1998 yyerrok;
2001 /* These rules are for the Icarus Verilog specific $attribute
2002 extensions. Then catch the parameters of the $attribute keyword. */
2004 | KK_attribute '(' IDENTIFIER ',' STRING ',' STRING ')' ';'
2005 { perm_string tmp3 = lex_strings.make($3);
2006 perm_string tmp5 = lex_strings.make($5);
2007 pform_set_attrib(tmp3, tmp5, $7);
2008 delete $3;
2009 delete $5;
2011 | KK_attribute '(' error ')' ';'
2012 { yyerror(@1, "error: Malformed $attribute parameter list."); }
2015 generate_if : K_if '(' expression ')' { pform_start_generate_if(@1, $3); }
2017 module_item_list
2018 : module_item_list module_item
2019 | module_item
2022 module_item_list_opt
2023 : module_item_list
2027 /* A generate block is the thing within a generate scheme. It may be
2028 a single module item, an anonymous block of module items, or a
2029 named module item. In all cases, the meat is in the module items
2030 inside, and the processing is done by the module_item rules. We
2031 only need to take note here of the scope name, if any. */
2033 generate_block
2034 : module_item
2035 | K_begin module_item_list_opt K_end
2036 | K_begin ':' IDENTIFIER module_item_list_opt K_end
2037 { pform_generate_block_name($3); }
2040 generate_block_opt : generate_block | ';' ;
2043 /* A net declaration assignment allows the programmer to combine the
2044 net declaration and the continuous assignment into a single
2045 statement.
2047 Note that the continuous assignment statement is generated as a
2048 side effect, and all I pass up is the name of the l-value. */
2050 net_decl_assign
2051 : IDENTIFIER '=' expression
2052 { net_decl_assign_t*tmp = new net_decl_assign_t;
2053 tmp->next = tmp;
2054 tmp->name = $1;
2055 tmp->expr = $3;
2056 $$ = tmp;
2060 net_decl_assigns
2061 : net_decl_assigns ',' net_decl_assign
2062 { net_decl_assign_t*tmp = $1;
2063 $3->next = tmp->next;
2064 tmp->next = $3;
2065 $$ = tmp;
2067 | net_decl_assign
2068 { $$ = $1;
2072 primitive_type
2073 : K_logic { $$ = IVL_VT_LOGIC; }
2074 | K_bool { $$ = IVL_VT_BOOL; }
2075 | K_real { $$ = IVL_VT_REAL; }
2078 primitive_type_opt : primitive_type { $$ = $1; } | { $$ = IVL_VT_NO_TYPE; } ;
2080 net_type
2081 : K_wire { $$ = NetNet::WIRE; }
2082 | K_tri { $$ = NetNet::TRI; }
2083 | K_tri1 { $$ = NetNet::TRI1; }
2084 | K_supply0 { $$ = NetNet::SUPPLY0; }
2085 | K_wand { $$ = NetNet::WAND; }
2086 | K_triand { $$ = NetNet::TRIAND; }
2087 | K_tri0 { $$ = NetNet::TRI0; }
2088 | K_supply1 { $$ = NetNet::SUPPLY1; }
2089 | K_wor { $$ = NetNet::WOR; }
2090 | K_trior { $$ = NetNet::TRIOR; }
2091 | K_wone { $$ = NetNet::WONE; }
2094 var_type
2095 : K_reg { $$ = NetNet::REG; }
2098 /* In this rule we have matched the "parameter" keyword. The rule
2099 generates a type (optional) and a list of assignments. */
2101 parameter_assign_decl
2102 : parameter_assign_list
2103 | range { active_range = $1; active_signed = false; }
2104 parameter_assign_list
2105 { active_range = 0;
2106 active_signed = false;
2108 | K_signed range { active_range = $2; active_signed = true; }
2109 parameter_assign_list
2110 { active_range = 0;
2111 active_signed = false;
2113 | K_integer { active_range = 0; active_signed = true; }
2114 parameter_assign_list
2115 { active_range = 0;
2116 active_signed = false;
2120 parameter_assign_list
2121 : parameter_assign
2122 | parameter_assign_list ',' parameter_assign
2125 parameter_assign
2126 : IDENTIFIER '=' expression
2127 { PExpr*tmp = $3;
2128 if (!pform_expression_is_constant(tmp)) {
2129 yyerror(@3, "error: parameter value "
2130 "must be a constant expression.");
2131 delete tmp;
2132 tmp = 0;
2133 } else {
2134 pform_set_parameter(lex_strings.make($1),
2135 active_signed,
2136 active_range, tmp);
2138 delete $1;
2142 /* Localparam assignments and assignment lists are broken into
2143 separate BNF so that I can call slightly different parameter
2144 handling code. They parse the same as parameters, they just
2145 behave differently when someone tries to override them. */
2147 localparam_assign
2148 : IDENTIFIER '=' expression
2149 { PExpr*tmp = $3;
2150 if (!pform_expression_is_constant(tmp)) {
2151 yyerror(@3, "error: parameter value "
2152 "must be constant.");
2153 delete tmp;
2154 tmp = 0;
2155 } else {
2156 pform_set_localparam(lex_strings.make($1),
2157 active_signed,
2158 active_range, tmp);
2160 delete $1;
2164 localparam_assign_decl
2165 : localparam_assign_list
2166 | range { active_range = $1; active_signed = false; }
2167 localparam_assign_list
2168 { active_range = 0;
2169 active_signed = false;
2171 | K_signed range { active_range = $2; active_signed = true; }
2172 localparam_assign_list
2173 { active_range = 0;
2174 active_signed = false;
2178 localparam_assign_list
2179 : localparam_assign
2180 | localparam_assign_list ',' localparam_assign
2185 /* The parameters of a module instance can be overridden by writing
2186 a list of expressions in a syntax much like a delay list. (The
2187 difference being the list can have any length.) The pform that
2188 attaches the expression list to the module checks that the
2189 expressions are constant.
2191 Although the BNF in IEEE1364-1995 implies that parameter value
2192 lists must be in parentheses, in practice most compilers will
2193 accept simple expressions outside of parentheses if there is only
2194 one value, so I'll accept simple numbers here.
2196 The parameter value by name syntax is OVI enhancement BTF-B06 as
2197 approved by WG1364 on 6/28/1998. */
2199 parameter_value_opt
2200 : '#' '(' expression_list_with_nuls ')'
2201 { struct parmvalue_t*tmp = new struct parmvalue_t;
2202 tmp->by_order = $3;
2203 tmp->by_name = 0;
2204 $$ = tmp;
2206 | '#' '(' parameter_value_byname_list ')'
2207 { struct parmvalue_t*tmp = new struct parmvalue_t;
2208 tmp->by_order = 0;
2209 tmp->by_name = $3;
2210 $$ = tmp;
2212 | '#' DEC_NUMBER
2213 { assert($2);
2214 PENumber*tmp = new PENumber($2);
2215 tmp->set_file(@1.text);
2216 tmp->set_lineno(@1.first_line);
2218 struct parmvalue_t*lst = new struct parmvalue_t;
2219 lst->by_order = new svector<PExpr*>(1);
2220 (*lst->by_order)[0] = tmp;
2221 lst->by_name = 0;
2222 $$ = lst;
2224 | '#' error
2225 { yyerror(@1, "error: syntax error in parameter value "
2226 "assignment list.");
2227 $$ = 0;
2230 { $$ = 0; }
2233 parameter_value_byname
2234 : '.' IDENTIFIER '(' expression ')'
2235 { named_pexpr_t*tmp = new named_pexpr_t;
2236 tmp->name = lex_strings.make($2);
2237 tmp->parm = $4;
2238 free($2);
2239 $$ = tmp;
2241 | '.' IDENTIFIER '(' ')'
2242 { named_pexpr_t*tmp = new named_pexpr_t;
2243 tmp->name = lex_strings.make($2);
2244 tmp->parm = 0;
2245 free($2);
2246 $$ = tmp;
2250 parameter_value_byname_list
2251 : parameter_value_byname
2252 { svector<named_pexpr_t*>*tmp = new svector<named_pexpr_t*>(1);
2253 (*tmp)[0] = $1;
2254 $$ = tmp;
2256 | parameter_value_byname_list ',' parameter_value_byname
2257 { svector<named_pexpr_t*>*tmp =
2258 new svector<named_pexpr_t*>(*$1,$3);
2259 delete $1;
2260 $$ = tmp;
2265 /* The port (of a module) is a fairly complex item. Each port is
2266 handled as a Module::port_t object. A simple port reference has a
2267 name and a PExpr object, but more complex constructs are possible
2268 where the name can be attached to a list of PWire objects.
2270 The port_reference returns a Module::port_t, and so does the
2271 port_reference_list. The port_reference_list may have built up a
2272 list of PWires in the port_t object, but it is still a single
2273 Module::port_t object.
2275 The port rule below takes the built up Module::port_t object and
2276 tweaks its name as needed. */
2278 port
2279 : port_reference
2280 { $$ = $1; }
2282 /* This syntax attaches an external name to the port reference so
2283 that the caller can bind by name to non-trivial port
2284 references. The port_t object gets its PWire from the
2285 port_reference, but its name from the IDENTIFIER. */
2287 | '.' IDENTIFIER '(' port_reference ')'
2288 { Module::port_t*tmp = $4;
2289 tmp->name = lex_strings.make($2);
2290 delete $2;
2291 $$ = tmp;
2294 /* A port can also be a concatenation of port references. In this
2295 case the port does not have a name available to the outside, only
2296 positional parameter passing is possible here. */
2298 | '{' port_reference_list '}'
2299 { Module::port_t*tmp = $2;
2300 tmp->name = perm_string();
2301 $$ = tmp;
2304 /* This attaches a name to a port reference concatenation list so
2305 that parameter passing be name is possible. */
2307 | '.' IDENTIFIER '(' '{' port_reference_list '}' ')'
2308 { Module::port_t*tmp = $5;
2309 tmp->name = lex_strings.make($2);
2310 delete $2;
2311 $$ = tmp;
2315 port_opt
2316 : port { $$ = $1; }
2317 | { $$ = 0; }
2321 /* A port reference is an internal (to the module) name of the port,
2322 possibly with a part of bit select to attach it to specific bits
2323 of a signal fully declared inside the module.
2325 The parser creates a PEIdent for every port reference, even if the
2326 signal is bound to different ports. The elaboration figures out
2327 the mess that this creates. The port_reference (and the
2328 port_reference_list below) puts the port reference PEIdent into the
2329 port_t object to pass it up to the module declaration code. */
2331 port_reference
2333 : IDENTIFIER
2334 { Module::port_t*ptmp;
2335 ptmp = pform_module_port_reference($1, @1.text, @1.first_line);
2336 delete $1;
2337 $$ = ptmp;
2340 | IDENTIFIER '[' expression ':' expression ']'
2341 { if (!pform_expression_is_constant($3)) {
2342 yyerror(@3, "error: msb expression of "
2343 "port part select must be constant.");
2345 if (!pform_expression_is_constant($5)) {
2346 yyerror(@5, "error: lsb expression of "
2347 "port part select must be constant.");
2349 index_component_t itmp;
2350 itmp.sel = index_component_t::SEL_PART;
2351 itmp.msb = $3;
2352 itmp.lsb = $5;
2354 name_component_t ntmp (lex_strings.make($1));
2355 ntmp.index.push_back(itmp);
2357 pform_name_t pname;
2358 pname.push_back(ntmp);
2360 PEIdent*wtmp = new PEIdent(pname);
2361 wtmp->set_file(@1.text);
2362 wtmp->set_lineno(@1.first_line);
2364 Module::port_t*ptmp = new Module::port_t;
2365 ptmp->name = perm_string();
2366 ptmp->expr = svector<PEIdent*>(1);
2367 ptmp->expr[0] = wtmp;
2369 delete $1;
2370 $$ = ptmp;
2373 | IDENTIFIER '[' expression ']'
2374 { if (!pform_expression_is_constant($3)) {
2375 yyerror(@3, "error: port bit select "
2376 "must be constant.");
2378 index_component_t itmp;
2379 itmp.sel = index_component_t::SEL_BIT;
2380 itmp.msb = $3;
2381 itmp.lsb = 0;
2383 name_component_t ntmp (lex_strings.make($1));
2384 ntmp.index.push_back(itmp);
2386 pform_name_t pname;
2387 pname.push_back(ntmp);
2389 PEIdent*tmp = new PEIdent(pname);
2390 tmp->set_file(@1.text);
2391 tmp->set_lineno(@1.first_line);
2393 Module::port_t*ptmp = new Module::port_t;
2394 ptmp->name = perm_string();
2395 ptmp->expr = svector<PEIdent*>(1);
2396 ptmp->expr[0] = tmp;
2397 delete $1;
2398 $$ = ptmp;
2401 | IDENTIFIER '[' error ']'
2402 { yyerror(@1, "error: invalid port bit select");
2403 Module::port_t*ptmp = new Module::port_t;
2404 PEIdent*wtmp = new PEIdent(lex_strings.make($1));
2405 wtmp->set_file(@1.text);
2406 wtmp->set_lineno(@1.first_line);
2407 ptmp->name = lex_strings.make($1);
2408 ptmp->expr = svector<PEIdent*>(1);
2409 ptmp->expr[0] = wtmp;
2410 delete $1;
2411 $$ = ptmp;
2416 port_reference_list
2417 : port_reference
2418 { $$ = $1; }
2419 | port_reference_list ',' port_reference
2420 { Module::port_t*tmp = $1;
2421 tmp->expr = svector<PEIdent*>(tmp->expr, $3->expr);
2422 delete $3;
2423 $$ = tmp;
2427 /* The port_name rule is used with a module is being *instantiated*,
2428 and not when it is being declared. See the port rule if you are
2429 looking for the ports of a module declaration. */
2431 port_name
2432 : '.' IDENTIFIER '(' expression ')'
2433 { named_pexpr_t*tmp = new named_pexpr_t;
2434 tmp->name = lex_strings.make($2);
2435 tmp->parm = $4;
2436 delete $2;
2437 $$ = tmp;
2439 | '.' IDENTIFIER '(' error ')'
2440 { yyerror(@4, "error: invalid port connection expression.");
2441 named_pexpr_t*tmp = new named_pexpr_t;
2442 tmp->name = lex_strings.make($2);
2443 tmp->parm = 0;
2444 delete $2;
2445 $$ = tmp;
2447 | '.' IDENTIFIER '(' ')'
2448 { named_pexpr_t*tmp = new named_pexpr_t;
2449 tmp->name = lex_strings.make($2);
2450 tmp->parm = 0;
2451 delete $2;
2452 $$ = tmp;
2456 port_name_list
2457 : port_name_list ',' port_name
2458 { svector<named_pexpr_t*>*tmp;
2459 tmp = new svector<named_pexpr_t*>(*$1, $3);
2460 delete $1;
2461 $$ = tmp;
2463 | port_name
2464 { svector<named_pexpr_t*>*tmp = new svector<named_pexpr_t*>(1);
2465 (*tmp)[0] = $1;
2466 $$ = tmp;
2470 port_type
2471 : K_input { $$ = NetNet::PINPUT; }
2472 | K_output { $$ = NetNet::POUTPUT; }
2473 | K_inout { $$ = NetNet::PINOUT; }
2476 range
2477 : '[' expression ':' expression ']'
2478 { svector<PExpr*>*tmp = new svector<PExpr*> (2);
2479 if (!pform_expression_is_constant($2))
2480 yyerror(@2, "error: msb of range must be constant.");
2482 (*tmp)[0] = $2;
2484 if (!pform_expression_is_constant($4))
2485 yyerror(@4, "error: lsb of range must be constant.");
2487 (*tmp)[1] = $4;
2489 $$ = tmp;
2493 range_opt
2494 : range
2495 | { $$ = 0; }
2497 dimensions_opt
2498 : { $$ = 0; }
2499 | dimensions { $$ = $1; }
2501 dimensions
2502 : '[' expression ':' expression ']'
2503 { list<index_component_t> *tmp = new list<index_component_t>;
2504 index_component_t index;
2505 if (!pform_expression_is_constant($2))
2506 yyerror(@2, "error: left array address must be "
2507 "constant.");
2508 index.msb = $2;
2509 if (!pform_expression_is_constant($4))
2510 yyerror(@4, "error: right array address must be "
2511 "constant.");
2512 index.lsb = $4;
2513 tmp->push_back(index);
2514 $$ = tmp;
2516 | dimensions '[' expression ':' expression ']'
2517 { list<index_component_t> *tmp = $1;
2518 index_component_t index;
2519 if (!pform_expression_is_constant($3))
2520 yyerror(@3, "error: left array address must be "
2521 "constant.");
2522 index.msb = $3;
2523 if (!pform_expression_is_constant($5))
2524 yyerror(@5, "error: right array address must be "
2525 "constant.");
2526 index.lsb = $5;
2527 tmp->push_back(index);
2528 $$ = tmp;
2531 /* This is used to express the return type of a function. */
2532 function_range_or_type_opt
2533 : range { $$.range = $1; $$.type = PTF_REG; }
2534 | K_signed range { $$.range = $2; $$.type = PTF_REG_S; }
2535 | K_integer { $$.range = 0; $$.type = PTF_INTEGER; }
2536 | K_real { $$.range = 0; $$.type = PTF_REAL; }
2537 | K_realtime { $$.range = 0; $$.type = PTF_REALTIME; }
2538 | K_time { $$.range = 0; $$.type = PTF_TIME; }
2539 | { $$.range = 0; $$.type = PTF_REG; }
2542 /* The register_variable rule is matched only when I am parsing
2543 variables in a "reg" definition. I therefore know that I am
2544 creating registers and I do not need to let the containing rule
2545 handle it. The register variable list simply packs them together
2546 so that bit ranges can be assigned. */
2547 register_variable
2548 : IDENTIFIER dimensions_opt
2549 { pform_makewire(@1, $1, NetNet::REG,
2550 NetNet::NOT_A_PORT, IVL_VT_NO_TYPE, 0);
2551 if ($2 != 0) {
2552 index_component_t index;
2553 if ($2->size() > 1) {
2554 yyerror(@2, "sorry: only 1 dimensional arrays "
2555 "are currently supported.");
2557 index = $2->front();
2558 pform_set_reg_idx($1, index.msb, index.lsb);
2559 delete $2;
2561 $$ = $1;
2563 | IDENTIFIER '=' expression
2564 { pform_makewire(@1, $1, NetNet::REG,
2565 NetNet::NOT_A_PORT,
2566 IVL_VT_NO_TYPE, 0);
2567 if (! pform_expression_is_constant($3))
2568 yyerror(@3, "error: register declaration assignment"
2569 " value must be a constant expression.");
2570 pform_make_reginit(@1, $1, $3);
2571 $$ = $1;
2575 register_variable_list
2576 : register_variable
2577 { list<perm_string>*tmp = new list<perm_string>;
2578 tmp->push_back(lex_strings.make($1));
2579 $$ = tmp;
2580 delete[]$1;
2582 | register_variable_list ',' register_variable
2583 { list<perm_string>*tmp = $1;
2584 tmp->push_back(lex_strings.make($3));
2585 $$ = tmp;
2586 delete[]$3;
2590 real_variable
2591 : IDENTIFIER dimensions_opt
2592 { pform_makewire(@1, $1, NetNet::REG, NetNet::NOT_A_PORT, IVL_VT_REAL, 0);
2593 if ($2 != 0) {
2594 yyerror(@2, "sorry: real variables do not currently support arrays.");
2595 delete $2;
2597 $$ = $1;
2599 | IDENTIFIER '=' expression
2600 { pform_makewire(@1, $1, NetNet::REG, NetNet::NOT_A_PORT, IVL_VT_REAL, 0);
2601 pform_make_reginit(@1, $1, $3);
2602 $$ = $1;
2606 real_variable_list
2607 : real_variable
2608 { list<perm_string>*tmp = new list<perm_string>;
2609 tmp->push_back(lex_strings.make($1));
2610 $$ = tmp;
2611 delete[]$1;
2613 | real_variable_list ',' real_variable
2614 { list<perm_string>*tmp = $1;
2615 tmp->push_back(lex_strings.make($3));
2616 $$ = tmp;
2617 delete[]$3;
2621 net_variable
2622 : IDENTIFIER dimensions_opt
2623 { pform_makewire(@1, $1, NetNet::IMPLICIT,
2624 NetNet::NOT_A_PORT, IVL_VT_NO_TYPE, 0);
2625 if ($2 != 0) {
2626 index_component_t index;
2627 if ($2->size() > 1) {
2628 yyerror(@2, "sorry: only 1 dimensional arrays "
2629 "are currently supported.");
2631 index = $2->front();
2632 pform_set_reg_idx($1, index.msb, index.lsb);
2633 delete $2;
2635 $$ = $1;
2638 net_variable_list
2639 : net_variable
2640 { list<perm_string>*tmp = new list<perm_string>;
2641 tmp->push_back(lex_strings.make($1));
2642 $$ = tmp;
2643 delete[]$1;
2645 | net_variable_list ',' net_variable
2646 { list<perm_string>*tmp = $1;
2647 tmp->push_back(lex_strings.make($3));
2648 $$ = tmp;
2649 delete[]$3;
2653 specify_item
2654 : K_specparam specparam_list ';'
2655 | specify_simple_path_decl ';'
2656 { pform_module_specify_path($1);
2658 | specify_edge_path_decl ';'
2659 { pform_module_specify_path($1);
2661 | K_if '(' expression ')' specify_simple_path_decl ';'
2662 { PSpecPath*tmp = $5;
2663 if (tmp) {
2664 tmp->conditional = true;
2665 tmp->condition = $3;
2667 pform_module_specify_path(tmp);
2669 | K_if '(' expression ')' specify_edge_path_decl ';'
2670 { PSpecPath*tmp = $5;
2671 if (tmp) {
2672 tmp->conditional = true;
2673 tmp->condition = $3;
2675 pform_module_specify_path(tmp);
2677 | K_ifnone specify_simple_path_decl ';'
2678 { PSpecPath*tmp = $2;
2679 if (tmp) {
2680 tmp->conditional = true;
2681 tmp->condition = 0;
2683 pform_module_specify_path(tmp);
2685 | K_Shold '(' spec_reference_event ',' spec_reference_event
2686 ',' delay_value spec_notifier_opt ')' ';'
2687 { delete $7;
2689 | K_Speriod '(' spec_reference_event ',' delay_value
2690 spec_notifier_opt ')' ';'
2691 { delete $5;
2693 | K_Srecovery '(' spec_reference_event ',' spec_reference_event
2694 ',' delay_value spec_notifier_opt ')' ';'
2695 { delete $7;
2697 | K_Ssetup '(' spec_reference_event ',' spec_reference_event
2698 ',' delay_value spec_notifier_opt ')' ';'
2699 { delete $7;
2701 | K_Ssetuphold '(' spec_reference_event ',' spec_reference_event
2702 ',' delay_value ',' delay_value spec_notifier_opt ')' ';'
2703 { delete $7;
2704 delete $9;
2706 | K_Srecrem '(' spec_reference_event ',' spec_reference_event
2707 ',' delay_value ',' delay_value spec_notifier_opt ')' ';'
2708 { delete $7;
2709 delete $9;
2711 | K_Swidth '(' spec_reference_event ',' delay_value ',' expression
2712 spec_notifier_opt ')' ';'
2713 { delete $5;
2714 delete $7;
2716 | K_Swidth '(' spec_reference_event ',' delay_value ')' ';'
2717 { delete $5;
2721 specify_item_list
2722 : specify_item
2723 | specify_item_list specify_item
2726 specify_edge_path_decl
2727 : specify_edge_path '=' '(' delay_value_list ')'
2728 { $$ = pform_assign_path_delay($1, $4); }
2729 | specify_edge_path '=' delay_value_simple
2730 { svector<PExpr*>*tmp = new svector<PExpr*>(1);
2731 (*tmp)[0] = $3;
2732 $$ = pform_assign_path_delay($1, tmp);
2736 edge_operator : K_posedge { $$ = true; } | K_negedge { $$ = false; } ;
2738 specify_edge_path
2739 : '(' specify_path_identifiers spec_polarity
2740 K_EG '(' specify_path_identifiers polarity_operator expression ')' ')'
2741 { int edge_flag = 0;
2742 $$ = pform_make_specify_edge_path(@1, edge_flag, $2, $3, false, $6, $8); }
2743 | '(' edge_operator specify_path_identifiers spec_polarity
2744 K_EG '(' specify_path_identifiers polarity_operator expression ')' ')'
2745 { int edge_flag = $2? 1 : -1;
2746 $$ = pform_make_specify_edge_path(@1, edge_flag, $3, $4, false, $7, $9);}
2747 | '(' specify_path_identifiers spec_polarity
2748 K_SG '(' specify_path_identifiers polarity_operator expression ')' ')'
2749 { int edge_flag = 0;
2750 $$ = pform_make_specify_edge_path(@1, edge_flag, $2, $3, true, $6, $8); }
2751 | '(' edge_operator specify_path_identifiers spec_polarity
2752 K_SG '(' specify_path_identifiers polarity_operator expression ')' ')'
2753 { int edge_flag = $2? 1 : -1;
2754 $$ = pform_make_specify_edge_path(@1, edge_flag, $3, $4, true, $7, $9); }
2757 polarity_operator
2758 : K_PO_POS
2759 | K_PO_NEG
2760 | ':'
2763 specify_simple_path_decl
2764 : specify_simple_path '=' '(' delay_value_list ')'
2765 { $$ = pform_assign_path_delay($1, $4); }
2766 | specify_simple_path '=' delay_value_simple
2767 { svector<PExpr*>*tmp = new svector<PExpr*>(1);
2768 (*tmp)[0] = $3;
2769 $$ = pform_assign_path_delay($1, tmp);
2771 | specify_simple_path '=' '(' error ')'
2772 { yyerror(@2, "Syntax error in delay value list.");
2773 yyerrok;
2774 $$ = 0;
2778 specify_simple_path
2779 : '(' specify_path_identifiers spec_polarity
2780 K_EG specify_path_identifiers ')'
2781 { $$ = pform_make_specify_path(@1, $2, $3, false, $5); }
2782 | '(' specify_path_identifiers spec_polarity
2783 K_SG specify_path_identifiers ')'
2784 { $$ = pform_make_specify_path(@1, $2, $3, true, $5); }
2785 | '(' error ')'
2786 { yyerror(@2, "Invalid simple path");
2787 yyerrok;
2791 specify_path_identifiers
2792 : IDENTIFIER
2793 { list<perm_string>*tmp = new list<perm_string>;
2794 tmp->push_back(lex_strings.make($1));
2795 $$ = tmp;
2796 delete[]$1;
2798 | IDENTIFIER '[' expr_primary ']'
2799 { list<perm_string>*tmp = new list<perm_string>;
2800 tmp->push_back(lex_strings.make($1));
2801 $$ = tmp;
2802 delete[]$1;
2804 | specify_path_identifiers ',' IDENTIFIER
2805 { list<perm_string>*tmp = $1;
2806 tmp->push_back(lex_strings.make($3));
2807 $$ = tmp;
2808 delete[]$3;
2810 | specify_path_identifiers ',' IDENTIFIER '[' expr_primary ']'
2811 { list<perm_string>*tmp = $1;
2812 tmp->push_back(lex_strings.make($3));
2813 $$ = tmp;
2814 delete[]$3;
2818 specparam
2819 : IDENTIFIER '=' expression
2820 { PExpr*tmp = $3;
2821 pform_set_specparam(lex_strings.make($1), tmp);
2822 delete $1;
2824 | IDENTIFIER '=' expression ':' expression ':' expression
2825 { PExpr*tmp = 0;
2826 switch (min_typ_max_flag) {
2827 case MIN:
2828 tmp = $3;
2829 delete $5;
2830 delete $7;
2831 break;
2832 case TYP:
2833 delete $3;
2834 tmp = $5;
2835 delete $7;
2836 break;
2837 case MAX:
2838 delete $3;
2839 delete $5;
2840 tmp = $7;
2841 break;
2843 pform_set_specparam(lex_strings.make($1), tmp);
2844 delete $1;
2846 | PATHPULSE_IDENTIFIER '=' expression
2847 { delete $1;
2848 delete $3;
2850 | PATHPULSE_IDENTIFIER '=' '(' expression ',' expression ')'
2851 { delete $1;
2852 delete $4;
2853 delete $6;
2857 specparam_list
2858 : specparam
2859 | specparam_list ',' specparam
2862 spec_polarity
2863 : '+' { $$ = '+'; }
2864 | '-' { $$ = '-'; }
2865 | { $$ = 0; }
2868 spec_reference_event
2869 : K_posedge expression
2870 { delete $2; }
2871 | K_negedge expression
2872 { delete $2; }
2873 | K_posedge expr_primary K_TAND expression
2874 { delete $2;
2875 delete $4;
2877 | K_negedge expr_primary K_TAND expression
2878 { delete $2;
2879 delete $4;
2881 | K_edge '[' edge_descriptor_list ']' expr_primary K_TAND expression
2882 { delete $5;
2883 delete $7;
2885 | expr_primary K_TAND expression
2886 { delete $1;
2887 delete $3;
2889 | expr_primary
2890 { delete $1; }
2893 /* The edge_descriptor is detected by the lexor as the various
2894 2-letter edge sequences that are supported here. For now, we
2895 don't care what they are, because we do not yet support specify
2896 edge events. */
2897 edge_descriptor_list
2898 : edge_descriptor_list ',' K_edge_descriptor
2899 | K_edge_descriptor
2902 spec_notifier_opt
2903 : /* empty */
2905 | spec_notifier
2908 spec_notifier
2909 : ','
2911 | ',' heirarchy_identifier
2912 { delete $2; }
2913 | spec_notifier ','
2915 | spec_notifier ',' heirarchy_identifier
2916 { delete $3; }
2917 | IDENTIFIER
2918 { delete $1; }
2922 statement
2924 /* assign and deassign statements are procedural code to do
2925 structural assignments, and to turn that structural assignment
2926 off. This stronger then any other assign, but weaker then the
2927 force assignments. */
2929 : K_assign lpvalue '=' expression ';'
2930 { PCAssign*tmp = new PCAssign($2, $4);
2931 tmp->set_file(@1.text);
2932 tmp->set_lineno(@1.first_line);
2933 $$ = tmp;
2936 | K_deassign lpvalue ';'
2937 { PDeassign*tmp = new PDeassign($2);
2938 tmp->set_file(@1.text);
2939 tmp->set_lineno(@1.first_line);
2940 $$ = tmp;
2944 /* Force and release statements are similar to assignments,
2945 syntactically, but they will be elaborated differently. */
2947 | K_force lpvalue '=' expression ';'
2948 { PForce*tmp = new PForce($2, $4);
2949 tmp->set_file(@1.text);
2950 tmp->set_lineno(@1.first_line);
2951 $$ = tmp;
2953 | K_release lpvalue ';'
2954 { PRelease*tmp = new PRelease($2);
2955 tmp->set_file(@1.text);
2956 tmp->set_lineno(@1.first_line);
2957 $$ = tmp;
2960 /* begin-end blocks come in a variety of forms, including named and
2961 anonymous. The named blocks can also carry their own reg
2962 variables, which are placed in the scope created by the block
2963 name. These are handled by pushing the scope name then matching
2964 the declarations. The scope is popped at the end of the block. */
2966 | K_begin statement_list K_end
2967 { PBlock*tmp = new PBlock(PBlock::BL_SEQ, *$2);
2968 tmp->set_file(@1.text);
2969 tmp->set_lineno(@1.first_line);
2970 delete $2;
2971 $$ = tmp;
2973 | K_begin ':' IDENTIFIER
2974 { pform_push_scope($3); }
2975 block_item_decls_opt
2976 statement_list K_end
2977 { pform_pop_scope();
2978 PBlock*tmp = new PBlock(lex_strings.make($3),
2979 PBlock::BL_SEQ, *$6);
2980 tmp->set_file(@1.text);
2981 tmp->set_lineno(@1.first_line);
2982 delete $3;
2983 delete $6;
2984 $$ = tmp;
2986 | K_begin K_end
2987 { PBlock*tmp = new PBlock(PBlock::BL_SEQ);
2988 tmp->set_file(@1.text);
2989 tmp->set_lineno(@1.first_line);
2990 $$ = tmp;
2992 | K_begin ':' IDENTIFIER K_end
2993 { PBlock*tmp = new PBlock(PBlock::BL_SEQ);
2994 tmp->set_file(@1.text);
2995 tmp->set_lineno(@1.first_line);
2996 $$ = tmp;
2998 | K_begin error K_end
2999 { yyerrok; }
3001 /* fork-join blocks are very similar to begin-end blocks. In fact,
3002 from the parser's perspective there is no real difference. All we
3003 need to do is remember that this is a parallel block so that the
3004 code generator can do the right thing. */
3006 | K_fork ':' IDENTIFIER
3007 { pform_push_scope($3); }
3008 block_item_decls_opt
3009 statement_list K_join
3010 { pform_pop_scope();
3011 PBlock*tmp = new PBlock(lex_strings.make($3),
3012 PBlock::BL_PAR, *$6);
3013 tmp->set_file(@1.text);
3014 tmp->set_lineno(@1.first_line);
3015 delete $3;
3016 delete $6;
3017 $$ = tmp;
3019 | K_fork K_join
3020 { PBlock*tmp = new PBlock(PBlock::BL_PAR);
3021 tmp->set_file(@1.text);
3022 tmp->set_lineno(@1.first_line);
3023 $$ = tmp;
3025 | K_fork ':' IDENTIFIER K_join
3026 { PBlock*tmp = new PBlock(PBlock::BL_PAR);
3027 tmp->set_file(@1.text);
3028 tmp->set_lineno(@1.first_line);
3029 delete $3;
3030 $$ = tmp;
3033 | K_disable heirarchy_identifier ';'
3034 { PDisable*tmp = new PDisable(*$2);
3035 tmp->set_file(@1.text);
3036 tmp->set_lineno(@1.first_line);
3037 delete $2;
3038 $$ = tmp;
3040 | K_TRIGGER heirarchy_identifier ';'
3041 { PTrigger*tmp = new PTrigger(*$2);
3042 tmp->set_file(@2.text);
3043 tmp->set_lineno(@2.first_line);
3044 delete $2;
3045 $$ = tmp;
3047 | K_forever statement
3048 { PForever*tmp = new PForever($2);
3049 tmp->set_file(@1.text);
3050 tmp->set_lineno(@1.first_line);
3051 $$ = tmp;
3053 | K_fork statement_list K_join
3054 { PBlock*tmp = new PBlock(PBlock::BL_PAR, *$2);
3055 tmp->set_file(@1.text);
3056 tmp->set_lineno(@1.first_line);
3057 delete $2;
3058 $$ = tmp;
3060 | K_repeat '(' expression ')' statement
3061 { PRepeat*tmp = new PRepeat($3, $5);
3062 tmp->set_file(@1.text);
3063 tmp->set_lineno(@1.first_line);
3064 $$ = tmp;
3066 | K_case '(' expression ')' case_items K_endcase
3067 { PCase*tmp = new PCase(NetCase::EQ, $3, $5);
3068 tmp->set_file(@1.text);
3069 tmp->set_lineno(@1.first_line);
3070 $$ = tmp;
3072 | K_casex '(' expression ')' case_items K_endcase
3073 { PCase*tmp = new PCase(NetCase::EQX, $3, $5);
3074 tmp->set_file(@1.text);
3075 tmp->set_lineno(@1.first_line);
3076 $$ = tmp;
3078 | K_casez '(' expression ')' case_items K_endcase
3079 { PCase*tmp = new PCase(NetCase::EQZ, $3, $5);
3080 tmp->set_file(@1.text);
3081 tmp->set_lineno(@1.first_line);
3082 $$ = tmp;
3084 | K_case '(' expression ')' error K_endcase
3085 { yyerrok; }
3086 | K_casex '(' expression ')' error K_endcase
3087 { yyerrok; }
3088 | K_casez '(' expression ')' error K_endcase
3089 { yyerrok; }
3090 | K_if '(' expression ')' statement_or_null %prec less_than_K_else
3091 { PCondit*tmp = new PCondit($3, $5, 0);
3092 tmp->set_file(@1.text);
3093 tmp->set_lineno(@1.first_line);
3094 $$ = tmp;
3096 | K_if '(' expression ')' statement_or_null K_else statement_or_null
3097 { PCondit*tmp = new PCondit($3, $5, $7);
3098 tmp->set_file(@1.text);
3099 tmp->set_lineno(@1.first_line);
3100 $$ = tmp;
3102 | K_if '(' error ')' statement_or_null %prec less_than_K_else
3103 { yyerror(@1, "error: Malformed conditional expression.");
3104 $$ = $5;
3106 | K_if '(' error ')' statement_or_null K_else statement_or_null
3107 { yyerror(@1, "error: Malformed conditional expression.");
3108 $$ = $5;
3110 | K_for '(' lpvalue '=' expression ';' expression ';'
3111 lpvalue '=' expression ')' statement
3112 { PForStatement*tmp = new PForStatement($3, $5, $7, $9, $11, $13);
3113 tmp->set_file(@1.text);
3114 tmp->set_lineno(@1.first_line);
3115 $$ = tmp;
3117 | K_for '(' lpvalue '=' expression ';' expression ';'
3118 error ')' statement
3119 { $$ = 0;
3120 yyerror(@9, "error: Error in for loop step assignment.");
3122 | K_for '(' lpvalue '=' expression ';' error ';'
3123 lpvalue '=' expression ')' statement
3124 { $$ = 0;
3125 yyerror(@7, "error: Error in for loop condition expression.");
3127 | K_for '(' error ')' statement
3128 { $$ = 0;
3129 yyerror(@3, "error: Incomprehensible for loop.");
3131 | K_while '(' expression ')' statement
3132 { PWhile*tmp = new PWhile($3, $5);
3133 $$ = tmp;
3135 | K_while '(' error ')' statement
3136 { $$ = 0;
3137 yyerror(@3, "error: Error in while loop condition.");
3139 | delay1 statement_or_null
3140 { PExpr*del = (*$1)[0];
3141 assert($1->count() == 1);
3142 PDelayStatement*tmp = new PDelayStatement(del, $2);
3143 tmp->set_file(@1.text);
3144 tmp->set_lineno(@1.first_line);
3145 $$ = tmp;
3147 | event_control statement_or_null
3148 { PEventStatement*tmp = $1;
3149 if (tmp == 0) {
3150 yyerror(@1, "error: Invalid event control.");
3151 $$ = 0;
3152 } else {
3153 tmp->set_statement($2);
3154 $$ = tmp;
3157 | '@' '*' statement_or_null
3158 { PEventStatement*tmp = new PEventStatement;
3159 tmp->set_file(@1.text);
3160 tmp->set_lineno(@1.first_line);
3161 tmp->set_statement($3);
3162 $$ = tmp;
3164 | '@' '(' '*' ')' statement_or_null
3165 { PEventStatement*tmp = new PEventStatement;
3166 tmp->set_file(@1.text);
3167 tmp->set_lineno(@1.first_line);
3168 tmp->set_statement($5);
3169 $$ = tmp;
3171 | lpvalue '=' expression ';'
3172 { PAssign*tmp = new PAssign($1,$3);
3173 tmp->set_file(@1.text);
3174 tmp->set_lineno(@1.first_line);
3175 $$ = tmp;
3177 | error '=' expression ';'
3178 { yyerror(@1, "Syntax in assignment statement l-value.");
3179 yyerrok;
3180 $$ = new PNoop;
3182 | lpvalue K_LE expression ';'
3183 { PAssignNB*tmp = new PAssignNB($1,$3);
3184 tmp->set_file(@1.text);
3185 tmp->set_lineno(@1.first_line);
3186 $$ = tmp;
3188 | error K_LE expression ';'
3189 { yyerror(@1, "Syntax in assignment statement l-value.");
3190 yyerrok;
3191 $$ = new PNoop;
3193 | lpvalue '=' delay1 expression ';'
3194 { assert($3->count() == 1);
3195 PExpr*del = (*$3)[0];
3196 PAssign*tmp = new PAssign($1,del,$4);
3197 tmp->set_file(@1.text);
3198 tmp->set_lineno(@1.first_line);
3199 $$ = tmp;
3201 | lpvalue K_LE delay1 expression ';'
3202 { assert($3->count() == 1);
3203 PExpr*del = (*$3)[0];
3204 PAssignNB*tmp = new PAssignNB($1,del,$4);
3205 tmp->set_file(@1.text);
3206 tmp->set_lineno(@1.first_line);
3207 $$ = tmp;
3209 | lpvalue '=' event_control expression ';'
3210 { PAssign*tmp = new PAssign($1,$3,$4);
3211 tmp->set_file(@1.text);
3212 tmp->set_lineno(@1.first_line);
3213 $$ = tmp;
3215 | lpvalue '=' K_repeat '(' expression ')' event_control expression ';'
3216 { PAssign*tmp = new PAssign($1,$7,$8);
3217 tmp->set_file(@1.text);
3218 tmp->set_lineno(@1.first_line);
3219 yyerror(@3, "sorry: repeat event control not supported.");
3220 delete $5;
3221 $$ = tmp;
3223 | lpvalue K_LE event_control expression ';'
3224 { yyerror(@1, "sorry: Event controls not supported here.");
3225 PAssignNB*tmp = new PAssignNB($1,$4);
3226 tmp->set_file(@1.text);
3227 tmp->set_lineno(@1.first_line);
3228 $$ = tmp;
3230 | lpvalue K_LE K_repeat '(' expression ')' event_control expression ';'
3231 { yyerror(@1, "sorry: Event controls not supported here.");
3232 delete $5;
3233 PAssignNB*tmp = new PAssignNB($1,$8);
3234 tmp->set_file(@1.text);
3235 tmp->set_lineno(@1.first_line);
3236 $$ = tmp;
3238 | K_wait '(' expression ')' statement_or_null
3239 { PEventStatement*tmp;
3240 PEEvent*etmp = new PEEvent(PEEvent::POSITIVE, $3);
3241 tmp = new PEventStatement(etmp);
3242 tmp->set_file(@1.text);
3243 tmp->set_lineno(@1.first_line);
3244 tmp->set_statement($5);
3245 $$ = tmp;
3247 | SYSTEM_IDENTIFIER '(' expression_list_with_nuls ')' ';'
3248 { PCallTask*tmp = new PCallTask(lex_strings.make($1), *$3);
3249 tmp->set_file(@1.text);
3250 tmp->set_lineno(@1.first_line);
3251 delete $1;
3252 delete $3;
3253 $$ = tmp;
3255 | SYSTEM_IDENTIFIER ';'
3256 { svector<PExpr*>pt (0);
3257 PCallTask*tmp = new PCallTask(lex_strings.make($1), pt);
3258 tmp->set_file(@1.text);
3259 tmp->set_lineno(@1.first_line);
3260 delete $1;
3261 $$ = tmp;
3263 | heirarchy_identifier '(' expression_list_proper ')' ';'
3264 { PCallTask*tmp = new PCallTask(*$1, *$3);
3265 tmp->set_file(@1.text);
3266 tmp->set_lineno(@1.first_line);
3267 delete $1;
3268 delete $3;
3269 $$ = tmp;
3272 /* NOTE: The standard doesn't really support an empty argument list
3273 between parentheses, but it seems natural, and people commonly
3274 want it. So accept it explicitly. */
3276 | heirarchy_identifier '(' ')' ';'
3277 { svector<PExpr*>pt (0);
3278 PCallTask*tmp = new PCallTask(*$1, pt);
3279 tmp->set_file(@1.text);
3280 tmp->set_lineno(@1.first_line);
3281 delete $1;
3282 $$ = tmp;
3284 | heirarchy_identifier ';'
3285 { svector<PExpr*>pt (0);
3286 PCallTask*tmp = new PCallTask(*$1, pt);
3287 tmp->set_file(@1.text);
3288 tmp->set_lineno(@1.first_line);
3289 delete $1;
3290 $$ = tmp;
3292 | error ';'
3293 { yyerror(@1, "error: malformed statement");
3294 yyerrok;
3295 $$ = new PNoop;
3299 statement_list
3300 : statement_list statement
3301 { svector<Statement*>*tmp = new svector<Statement*>(*$1, $2);
3302 delete $1;
3303 $$ = tmp;
3305 | statement
3306 { svector<Statement*>*tmp = new svector<Statement*>(1);
3307 (*tmp)[0] = $1;
3308 $$ = tmp;
3312 statement_or_null
3313 : statement
3314 | ';' { $$ = 0; }
3317 /* Task items are, other than the statement, task port items and
3318 other block items. */
3319 task_item
3320 : block_item_decl { $$ = new svector<PWire*>(0); }
3321 | task_port_item { $$ = $1; }
3324 task_port_item
3326 : K_input signed_opt range_opt list_of_identifiers ';'
3327 { svector<PWire*>*tmp
3328 = pform_make_task_ports(NetNet::PINPUT,
3329 IVL_VT_LOGIC, $2,
3330 $3, $4,
3331 @1.text, @1.first_line);
3332 $$ = tmp;
3334 | K_output signed_opt range_opt list_of_identifiers ';'
3335 { svector<PWire*>*tmp
3336 = pform_make_task_ports(NetNet::POUTPUT,
3337 IVL_VT_LOGIC, $2,
3338 $3, $4,
3339 @1.text, @1.first_line);
3340 $$ = tmp;
3342 | K_inout signed_opt range_opt list_of_identifiers ';'
3343 { svector<PWire*>*tmp
3344 = pform_make_task_ports(NetNet::PINOUT,
3345 IVL_VT_LOGIC, $2,
3346 $3, $4,
3347 @1.text, @1.first_line);
3348 $$ = tmp;
3351 /* When the port is an integer, infer a signed vector of the integer
3352 shape. Generate a range to make it work. */
3354 | K_input K_integer list_of_identifiers ';'
3355 { svector<PExpr*>*range_stub
3356 = new svector<PExpr*>(2);
3357 PExpr*re;
3358 re = new PENumber(new verinum(integer_width-1,
3359 integer_width));
3360 (*range_stub)[0] = re;
3361 re = new PENumber(new verinum((uint64_t)0, integer_width));
3362 (*range_stub)[1] = re;
3363 svector<PWire*>*tmp
3364 = pform_make_task_ports(NetNet::PINPUT,
3365 IVL_VT_LOGIC, true,
3366 range_stub, $3,
3367 @1.text, @1.first_line);
3368 $$ = tmp;
3370 | K_output K_integer list_of_identifiers ';'
3371 { svector<PExpr*>*range_stub
3372 = new svector<PExpr*>(2);
3373 PExpr*re;
3374 re = new PENumber(new verinum(integer_width-1,
3375 integer_width));
3376 (*range_stub)[0] = re;
3377 re = new PENumber(new verinum((uint64_t)0, integer_width));
3378 (*range_stub)[1] = re;
3379 svector<PWire*>*tmp
3380 = pform_make_task_ports(NetNet::POUTPUT,
3381 IVL_VT_LOGIC, true,
3382 range_stub, $3,
3383 @1.text, @1.first_line);
3384 $$ = tmp;
3386 | K_inout K_integer list_of_identifiers ';'
3387 { svector<PExpr*>*range_stub
3388 = new svector<PExpr*>(2);
3389 PExpr*re;
3390 re = new PENumber(new verinum(integer_width-1,
3391 integer_width));
3392 (*range_stub)[0] = re;
3393 re = new PENumber(new verinum((uint64_t)0, integer_width));
3394 (*range_stub)[1] = re;
3395 svector<PWire*>*tmp
3396 = pform_make_task_ports(NetNet::PINOUT,
3397 IVL_VT_LOGIC, true,
3398 range_stub, $3,
3399 @1.text, @1.first_line);
3400 $$ = tmp;
3403 /* Ports can be real. */
3405 | K_input K_real list_of_identifiers ';'
3406 { svector<PWire*>*tmp
3407 = pform_make_task_ports(NetNet::PINPUT,
3408 IVL_VT_REAL, false,
3409 0, $3,
3410 @1.text, @1.first_line);
3411 $$ = tmp;
3413 | K_output K_real list_of_identifiers ';'
3414 { svector<PWire*>*tmp
3415 = pform_make_task_ports(NetNet::POUTPUT,
3416 IVL_VT_REAL, true,
3417 0, $3,
3418 @1.text, @1.first_line);
3419 $$ = tmp;
3421 | K_inout K_real list_of_identifiers ';'
3422 { svector<PWire*>*tmp
3423 = pform_make_task_ports(NetNet::PINOUT,
3424 IVL_VT_REAL, true,
3425 0, $3,
3426 @1.text, @1.first_line);
3427 $$ = tmp;
3431 task_item_list
3432 : task_item_list task_item
3433 { svector<PWire*>*tmp = new svector<PWire*>(*$1, *$2);
3434 delete $1;
3435 delete $2;
3436 $$ = tmp;
3438 | task_item
3439 { $$ = $1; }
3442 task_item_list_opt
3443 : task_item_list
3444 { $$ = $1; }
3446 { $$ = 0; }
3449 task_port_decl
3451 : K_input signed_opt range_opt IDENTIFIER
3452 { svector<PWire*>*tmp
3453 = pform_make_task_ports(NetNet::PINPUT,
3454 IVL_VT_LOGIC, $2,
3455 $3, list_from_identifier($4),
3456 @1.text, @1.first_line);
3457 $$ = tmp;
3460 | K_output signed_opt range_opt IDENTIFIER
3461 { svector<PWire*>*tmp
3462 = pform_make_task_ports(NetNet::POUTPUT,
3463 IVL_VT_LOGIC, $2,
3464 $3, list_from_identifier($4),
3465 @1.text, @1.first_line);
3466 $$ = tmp;
3468 | K_inout signed_opt range_opt IDENTIFIER
3469 { svector<PWire*>*tmp
3470 = pform_make_task_ports(NetNet::PINOUT,
3471 IVL_VT_LOGIC, $2,
3472 $3, list_from_identifier($4),
3473 @1.text, @1.first_line);
3474 $$ = tmp;
3477 | K_input K_integer IDENTIFIER
3478 { svector<PExpr*>*range_stub
3479 = new svector<PExpr*>(2);
3480 PExpr*re;
3481 re = new PENumber(new verinum(integer_width-1,
3482 integer_width));
3483 (*range_stub)[0] = re;
3484 re = new PENumber(new verinum((uint64_t)0, integer_width));
3485 (*range_stub)[1] = re;
3486 svector<PWire*>*tmp
3487 = pform_make_task_ports(NetNet::PINPUT,
3488 IVL_VT_LOGIC, true,
3489 range_stub,
3490 list_from_identifier($3),
3491 @1.text, @1.first_line);
3492 $$ = tmp;
3494 | K_output K_integer IDENTIFIER
3495 { svector<PExpr*>*range_stub
3496 = new svector<PExpr*>(2);
3497 PExpr*re;
3498 re = new PENumber(new verinum(integer_width-1,
3499 integer_width));
3500 (*range_stub)[0] = re;
3501 re = new PENumber(new verinum((uint64_t)0, integer_width));
3502 (*range_stub)[1] = re;
3503 svector<PWire*>*tmp
3504 = pform_make_task_ports(NetNet::POUTPUT,
3505 IVL_VT_LOGIC, true,
3506 range_stub,
3507 list_from_identifier($3),
3508 @1.text, @1.first_line);
3509 $$ = tmp;
3511 | K_inout K_integer IDENTIFIER
3512 { svector<PExpr*>*range_stub
3513 = new svector<PExpr*>(2);
3514 PExpr*re;
3515 re = new PENumber(new verinum(integer_width-1,
3516 integer_width));
3517 (*range_stub)[0] = re;
3518 re = new PENumber(new verinum((uint64_t)0, integer_width));
3519 (*range_stub)[1] = re;
3520 svector<PWire*>*tmp
3521 = pform_make_task_ports(NetNet::PINOUT,
3522 IVL_VT_LOGIC, true,
3523 range_stub,
3524 list_from_identifier($3),
3525 @1.text, @1.first_line);
3526 $$ = tmp;
3529 /* Ports can be real. */
3531 | K_input K_real IDENTIFIER
3532 { svector<PWire*>*tmp
3533 = pform_make_task_ports(NetNet::PINPUT,
3534 IVL_VT_REAL, false,
3535 0, list_from_identifier($3),
3536 @1.text, @1.first_line);
3537 $$ = tmp;
3539 | K_output K_real IDENTIFIER
3540 { svector<PWire*>*tmp
3541 = pform_make_task_ports(NetNet::POUTPUT,
3542 IVL_VT_REAL, false,
3543 0, list_from_identifier($3),
3544 @1.text, @1.first_line);
3545 $$ = tmp;
3547 | K_inout K_real IDENTIFIER
3548 { svector<PWire*>*tmp
3549 = pform_make_task_ports(NetNet::PINOUT,
3550 IVL_VT_REAL, false,
3551 0, list_from_identifier($3),
3552 @1.text, @1.first_line);
3553 $$ = tmp;
3557 task_port_decl_list
3558 : task_port_decl_list ',' task_port_decl
3559 { svector<PWire*>*tmp = new svector<PWire*>(*$1, *$3);
3560 delete $1;
3561 delete $3;
3562 $$ = tmp;
3564 | task_port_decl
3565 { $$ = $1; }
3568 udp_body
3569 : K_table { lex_start_table(); }
3570 udp_entry_list
3571 K_endtable { lex_end_table(); $$ = $3; }
3574 udp_entry_list
3575 : udp_comb_entry_list
3576 | udp_sequ_entry_list
3579 udp_comb_entry
3580 : udp_input_list ':' udp_output_sym ';'
3581 { char*tmp = new char[strlen($1)+3];
3582 strcpy(tmp, $1);
3583 char*tp = tmp+strlen(tmp);
3584 *tp++ = ':';
3585 *tp++ = $3;
3586 *tp++ = 0;
3587 delete[]$1;
3588 $$ = tmp;
3592 udp_comb_entry_list
3593 : udp_comb_entry
3594 { list<string>*tmp = new list<string>;
3595 tmp->push_back($1);
3596 delete $1;
3597 $$ = tmp;
3599 | udp_comb_entry_list udp_comb_entry
3600 { list<string>*tmp = $1;
3601 tmp->push_back($2);
3602 delete $2;
3603 $$ = tmp;
3607 udp_sequ_entry_list
3608 : udp_sequ_entry
3609 { list<string>*tmp = new list<string>;
3610 tmp->push_back($1);
3611 delete $1;
3612 $$ = tmp;
3614 | udp_sequ_entry_list udp_sequ_entry
3615 { list<string>*tmp = $1;
3616 tmp->push_back($2);
3617 delete $2;
3618 $$ = tmp;
3622 udp_sequ_entry
3623 : udp_input_list ':' udp_input_sym ':' udp_output_sym ';'
3624 { char*tmp = new char[strlen($1)+5];
3625 strcpy(tmp, $1);
3626 char*tp = tmp+strlen(tmp);
3627 *tp++ = ':';
3628 *tp++ = $3;
3629 *tp++ = ':';
3630 *tp++ = $5;
3631 *tp++ = 0;
3632 $$ = tmp;
3636 udp_initial
3637 : K_initial IDENTIFIER '=' number ';'
3638 { PExpr*etmp = new PENumber($4);
3639 PEIdent*itmp = new PEIdent(lex_strings.make($2));
3640 PAssign*atmp = new PAssign(itmp, etmp);
3641 atmp->set_file(@2.text);
3642 atmp->set_lineno(@2.first_line);
3643 delete $2;
3644 $$ = atmp;
3648 udp_init_opt
3649 : udp_initial { $$ = $1; }
3650 | { $$ = 0; }
3653 udp_input_list
3654 : udp_input_sym
3655 { char*tmp = new char[2];
3656 tmp[0] = $1;
3657 tmp[1] = 0;
3658 $$ = tmp;
3660 | udp_input_list udp_input_sym
3661 { char*tmp = new char[strlen($1)+2];
3662 strcpy(tmp, $1);
3663 char*tp = tmp+strlen(tmp);
3664 *tp++ = $2;
3665 *tp++ = 0;
3666 delete[]$1;
3667 $$ = tmp;
3671 udp_input_sym
3672 : '0' { $$ = '0'; }
3673 | '1' { $$ = '1'; }
3674 | 'x' { $$ = 'x'; }
3675 | '?' { $$ = '?'; }
3676 | 'b' { $$ = 'b'; }
3677 | '*' { $$ = '*'; }
3678 | '%' { $$ = '%'; }
3679 | 'f' { $$ = 'f'; }
3680 | 'F' { $$ = 'F'; }
3681 | 'l' { $$ = 'l'; }
3682 | 'h' { $$ = 'H'; }
3683 | 'B' { $$ = 'B'; }
3684 | 'r' { $$ = 'r'; }
3685 | 'R' { $$ = 'R'; }
3686 | 'M' { $$ = 'M'; }
3687 | 'n' { $$ = 'n'; }
3688 | 'N' { $$ = 'N'; }
3689 | 'p' { $$ = 'p'; }
3690 | 'P' { $$ = 'P'; }
3691 | 'Q' { $$ = 'Q'; }
3692 | 'q' { $$ = 'q'; }
3693 | '_' { $$ = '_'; }
3694 | '+' { $$ = '+'; }
3697 udp_output_sym
3698 : '0' { $$ = '0'; }
3699 | '1' { $$ = '1'; }
3700 | 'x' { $$ = 'x'; }
3701 | '-' { $$ = '-'; }
3704 /* Port declarations create wires for the inputs and the output. The
3705 makes for these ports are scoped within the UDP, so there is no
3706 heirarchy involved. */
3707 udp_port_decl
3708 : K_input list_of_identifiers ';'
3709 { $$ = pform_make_udp_input_ports($2); }
3710 | K_output IDENTIFIER ';'
3711 { pform_name_t pname;
3712 pname.push_back(name_component_t(lex_strings.make($2)));
3713 PWire*pp = new PWire(pname, NetNet::IMPLICIT, NetNet::POUTPUT, IVL_VT_LOGIC);
3714 svector<PWire*>*tmp = new svector<PWire*>(1);
3715 (*tmp)[0] = pp;
3716 $$ = tmp;
3717 delete $2;
3719 | K_reg IDENTIFIER ';'
3720 { pform_name_t pname;
3721 pname.push_back(name_component_t(lex_strings.make($2)));
3722 PWire*pp = new PWire(pname, NetNet::REG, NetNet::PIMPLICIT, IVL_VT_LOGIC);
3723 svector<PWire*>*tmp = new svector<PWire*>(1);
3724 (*tmp)[0] = pp;
3725 $$ = tmp;
3726 delete $2;
3728 | K_reg K_output IDENTIFIER ';'
3729 { pform_name_t pname;
3730 pname.push_back(name_component_t(lex_strings.make($3)));
3731 PWire*pp = new PWire(pname, NetNet::REG, NetNet::POUTPUT, IVL_VT_LOGIC);
3732 svector<PWire*>*tmp = new svector<PWire*>(1);
3733 (*tmp)[0] = pp;
3734 $$ = tmp;
3735 delete $3;
3739 udp_port_decls
3740 : udp_port_decl
3741 { $$ = $1; }
3742 | udp_port_decls udp_port_decl
3743 { svector<PWire*>*tmp = new svector<PWire*>(*$1, *$2);
3744 delete $1;
3745 delete $2;
3746 $$ = tmp;
3750 udp_port_list
3751 : IDENTIFIER
3752 { list<string>*tmp = new list<string>;
3753 tmp->push_back($1);
3754 delete $1;
3755 $$ = tmp;
3757 | udp_port_list ',' IDENTIFIER
3758 { list<string>*tmp = $1;
3759 tmp->push_back($3);
3760 delete $3;
3761 $$ = tmp;
3765 udp_reg_opt: K_reg { $$ = true; } | { $$ = false; };
3767 udp_initial_expr_opt
3768 : '=' expression { $$ = $2; }
3769 | { $$ = 0; }
3772 udp_input_declaration_list
3773 : K_input IDENTIFIER
3774 { list<perm_string>*tmp = new list<perm_string>;
3775 tmp->push_back(lex_strings.make($2));
3776 $$ = tmp;
3777 delete[]$2;
3779 | udp_input_declaration_list ',' K_input IDENTIFIER
3780 { list<perm_string>*tmp = $1;
3781 tmp->push_back(lex_strings.make($4));
3782 $$ = tmp;
3783 delete[]$4;
3787 udp_primitive
3788 /* This is the syntax for primitives that uses the IEEE1364-1995
3789 format. The ports are simply names in the port list, and the
3790 declarations are in the body. */
3792 : K_primitive IDENTIFIER '(' udp_port_list ')' ';'
3793 udp_port_decls
3794 udp_init_opt
3795 udp_body
3796 K_endprimitive
3798 { perm_string tmp2 = lex_strings.make($2);
3799 pform_make_udp(tmp2, $4, $7, $9, $8,
3800 @2.text, @2.first_line);
3801 delete[]$2;
3804 /* This is the syntax for IEEE1364-2001 format definitions. The port
3805 names and declarations are all in the parameter list. */
3807 | K_primitive IDENTIFIER
3808 '(' K_output udp_reg_opt IDENTIFIER udp_initial_expr_opt ','
3809 udp_input_declaration_list ')' ';'
3810 udp_body
3811 K_endprimitive
3813 { perm_string tmp2 = lex_strings.make($2);
3814 perm_string tmp6 = lex_strings.make($6);
3815 pform_make_udp(tmp2, $5, tmp6, $7, $9, $12,
3816 @2.text, @2.first_line);
3817 delete[]$2;
3818 delete[]$6;