Fix the debugger to finish correctly.
[iverilog.git] / parse.y
blobf1a56c7df5af0632c03b45cfe4425de7e7fce965
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;
150 %token <text> IDENTIFIER SYSTEM_IDENTIFIER STRING
151 %token <text> PATHPULSE_IDENTIFIER
152 %token <number> BASED_NUMBER DEC_NUMBER
153 %token <realtime> REALTIME
154 %token K_LE K_GE K_EG K_EQ K_NE K_CEQ K_CNE K_LS K_RS K_RSS K_SG
155 %token K_PO_POS K_PO_NEG K_POW
156 %token K_PSTAR K_STARP
157 %token K_LOR K_LAND K_NAND K_NOR K_NXOR K_TRIGGER
158 %token K_always K_and K_assign K_begin K_bool K_buf K_bufif0 K_bufif1 K_case
159 %token K_casex K_casez K_cmos K_deassign K_default K_defparam K_disable
160 %token K_edge K_edge_descriptor
161 %token K_else K_end K_endcase K_endfunction K_endgenerate K_endmodule
162 %token K_endprimitive K_endspecify K_endtable K_endtask K_event K_for
163 %token K_force K_forever K_fork K_function K_generate K_genvar
164 %token K_highz0 K_highz1 K_if K_ifnone
165 %token K_initial K_inout K_input K_integer K_join K_large K_localparam
166 %token K_logic K_macromodule
167 %token K_medium K_module K_nand K_negedge K_nmos K_nor K_not K_notif0
168 %token K_notif1 K_or K_output K_parameter K_pmos K_posedge K_primitive
169 %token K_pull0 K_pull1 K_pulldown K_pullup K_rcmos K_real K_realtime
170 %token K_reg K_release K_repeat
171 %token K_rnmos K_rpmos K_rtran K_rtranif0 K_rtranif1 K_scalared
172 %token K_signed K_small K_specify
173 %token K_specparam K_strong0 K_strong1 K_supply0 K_supply1 K_table K_task
174 %token K_time K_tran K_tranif0 K_tranif1 K_tri K_tri0 K_tri1 K_triand
175 %token K_trior K_trireg K_vectored K_wait K_wand K_weak0 K_weak1
176 %token K_while K_wire
177 %token K_wone K_wor K_xnor K_xor
178 %token K_Shold K_Speriod K_Srecovery K_Srecrem K_Ssetup K_Swidth K_Ssetuphold
180 %token KK_attribute
182 %type <number> number
183 %type <flag> signed_opt udp_reg_opt edge_operator
184 %type <drive> drive_strength drive_strength_opt dr_strength0 dr_strength1
185 %type <letter> udp_input_sym udp_output_sym
186 %type <text> udp_input_list udp_sequ_entry udp_comb_entry
187 %type <perm_strings> udp_input_declaration_list
188 %type <strings> udp_entry_list udp_comb_entry_list udp_sequ_entry_list
189 %type <strings> udp_body udp_port_list
190 %type <wires> udp_port_decl udp_port_decls
191 %type <statement> udp_initial udp_init_opt
192 %type <expr> udp_initial_expr_opt
194 %type <text> register_variable net_variable real_variable
195 %type <perm_strings> register_variable_list net_variable_list real_variable_list list_of_identifiers
197 %type <net_decl_assign> net_decl_assign net_decl_assigns
199 %type <mport> port port_opt port_reference port_reference_list
200 %type <mport> port_declaration
201 %type <mports> list_of_ports module_port_list_opt list_of_port_declarations
203 %type <wires> task_item task_item_list task_item_list_opt
204 %type <wires> task_port_item task_port_decl task_port_decl_list
205 %type <wires> function_item function_item_list
207 %type <named_pexpr> port_name parameter_value_byname
208 %type <named_pexprs> port_name_list parameter_value_byname_list
210 %type <named_pexpr> attribute
211 %type <named_pexprs> attribute_list attribute_list_opt
213 %type <citem> case_item
214 %type <citems> case_items
216 %type <gate> gate_instance
217 %type <gates> gate_instance_list
219 %type <pform_name> heirarchy_identifier
220 %type <expr> expression expr_primary expr_mintypmax
221 %type <expr> lpvalue
222 %type <expr> delay_value delay_value_simple
223 %type <exprs> delay1 delay3 delay3_opt delay_value_list
224 %type <exprs> expression_list_with_nuls expression_list_proper
225 %type <exprs> cont_assign cont_assign_list
227 %type <exprs> range range_opt
228 %type <nettype> net_type var_type net_type_opt
229 %type <gatetype> gatetype
230 %type <porttype> port_type
231 %type <datatype> primitive_type primitive_type_opt
232 %type <parmvalue> parameter_value_opt
234 %type <function_type> function_range_or_type_opt
235 %type <event_expr> event_expression_list
236 %type <event_expr> event_expression
237 %type <event_statement> event_control
238 %type <statement> statement statement_or_null
239 %type <statement_list> statement_list
241 %type <letter> spec_polarity
242 %type <perm_strings> specify_path_identifiers
244 %type <specpath> specify_simple_path specify_simple_path_decl
245 %type <specpath> specify_edge_path specify_edge_path_decl
247 %token K_TAND
248 %right '?' ':'
249 %left K_LOR
250 %left K_LAND
251 %left '|'
252 %left '^' K_NXOR K_NOR
253 %left '&' K_NAND
254 %left K_EQ K_NE K_CEQ K_CNE
255 %left K_GE K_LE '<' '>'
256 %left K_LS K_RS K_RSS
257 %left '+' '-'
258 %left '*' '/' '%'
259 %left K_POW
260 %left UNARY_PREC
262 /* to resolve dangling else ambiguity. */
263 %nonassoc less_than_K_else
264 %nonassoc K_else
268 /* A degenerate source file can be completely empty. */
269 main : source_file | ;
271 source_file
272 : description
273 | source_file description
276 number : BASED_NUMBER
277 { $$ = $1; based_size = 0;}
278 | DEC_NUMBER
279 { $$ = $1; based_size = 0;}
280 | DEC_NUMBER BASED_NUMBER
281 { $$ = pform_verinum_with_size($1,$2, @2.text, @2.first_line);
282 based_size = 0; }
285 /* Verilog-2001 supports attribute lists, which can be attached to a
286 variety of different objects. The syntax inside the (* *) is a
287 comma separated list of names or names with assigned values. */
288 attribute_list_opt
289 : K_PSTAR attribute_list K_STARP { $$ = $2; }
290 | K_PSTAR K_STARP { $$ = 0; }
291 | { $$ = 0; }
294 attribute_list
295 : attribute_list ',' attribute
296 { svector<named_pexpr_t*>*tmp =
297 new svector<named_pexpr_t*>(*$1,$3);
298 delete $1;
299 $$ = tmp;
301 | attribute
302 { svector<named_pexpr_t*>*tmp = new svector<named_pexpr_t*>(1);
303 (*tmp)[0] = $1;
304 $$ = tmp;
309 attribute
310 : IDENTIFIER
311 { named_pexpr_t*tmp = new named_pexpr_t;
312 tmp->name = lex_strings.make($1);
313 tmp->parm = 0;
314 delete $1;
315 $$ = tmp;
317 | IDENTIFIER '=' expression
318 { PExpr*tmp = $3;
319 if (!pform_expression_is_constant(tmp)) {
320 yyerror(@3, "error: attribute value "
321 "expression must be constant.");
322 delete tmp;
323 tmp = 0;
325 named_pexpr_t*tmp2 = new named_pexpr_t;
326 tmp2->name = lex_strings.make($1);
327 tmp2->parm = tmp;
328 delete $1;
329 $$ = tmp2;
334 /* The block_item_decl is used in function definitions, task
335 definitions, module definitions and named blocks. Wherever a new
336 scope is entered, the source may declare new registers and
337 integers. This rule matches those declarations. The containing
338 rule has presumably set up the scope. */
340 block_item_decl
341 : attribute_list_opt K_reg
342 primitive_type_opt signed_opt range
343 register_variable_list ';'
344 { ivl_variable_type_t dtype = $3;
345 if (dtype == IVL_VT_NO_TYPE)
346 dtype = IVL_VT_LOGIC;
347 pform_set_net_range($6, $5, $4, dtype);
348 if ($1) delete $1;
351 /* This differs from the above pattern only in the absence of the
352 range. This is the rule for a scalar. */
354 | attribute_list_opt K_reg
355 primitive_type_opt signed_opt
356 register_variable_list ';'
357 { ivl_variable_type_t dtype = $3;
358 if (dtype == IVL_VT_NO_TYPE)
359 dtype = IVL_VT_LOGIC;
360 pform_set_net_range($5, 0, $4, dtype);
361 if ($1) delete $1;
364 /* Integer declarations are simpler in that they do not have all the
365 trappings of a general variable declaration. All of that is
366 implicit in the "integer" of the declaratin. */
368 | attribute_list_opt K_integer register_variable_list ';'
369 { pform_set_reg_integer($3);
370 if ($1) delete $1;
373 | attribute_list_opt K_time register_variable_list ';'
374 { pform_set_reg_time($3);
377 /* real declarations are fairly simple as there is no range of
378 signed flag in the declaration. Create the real as a NetNet::REG
379 with real value. Note that real and realtime are interchangable
380 in this context. */
382 | attribute_list_opt K_real real_variable_list ';'
383 { delete $3; }
384 | attribute_list_opt K_realtime real_variable_list ';'
385 { delete $3; }
387 | K_parameter parameter_assign_decl ';'
388 | K_localparam localparam_assign_decl ';'
390 /* Recover from errors that happen within variable lists. Use the
391 trailing semi-colon to resync the parser. */
393 | attribute_list_opt K_reg error ';'
394 { yyerror(@2, "error: syntax error in reg variable list.");
395 yyerrok;
396 if ($1) delete $1;
398 | attribute_list_opt K_integer error ';'
399 { yyerror(@2, "error: syntax error in integer variable list.");
400 yyerrok;
401 if ($1) delete $1;
403 | attribute_list_opt K_time error ';'
404 { yyerror(@2, "error: syntax error in time variable list.");
405 yyerrok;
407 | attribute_list_opt K_real error ';'
408 { yyerror(@2, "error: syntax error in real variable list.");
409 yyerrok;
411 | attribute_list_opt K_realtime error ';'
412 { yyerror(@1, "error: syntax error in realtime variable list.");
413 yyerrok;
415 | K_parameter error ';'
416 { yyerror(@1, "error: syntax error in parameter list.");
417 yyerrok;
419 | K_localparam error ';'
420 { yyerror(@1, "error: syntax error localparam list.");
421 yyerrok;
425 block_item_decls
426 : block_item_decl
427 | block_item_decls block_item_decl
430 block_item_decls_opt
431 : block_item_decls
435 case_item
436 : expression_list_proper ':' statement_or_null
437 { PCase::Item*tmp = new PCase::Item;
438 tmp->expr = *$1;
439 tmp->stat = $3;
440 delete $1;
441 $$ = tmp;
443 | K_default ':' statement_or_null
444 { PCase::Item*tmp = new PCase::Item;
445 tmp->stat = $3;
446 $$ = tmp;
448 | K_default statement_or_null
449 { PCase::Item*tmp = new PCase::Item;
450 tmp->stat = $2;
451 $$ = tmp;
453 | error ':' statement_or_null
454 { yyerror(@1, "error: Incomprehensible case expression.");
455 yyerrok;
459 case_items
460 : case_items case_item
461 { svector<PCase::Item*>*tmp;
462 tmp = new svector<PCase::Item*>(*$1, $2);
463 delete $1;
464 $$ = tmp;
466 | case_item
467 { svector<PCase::Item*>*tmp = new svector<PCase::Item*>(1);
468 (*tmp)[0] = $1;
469 $$ = tmp;
473 charge_strength
474 : '(' K_small ')'
475 | '(' K_medium ')'
476 | '(' K_large ')'
479 charge_strength_opt
480 : charge_strength
484 defparam_assign
485 : heirarchy_identifier '=' expression
486 { PExpr*tmp = $3;
487 if (!pform_expression_is_constant(tmp)) {
488 yyerror(@3, "error: parameter value "
489 "must be constant.");
490 delete tmp;
491 tmp = 0;
493 pform_set_defparam(*$1, $3);
494 delete $1;
498 defparam_assign_list
499 : defparam_assign
500 | range defparam_assign
501 { yyerror(@1, "error: defparam may not include a range.");
502 delete $1;
504 | defparam_assign_list ',' defparam_assign
507 delay1
508 : '#' delay_value_simple
509 { svector<PExpr*>*tmp = new svector<PExpr*>(1);
510 (*tmp)[0] = $2;
511 $$ = tmp;
513 | '#' '(' delay_value ')'
514 { svector<PExpr*>*tmp = new svector<PExpr*>(1);
515 (*tmp)[0] = $3;
516 $$ = tmp;
520 delay3
521 : '#' delay_value_simple
522 { svector<PExpr*>*tmp = new svector<PExpr*>(1);
523 (*tmp)[0] = $2;
524 $$ = tmp;
526 | '#' '(' delay_value ')'
527 { svector<PExpr*>*tmp = new svector<PExpr*>(1);
528 (*tmp)[0] = $3;
529 $$ = tmp;
531 | '#' '(' delay_value ',' delay_value ')'
532 { svector<PExpr*>*tmp = new svector<PExpr*>(2);
533 (*tmp)[0] = $3;
534 (*tmp)[1] = $5;
535 $$ = tmp;
537 | '#' '(' delay_value ',' delay_value ',' delay_value ')'
538 { svector<PExpr*>*tmp = new svector<PExpr*>(3);
539 (*tmp)[0] = $3;
540 (*tmp)[1] = $5;
541 (*tmp)[2] = $7;
542 $$ = tmp;
546 delay3_opt
547 : delay3 { $$ = $1; }
548 | { $$ = 0; }
551 delay_value_list
552 : delay_value
553 { svector<PExpr*>*tmp = new svector<PExpr*>(1);
554 (*tmp)[0] = $1;
555 $$ = tmp;
557 | delay_value_list ',' delay_value
558 { svector<PExpr*>*tmp = new svector<PExpr*>(*$1, $3);
559 delete $1;
560 $$ = tmp;
564 delay_value
565 : expression
566 { PExpr*tmp = $1;
567 $$ = tmp;
569 | expression ':' expression ':' expression
570 { $$ = pform_select_mtm_expr($1, $3, $5); }
574 delay_value_simple
575 : DEC_NUMBER
576 { verinum*tmp = $1;
577 if (tmp == 0) {
578 yyerror(@1, "internal error: delay.");
579 $$ = 0;
580 } else {
581 $$ = new PENumber(tmp);
582 $$->set_file(@1.text);
583 $$->set_lineno(@1.first_line);
586 | REALTIME
587 { verireal*tmp = $1;
588 if (tmp == 0) {
589 yyerror(@1, "internal error: delay.");
590 $$ = 0;
591 } else {
592 $$ = new PEFNumber(tmp);
593 $$->set_file(@1.text);
594 $$->set_lineno(@1.first_line);
597 | IDENTIFIER
598 { PEIdent*tmp = new PEIdent(lex_strings.make($1));
599 tmp->set_file(@1.text);
600 tmp->set_lineno(@1.first_line);
601 $$ = tmp;
602 delete $1;
606 description
607 : module
608 | udp_primitive
609 | KK_attribute '(' IDENTIFIER ',' STRING ',' STRING ')'
610 { perm_string tmp3 = lex_strings.make($3);
611 pform_set_type_attrib(tmp3, $5, $7);
612 delete $3;
613 delete $5;
617 drive_strength
618 : '(' dr_strength0 ',' dr_strength1 ')'
619 { $$.str0 = $2.str0;
620 $$.str1 = $4.str1;
622 | '(' dr_strength1 ',' dr_strength0 ')'
623 { $$.str0 = $4.str0;
624 $$.str1 = $2.str1;
626 | '(' dr_strength0 ',' K_highz1 ')'
627 { $$.str0 = $2.str0;
628 $$.str1 = PGate::HIGHZ;
630 | '(' dr_strength1 ',' K_highz0 ')'
631 { $$.str0 = PGate::HIGHZ;
632 $$.str1 = $2.str1;
634 | '(' K_highz1 ',' dr_strength0 ')'
635 { $$.str0 = $4.str0;
636 $$.str1 = PGate::HIGHZ;
638 | '(' K_highz0 ',' dr_strength1 ')'
639 { $$.str0 = PGate::HIGHZ;
640 $$.str1 = $4.str1;
644 drive_strength_opt
645 : drive_strength { $$ = $1; }
646 | { $$.str0 = PGate::STRONG; $$.str1 = PGate::STRONG; }
649 dr_strength0
650 : K_supply0 { $$.str0 = PGate::SUPPLY; }
651 | K_strong0 { $$.str0 = PGate::STRONG; }
652 | K_pull0 { $$.str0 = PGate::PULL; }
653 | K_weak0 { $$.str0 = PGate::WEAK; }
656 dr_strength1
657 : K_supply1 { $$.str1 = PGate::SUPPLY; }
658 | K_strong1 { $$.str1 = PGate::STRONG; }
659 | K_pull1 { $$.str1 = PGate::PULL; }
660 | K_weak1 { $$.str1 = PGate::WEAK; }
663 event_control
664 : '@' heirarchy_identifier
665 { PEIdent*tmpi = new PEIdent(*$2);
666 PEEvent*tmpe = new PEEvent(PEEvent::ANYEDGE, tmpi);
667 PEventStatement*tmps = new PEventStatement(tmpe);
668 tmps->set_file(@1.text);
669 tmps->set_lineno(@1.first_line);
670 $$ = tmps;
671 delete $2;
673 | '@' '(' event_expression_list ')'
674 { PEventStatement*tmp = new PEventStatement(*$3);
675 tmp->set_file(@1.text);
676 tmp->set_lineno(@1.first_line);
677 delete $3;
678 $$ = tmp;
680 | '@' '(' error ')'
681 { yyerror(@1, "error: Malformed event control expression.");
682 $$ = 0;
686 event_expression_list
687 : event_expression
688 { $$ = $1; }
689 | event_expression_list K_or event_expression
690 { svector<PEEvent*>*tmp = new svector<PEEvent*>(*$1, *$3);
691 delete $1;
692 delete $3;
693 $$ = tmp;
695 | event_expression_list ',' event_expression
696 { svector<PEEvent*>*tmp = new svector<PEEvent*>(*$1, *$3);
697 delete $1;
698 delete $3;
699 $$ = tmp;
703 event_expression
704 : K_posedge expression
705 { PEEvent*tmp = new PEEvent(PEEvent::POSEDGE, $2);
706 tmp->set_file(@1.text);
707 tmp->set_lineno(@1.first_line);
708 svector<PEEvent*>*tl = new svector<PEEvent*>(1);
709 (*tl)[0] = tmp;
710 $$ = tl;
712 | K_negedge expression
713 { PEEvent*tmp = new PEEvent(PEEvent::NEGEDGE, $2);
714 tmp->set_file(@1.text);
715 tmp->set_lineno(@1.first_line);
716 svector<PEEvent*>*tl = new svector<PEEvent*>(1);
717 (*tl)[0] = tmp;
718 $$ = tl;
720 | expression
721 { PEEvent*tmp = new PEEvent(PEEvent::ANYEDGE, $1);
722 tmp->set_file(@1.text);
723 tmp->set_lineno(@1.first_line);
724 svector<PEEvent*>*tl = new svector<PEEvent*>(1);
725 (*tl)[0] = tmp;
726 $$ = tl;
730 expression
731 : expr_primary
732 { $$ = $1; }
733 | '+' expr_primary %prec UNARY_PREC
734 { $$ = $2; }
735 | '-' expr_primary %prec UNARY_PREC
736 { PEUnary*tmp = new PEUnary('-', $2);
737 tmp->set_file(@2.text);
738 tmp->set_lineno(@2.first_line);
739 $$ = tmp;
741 | '~' expr_primary %prec UNARY_PREC
742 { PEUnary*tmp = new PEUnary('~', $2);
743 tmp->set_file(@2.text);
744 tmp->set_lineno(@2.first_line);
745 $$ = tmp;
747 | '&' expr_primary %prec UNARY_PREC
748 { PEUnary*tmp = new PEUnary('&', $2);
749 tmp->set_file(@2.text);
750 tmp->set_lineno(@2.first_line);
751 $$ = tmp;
753 | '!' expr_primary %prec UNARY_PREC
754 { PEUnary*tmp = new PEUnary('!', $2);
755 tmp->set_file(@2.text);
756 tmp->set_lineno(@2.first_line);
757 $$ = tmp;
759 | '|' expr_primary %prec UNARY_PREC
760 { PEUnary*tmp = new PEUnary('|', $2);
761 tmp->set_file(@2.text);
762 tmp->set_lineno(@2.first_line);
763 $$ = tmp;
765 | '^' expr_primary %prec UNARY_PREC
766 { PEUnary*tmp = new PEUnary('^', $2);
767 tmp->set_file(@2.text);
768 tmp->set_lineno(@2.first_line);
769 $$ = tmp;
771 | K_NAND expr_primary %prec UNARY_PREC
772 { PEUnary*tmp = new PEUnary('A', $2);
773 tmp->set_file(@2.text);
774 tmp->set_lineno(@2.first_line);
775 $$ = tmp;
777 | K_NOR expr_primary %prec UNARY_PREC
778 { PEUnary*tmp = new PEUnary('N', $2);
779 tmp->set_file(@2.text);
780 tmp->set_lineno(@2.first_line);
781 $$ = tmp;
783 | K_NXOR expr_primary %prec UNARY_PREC
784 { PEUnary*tmp = new PEUnary('X', $2);
785 tmp->set_file(@2.text);
786 tmp->set_lineno(@2.first_line);
787 $$ = tmp;
789 | '!' error %prec UNARY_PREC
790 { yyerror(@1, "error: Operand of unary ! "
791 "is not a primary expression.");
792 $$ = 0;
794 | '^' error %prec UNARY_PREC
795 { yyerror(@1, "error: Operand of reduction ^ "
796 "is not a primary expression.");
797 $$ = 0;
799 | expression '^' expression
800 { PEBinary*tmp = new PEBinary('^', $1, $3);
801 tmp->set_file(@2.text);
802 tmp->set_lineno(@2.first_line);
803 $$ = tmp;
805 | expression K_POW expression
806 { PEBinary*tmp = new PEBinary('p', $1, $3);
807 tmp->set_file(@2.text);
808 tmp->set_lineno(@2.first_line);
809 $$ = tmp;
811 | expression '*' expression
812 { PEBinary*tmp = new PEBinary('*', $1, $3);
813 tmp->set_file(@2.text);
814 tmp->set_lineno(@2.first_line);
815 $$ = tmp;
817 | expression '/' expression
818 { PEBinary*tmp = new PEBinary('/', $1, $3);
819 tmp->set_file(@2.text);
820 tmp->set_lineno(@2.first_line);
821 $$ = tmp;
823 | expression '%' expression
824 { PEBinary*tmp = new PEBinary('%', $1, $3);
825 tmp->set_file(@2.text);
826 tmp->set_lineno(@2.first_line);
827 $$ = tmp;
829 | expression '+' expression
830 { PEBinary*tmp = new PEBinary('+', $1, $3);
831 tmp->set_file(@2.text);
832 tmp->set_lineno(@2.first_line);
833 $$ = tmp;
835 | expression '-' expression
836 { PEBinary*tmp = new PEBinary('-', $1, $3);
837 tmp->set_file(@2.text);
838 tmp->set_lineno(@2.first_line);
839 $$ = tmp;
841 | expression '&' expression
842 { PEBinary*tmp = new PEBinary('&', $1, $3);
843 tmp->set_file(@2.text);
844 tmp->set_lineno(@2.first_line);
845 $$ = tmp;
847 | expression '|' expression
848 { PEBinary*tmp = new PEBinary('|', $1, $3);
849 tmp->set_file(@2.text);
850 tmp->set_lineno(@2.first_line);
851 $$ = tmp;
853 | expression K_NAND expression
854 { PEBinary*tmp = new PEBinary('A', $1, $3);
855 tmp->set_file(@2.text);
856 tmp->set_lineno(@2.first_line);
857 $$ = tmp;
859 | expression K_NOR expression
860 { PEBinary*tmp = new PEBinary('O', $1, $3);
861 tmp->set_file(@2.text);
862 tmp->set_lineno(@2.first_line);
863 $$ = tmp;
865 | expression K_NXOR expression
866 { PEBinary*tmp = new PEBinary('X', $1, $3);
867 tmp->set_file(@2.text);
868 tmp->set_lineno(@2.first_line);
869 $$ = tmp;
871 | expression '<' expression
872 { PEBinary*tmp = new PEBComp('<', $1, $3);
873 tmp->set_file(@2.text);
874 tmp->set_lineno(@2.first_line);
875 $$ = tmp;
877 | expression '>' expression
878 { PEBinary*tmp = new PEBComp('>', $1, $3);
879 tmp->set_file(@2.text);
880 tmp->set_lineno(@2.first_line);
881 $$ = tmp;
883 | expression K_LS expression
884 { PEBinary*tmp = new PEBShift('l', $1, $3);
885 tmp->set_file(@2.text);
886 tmp->set_lineno(@2.first_line);
887 $$ = tmp;
889 | expression K_RS expression
890 { PEBinary*tmp = new PEBShift('r', $1, $3);
891 tmp->set_file(@2.text);
892 tmp->set_lineno(@2.first_line);
893 $$ = tmp;
895 | expression K_RSS expression
896 { PEBinary*tmp = new PEBShift('R', $1, $3);
897 tmp->set_file(@2.text);
898 tmp->set_lineno(@2.first_line);
899 $$ = tmp;
901 | expression K_EQ expression
902 { PEBinary*tmp = new PEBComp('e', $1, $3);
903 tmp->set_file(@2.text);
904 tmp->set_lineno(@2.first_line);
905 $$ = tmp;
907 | expression K_CEQ expression
908 { PEBinary*tmp = new PEBComp('E', $1, $3);
909 tmp->set_file(@2.text);
910 tmp->set_lineno(@2.first_line);
911 $$ = tmp;
913 | expression K_LE expression
914 { PEBinary*tmp = new PEBComp('L', $1, $3);
915 tmp->set_file(@2.text);
916 tmp->set_lineno(@2.first_line);
917 $$ = tmp;
919 | expression K_GE expression
920 { PEBinary*tmp = new PEBComp('G', $1, $3);
921 tmp->set_file(@2.text);
922 tmp->set_lineno(@2.first_line);
923 $$ = tmp;
925 | expression K_NE expression
926 { PEBinary*tmp = new PEBComp('n', $1, $3);
927 tmp->set_file(@2.text);
928 tmp->set_lineno(@2.first_line);
929 $$ = tmp;
931 | expression K_CNE expression
932 { PEBinary*tmp = new PEBComp('N', $1, $3);
933 tmp->set_file(@2.text);
934 tmp->set_lineno(@2.first_line);
935 $$ = tmp;
937 | expression K_LOR expression
938 { PEBinary*tmp = new PEBinary('o', $1, $3);
939 tmp->set_file(@2.text);
940 tmp->set_lineno(@2.first_line);
941 $$ = tmp;
943 | expression K_LAND expression
944 { PEBinary*tmp = new PEBinary('a', $1, $3);
945 tmp->set_file(@2.text);
946 tmp->set_lineno(@2.first_line);
947 $$ = tmp;
949 | expression '?' expression ':' expression
950 { PETernary*tmp = new PETernary($1, $3, $5);
951 tmp->set_file(@2.text);
952 tmp->set_lineno(@2.first_line);
953 $$ = tmp;
957 expr_mintypmax
958 : expression
959 { $$ = $1; }
960 | expression ':' expression ':' expression
961 { switch (min_typ_max_flag) {
962 case MIN:
963 $$ = $1;
964 delete $3;
965 delete $5;
966 break;
967 case TYP:
968 delete $1;
969 $$ = $3;
970 delete $5;
971 break;
972 case MAX:
973 delete $1;
974 delete $3;
975 $$ = $5;
976 break;
982 /* Many contexts take a comma separated list of expressions. Null
983 expressions can happen anywhere in the list, so there are two
984 extra rules in expression_list_with_nuls for parsing and
985 installing those nulls.
987 The expression_list_proper rules do not allow null items in the
988 expression list, so can be used where nul expressions are not allowed. */
990 expression_list_with_nuls
991 : expression_list_with_nuls ',' expression
992 { svector<PExpr*>*tmp = new svector<PExpr*>(*$1, $3);
993 delete $1;
994 $$ = tmp;
996 | expression
997 { svector<PExpr*>*tmp = new svector<PExpr*>(1);
998 (*tmp)[0] = $1;
999 $$ = tmp;
1002 { svector<PExpr*>*tmp = new svector<PExpr*>(1);
1003 (*tmp)[0] = 0;
1004 $$ = tmp;
1007 | expression_list_with_nuls ','
1008 { svector<PExpr*>*tmp = new svector<PExpr*>(*$1, 0);
1009 delete $1;
1010 $$ = tmp;
1014 expression_list_proper
1015 : expression_list_proper ',' expression
1016 { svector<PExpr*>*tmp = new svector<PExpr*>(*$1, $3);
1017 delete $1;
1018 $$ = tmp;
1020 | expression
1021 { svector<PExpr*>*tmp = new svector<PExpr*>(1);
1022 (*tmp)[0] = $1;
1023 $$ = tmp;
1027 expr_primary
1028 : number
1029 { assert($1);
1030 PENumber*tmp = new PENumber($1);
1031 tmp->set_file(@1.text);
1032 tmp->set_lineno(@1.first_line);
1033 $$ = tmp;
1035 | REALTIME
1036 { PEFNumber*tmp = new PEFNumber($1);
1037 tmp->set_file(@1.text);
1038 tmp->set_lineno(@1.first_line);
1039 $$ = tmp;
1041 | STRING
1042 { PEString*tmp = new PEString($1);
1043 tmp->set_file(@1.text);
1044 tmp->set_lineno(@1.first_line);
1045 $$ = tmp;
1047 | SYSTEM_IDENTIFIER
1048 { perm_string tn = lex_strings.make($1);
1049 PECallFunction*tmp = new PECallFunction(tn);
1050 tmp->set_file(@1.text);
1051 tmp->set_lineno(@1.first_line);
1052 $$ = tmp;
1053 delete $1;
1056 /* The heirarchy_identifier rule matches simple identifiers as well as
1057 indexed arrays and part selects */
1059 | heirarchy_identifier
1060 { PEIdent*tmp = new PEIdent(*$1);
1061 tmp->set_file(@1.text);
1062 tmp->set_lineno(@1.first_line);
1063 $$ = tmp;
1064 delete $1;
1067 /* An identifer followed by an expression list in parentheses is a
1068 function call. If a system identifier, then a system function
1069 call. */
1071 | heirarchy_identifier '(' expression_list_proper ')'
1072 { PECallFunction*tmp = new PECallFunction(*$1, *$3);
1073 tmp->set_file(@1.text);
1074 tmp->set_lineno(@1.first_line);
1075 delete $1;
1076 $$ = tmp;
1078 | SYSTEM_IDENTIFIER '(' expression_list_proper ')'
1079 { perm_string tn = lex_strings.make($1);
1080 PECallFunction*tmp = new PECallFunction(tn, *$3);
1081 tmp->set_file(@1.text);
1082 tmp->set_lineno(@1.first_line);
1083 $$ = tmp;
1086 /* Parenthesized expressions are primaries. */
1088 | '(' expr_mintypmax ')'
1089 { $$ = $2; }
1091 /* Various kinds of concatenation expressions. */
1093 | '{' expression_list_proper '}'
1094 { PEConcat*tmp = new PEConcat(*$2);
1095 tmp->set_file(@1.text);
1096 tmp->set_lineno(@1.first_line);
1097 delete $2;
1098 $$ = tmp;
1100 | '{' expression '{' expression_list_proper '}' '}'
1101 { PExpr*rep = $2;
1102 PEConcat*tmp = new PEConcat(*$4, rep);
1103 tmp->set_file(@1.text);
1104 tmp->set_lineno(@1.first_line);
1105 delete $4;
1106 $$ = tmp;
1108 | '{' expression '{' expression_list_proper '}' error '}'
1109 { PExpr*rep = $2;
1110 PEConcat*tmp = new PEConcat(*$4, rep);
1111 tmp->set_file(@1.text);
1112 tmp->set_lineno(@1.first_line);
1113 delete $4;
1114 $$ = tmp;
1115 yyerror(@5, "error: Syntax error between internal '}' "
1116 "and closing '}' of repeat concatenation.");
1117 yyerrok;
1121 /* A function_item is either a block item (i.e. a reg or integer
1122 declaration) or an input declaration. There are no output or
1123 inout ports. */
1124 function_item
1125 : K_input signed_opt range_opt list_of_identifiers ';'
1126 { svector<PWire*>*tmp
1127 = pform_make_task_ports(NetNet::PINPUT,
1128 IVL_VT_NO_TYPE, $2,
1129 $3, $4,
1130 @1.text, @1.first_line);
1131 $$ = tmp;
1133 | K_output signed_opt range_opt list_of_identifiers ';'
1134 { svector<PWire*>*tmp
1135 = pform_make_task_ports(NetNet::PINPUT,
1136 IVL_VT_NO_TYPE, $2,
1137 $3, $4,
1138 @1.text, @1.first_line);
1139 $$ = tmp;
1140 yyerror(@1, "Functions may not have output ports.");
1142 | K_inout signed_opt range_opt list_of_identifiers ';'
1143 { svector<PWire*>*tmp
1144 = pform_make_task_ports(NetNet::PINPUT,
1145 IVL_VT_NO_TYPE, $2,
1146 $3, $4,
1147 @1.text, @1.first_line);
1148 $$ = tmp;
1149 yyerror(@1, "Functions may not have inout ports.");
1152 /* When the port is an integer, infer a signed vector of the integer
1153 shape. Generate a range to make it work. */
1155 | K_input K_integer list_of_identifiers ';'
1156 { svector<PExpr*>*range_stub
1157 = new svector<PExpr*>(2);
1158 PExpr*re;
1159 re = new PENumber(new verinum(integer_width-1,
1160 integer_width));
1161 (*range_stub)[0] = re;
1162 re = new PENumber(new verinum((uint64_t)0, integer_width));
1163 (*range_stub)[1] = re;
1164 svector<PWire*>*tmp
1165 = pform_make_task_ports(NetNet::PINPUT,
1166 IVL_VT_LOGIC, true,
1167 range_stub, $3,
1168 @1.text, @1.first_line);
1169 $$ = tmp;
1172 /* Ports can be real. */
1174 | K_input K_real list_of_identifiers ';'
1175 { svector<PWire*>*tmp
1176 = pform_make_task_ports(NetNet::PINPUT,
1177 IVL_VT_REAL, false,
1178 0, $3,
1179 @1.text, @1.first_line);
1180 $$ = tmp;
1183 | block_item_decl
1184 { $$ = 0; }
1187 /* A function_item_list only lists the input/output/inout
1188 declarations. The integer and reg declarations are handled in
1189 place, so are not listed. The list builder needs to account for
1190 the possibility that the various parts may be NULL. */
1191 function_item_list
1192 : function_item
1193 { $$ = $1; }
1194 | function_item_list function_item
1195 { if ($1 && $2) {
1196 svector<PWire*>*tmp = new svector<PWire*>(*$1, *$2);
1197 delete $1;
1198 delete $2;
1199 $$ = tmp;
1200 } else if ($1) {
1201 $$ = $1;
1202 } else {
1203 $$ = $2;
1208 /* A gate_instance is a module instantiation or a built in part
1209 type. In any case, the gate has a set of connections to ports. */
1210 gate_instance
1211 : IDENTIFIER '(' expression_list_with_nuls ')'
1212 { lgate*tmp = new lgate;
1213 tmp->name = $1;
1214 tmp->parms = $3;
1215 tmp->file = @1.text;
1216 tmp->lineno = @1.first_line;
1217 delete $1;
1218 $$ = tmp;
1221 | IDENTIFIER range '(' expression_list_with_nuls ')'
1222 { lgate*tmp = new lgate;
1223 svector<PExpr*>*rng = $2;
1224 tmp->name = $1;
1225 tmp->parms = $4;
1226 tmp->range[0] = (*rng)[0];
1227 tmp->range[1] = (*rng)[1];
1228 tmp->file = @1.text;
1229 tmp->lineno = @1.first_line;
1230 delete $1;
1231 delete rng;
1232 $$ = tmp;
1234 | '(' expression_list_with_nuls ')'
1235 { lgate*tmp = new lgate;
1236 tmp->name = "";
1237 tmp->parms = $2;
1238 tmp->file = @1.text;
1239 tmp->lineno = @1.first_line;
1240 $$ = tmp;
1243 /* Degenerate modules can have no ports. */
1245 | IDENTIFIER range
1246 { lgate*tmp = new lgate;
1247 svector<PExpr*>*rng = $2;
1248 tmp->name = $1;
1249 tmp->parms = 0;
1250 tmp->parms_by_name = 0;
1251 tmp->range[0] = (*rng)[0];
1252 tmp->range[1] = (*rng)[1];
1253 tmp->file = @1.text;
1254 tmp->lineno = @1.first_line;
1255 delete $1;
1256 delete rng;
1257 $$ = tmp;
1260 /* Modules can also take ports by port-name expressions. */
1262 | IDENTIFIER '(' port_name_list ')'
1263 { lgate*tmp = new lgate;
1264 tmp->name = $1;
1265 tmp->parms = 0;
1266 tmp->parms_by_name = $3;
1267 tmp->file = @1.text;
1268 tmp->lineno = @1.first_line;
1269 delete $1;
1270 $$ = tmp;
1273 | IDENTIFIER range '(' port_name_list ')'
1274 { lgate*tmp = new lgate;
1275 svector<PExpr*>*rng = $2;
1276 tmp->name = $1;
1277 tmp->parms = 0;
1278 tmp->parms_by_name = $4;
1279 tmp->range[0] = (*rng)[0];
1280 tmp->range[1] = (*rng)[1];
1281 tmp->file = @1.text;
1282 tmp->lineno = @1.first_line;
1283 delete $1;
1284 delete rng;
1285 $$ = tmp;
1289 gate_instance_list
1290 : gate_instance_list ',' gate_instance
1291 { svector<lgate>*tmp1 = $1;
1292 lgate*tmp2 = $3;
1293 svector<lgate>*out = new svector<lgate> (*tmp1, *tmp2);
1294 delete tmp1;
1295 delete tmp2;
1296 $$ = out;
1298 | gate_instance
1299 { svector<lgate>*tmp = new svector<lgate>(1);
1300 (*tmp)[0] = *$1;
1301 delete $1;
1302 $$ = tmp;
1306 gatetype
1307 : K_and { $$ = PGBuiltin::AND; }
1308 | K_nand { $$ = PGBuiltin::NAND; }
1309 | K_or { $$ = PGBuiltin::OR; }
1310 | K_nor { $$ = PGBuiltin::NOR; }
1311 | K_xor { $$ = PGBuiltin::XOR; }
1312 | K_xnor { $$ = PGBuiltin::XNOR; }
1313 | K_buf { $$ = PGBuiltin::BUF; }
1314 | K_bufif0 { $$ = PGBuiltin::BUFIF0; }
1315 | K_bufif1 { $$ = PGBuiltin::BUFIF1; }
1316 | K_not { $$ = PGBuiltin::NOT; }
1317 | K_notif0 { $$ = PGBuiltin::NOTIF0; }
1318 | K_notif1 { $$ = PGBuiltin::NOTIF1; }
1319 | K_nmos { $$ = PGBuiltin::NMOS; }
1320 | K_rnmos { $$ = PGBuiltin::RNMOS; }
1321 | K_pmos { $$ = PGBuiltin::PMOS; }
1322 | K_rpmos { $$ = PGBuiltin::RPMOS; }
1323 | K_cmos { $$ = PGBuiltin::CMOS; }
1324 | K_rcmos { $$ = PGBuiltin::RCMOS; }
1325 | K_tran { $$ = PGBuiltin::TRAN; }
1326 | K_rtran { $$ = PGBuiltin::RTRAN; }
1327 | K_tranif0 { $$ = PGBuiltin::TRANIF0; }
1328 | K_tranif1 { $$ = PGBuiltin::TRANIF1; }
1329 | K_rtranif0 { $$ = PGBuiltin::RTRANIF0; }
1330 | K_rtranif1 { $$ = PGBuiltin::RTRANIF1; }
1334 /* A general identifier is a hierarchical name, with the right most
1335 name the base of the identifier. This rule builds up a
1336 hierarchical name from the left to the right, forming a list of
1337 names. */
1339 heirarchy_identifier
1340 : IDENTIFIER
1341 { $$ = new pform_name_t;
1342 $$->push_back(name_component_t(lex_strings.make($1)));
1343 delete $1;
1345 | heirarchy_identifier '.' IDENTIFIER
1346 { pform_name_t * tmp = $1;
1347 tmp->push_back(name_component_t(lex_strings.make($3)));
1348 delete $3;
1349 $$ = tmp;
1351 | heirarchy_identifier '[' expression ']'
1352 { pform_name_t * tmp = $1;
1353 name_component_t&tail = tmp->back();
1354 index_component_t itmp;
1355 itmp.sel = index_component_t::SEL_BIT;
1356 itmp.msb = $3;
1357 tail.index.push_back(itmp);
1358 $$ = tmp;
1360 | heirarchy_identifier '[' expression ':' expression ']'
1361 { pform_name_t * tmp = $1;
1362 name_component_t&tail = tmp->back();
1363 index_component_t itmp;
1364 itmp.sel = index_component_t::SEL_PART;
1365 itmp.msb = $3;
1366 itmp.lsb = $5;
1367 tail.index.push_back(itmp);
1368 $$ = tmp;
1370 | heirarchy_identifier '[' expression K_PO_POS expression ']'
1371 { pform_name_t * tmp = $1;
1372 name_component_t&tail = tmp->back();
1373 index_component_t itmp;
1374 itmp.sel = index_component_t::SEL_IDX_UP;
1375 itmp.msb = $3;
1376 itmp.lsb = $5;
1377 tail.index.push_back(itmp);
1378 $$ = tmp;
1380 | heirarchy_identifier '[' expression K_PO_NEG expression ']'
1381 { pform_name_t * tmp = $1;
1382 name_component_t&tail = tmp->back();
1383 index_component_t itmp;
1384 itmp.sel = index_component_t::SEL_IDX_DO;
1385 itmp.msb = $3;
1386 itmp.lsb = $5;
1387 tail.index.push_back(itmp);
1388 $$ = tmp;
1392 /* This is a list of identifiers. The result is a list of strings,
1393 each one of the identifiers in the list. These are simple,
1394 non-hierarchical names separated by ',' characters. */
1395 list_of_identifiers
1396 : IDENTIFIER
1397 { $$ = list_from_identifier($1); }
1398 | list_of_identifiers ',' IDENTIFIER
1399 { $$ = list_from_identifier($1, $3); }
1403 /* The list_of_ports and list_of_port_declarations rules are the
1404 port list formats for module ports. The list_of_ports_opt rule is
1405 only used by the module start rule.
1407 The first, the list_of_ports, is the 1364-1995 format, a list of
1408 port names, including .name() syntax.
1410 The list_of_port_declarations the 1364-2001 format, an in-line
1411 declaration of the ports.
1413 In both cases, the list_of_ports and list_of_port_declarations
1414 returns an array of Module::port_t* items that include the name
1415 of the port internally and externally. The actual creation of the
1416 nets/variables is done in the declaration, whether internal to
1417 the port list or in amongst the module items. */
1419 list_of_ports
1420 : port_opt
1421 { svector<Module::port_t*>*tmp
1422 = new svector<Module::port_t*>(1);
1423 (*tmp)[0] = $1;
1424 $$ = tmp;
1426 | list_of_ports ',' port_opt
1427 { svector<Module::port_t*>*tmp
1428 = new svector<Module::port_t*>(*$1, $3);
1429 delete $1;
1430 $$ = tmp;
1434 list_of_port_declarations
1435 : port_declaration
1436 { svector<Module::port_t*>*tmp
1437 = new svector<Module::port_t*>(1);
1438 (*tmp)[0] = $1;
1440 * Uncommenting this makes lopd always fully specified.
1441 * Some wanted an implicit net to not be fully defined.
1443 * pform_set_net_range($1[0].name);
1445 $$ = tmp;
1447 | list_of_port_declarations ',' port_declaration
1448 { svector<Module::port_t*>*tmp
1449 = new svector<Module::port_t*>(*$1, $3);
1450 delete $1;
1452 * Same as above.
1454 * pform_set_net_range($3[0].name);
1456 $$ = tmp;
1458 | list_of_port_declarations ',' IDENTIFIER
1459 { Module::port_t*ptmp;
1460 ptmp = pform_module_port_reference($3, @3.text,
1461 @3.first_line);
1462 svector<Module::port_t*>*tmp
1463 = new svector<Module::port_t*>(*$1, ptmp);
1465 /* Get the port declaration details, the port type
1466 and what not, from context data stored by the
1467 last port_declaration rule. */
1468 pform_module_define_port(@3, $3,
1469 port_declaration_context.port_type,
1470 port_declaration_context.port_net_type,
1471 port_declaration_context.sign_flag,
1472 port_declaration_context.range, 0);
1473 delete $1;
1475 * Same as above.
1477 * pform_set_net_range($3);
1479 $$ = tmp;
1483 port_declaration
1484 : attribute_list_opt
1485 K_input net_type_opt signed_opt range_opt IDENTIFIER
1486 { Module::port_t*ptmp;
1487 ptmp = pform_module_port_reference($6, @2.text,
1488 @2.first_line);
1489 pform_module_define_port(@2, $6, NetNet::PINPUT,
1490 $3, $4, $5, $1);
1491 port_declaration_context.port_type = NetNet::PINPUT;
1492 port_declaration_context.port_net_type = $3;
1493 port_declaration_context.sign_flag = $4;
1494 port_declaration_context.range = $5;
1495 delete $1;
1496 delete $6;
1497 $$ = ptmp;
1499 | attribute_list_opt
1500 K_inout net_type_opt signed_opt range_opt IDENTIFIER
1501 { Module::port_t*ptmp;
1502 ptmp = pform_module_port_reference($6, @2.text,
1503 @2.first_line);
1504 pform_module_define_port(@2, $6, NetNet::PINOUT,
1505 $3, $4, $5, $1);
1506 port_declaration_context.port_type = NetNet::PINOUT;
1507 port_declaration_context.port_net_type = $3;
1508 port_declaration_context.sign_flag = $4;
1509 port_declaration_context.range = $5;
1510 delete $1;
1511 delete $6;
1512 $$ = ptmp;
1514 | attribute_list_opt
1515 K_output net_type_opt signed_opt range_opt IDENTIFIER
1516 { Module::port_t*ptmp;
1517 ptmp = pform_module_port_reference($6, @2.text,
1518 @2.first_line);
1519 pform_module_define_port(@2, $6, NetNet::POUTPUT,
1520 $3, $4, $5, $1);
1521 port_declaration_context.port_type = NetNet::POUTPUT;
1522 port_declaration_context.port_net_type = $3;
1523 port_declaration_context.sign_flag = $4;
1524 port_declaration_context.range = $5;
1525 delete $1;
1526 delete $6;
1527 $$ = ptmp;
1529 | attribute_list_opt
1530 K_output var_type signed_opt range_opt IDENTIFIER
1531 { Module::port_t*ptmp;
1532 ptmp = pform_module_port_reference($6, @2.text,
1533 @2.first_line);
1534 pform_module_define_port(@2, $6, NetNet::POUTPUT,
1535 $3, $4, $5, $1);
1536 port_declaration_context.port_type = NetNet::POUTPUT;
1537 port_declaration_context.port_net_type = $3;
1538 port_declaration_context.sign_flag = $4;
1539 port_declaration_context.range = $5;
1540 delete $1;
1541 delete $6;
1542 $$ = ptmp;
1544 | attribute_list_opt
1545 K_output var_type signed_opt range_opt IDENTIFIER '=' expression
1546 { Module::port_t*ptmp;
1547 ptmp = pform_module_port_reference($6, @2.text,
1548 @2.first_line);
1549 pform_module_define_port(@2, $6, NetNet::POUTPUT,
1550 $3, $4, $5, $1);
1551 port_declaration_context.port_type = NetNet::POUTPUT;
1552 port_declaration_context.port_net_type = $3;
1553 port_declaration_context.sign_flag = $4;
1554 port_declaration_context.range = $5;
1556 if (! pform_expression_is_constant($8))
1557 yyerror(@8, "error: register declaration assignment"
1558 " value must be a constant expression.");
1559 pform_make_reginit(@6, $6, $8);
1561 delete $1;
1562 delete $6;
1563 $$ = ptmp;
1569 net_type_opt
1570 : net_type { $$ = $1; }
1571 | { $$ = NetNet::IMPLICIT; }
1574 signed_opt : K_signed { $$ = true; } | {$$ = false; } ;
1576 /* An lpvalue is the expression that can go on the left side of a
1577 procedural assignment. This rule handles only procedural
1578 assignments. It is more limited then the general expr_primary
1579 rule to reflect the rules for assignment l-values. */
1580 lpvalue
1581 : heirarchy_identifier
1582 { PEIdent*tmp = new PEIdent(*$1);
1583 tmp->set_file(@1.text);
1584 tmp->set_lineno(@1.first_line);
1585 $$ = tmp;
1586 delete $1;
1588 | '{' expression_list_proper '}'
1589 { PEConcat*tmp = new PEConcat(*$2);
1590 tmp->set_file(@1.text);
1591 tmp->set_lineno(@1.first_line);
1592 delete $2;
1593 $$ = tmp;
1598 /* Continuous assignments have a list of individual assignments. */
1600 cont_assign
1601 : lpvalue '=' expression
1602 { svector<PExpr*>*tmp = new svector<PExpr*>(2);
1603 (*tmp)[0] = $1;
1604 (*tmp)[1] = $3;
1605 $$ = tmp;
1609 cont_assign_list
1610 : cont_assign_list ',' cont_assign
1611 { svector<PExpr*>*tmp = new svector<PExpr*>(*$1, *$3);
1612 delete $1;
1613 delete $3;
1614 $$ = tmp;
1616 | cont_assign
1617 { $$ = $1; }
1621 /* This is the global structure of a module. A module in a start
1622 section, with optional ports, then an optional list of module
1623 items, and finally an end marker. */
1625 module : attribute_list_opt module_start IDENTIFIER
1626 { pform_startmodule($3, @2.text, @2.first_line, $1); }
1627 module_parameter_port_list_opt
1628 module_port_list_opt ';'
1629 { pform_module_set_ports($6); }
1630 module_item_list_opt
1631 K_endmodule
1632 { pform_endmodule($3);
1633 delete $3;
1638 module_start : K_module | K_macromodule ;
1640 module_port_list_opt
1641 : '(' list_of_ports ')' { $$ = $2; }
1642 | '(' list_of_port_declarations ')' { $$ = $2; }
1643 | { $$ = 0; }
1646 /* Module declarations include optional ANSII style module parameter
1647 ports. These are simply advance ways to declare parameters, so
1648 that the port declarations may use them. */
1649 module_parameter_port_list_opt
1651 | '#' '(' module_parameter_port_list ')'
1654 module_parameter_port_list
1655 : K_parameter parameter_assign
1656 | module_parameter_port_list ',' parameter_assign
1657 | module_parameter_port_list ',' K_parameter parameter_assign
1660 module_item
1662 /* This rule detects net declarations that possibly include a
1663 primitive type, an optional vector range and signed flag. This
1664 also includes an optional delay set. The values are then applied
1665 to a list of names. If the primitive type is not specified, then
1666 resort to the default type LOGIC. */
1668 : attribute_list_opt net_type
1669 primitive_type_opt signed_opt range_opt
1670 delay3_opt
1671 net_variable_list ';'
1673 { ivl_variable_type_t dtype = $3;
1674 if (dtype == IVL_VT_NO_TYPE)
1675 dtype = IVL_VT_LOGIC;
1676 pform_makewire(@2, $5, $4, $7, $2,
1677 NetNet::NOT_A_PORT, dtype, $1);
1678 if ($6 != 0) {
1679 yyerror(@6, "sorry: net delays not supported.");
1680 delete $6;
1682 if ($1) delete $1;
1685 /* Very similar to the rule above, but this takes a list of
1686 net_decl_assigns, which are <name> = <expr> assignment
1687 declarations. */
1689 | attribute_list_opt net_type
1690 primitive_type_opt signed_opt range_opt
1691 delay3_opt net_decl_assigns ';'
1693 { ivl_variable_type_t dtype = $3;
1694 if (dtype == IVL_VT_NO_TYPE)
1695 dtype = IVL_VT_LOGIC;
1696 pform_makewire(@2, $5, $4, $6,
1697 str_strength, $7, $2, dtype);
1698 if ($1) {
1699 yyerror(@2, "sorry: Attributes not supported "
1700 "on net declaration assignments.");
1701 delete $1;
1705 /* This form doesn't have the range, but does have strengths. This
1706 gives strength to the assignment drivers. */
1708 | attribute_list_opt net_type
1709 primitive_type_opt signed_opt
1710 drive_strength net_decl_assigns ';'
1712 { ivl_variable_type_t dtype = $3;
1713 if (dtype == IVL_VT_NO_TYPE)
1714 dtype = IVL_VT_LOGIC;
1715 pform_makewire(@2, 0, $4, 0, $5, $6, $2, dtype);
1716 if ($1) {
1717 yyerror(@2, "sorry: Attributes not supported "
1718 "on net declaration assignments.");
1719 delete $1;
1723 | K_trireg charge_strength_opt range_opt delay3_opt list_of_identifiers ';'
1724 { yyerror(@1, "sorry: trireg nets not supported.");
1725 delete $3;
1726 delete $4;
1729 | port_type signed_opt range_opt delay3_opt list_of_identifiers ';'
1730 { pform_set_port_type(@1, $5, $3, $2, $1);
1733 /* The next two rules handle Verilog 2001 statements of the form:
1734 input wire signed [h:l] <list>;
1735 This creates the wire and sets the port type all at once. */
1737 | port_type net_type signed_opt range_opt list_of_identifiers ';'
1738 { pform_makewire(@1, $4, $3, $5, $2, $1, IVL_VT_NO_TYPE, 0,
1739 SR_BOTH);
1742 | K_output var_type signed_opt range_opt list_of_identifiers ';'
1743 { pform_makewire(@1, $4, $3, $5, $2, NetNet::POUTPUT,
1744 IVL_VT_NO_TYPE, 0, SR_BOTH);
1747 /* var_type declaration (reg variables) cannot be input or output,
1748 because the port declaration implies an external driver, which
1749 cannot be attached to a reg. These rules catch that error early. */
1751 | K_input var_type signed_opt range_opt list_of_identifiers ';'
1752 { pform_makewire(@1, $4, $3, $5, $2, NetNet::PINPUT,
1753 IVL_VT_NO_TYPE, 0);
1754 yyerror(@2, "error: reg variables cannot be inputs.");
1757 | K_inout var_type signed_opt range_opt list_of_identifiers ';'
1758 { pform_makewire(@1, $4, $3, $5, $2, NetNet::PINOUT,
1759 IVL_VT_NO_TYPE, 0);
1760 yyerror(@2, "error: reg variables cannot be inouts.");
1763 | port_type signed_opt range_opt delay3_opt error ';'
1764 { yyerror(@1, "error: Invalid variable list"
1765 " in port declaration.");
1766 if ($3) delete $3;
1767 if ($4) delete $4;
1768 yyerrok;
1771 /* block_item_decl rule is shared with task blocks and named
1772 begin/end. */
1774 | block_item_decl
1776 /* */
1778 | K_defparam defparam_assign_list ';'
1779 | K_event list_of_identifiers ';'
1780 { pform_make_events($2, @1.text, @1.first_line);
1783 /* Most gate types have an optional drive strength and optional
1784 three-value delay. These rules handle the different cases. */
1786 | attribute_list_opt gatetype gate_instance_list ';'
1787 { pform_makegates($2, str_strength, 0, $3, $1);
1790 | attribute_list_opt gatetype delay3 gate_instance_list ';'
1791 { pform_makegates($2, str_strength, $3, $4, $1);
1794 | attribute_list_opt gatetype drive_strength gate_instance_list ';'
1795 { pform_makegates($2, $3, 0, $4, $1);
1798 | attribute_list_opt gatetype drive_strength delay3 gate_instance_list ';'
1799 { pform_makegates($2, $3, $4, $5, $1);
1802 /* Pullup and pulldown devices cannot have delays, and their
1803 strengths are limited. */
1805 | K_pullup gate_instance_list ';'
1806 { pform_makegates(PGBuiltin::PULLUP, pull_strength, 0,
1807 $2, 0);
1809 | K_pulldown gate_instance_list ';'
1810 { pform_makegates(PGBuiltin::PULLDOWN, pull_strength,
1811 0, $2, 0);
1814 | K_pullup '(' dr_strength1 ')' gate_instance_list ';'
1815 { pform_makegates(PGBuiltin::PULLUP, $3, 0, $5, 0);
1818 | K_pulldown '(' dr_strength0 ')' gate_instance_list ';'
1819 { pform_makegates(PGBuiltin::PULLDOWN, $3, 0, $5, 0);
1822 /* This rule handles instantiations of modules and user defined
1823 primitives. These devices to not have delay lists or strengths,
1824 but then can have parameter lists. */
1826 | attribute_list_opt
1827 IDENTIFIER parameter_value_opt gate_instance_list ';'
1828 { perm_string tmp1 = lex_strings.make($2);
1829 pform_make_modgates(tmp1, $3, $4);
1830 delete $2;
1831 if ($1) delete $1;
1834 | attribute_list_opt
1835 IDENTIFIER parameter_value_opt error ';'
1836 { yyerror(@2, "error: Invalid module instantiation");
1837 if ($1) delete $1;
1840 /* Continuous assignment can have an optional drive strength, then
1841 an optional delay3 that applies to all the assignments in the
1842 cont_assign_list. */
1844 | K_assign drive_strength_opt delay3_opt cont_assign_list ';'
1845 { pform_make_pgassign_list($4, $3, $2, @1.text, @1.first_line); }
1847 /* Always and initial items are behavioral processes. */
1849 | attribute_list_opt K_always statement
1850 { PProcess*tmp = pform_make_behavior(PProcess::PR_ALWAYS,
1851 $3, $1);
1852 tmp->set_file(@2.text);
1853 tmp->set_lineno(@2.first_line);
1855 | attribute_list_opt K_initial statement
1856 { PProcess*tmp = pform_make_behavior(PProcess::PR_INITIAL,
1857 $3, $1);
1858 tmp->set_file(@2.text);
1859 tmp->set_lineno(@2.first_line);
1862 /* The task declaration rule matches the task declaration
1863 header, then pushes the function scope. This causes the
1864 definitions in the task_body to take on the scope of the task
1865 instead of the module. Note that these runs accept for the task
1866 body statement_or_null, although the standard does not allow null
1867 statements in the task body. But we continue to accept it as an
1868 extension. */
1870 | K_task IDENTIFIER ';'
1871 { pform_push_scope($2); }
1872 task_item_list_opt
1873 statement_or_null
1874 K_endtask
1875 { PTask*tmp = new PTask;
1876 perm_string tmp2 = lex_strings.make($2);
1877 tmp->set_file(@1.text);
1878 tmp->set_lineno(@1.first_line);
1879 tmp->set_ports($5);
1880 tmp->set_statement($6);
1881 pform_set_task(tmp2, tmp);
1882 pform_pop_scope();
1883 delete $2;
1886 | K_task IDENTIFIER
1887 { pform_push_scope($2); }
1888 '(' task_port_decl_list ')' ';'
1889 task_item_list_opt
1890 statement_or_null
1891 K_endtask
1892 { PTask*tmp = new PTask;
1893 perm_string tmp2 = lex_strings.make($2);
1894 tmp->set_file(@1.text);
1895 tmp->set_lineno(@1.first_line);
1896 tmp->set_ports($5);
1897 tmp->set_statement($9);
1898 pform_set_task(tmp2, tmp);
1899 pform_pop_scope();
1900 delete $2;
1903 /* The function declaration rule matches the function declaration
1904 header, then pushes the function scope. This causes the
1905 definitions in the func_body to take on the scope of the function
1906 instead of the module. */
1908 | K_function function_range_or_type_opt IDENTIFIER ';'
1909 { pform_push_scope($3); }
1910 function_item_list statement
1911 K_endfunction
1912 { perm_string name = lex_strings.make($3);
1913 PFunction *tmp = new PFunction(name);
1914 tmp->set_file(@1.text);
1915 tmp->set_lineno(@1.first_line);
1916 tmp->set_ports($6);
1917 tmp->set_statement($7);
1918 tmp->set_return($2);
1919 pform_set_function(name, tmp);
1920 pform_pop_scope();
1921 delete $3;
1924 /* A generate region can contain further module items. Actually, it
1925 is supposed to be limited to certain kinds of module items, but
1926 the semantic tests will check that for us. */
1928 | K_generate module_item_list_opt K_endgenerate
1930 | K_genvar list_of_identifiers ';'
1931 { pform_genvars($2); }
1933 | K_for '(' IDENTIFIER '=' expression ';'
1934 expression ';'
1935 IDENTIFIER '=' expression ')'
1936 { pform_start_generate_for(@1, $3, $5, $7, $9, $11); }
1937 generate_block
1938 { pform_endgenerate(); }
1940 | generate_if
1941 generate_block_opt
1942 K_else
1943 { pform_start_generate_else(@1); }
1944 generate_block
1945 { pform_endgenerate(); }
1947 | generate_if
1948 generate_block_opt %prec less_than_K_else
1949 { pform_endgenerate(); }
1951 /* specify blocks are parsed but ignored. */
1953 | K_specify K_endspecify
1954 { /* empty lists are legal syntax. */ }
1956 | K_specify specify_item_list K_endspecify
1960 | K_specify error K_endspecify
1961 { yyerror(@1, "error: syntax error in specify block");
1962 yyerrok;
1965 /* These rules match various errors that the user can type into
1966 module items. These rules try to catch them at a point where a
1967 reasonable error message can be produced. */
1969 | K_module error ';'
1970 { yyerror(@2, "error: missing endmodule or attempt to "
1971 "nest modules.");
1972 pform_error_nested_modules();
1973 yyerrok;
1976 | error ';'
1977 { yyerror(@2, "error: invalid module item.");
1978 yyerrok;
1981 | K_assign error '=' expression ';'
1982 { yyerror(@1, "error: syntax error in left side "
1983 "of continuous assignment.");
1984 yyerrok;
1987 | K_assign error ';'
1988 { yyerror(@1, "error: syntax error in "
1989 "continuous assignment");
1990 yyerrok;
1993 | K_function error K_endfunction
1994 { yyerror(@1, "error: I give up on this "
1995 "function definition.");
1996 yyerrok;
1999 /* These rules are for the Icarus Verilog specific $attribute
2000 extensions. Then catch the parameters of the $attribute keyword. */
2002 | KK_attribute '(' IDENTIFIER ',' STRING ',' STRING ')' ';'
2003 { perm_string tmp3 = lex_strings.make($3);
2004 perm_string tmp5 = lex_strings.make($5);
2005 pform_set_attrib(tmp3, tmp5, $7);
2006 delete $3;
2007 delete $5;
2009 | KK_attribute '(' error ')' ';'
2010 { yyerror(@1, "error: Malformed $attribute parameter list."); }
2013 generate_if : K_if '(' expression ')' { pform_start_generate_if(@1, $3); }
2015 module_item_list
2016 : module_item_list module_item
2017 | module_item
2020 module_item_list_opt
2021 : module_item_list
2025 /* A generate block is the thing within a generate scheme. It may be
2026 a single module item, an anonymous block of module items, or a
2027 named module item. In all cases, the meat is in the module items
2028 inside, and the processing is done by the module_item rules. We
2029 only need to take note here of the scope name, if any. */
2031 generate_block
2032 : module_item
2033 | K_begin module_item_list_opt K_end
2034 | K_begin ':' IDENTIFIER module_item_list_opt K_end
2035 { pform_generate_block_name($3); }
2038 generate_block_opt : generate_block | ';' ;
2041 /* A net declaration assignment allows the programmer to combine the
2042 net declaration and the continuous assignment into a single
2043 statement.
2045 Note that the continuous assignment statement is generated as a
2046 side effect, and all I pass up is the name of the l-value. */
2048 net_decl_assign
2049 : IDENTIFIER '=' expression
2050 { net_decl_assign_t*tmp = new net_decl_assign_t;
2051 tmp->next = tmp;
2052 tmp->name = $1;
2053 tmp->expr = $3;
2054 $$ = tmp;
2058 net_decl_assigns
2059 : net_decl_assigns ',' net_decl_assign
2060 { net_decl_assign_t*tmp = $1;
2061 $3->next = tmp->next;
2062 tmp->next = $3;
2063 $$ = tmp;
2065 | net_decl_assign
2066 { $$ = $1;
2070 primitive_type
2071 : K_logic { $$ = IVL_VT_LOGIC; }
2072 | K_bool { $$ = IVL_VT_BOOL; }
2073 | K_real { $$ = IVL_VT_REAL; }
2076 primitive_type_opt : primitive_type { $$ = $1; } | { $$ = IVL_VT_NO_TYPE; } ;
2078 net_type
2079 : K_wire { $$ = NetNet::WIRE; }
2080 | K_tri { $$ = NetNet::TRI; }
2081 | K_tri1 { $$ = NetNet::TRI1; }
2082 | K_supply0 { $$ = NetNet::SUPPLY0; }
2083 | K_wand { $$ = NetNet::WAND; }
2084 | K_triand { $$ = NetNet::TRIAND; }
2085 | K_tri0 { $$ = NetNet::TRI0; }
2086 | K_supply1 { $$ = NetNet::SUPPLY1; }
2087 | K_wor { $$ = NetNet::WOR; }
2088 | K_trior { $$ = NetNet::TRIOR; }
2089 | K_wone { $$ = NetNet::WONE; }
2092 var_type
2093 : K_reg { $$ = NetNet::REG; }
2096 /* In this rule we have matched the "parameter" keyword. The rule
2097 generates a type (optional) and a list of assignments. */
2099 parameter_assign_decl
2100 : parameter_assign_list
2101 | range { active_range = $1; active_signed = false; }
2102 parameter_assign_list
2103 { active_range = 0;
2104 active_signed = false;
2106 | K_signed range { active_range = $2; active_signed = true; }
2107 parameter_assign_list
2108 { active_range = 0;
2109 active_signed = false;
2111 | K_integer { active_range = 0; active_signed = true; }
2112 parameter_assign_list
2113 { active_range = 0;
2114 active_signed = false;
2118 parameter_assign_list
2119 : parameter_assign
2120 | parameter_assign_list ',' parameter_assign
2123 parameter_assign
2124 : IDENTIFIER '=' expression
2125 { PExpr*tmp = $3;
2126 if (!pform_expression_is_constant(tmp)) {
2127 yyerror(@3, "error: parameter value "
2128 "must be a constant expression.");
2129 delete tmp;
2130 tmp = 0;
2131 } else {
2132 pform_set_parameter(lex_strings.make($1),
2133 active_signed,
2134 active_range, tmp);
2136 delete $1;
2140 /* Localparam assignments and assignment lists are broken into
2141 separate BNF so that I can call slightly different parameter
2142 handling code. They parse the same as parameters, they just
2143 behave differently when someone tries to override them. */
2145 localparam_assign
2146 : IDENTIFIER '=' expression
2147 { PExpr*tmp = $3;
2148 if (!pform_expression_is_constant(tmp)) {
2149 yyerror(@3, "error: parameter value "
2150 "must be constant.");
2151 delete tmp;
2152 tmp = 0;
2153 } else {
2154 pform_set_localparam(lex_strings.make($1),
2155 active_signed,
2156 active_range, tmp);
2158 delete $1;
2162 localparam_assign_decl
2163 : localparam_assign_list
2164 | range { active_range = $1; active_signed = false; }
2165 localparam_assign_list
2166 { active_range = 0;
2167 active_signed = false;
2169 | K_signed range { active_range = $2; active_signed = true; }
2170 localparam_assign_list
2171 { active_range = 0;
2172 active_signed = false;
2176 localparam_assign_list
2177 : localparam_assign
2178 | localparam_assign_list ',' localparam_assign
2183 /* The parameters of a module instance can be overridden by writing
2184 a list of expressions in a syntax much like a delay list. (The
2185 difference being the list can have any length.) The pform that
2186 attaches the expression list to the module checks that the
2187 expressions are constant.
2189 Although the BNF in IEEE1364-1995 implies that parameter value
2190 lists must be in parentheses, in practice most compilers will
2191 accept simple expressions outside of parentheses if there is only
2192 one value, so I'll accept simple numbers here.
2194 The parameter value by name syntax is OVI enhancement BTF-B06 as
2195 approved by WG1364 on 6/28/1998. */
2197 parameter_value_opt
2198 : '#' '(' expression_list_with_nuls ')'
2199 { struct parmvalue_t*tmp = new struct parmvalue_t;
2200 tmp->by_order = $3;
2201 tmp->by_name = 0;
2202 $$ = tmp;
2204 | '#' '(' parameter_value_byname_list ')'
2205 { struct parmvalue_t*tmp = new struct parmvalue_t;
2206 tmp->by_order = 0;
2207 tmp->by_name = $3;
2208 $$ = tmp;
2210 | '#' DEC_NUMBER
2211 { assert($2);
2212 PENumber*tmp = new PENumber($2);
2213 tmp->set_file(@1.text);
2214 tmp->set_lineno(@1.first_line);
2216 struct parmvalue_t*lst = new struct parmvalue_t;
2217 lst->by_order = new svector<PExpr*>(1);
2218 (*lst->by_order)[0] = tmp;
2219 lst->by_name = 0;
2220 $$ = lst;
2222 | '#' error
2223 { yyerror(@1, "error: syntax error in parameter value "
2224 "assignment list.");
2225 $$ = 0;
2228 { $$ = 0; }
2231 parameter_value_byname
2232 : '.' IDENTIFIER '(' expression ')'
2233 { named_pexpr_t*tmp = new named_pexpr_t;
2234 tmp->name = lex_strings.make($2);
2235 tmp->parm = $4;
2236 free($2);
2237 $$ = tmp;
2239 | '.' IDENTIFIER '(' ')'
2240 { named_pexpr_t*tmp = new named_pexpr_t;
2241 tmp->name = lex_strings.make($2);
2242 tmp->parm = 0;
2243 free($2);
2244 $$ = tmp;
2248 parameter_value_byname_list
2249 : parameter_value_byname
2250 { svector<named_pexpr_t*>*tmp = new svector<named_pexpr_t*>(1);
2251 (*tmp)[0] = $1;
2252 $$ = tmp;
2254 | parameter_value_byname_list ',' parameter_value_byname
2255 { svector<named_pexpr_t*>*tmp =
2256 new svector<named_pexpr_t*>(*$1,$3);
2257 delete $1;
2258 $$ = tmp;
2263 /* The port (of a module) is a fairly complex item. Each port is
2264 handled as a Module::port_t object. A simple port reference has a
2265 name and a PExpr object, but more complex constructs are possible
2266 where the name can be attached to a list of PWire objects.
2268 The port_reference returns a Module::port_t, and so does the
2269 port_reference_list. The port_reference_list may have built up a
2270 list of PWires in the port_t object, but it is still a single
2271 Module::port_t object.
2273 The port rule below takes the built up Module::port_t object and
2274 tweaks its name as needed. */
2276 port
2277 : port_reference
2278 { $$ = $1; }
2280 /* This syntax attaches an external name to the port reference so
2281 that the caller can bind by name to non-trivial port
2282 references. The port_t object gets its PWire from the
2283 port_reference, but its name from the IDENTIFIER. */
2285 | '.' IDENTIFIER '(' port_reference ')'
2286 { Module::port_t*tmp = $4;
2287 tmp->name = lex_strings.make($2);
2288 delete $2;
2289 $$ = tmp;
2292 /* A port can also be a concatenation of port references. In this
2293 case the port does not have a name available to the outside, only
2294 positional parameter passing is possible here. */
2296 | '{' port_reference_list '}'
2297 { Module::port_t*tmp = $2;
2298 tmp->name = perm_string();
2299 $$ = tmp;
2302 /* This attaches a name to a port reference concatenation list so
2303 that parameter passing be name is possible. */
2305 | '.' IDENTIFIER '(' '{' port_reference_list '}' ')'
2306 { Module::port_t*tmp = $5;
2307 tmp->name = lex_strings.make($2);
2308 delete $2;
2309 $$ = tmp;
2313 port_opt
2314 : port { $$ = $1; }
2315 | { $$ = 0; }
2319 /* A port reference is an internal (to the module) name of the port,
2320 possibly with a part of bit select to attach it to specific bits
2321 of a signal fully declared inside the module.
2323 The parser creates a PEIdent for every port reference, even if the
2324 signal is bound to different ports. The elaboration figures out
2325 the mess that this creates. The port_reference (and the
2326 port_reference_list below) puts the port reference PEIdent into the
2327 port_t object to pass it up to the module declaration code. */
2329 port_reference
2331 : IDENTIFIER
2332 { Module::port_t*ptmp;
2333 ptmp = pform_module_port_reference($1, @1.text, @1.first_line);
2334 delete $1;
2335 $$ = ptmp;
2338 | IDENTIFIER '[' expression ':' expression ']'
2339 { if (!pform_expression_is_constant($3)) {
2340 yyerror(@3, "error: msb expression of "
2341 "port part select must be constant.");
2343 if (!pform_expression_is_constant($5)) {
2344 yyerror(@5, "error: lsb expression of "
2345 "port part select must be constant.");
2347 index_component_t itmp;
2348 itmp.sel = index_component_t::SEL_PART;
2349 itmp.msb = $3;
2350 itmp.lsb = $5;
2352 name_component_t ntmp (lex_strings.make($1));
2353 ntmp.index.push_back(itmp);
2355 pform_name_t pname;
2356 pname.push_back(ntmp);
2358 PEIdent*wtmp = new PEIdent(pname);
2359 wtmp->set_file(@1.text);
2360 wtmp->set_lineno(@1.first_line);
2362 Module::port_t*ptmp = new Module::port_t;
2363 ptmp->name = perm_string();
2364 ptmp->expr = svector<PEIdent*>(1);
2365 ptmp->expr[0] = wtmp;
2367 delete $1;
2368 $$ = ptmp;
2371 | IDENTIFIER '[' expression ']'
2372 { if (!pform_expression_is_constant($3)) {
2373 yyerror(@3, "error: port bit select "
2374 "must be constant.");
2376 index_component_t itmp;
2377 itmp.sel = index_component_t::SEL_BIT;
2378 itmp.msb = $3;
2379 itmp.lsb = 0;
2381 name_component_t ntmp (lex_strings.make($1));
2382 ntmp.index.push_back(itmp);
2384 pform_name_t pname;
2385 pname.push_back(ntmp);
2387 PEIdent*tmp = new PEIdent(pname);
2388 tmp->set_file(@1.text);
2389 tmp->set_lineno(@1.first_line);
2391 Module::port_t*ptmp = new Module::port_t;
2392 ptmp->name = perm_string();
2393 ptmp->expr = svector<PEIdent*>(1);
2394 ptmp->expr[0] = tmp;
2395 delete $1;
2396 $$ = ptmp;
2399 | IDENTIFIER '[' error ']'
2400 { yyerror(@1, "error: invalid port bit select");
2401 Module::port_t*ptmp = new Module::port_t;
2402 PEIdent*wtmp = new PEIdent(lex_strings.make($1));
2403 wtmp->set_file(@1.text);
2404 wtmp->set_lineno(@1.first_line);
2405 ptmp->name = lex_strings.make($1);
2406 ptmp->expr = svector<PEIdent*>(1);
2407 ptmp->expr[0] = wtmp;
2408 delete $1;
2409 $$ = ptmp;
2414 port_reference_list
2415 : port_reference
2416 { $$ = $1; }
2417 | port_reference_list ',' port_reference
2418 { Module::port_t*tmp = $1;
2419 tmp->expr = svector<PEIdent*>(tmp->expr, $3->expr);
2420 delete $3;
2421 $$ = tmp;
2425 /* The port_name rule is used with a module is being *instantiated*,
2426 and not when it is being declared. See the port rule if you are
2427 looking for the ports of a module declaration. */
2429 port_name
2430 : '.' IDENTIFIER '(' expression ')'
2431 { named_pexpr_t*tmp = new named_pexpr_t;
2432 tmp->name = lex_strings.make($2);
2433 tmp->parm = $4;
2434 delete $2;
2435 $$ = tmp;
2437 | '.' IDENTIFIER '(' error ')'
2438 { yyerror(@4, "error: invalid port connection expression.");
2439 named_pexpr_t*tmp = new named_pexpr_t;
2440 tmp->name = lex_strings.make($2);
2441 tmp->parm = 0;
2442 delete $2;
2443 $$ = tmp;
2445 | '.' IDENTIFIER '(' ')'
2446 { named_pexpr_t*tmp = new named_pexpr_t;
2447 tmp->name = lex_strings.make($2);
2448 tmp->parm = 0;
2449 delete $2;
2450 $$ = tmp;
2454 port_name_list
2455 : port_name_list ',' port_name
2456 { svector<named_pexpr_t*>*tmp;
2457 tmp = new svector<named_pexpr_t*>(*$1, $3);
2458 delete $1;
2459 $$ = tmp;
2461 | port_name
2462 { svector<named_pexpr_t*>*tmp = new svector<named_pexpr_t*>(1);
2463 (*tmp)[0] = $1;
2464 $$ = tmp;
2468 port_type
2469 : K_input { $$ = NetNet::PINPUT; }
2470 | K_output { $$ = NetNet::POUTPUT; }
2471 | K_inout { $$ = NetNet::PINOUT; }
2474 range
2475 : '[' expression ':' expression ']'
2476 { svector<PExpr*>*tmp = new svector<PExpr*> (2);
2477 if (!pform_expression_is_constant($2))
2478 yyerror(@2, "error: msb of range must be constant.");
2480 (*tmp)[0] = $2;
2482 if (!pform_expression_is_constant($4))
2483 yyerror(@4, "error: lsb of range must be constant.");
2485 (*tmp)[1] = $4;
2487 $$ = tmp;
2491 range_opt
2492 : range
2493 | { $$ = 0; }
2496 /* This is used to express the return type of a function. */
2497 function_range_or_type_opt
2498 : range { $$.range = $1; $$.type = PTF_REG; }
2499 | K_signed range { $$.range = $2; $$.type = PTF_REG_S; }
2500 | K_integer { $$.range = 0; $$.type = PTF_INTEGER; }
2501 | K_real { $$.range = 0; $$.type = PTF_REAL; }
2502 | K_realtime { $$.range = 0; $$.type = PTF_REALTIME; }
2503 | K_time { $$.range = 0; $$.type = PTF_TIME; }
2504 | { $$.range = 0; $$.type = PTF_REG; }
2507 /* The register_variable rule is matched only when I am parsing
2508 variables in a "reg" definition. I therefore know that I am
2509 creating registers and I do not need to let the containing rule
2510 handle it. The register variable list simply packs them together
2511 so that bit ranges can be assigned. */
2512 register_variable
2513 : IDENTIFIER
2514 { pform_makewire(@1, $1, NetNet::REG,
2515 NetNet::NOT_A_PORT,
2516 IVL_VT_NO_TYPE, 0);
2517 $$ = $1;
2519 | IDENTIFIER '=' expression
2520 { pform_makewire(@1, $1, NetNet::REG,
2521 NetNet::NOT_A_PORT,
2522 IVL_VT_NO_TYPE, 0);
2523 if (! pform_expression_is_constant($3))
2524 yyerror(@3, "error: register declaration assignment"
2525 " value must be a constant expression.");
2526 pform_make_reginit(@1, $1, $3);
2527 $$ = $1;
2529 | IDENTIFIER '[' expression ':' expression ']'
2530 { pform_makewire(@1, $1, NetNet::REG,
2531 NetNet::NOT_A_PORT,
2532 IVL_VT_NO_TYPE, 0);
2533 if (! pform_expression_is_constant($3))
2534 yyerror(@3, "error: msb of register range must be constant.");
2535 if (! pform_expression_is_constant($5))
2536 yyerror(@3, "error: lsb of register range must be constant.");
2537 pform_set_reg_idx($1, $3, $5);
2538 $$ = $1;
2542 register_variable_list
2543 : register_variable
2544 { list<perm_string>*tmp = new list<perm_string>;
2545 tmp->push_back(lex_strings.make($1));
2546 $$ = tmp;
2547 delete[]$1;
2549 | register_variable_list ',' register_variable
2550 { list<perm_string>*tmp = $1;
2551 tmp->push_back(lex_strings.make($3));
2552 $$ = tmp;
2553 delete[]$3;
2557 real_variable
2558 : IDENTIFIER
2559 { pform_makewire(@1, $1, NetNet::REG, NetNet::NOT_A_PORT, IVL_VT_REAL, 0);
2560 $$ = $1;
2562 | IDENTIFIER '=' expression
2563 { pform_makewire(@1, $1, NetNet::REG, NetNet::NOT_A_PORT, IVL_VT_REAL, 0);
2564 pform_make_reginit(@1, $1, $3);
2565 $$ = $1;
2569 real_variable_list
2570 : real_variable
2571 { list<perm_string>*tmp = new list<perm_string>;
2572 tmp->push_back(lex_strings.make($1));
2573 $$ = tmp;
2574 delete[]$1;
2576 | real_variable_list ',' real_variable
2577 { list<perm_string>*tmp = $1;
2578 tmp->push_back(lex_strings.make($3));
2579 $$ = tmp;
2580 delete[]$3;
2584 net_variable
2585 : IDENTIFIER
2586 { pform_makewire(@1, $1, NetNet::IMPLICIT,
2587 NetNet::NOT_A_PORT,
2588 IVL_VT_NO_TYPE, 0);
2589 $$ = $1;
2591 | IDENTIFIER '[' expression ':' expression ']'
2592 { pform_makewire(@1, $1, NetNet::IMPLICIT,
2593 NetNet::NOT_A_PORT,
2594 IVL_VT_NO_TYPE, 0);
2595 if (! pform_expression_is_constant($3))
2596 yyerror(@3, "error: msb of net range must be constant.");
2597 if (! pform_expression_is_constant($5))
2598 yyerror(@3, "error: lsb of net range must be constant.");
2599 pform_set_reg_idx($1, $3, $5);
2600 $$ = $1;
2603 net_variable_list
2604 : net_variable
2605 { list<perm_string>*tmp = new list<perm_string>;
2606 tmp->push_back(lex_strings.make($1));
2607 $$ = tmp;
2608 delete[]$1;
2610 | net_variable_list ',' net_variable
2611 { list<perm_string>*tmp = $1;
2612 tmp->push_back(lex_strings.make($3));
2613 $$ = tmp;
2614 delete[]$3;
2618 specify_item
2619 : K_specparam specparam_list ';'
2620 | specify_simple_path_decl ';'
2621 { pform_module_specify_path($1);
2623 | specify_edge_path_decl ';'
2624 { pform_module_specify_path($1);
2626 | K_if '(' expression ')' specify_simple_path_decl ';'
2627 { PSpecPath*tmp = $5;
2628 if (tmp) {
2629 tmp->conditional = true;
2630 tmp->condition = $3;
2632 pform_module_specify_path(tmp);
2634 | K_if '(' expression ')' specify_edge_path_decl ';'
2635 { PSpecPath*tmp = $5;
2636 if (tmp) {
2637 tmp->conditional = true;
2638 tmp->condition = $3;
2640 pform_module_specify_path(tmp);
2642 | K_ifnone specify_simple_path_decl ';'
2643 { PSpecPath*tmp = $2;
2644 if (tmp) {
2645 tmp->conditional = true;
2646 tmp->condition = 0;
2648 pform_module_specify_path(tmp);
2650 | K_Shold '(' spec_reference_event ',' spec_reference_event
2651 ',' delay_value spec_notifier_opt ')' ';'
2652 { delete $7;
2654 | K_Speriod '(' spec_reference_event ',' delay_value
2655 spec_notifier_opt ')' ';'
2656 { delete $5;
2658 | K_Srecovery '(' spec_reference_event ',' spec_reference_event
2659 ',' delay_value spec_notifier_opt ')' ';'
2660 { delete $7;
2662 | K_Ssetup '(' spec_reference_event ',' spec_reference_event
2663 ',' delay_value spec_notifier_opt ')' ';'
2664 { delete $7;
2666 | K_Ssetuphold '(' spec_reference_event ',' spec_reference_event
2667 ',' delay_value ',' delay_value spec_notifier_opt ')' ';'
2668 { delete $7;
2669 delete $9;
2671 | K_Srecrem '(' spec_reference_event ',' spec_reference_event
2672 ',' delay_value ',' delay_value spec_notifier_opt ')' ';'
2673 { delete $7;
2674 delete $9;
2676 | K_Swidth '(' spec_reference_event ',' delay_value ',' expression
2677 spec_notifier_opt ')' ';'
2678 { delete $5;
2679 delete $7;
2681 | K_Swidth '(' spec_reference_event ',' delay_value ')' ';'
2682 { delete $5;
2686 specify_item_list
2687 : specify_item
2688 | specify_item_list specify_item
2691 specify_edge_path_decl
2692 : specify_edge_path '=' '(' delay_value_list ')'
2693 { $$ = pform_assign_path_delay($1, $4); }
2694 | specify_edge_path '=' delay_value_simple
2695 { svector<PExpr*>*tmp = new svector<PExpr*>(1);
2696 (*tmp)[0] = $3;
2697 $$ = pform_assign_path_delay($1, tmp);
2701 edge_operator : K_posedge { $$ = true; } | K_negedge { $$ = false; } ;
2703 specify_edge_path
2704 : '(' specify_path_identifiers spec_polarity
2705 K_EG '(' specify_path_identifiers polarity_operator expression ')' ')'
2706 { int edge_flag = 0;
2707 $$ = pform_make_specify_edge_path(@1, edge_flag, $2, $3, false, $6, $8); }
2708 | '(' edge_operator specify_path_identifiers spec_polarity
2709 K_EG '(' specify_path_identifiers polarity_operator expression ')' ')'
2710 { int edge_flag = $2? 1 : -1;
2711 $$ = pform_make_specify_edge_path(@1, edge_flag, $3, $4, false, $7, $9);}
2712 | '(' specify_path_identifiers spec_polarity
2713 K_SG '(' specify_path_identifiers polarity_operator expression ')' ')'
2714 { int edge_flag = 0;
2715 $$ = pform_make_specify_edge_path(@1, edge_flag, $2, $3, true, $6, $8); }
2716 | '(' edge_operator specify_path_identifiers spec_polarity
2717 K_SG '(' specify_path_identifiers polarity_operator expression ')' ')'
2718 { int edge_flag = $2? 1 : -1;
2719 $$ = pform_make_specify_edge_path(@1, edge_flag, $3, $4, true, $7, $9); }
2722 polarity_operator
2723 : K_PO_POS
2724 | K_PO_NEG
2725 | ':'
2728 specify_simple_path_decl
2729 : specify_simple_path '=' '(' delay_value_list ')'
2730 { $$ = pform_assign_path_delay($1, $4); }
2731 | specify_simple_path '=' delay_value_simple
2732 { svector<PExpr*>*tmp = new svector<PExpr*>(1);
2733 (*tmp)[0] = $3;
2734 $$ = pform_assign_path_delay($1, tmp);
2736 | specify_simple_path '=' '(' error ')'
2737 { yyerror(@2, "Syntax error in delay value list.");
2738 yyerrok;
2739 $$ = 0;
2743 specify_simple_path
2744 : '(' specify_path_identifiers spec_polarity
2745 K_EG specify_path_identifiers ')'
2746 { $$ = pform_make_specify_path(@1, $2, $3, false, $5); }
2747 | '(' specify_path_identifiers spec_polarity
2748 K_SG specify_path_identifiers ')'
2749 { $$ = pform_make_specify_path(@1, $2, $3, true, $5); }
2750 | '(' error ')'
2751 { yyerror(@2, "Invalid simple path");
2752 yyerrok;
2756 specify_path_identifiers
2757 : IDENTIFIER
2758 { list<perm_string>*tmp = new list<perm_string>;
2759 tmp->push_back(lex_strings.make($1));
2760 $$ = tmp;
2761 delete[]$1;
2763 | IDENTIFIER '[' expr_primary ']'
2764 { list<perm_string>*tmp = new list<perm_string>;
2765 tmp->push_back(lex_strings.make($1));
2766 $$ = tmp;
2767 delete[]$1;
2769 | specify_path_identifiers ',' IDENTIFIER
2770 { list<perm_string>*tmp = $1;
2771 tmp->push_back(lex_strings.make($3));
2772 $$ = tmp;
2773 delete[]$3;
2775 | specify_path_identifiers ',' IDENTIFIER '[' expr_primary ']'
2776 { list<perm_string>*tmp = $1;
2777 tmp->push_back(lex_strings.make($3));
2778 $$ = tmp;
2779 delete[]$3;
2783 specparam
2784 : IDENTIFIER '=' expression
2785 { PExpr*tmp = $3;
2786 pform_set_specparam(lex_strings.make($1), tmp);
2787 delete $1;
2789 | IDENTIFIER '=' expression ':' expression ':' expression
2790 { PExpr*tmp = 0;
2791 switch (min_typ_max_flag) {
2792 case MIN:
2793 tmp = $3;
2794 delete $5;
2795 delete $7;
2796 break;
2797 case TYP:
2798 delete $3;
2799 tmp = $5;
2800 delete $7;
2801 break;
2802 case MAX:
2803 delete $3;
2804 delete $5;
2805 tmp = $7;
2806 break;
2808 pform_set_specparam(lex_strings.make($1), tmp);
2809 delete $1;
2811 | PATHPULSE_IDENTIFIER '=' expression
2812 { delete $1;
2813 delete $3;
2815 | PATHPULSE_IDENTIFIER '=' '(' expression ',' expression ')'
2816 { delete $1;
2817 delete $4;
2818 delete $6;
2822 specparam_list
2823 : specparam
2824 | specparam_list ',' specparam
2827 spec_polarity
2828 : '+' { $$ = '+'; }
2829 | '-' { $$ = '-'; }
2830 | { $$ = 0; }
2833 spec_reference_event
2834 : K_posedge expression
2835 { delete $2; }
2836 | K_negedge expression
2837 { delete $2; }
2838 | K_posedge expr_primary K_TAND expression
2839 { delete $2;
2840 delete $4;
2842 | K_negedge expr_primary K_TAND expression
2843 { delete $2;
2844 delete $4;
2846 | K_edge '[' edge_descriptor_list ']' expr_primary K_TAND expression
2847 { delete $5;
2848 delete $7;
2850 | expr_primary K_TAND expression
2851 { delete $1;
2852 delete $3;
2854 | expr_primary
2855 { delete $1; }
2858 /* The edge_descriptor is detected by the lexor as the various
2859 2-letter edge sequences that are supported here. For now, we
2860 don't care what they are, because we do not yet support specify
2861 edge events. */
2862 edge_descriptor_list
2863 : edge_descriptor_list ',' K_edge_descriptor
2864 | K_edge_descriptor
2867 spec_notifier_opt
2868 : /* empty */
2870 | spec_notifier
2873 spec_notifier
2874 : ','
2876 | ',' heirarchy_identifier
2877 { delete $2; }
2878 | spec_notifier ','
2880 | spec_notifier ',' heirarchy_identifier
2881 { delete $3; }
2882 | IDENTIFIER
2883 { delete $1; }
2887 statement
2889 /* assign and deassign statements are procedural code to do
2890 structural assignments, and to turn that structural assignment
2891 off. This stronger then any other assign, but weaker then the
2892 force assignments. */
2894 : K_assign lpvalue '=' expression ';'
2895 { PCAssign*tmp = new PCAssign($2, $4);
2896 tmp->set_file(@1.text);
2897 tmp->set_lineno(@1.first_line);
2898 $$ = tmp;
2901 | K_deassign lpvalue ';'
2902 { PDeassign*tmp = new PDeassign($2);
2903 tmp->set_file(@1.text);
2904 tmp->set_lineno(@1.first_line);
2905 $$ = tmp;
2909 /* Force and release statements are similar to assignments,
2910 syntactically, but they will be elaborated differently. */
2912 | K_force lpvalue '=' expression ';'
2913 { PForce*tmp = new PForce($2, $4);
2914 tmp->set_file(@1.text);
2915 tmp->set_lineno(@1.first_line);
2916 $$ = tmp;
2918 | K_release lpvalue ';'
2919 { PRelease*tmp = new PRelease($2);
2920 tmp->set_file(@1.text);
2921 tmp->set_lineno(@1.first_line);
2922 $$ = tmp;
2925 /* begin-end blocks come in a variety of forms, including named and
2926 anonymous. The named blocks can also carry their own reg
2927 variables, which are placed in the scope created by the block
2928 name. These are handled by pushing the scope name then matching
2929 the declarations. The scope is popped at the end of the block. */
2931 | K_begin statement_list K_end
2932 { PBlock*tmp = new PBlock(PBlock::BL_SEQ, *$2);
2933 tmp->set_file(@1.text);
2934 tmp->set_lineno(@1.first_line);
2935 delete $2;
2936 $$ = tmp;
2938 | K_begin ':' IDENTIFIER
2939 { pform_push_scope($3); }
2940 block_item_decls_opt
2941 statement_list K_end
2942 { pform_pop_scope();
2943 PBlock*tmp = new PBlock(lex_strings.make($3),
2944 PBlock::BL_SEQ, *$6);
2945 tmp->set_file(@1.text);
2946 tmp->set_lineno(@1.first_line);
2947 delete $3;
2948 delete $6;
2949 $$ = tmp;
2951 | K_begin K_end
2952 { PBlock*tmp = new PBlock(PBlock::BL_SEQ);
2953 tmp->set_file(@1.text);
2954 tmp->set_lineno(@1.first_line);
2955 $$ = tmp;
2957 | K_begin ':' IDENTIFIER K_end
2958 { PBlock*tmp = new PBlock(PBlock::BL_SEQ);
2959 tmp->set_file(@1.text);
2960 tmp->set_lineno(@1.first_line);
2961 $$ = tmp;
2963 | K_begin error K_end
2964 { yyerrok; }
2966 /* fork-join blocks are very similar to begin-end blocks. In fact,
2967 from the parser's perspective there is no real difference. All we
2968 need to do is remember that this is a parallel block so that the
2969 code generator can do the right thing. */
2971 | K_fork ':' IDENTIFIER
2972 { pform_push_scope($3); }
2973 block_item_decls_opt
2974 statement_list K_join
2975 { pform_pop_scope();
2976 PBlock*tmp = new PBlock(lex_strings.make($3),
2977 PBlock::BL_PAR, *$6);
2978 tmp->set_file(@1.text);
2979 tmp->set_lineno(@1.first_line);
2980 delete $3;
2981 delete $6;
2982 $$ = tmp;
2984 | K_fork K_join
2985 { PBlock*tmp = new PBlock(PBlock::BL_PAR);
2986 tmp->set_file(@1.text);
2987 tmp->set_lineno(@1.first_line);
2988 $$ = tmp;
2990 | K_fork ':' IDENTIFIER K_join
2991 { PBlock*tmp = new PBlock(PBlock::BL_PAR);
2992 tmp->set_file(@1.text);
2993 tmp->set_lineno(@1.first_line);
2994 delete $3;
2995 $$ = tmp;
2998 | K_disable heirarchy_identifier ';'
2999 { PDisable*tmp = new PDisable(*$2);
3000 tmp->set_file(@1.text);
3001 tmp->set_lineno(@1.first_line);
3002 delete $2;
3003 $$ = tmp;
3005 | K_TRIGGER heirarchy_identifier ';'
3006 { PTrigger*tmp = new PTrigger(*$2);
3007 tmp->set_file(@2.text);
3008 tmp->set_lineno(@2.first_line);
3009 delete $2;
3010 $$ = tmp;
3012 | K_forever statement
3013 { PForever*tmp = new PForever($2);
3014 tmp->set_file(@1.text);
3015 tmp->set_lineno(@1.first_line);
3016 $$ = tmp;
3018 | K_fork statement_list K_join
3019 { PBlock*tmp = new PBlock(PBlock::BL_PAR, *$2);
3020 tmp->set_file(@1.text);
3021 tmp->set_lineno(@1.first_line);
3022 delete $2;
3023 $$ = tmp;
3025 | K_repeat '(' expression ')' statement
3026 { PRepeat*tmp = new PRepeat($3, $5);
3027 tmp->set_file(@1.text);
3028 tmp->set_lineno(@1.first_line);
3029 $$ = tmp;
3031 | K_case '(' expression ')' case_items K_endcase
3032 { PCase*tmp = new PCase(NetCase::EQ, $3, $5);
3033 tmp->set_file(@1.text);
3034 tmp->set_lineno(@1.first_line);
3035 $$ = tmp;
3037 | K_casex '(' expression ')' case_items K_endcase
3038 { PCase*tmp = new PCase(NetCase::EQX, $3, $5);
3039 tmp->set_file(@1.text);
3040 tmp->set_lineno(@1.first_line);
3041 $$ = tmp;
3043 | K_casez '(' expression ')' case_items K_endcase
3044 { PCase*tmp = new PCase(NetCase::EQZ, $3, $5);
3045 tmp->set_file(@1.text);
3046 tmp->set_lineno(@1.first_line);
3047 $$ = tmp;
3049 | K_case '(' expression ')' error K_endcase
3050 { yyerrok; }
3051 | K_casex '(' expression ')' error K_endcase
3052 { yyerrok; }
3053 | K_casez '(' expression ')' error K_endcase
3054 { yyerrok; }
3055 | K_if '(' expression ')' statement_or_null %prec less_than_K_else
3056 { PCondit*tmp = new PCondit($3, $5, 0);
3057 tmp->set_file(@1.text);
3058 tmp->set_lineno(@1.first_line);
3059 $$ = tmp;
3061 | K_if '(' expression ')' statement_or_null K_else statement_or_null
3062 { PCondit*tmp = new PCondit($3, $5, $7);
3063 tmp->set_file(@1.text);
3064 tmp->set_lineno(@1.first_line);
3065 $$ = tmp;
3067 | K_if '(' error ')' statement_or_null %prec less_than_K_else
3068 { yyerror(@1, "error: Malformed conditional expression.");
3069 $$ = $5;
3071 | K_if '(' error ')' statement_or_null K_else statement_or_null
3072 { yyerror(@1, "error: Malformed conditional expression.");
3073 $$ = $5;
3075 | K_for '(' lpvalue '=' expression ';' expression ';'
3076 lpvalue '=' expression ')' statement
3077 { PForStatement*tmp = new PForStatement($3, $5, $7, $9, $11, $13);
3078 tmp->set_file(@1.text);
3079 tmp->set_lineno(@1.first_line);
3080 $$ = tmp;
3082 | K_for '(' lpvalue '=' expression ';' expression ';'
3083 error ')' statement
3084 { $$ = 0;
3085 yyerror(@9, "error: Error in for loop step assignment.");
3087 | K_for '(' lpvalue '=' expression ';' error ';'
3088 lpvalue '=' expression ')' statement
3089 { $$ = 0;
3090 yyerror(@7, "error: Error in for loop condition expression.");
3092 | K_for '(' error ')' statement
3093 { $$ = 0;
3094 yyerror(@3, "error: Incomprehensible for loop.");
3096 | K_while '(' expression ')' statement
3097 { PWhile*tmp = new PWhile($3, $5);
3098 $$ = tmp;
3100 | K_while '(' error ')' statement
3101 { $$ = 0;
3102 yyerror(@3, "error: Error in while loop condition.");
3104 | delay1 statement_or_null
3105 { PExpr*del = (*$1)[0];
3106 assert($1->count() == 1);
3107 PDelayStatement*tmp = new PDelayStatement(del, $2);
3108 tmp->set_file(@1.text);
3109 tmp->set_lineno(@1.first_line);
3110 $$ = tmp;
3112 | event_control statement_or_null
3113 { PEventStatement*tmp = $1;
3114 if (tmp == 0) {
3115 yyerror(@1, "error: Invalid event control.");
3116 $$ = 0;
3117 } else {
3118 tmp->set_statement($2);
3119 $$ = tmp;
3122 | '@' '*' statement_or_null
3123 { PEventStatement*tmp = new PEventStatement;
3124 tmp->set_file(@1.text);
3125 tmp->set_lineno(@1.first_line);
3126 tmp->set_statement($3);
3127 $$ = tmp;
3129 | '@' '(' '*' ')' statement_or_null
3130 { PEventStatement*tmp = new PEventStatement;
3131 tmp->set_file(@1.text);
3132 tmp->set_lineno(@1.first_line);
3133 tmp->set_statement($5);
3134 $$ = tmp;
3136 | lpvalue '=' expression ';'
3137 { PAssign*tmp = new PAssign($1,$3);
3138 tmp->set_file(@1.text);
3139 tmp->set_lineno(@1.first_line);
3140 $$ = tmp;
3142 | error '=' expression ';'
3143 { yyerror(@1, "Syntax in assignment statement l-value.");
3144 yyerrok;
3145 $$ = new PNoop;
3147 | lpvalue K_LE expression ';'
3148 { PAssignNB*tmp = new PAssignNB($1,$3);
3149 tmp->set_file(@1.text);
3150 tmp->set_lineno(@1.first_line);
3151 $$ = tmp;
3153 | error K_LE expression ';'
3154 { yyerror(@1, "Syntax in assignment statement l-value.");
3155 yyerrok;
3156 $$ = new PNoop;
3158 | lpvalue '=' delay1 expression ';'
3159 { assert($3->count() == 1);
3160 PExpr*del = (*$3)[0];
3161 PAssign*tmp = new PAssign($1,del,$4);
3162 tmp->set_file(@1.text);
3163 tmp->set_lineno(@1.first_line);
3164 $$ = tmp;
3166 | lpvalue K_LE delay1 expression ';'
3167 { assert($3->count() == 1);
3168 PExpr*del = (*$3)[0];
3169 PAssignNB*tmp = new PAssignNB($1,del,$4);
3170 tmp->set_file(@1.text);
3171 tmp->set_lineno(@1.first_line);
3172 $$ = tmp;
3174 | lpvalue '=' event_control expression ';'
3175 { PAssign*tmp = new PAssign($1,$3,$4);
3176 tmp->set_file(@1.text);
3177 tmp->set_lineno(@1.first_line);
3178 $$ = tmp;
3180 | lpvalue '=' K_repeat '(' expression ')' event_control expression ';'
3181 { PAssign*tmp = new PAssign($1,$7,$8);
3182 tmp->set_file(@1.text);
3183 tmp->set_lineno(@1.first_line);
3184 yyerror(@3, "sorry: repeat event control not supported.");
3185 delete $5;
3186 $$ = tmp;
3188 | lpvalue K_LE event_control expression ';'
3189 { yyerror(@1, "sorry: Event controls not supported here.");
3190 PAssignNB*tmp = new PAssignNB($1,$4);
3191 tmp->set_file(@1.text);
3192 tmp->set_lineno(@1.first_line);
3193 $$ = tmp;
3195 | lpvalue K_LE K_repeat '(' expression ')' event_control expression ';'
3196 { yyerror(@1, "sorry: Event controls not supported here.");
3197 delete $5;
3198 PAssignNB*tmp = new PAssignNB($1,$8);
3199 tmp->set_file(@1.text);
3200 tmp->set_lineno(@1.first_line);
3201 $$ = tmp;
3203 | K_wait '(' expression ')' statement_or_null
3204 { PEventStatement*tmp;
3205 PEEvent*etmp = new PEEvent(PEEvent::POSITIVE, $3);
3206 tmp = new PEventStatement(etmp);
3207 tmp->set_file(@1.text);
3208 tmp->set_lineno(@1.first_line);
3209 tmp->set_statement($5);
3210 $$ = tmp;
3212 | SYSTEM_IDENTIFIER '(' expression_list_with_nuls ')' ';'
3213 { PCallTask*tmp = new PCallTask(lex_strings.make($1), *$3);
3214 tmp->set_file(@1.text);
3215 tmp->set_lineno(@1.first_line);
3216 delete $1;
3217 delete $3;
3218 $$ = tmp;
3220 | SYSTEM_IDENTIFIER ';'
3221 { svector<PExpr*>pt (0);
3222 PCallTask*tmp = new PCallTask(lex_strings.make($1), pt);
3223 tmp->set_file(@1.text);
3224 tmp->set_lineno(@1.first_line);
3225 delete $1;
3226 $$ = tmp;
3228 | heirarchy_identifier '(' expression_list_proper ')' ';'
3229 { PCallTask*tmp = new PCallTask(*$1, *$3);
3230 tmp->set_file(@1.text);
3231 tmp->set_lineno(@1.first_line);
3232 delete $1;
3233 delete $3;
3234 $$ = tmp;
3237 /* NOTE: The standard doesn't really support an empty argument list
3238 between parentheses, but it seems natural, and people commonly
3239 want it. So accept it explicitly. */
3241 | heirarchy_identifier '(' ')' ';'
3242 { svector<PExpr*>pt (0);
3243 PCallTask*tmp = new PCallTask(*$1, pt);
3244 tmp->set_file(@1.text);
3245 tmp->set_lineno(@1.first_line);
3246 delete $1;
3247 $$ = tmp;
3249 | heirarchy_identifier ';'
3250 { svector<PExpr*>pt (0);
3251 PCallTask*tmp = new PCallTask(*$1, pt);
3252 tmp->set_file(@1.text);
3253 tmp->set_lineno(@1.first_line);
3254 delete $1;
3255 $$ = tmp;
3257 | error ';'
3258 { yyerror(@1, "error: malformed statement");
3259 yyerrok;
3260 $$ = new PNoop;
3264 statement_list
3265 : statement_list statement
3266 { svector<Statement*>*tmp = new svector<Statement*>(*$1, $2);
3267 delete $1;
3268 $$ = tmp;
3270 | statement
3271 { svector<Statement*>*tmp = new svector<Statement*>(1);
3272 (*tmp)[0] = $1;
3273 $$ = tmp;
3277 statement_or_null
3278 : statement
3279 | ';' { $$ = 0; }
3282 /* Task items are, other than the statement, task port items and
3283 other block items. */
3284 task_item
3285 : block_item_decl { $$ = new svector<PWire*>(0); }
3286 | task_port_item { $$ = $1; }
3289 task_port_item
3291 : K_input signed_opt range_opt list_of_identifiers ';'
3292 { svector<PWire*>*tmp
3293 = pform_make_task_ports(NetNet::PINPUT,
3294 IVL_VT_LOGIC, $2,
3295 $3, $4,
3296 @1.text, @1.first_line);
3297 $$ = tmp;
3299 | K_output signed_opt range_opt list_of_identifiers ';'
3300 { svector<PWire*>*tmp
3301 = pform_make_task_ports(NetNet::POUTPUT,
3302 IVL_VT_LOGIC, $2,
3303 $3, $4,
3304 @1.text, @1.first_line);
3305 $$ = tmp;
3307 | K_inout signed_opt range_opt list_of_identifiers ';'
3308 { svector<PWire*>*tmp
3309 = pform_make_task_ports(NetNet::PINOUT,
3310 IVL_VT_LOGIC, $2,
3311 $3, $4,
3312 @1.text, @1.first_line);
3313 $$ = tmp;
3316 /* When the port is an integer, infer a signed vector of the integer
3317 shape. Generate a range to make it work. */
3319 | K_input K_integer list_of_identifiers ';'
3320 { svector<PExpr*>*range_stub
3321 = new svector<PExpr*>(2);
3322 PExpr*re;
3323 re = new PENumber(new verinum(integer_width-1,
3324 integer_width));
3325 (*range_stub)[0] = re;
3326 re = new PENumber(new verinum((uint64_t)0, integer_width));
3327 (*range_stub)[1] = re;
3328 svector<PWire*>*tmp
3329 = pform_make_task_ports(NetNet::PINPUT,
3330 IVL_VT_LOGIC, true,
3331 range_stub, $3,
3332 @1.text, @1.first_line);
3333 $$ = tmp;
3335 | K_output K_integer list_of_identifiers ';'
3336 { svector<PExpr*>*range_stub
3337 = new svector<PExpr*>(2);
3338 PExpr*re;
3339 re = new PENumber(new verinum(integer_width-1,
3340 integer_width));
3341 (*range_stub)[0] = re;
3342 re = new PENumber(new verinum((uint64_t)0, integer_width));
3343 (*range_stub)[1] = re;
3344 svector<PWire*>*tmp
3345 = pform_make_task_ports(NetNet::POUTPUT,
3346 IVL_VT_LOGIC, true,
3347 range_stub, $3,
3348 @1.text, @1.first_line);
3349 $$ = tmp;
3351 | K_inout K_integer list_of_identifiers ';'
3352 { svector<PExpr*>*range_stub
3353 = new svector<PExpr*>(2);
3354 PExpr*re;
3355 re = new PENumber(new verinum(integer_width-1,
3356 integer_width));
3357 (*range_stub)[0] = re;
3358 re = new PENumber(new verinum((uint64_t)0, integer_width));
3359 (*range_stub)[1] = re;
3360 svector<PWire*>*tmp
3361 = pform_make_task_ports(NetNet::PINOUT,
3362 IVL_VT_LOGIC, true,
3363 range_stub, $3,
3364 @1.text, @1.first_line);
3365 $$ = tmp;
3368 /* Ports can be real. */
3370 | K_input K_real list_of_identifiers ';'
3371 { svector<PWire*>*tmp
3372 = pform_make_task_ports(NetNet::PINPUT,
3373 IVL_VT_REAL, false,
3374 0, $3,
3375 @1.text, @1.first_line);
3376 $$ = tmp;
3378 | K_output K_real list_of_identifiers ';'
3379 { svector<PWire*>*tmp
3380 = pform_make_task_ports(NetNet::POUTPUT,
3381 IVL_VT_REAL, true,
3382 0, $3,
3383 @1.text, @1.first_line);
3384 $$ = tmp;
3386 | K_inout K_real list_of_identifiers ';'
3387 { svector<PWire*>*tmp
3388 = pform_make_task_ports(NetNet::PINOUT,
3389 IVL_VT_REAL, true,
3390 0, $3,
3391 @1.text, @1.first_line);
3392 $$ = tmp;
3396 task_item_list
3397 : task_item_list task_item
3398 { svector<PWire*>*tmp = new svector<PWire*>(*$1, *$2);
3399 delete $1;
3400 delete $2;
3401 $$ = tmp;
3403 | task_item
3404 { $$ = $1; }
3407 task_item_list_opt
3408 : task_item_list
3409 { $$ = $1; }
3411 { $$ = 0; }
3414 task_port_decl
3416 : K_input signed_opt range_opt IDENTIFIER
3417 { svector<PWire*>*tmp
3418 = pform_make_task_ports(NetNet::PINPUT,
3419 IVL_VT_LOGIC, $2,
3420 $3, list_from_identifier($4),
3421 @1.text, @1.first_line);
3422 $$ = tmp;
3425 | K_output signed_opt range_opt IDENTIFIER
3426 { svector<PWire*>*tmp
3427 = pform_make_task_ports(NetNet::POUTPUT,
3428 IVL_VT_LOGIC, $2,
3429 $3, list_from_identifier($4),
3430 @1.text, @1.first_line);
3431 $$ = tmp;
3433 | K_inout signed_opt range_opt IDENTIFIER
3434 { svector<PWire*>*tmp
3435 = pform_make_task_ports(NetNet::PINOUT,
3436 IVL_VT_LOGIC, $2,
3437 $3, list_from_identifier($4),
3438 @1.text, @1.first_line);
3439 $$ = tmp;
3442 | K_input K_integer IDENTIFIER
3443 { svector<PExpr*>*range_stub
3444 = new svector<PExpr*>(2);
3445 PExpr*re;
3446 re = new PENumber(new verinum(integer_width-1,
3447 integer_width));
3448 (*range_stub)[0] = re;
3449 re = new PENumber(new verinum((uint64_t)0, integer_width));
3450 (*range_stub)[1] = re;
3451 svector<PWire*>*tmp
3452 = pform_make_task_ports(NetNet::PINPUT,
3453 IVL_VT_LOGIC, true,
3454 range_stub,
3455 list_from_identifier($3),
3456 @1.text, @1.first_line);
3457 $$ = tmp;
3459 | K_output K_integer IDENTIFIER
3460 { svector<PExpr*>*range_stub
3461 = new svector<PExpr*>(2);
3462 PExpr*re;
3463 re = new PENumber(new verinum(integer_width-1,
3464 integer_width));
3465 (*range_stub)[0] = re;
3466 re = new PENumber(new verinum((uint64_t)0, integer_width));
3467 (*range_stub)[1] = re;
3468 svector<PWire*>*tmp
3469 = pform_make_task_ports(NetNet::POUTPUT,
3470 IVL_VT_LOGIC, true,
3471 range_stub,
3472 list_from_identifier($3),
3473 @1.text, @1.first_line);
3474 $$ = tmp;
3476 | K_inout K_integer IDENTIFIER
3477 { svector<PExpr*>*range_stub
3478 = new svector<PExpr*>(2);
3479 PExpr*re;
3480 re = new PENumber(new verinum(integer_width-1,
3481 integer_width));
3482 (*range_stub)[0] = re;
3483 re = new PENumber(new verinum((uint64_t)0, integer_width));
3484 (*range_stub)[1] = re;
3485 svector<PWire*>*tmp
3486 = pform_make_task_ports(NetNet::PINOUT,
3487 IVL_VT_LOGIC, true,
3488 range_stub,
3489 list_from_identifier($3),
3490 @1.text, @1.first_line);
3491 $$ = tmp;
3494 /* Ports can be real. */
3496 | K_input K_real IDENTIFIER
3497 { svector<PWire*>*tmp
3498 = pform_make_task_ports(NetNet::PINPUT,
3499 IVL_VT_REAL, false,
3500 0, list_from_identifier($3),
3501 @1.text, @1.first_line);
3502 $$ = tmp;
3504 | K_output K_real IDENTIFIER
3505 { svector<PWire*>*tmp
3506 = pform_make_task_ports(NetNet::POUTPUT,
3507 IVL_VT_REAL, false,
3508 0, list_from_identifier($3),
3509 @1.text, @1.first_line);
3510 $$ = tmp;
3512 | K_inout K_real IDENTIFIER
3513 { svector<PWire*>*tmp
3514 = pform_make_task_ports(NetNet::PINOUT,
3515 IVL_VT_REAL, false,
3516 0, list_from_identifier($3),
3517 @1.text, @1.first_line);
3518 $$ = tmp;
3522 task_port_decl_list
3523 : task_port_decl_list ',' task_port_decl
3524 { svector<PWire*>*tmp = new svector<PWire*>(*$1, *$3);
3525 delete $1;
3526 delete $3;
3527 $$ = tmp;
3529 | task_port_decl
3530 { $$ = $1; }
3533 udp_body
3534 : K_table { lex_start_table(); }
3535 udp_entry_list
3536 K_endtable { lex_end_table(); $$ = $3; }
3539 udp_entry_list
3540 : udp_comb_entry_list
3541 | udp_sequ_entry_list
3544 udp_comb_entry
3545 : udp_input_list ':' udp_output_sym ';'
3546 { char*tmp = new char[strlen($1)+3];
3547 strcpy(tmp, $1);
3548 char*tp = tmp+strlen(tmp);
3549 *tp++ = ':';
3550 *tp++ = $3;
3551 *tp++ = 0;
3552 delete[]$1;
3553 $$ = tmp;
3557 udp_comb_entry_list
3558 : udp_comb_entry
3559 { list<string>*tmp = new list<string>;
3560 tmp->push_back($1);
3561 delete $1;
3562 $$ = tmp;
3564 | udp_comb_entry_list udp_comb_entry
3565 { list<string>*tmp = $1;
3566 tmp->push_back($2);
3567 delete $2;
3568 $$ = tmp;
3572 udp_sequ_entry_list
3573 : udp_sequ_entry
3574 { list<string>*tmp = new list<string>;
3575 tmp->push_back($1);
3576 delete $1;
3577 $$ = tmp;
3579 | udp_sequ_entry_list udp_sequ_entry
3580 { list<string>*tmp = $1;
3581 tmp->push_back($2);
3582 delete $2;
3583 $$ = tmp;
3587 udp_sequ_entry
3588 : udp_input_list ':' udp_input_sym ':' udp_output_sym ';'
3589 { char*tmp = new char[strlen($1)+5];
3590 strcpy(tmp, $1);
3591 char*tp = tmp+strlen(tmp);
3592 *tp++ = ':';
3593 *tp++ = $3;
3594 *tp++ = ':';
3595 *tp++ = $5;
3596 *tp++ = 0;
3597 $$ = tmp;
3601 udp_initial
3602 : K_initial IDENTIFIER '=' number ';'
3603 { PExpr*etmp = new PENumber($4);
3604 PEIdent*itmp = new PEIdent(lex_strings.make($2));
3605 PAssign*atmp = new PAssign(itmp, etmp);
3606 atmp->set_file(@2.text);
3607 atmp->set_lineno(@2.first_line);
3608 delete $2;
3609 $$ = atmp;
3613 udp_init_opt
3614 : udp_initial { $$ = $1; }
3615 | { $$ = 0; }
3618 udp_input_list
3619 : udp_input_sym
3620 { char*tmp = new char[2];
3621 tmp[0] = $1;
3622 tmp[1] = 0;
3623 $$ = tmp;
3625 | udp_input_list udp_input_sym
3626 { char*tmp = new char[strlen($1)+2];
3627 strcpy(tmp, $1);
3628 char*tp = tmp+strlen(tmp);
3629 *tp++ = $2;
3630 *tp++ = 0;
3631 delete[]$1;
3632 $$ = tmp;
3636 udp_input_sym
3637 : '0' { $$ = '0'; }
3638 | '1' { $$ = '1'; }
3639 | 'x' { $$ = 'x'; }
3640 | '?' { $$ = '?'; }
3641 | 'b' { $$ = 'b'; }
3642 | '*' { $$ = '*'; }
3643 | '%' { $$ = '%'; }
3644 | 'f' { $$ = 'f'; }
3645 | 'F' { $$ = 'F'; }
3646 | 'l' { $$ = 'l'; }
3647 | 'h' { $$ = 'H'; }
3648 | 'B' { $$ = 'B'; }
3649 | 'r' { $$ = 'r'; }
3650 | 'R' { $$ = 'R'; }
3651 | 'M' { $$ = 'M'; }
3652 | 'n' { $$ = 'n'; }
3653 | 'N' { $$ = 'N'; }
3654 | 'p' { $$ = 'p'; }
3655 | 'P' { $$ = 'P'; }
3656 | 'Q' { $$ = 'Q'; }
3657 | 'q' { $$ = 'q'; }
3658 | '_' { $$ = '_'; }
3659 | '+' { $$ = '+'; }
3662 udp_output_sym
3663 : '0' { $$ = '0'; }
3664 | '1' { $$ = '1'; }
3665 | 'x' { $$ = 'x'; }
3666 | '-' { $$ = '-'; }
3669 /* Port declarations create wires for the inputs and the output. The
3670 makes for these ports are scoped within the UDP, so there is no
3671 heirarchy involved. */
3672 udp_port_decl
3673 : K_input list_of_identifiers ';'
3674 { $$ = pform_make_udp_input_ports($2); }
3675 | K_output IDENTIFIER ';'
3676 { pform_name_t pname;
3677 pname.push_back(name_component_t(lex_strings.make($2)));
3678 PWire*pp = new PWire(pname, NetNet::IMPLICIT, NetNet::POUTPUT, IVL_VT_LOGIC);
3679 svector<PWire*>*tmp = new svector<PWire*>(1);
3680 (*tmp)[0] = pp;
3681 $$ = tmp;
3682 delete $2;
3684 | K_reg IDENTIFIER ';'
3685 { pform_name_t pname;
3686 pname.push_back(name_component_t(lex_strings.make($2)));
3687 PWire*pp = new PWire(pname, NetNet::REG, NetNet::PIMPLICIT, IVL_VT_LOGIC);
3688 svector<PWire*>*tmp = new svector<PWire*>(1);
3689 (*tmp)[0] = pp;
3690 $$ = tmp;
3691 delete $2;
3693 | K_reg K_output IDENTIFIER ';'
3694 { pform_name_t pname;
3695 pname.push_back(name_component_t(lex_strings.make($3)));
3696 PWire*pp = new PWire(pname, NetNet::REG, NetNet::POUTPUT, IVL_VT_LOGIC);
3697 svector<PWire*>*tmp = new svector<PWire*>(1);
3698 (*tmp)[0] = pp;
3699 $$ = tmp;
3700 delete $3;
3704 udp_port_decls
3705 : udp_port_decl
3706 { $$ = $1; }
3707 | udp_port_decls udp_port_decl
3708 { svector<PWire*>*tmp = new svector<PWire*>(*$1, *$2);
3709 delete $1;
3710 delete $2;
3711 $$ = tmp;
3715 udp_port_list
3716 : IDENTIFIER
3717 { list<string>*tmp = new list<string>;
3718 tmp->push_back($1);
3719 delete $1;
3720 $$ = tmp;
3722 | udp_port_list ',' IDENTIFIER
3723 { list<string>*tmp = $1;
3724 tmp->push_back($3);
3725 delete $3;
3726 $$ = tmp;
3730 udp_reg_opt: K_reg { $$ = true; } | { $$ = false; };
3732 udp_initial_expr_opt
3733 : '=' expression { $$ = $2; }
3734 | { $$ = 0; }
3737 udp_input_declaration_list
3738 : K_input IDENTIFIER
3739 { list<perm_string>*tmp = new list<perm_string>;
3740 tmp->push_back(lex_strings.make($2));
3741 $$ = tmp;
3742 delete[]$2;
3744 | udp_input_declaration_list ',' K_input IDENTIFIER
3745 { list<perm_string>*tmp = $1;
3746 tmp->push_back(lex_strings.make($4));
3747 $$ = tmp;
3748 delete[]$4;
3752 udp_primitive
3753 /* This is the syntax for primitives that uses the IEEE1364-1995
3754 format. The ports are simply names in the port list, and the
3755 declarations are in the body. */
3757 : K_primitive IDENTIFIER '(' udp_port_list ')' ';'
3758 udp_port_decls
3759 udp_init_opt
3760 udp_body
3761 K_endprimitive
3763 { perm_string tmp2 = lex_strings.make($2);
3764 pform_make_udp(tmp2, $4, $7, $9, $8,
3765 @2.text, @2.first_line);
3766 delete[]$2;
3769 /* This is the syntax for IEEE1364-2001 format definitions. The port
3770 names and declarations are all in the parameter list. */
3772 | K_primitive IDENTIFIER
3773 '(' K_output udp_reg_opt IDENTIFIER udp_initial_expr_opt ','
3774 udp_input_declaration_list ')' ';'
3775 udp_body
3776 K_endprimitive
3778 { perm_string tmp2 = lex_strings.make($2);
3779 perm_string tmp6 = lex_strings.make($6);
3780 pform_make_udp(tmp2, $5, tmp6, $7, $9, $12,
3781 @2.text, @2.first_line);
3782 delete[]$2;
3783 delete[]$6;