Make C style comments work in false/suppressed ifdef/etc. blocks.
[iverilog.git] / parse.y
blob4d3848f261aac1a4352160871a37fde5e383cb2e
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
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; }
278 | DEC_NUMBER
279 { $$ = $1; }
280 | DEC_NUMBER BASED_NUMBER
281 { $$ = pform_verinum_with_size($1,$2, @2.text, @2.first_line); }
284 /* Verilog-2001 supports attribute lists, which can be attached to a
285 variety of different objects. The syntax inside the (* *) is a
286 comma separated list of names or names with assigned values. */
287 attribute_list_opt
288 : K_PSTAR attribute_list K_STARP { $$ = $2; }
289 | K_PSTAR K_STARP { $$ = 0; }
290 | { $$ = 0; }
293 attribute_list
294 : attribute_list ',' attribute
295 { svector<named_pexpr_t*>*tmp =
296 new svector<named_pexpr_t*>(*$1,$3);
297 delete $1;
298 $$ = tmp;
300 | attribute
301 { svector<named_pexpr_t*>*tmp = new svector<named_pexpr_t*>(1);
302 (*tmp)[0] = $1;
303 $$ = tmp;
308 attribute
309 : IDENTIFIER
310 { named_pexpr_t*tmp = new named_pexpr_t;
311 tmp->name = lex_strings.make($1);
312 tmp->parm = 0;
313 delete $1;
314 $$ = tmp;
316 | IDENTIFIER '=' expression
317 { PExpr*tmp = $3;
318 if (!pform_expression_is_constant(tmp)) {
319 yyerror(@3, "error: attribute value "
320 "expression must be constant.");
321 delete tmp;
322 tmp = 0;
324 named_pexpr_t*tmp2 = new named_pexpr_t;
325 tmp2->name = lex_strings.make($1);
326 tmp2->parm = tmp;
327 delete $1;
328 $$ = tmp2;
333 /* The block_item_decl is used in function definitions, task
334 definitions, module definitions and named blocks. Wherever a new
335 scope is entered, the source may declare new registers and
336 integers. This rule matches those declarations. The containing
337 rule has presumably set up the scope. */
339 block_item_decl
340 : attribute_list_opt K_reg
341 primitive_type_opt signed_opt range
342 register_variable_list ';'
343 { ivl_variable_type_t dtype = $3;
344 if (dtype == IVL_VT_NO_TYPE)
345 dtype = IVL_VT_LOGIC;
346 pform_set_net_range($6, $5, $4, dtype);
347 if ($1) delete $1;
350 /* This differs from the above pattern only in the absence of the
351 range. This is the rule for a scalar. */
353 | attribute_list_opt K_reg
354 primitive_type_opt signed_opt
355 register_variable_list ';'
356 { ivl_variable_type_t dtype = $3;
357 if (dtype == IVL_VT_NO_TYPE)
358 dtype = IVL_VT_LOGIC;
359 pform_set_net_range($5, 0, $4, dtype);
360 if ($1) delete $1;
363 /* Integer declarations are simpler in that they do not have all the
364 trappings of a general variable declaration. All of that is
365 implicit in the "integer" of the declaratin. */
367 | attribute_list_opt K_integer register_variable_list ';'
368 { pform_set_reg_integer($3);
369 if ($1) delete $1;
372 | attribute_list_opt K_time register_variable_list ';'
373 { pform_set_reg_time($3);
376 /* real declarations are fairly simple as there is no range of
377 signed flag in the declaration. Create the real as a NetNet::REG
378 with real value. Note that real and realtime are interchangable
379 in this context. */
381 | attribute_list_opt K_real real_variable_list ';'
382 { delete $3; }
383 | attribute_list_opt K_realtime real_variable_list ';'
384 { delete $3; }
386 | K_parameter parameter_assign_decl ';'
387 | K_localparam localparam_assign_decl ';'
389 /* Recover from errors that happen within variable lists. Use the
390 trailing semi-colon to resync the parser. */
392 | attribute_list_opt K_reg error ';'
393 { yyerror(@2, "error: syntax error in reg variable list.");
394 yyerrok;
395 if ($1) delete $1;
397 | attribute_list_opt K_integer error ';'
398 { yyerror(@2, "error: syntax error in integer variable list.");
399 yyerrok;
400 if ($1) delete $1;
402 | attribute_list_opt K_time error ';'
403 { yyerror(@2, "error: syntax error in time variable list.");
404 yyerrok;
406 | attribute_list_opt K_real error ';'
407 { yyerror(@2, "error: syntax error in real variable list.");
408 yyerrok;
410 | attribute_list_opt K_realtime error ';'
411 { yyerror(@1, "error: syntax error in realtime variable list.");
412 yyerrok;
414 | K_parameter error ';'
415 { yyerror(@1, "error: syntax error in parameter list.");
416 yyerrok;
418 | K_localparam error ';'
419 { yyerror(@1, "error: syntax error localparam list.");
420 yyerrok;
424 block_item_decls
425 : block_item_decl
426 | block_item_decls block_item_decl
429 block_item_decls_opt
430 : block_item_decls
434 case_item
435 : expression_list_proper ':' statement_or_null
436 { PCase::Item*tmp = new PCase::Item;
437 tmp->expr = *$1;
438 tmp->stat = $3;
439 delete $1;
440 $$ = tmp;
442 | K_default ':' statement_or_null
443 { PCase::Item*tmp = new PCase::Item;
444 tmp->stat = $3;
445 $$ = tmp;
447 | K_default statement_or_null
448 { PCase::Item*tmp = new PCase::Item;
449 tmp->stat = $2;
450 $$ = tmp;
452 | error ':' statement_or_null
453 { yyerror(@1, "error: Incomprehensible case expression.");
454 yyerrok;
458 case_items
459 : case_items case_item
460 { svector<PCase::Item*>*tmp;
461 tmp = new svector<PCase::Item*>(*$1, $2);
462 delete $1;
463 $$ = tmp;
465 | case_item
466 { svector<PCase::Item*>*tmp = new svector<PCase::Item*>(1);
467 (*tmp)[0] = $1;
468 $$ = tmp;
472 charge_strength
473 : '(' K_small ')'
474 | '(' K_medium ')'
475 | '(' K_large ')'
478 charge_strength_opt
479 : charge_strength
483 defparam_assign
484 : heirarchy_identifier '=' expression
485 { PExpr*tmp = $3;
486 if (!pform_expression_is_constant(tmp)) {
487 yyerror(@3, "error: parameter value "
488 "must be constant.");
489 delete tmp;
490 tmp = 0;
492 pform_set_defparam(*$1, $3);
493 delete $1;
497 defparam_assign_list
498 : defparam_assign
499 | range defparam_assign
500 { yyerror(@1, "error: defparam may not include a range.");
501 delete $1;
503 | defparam_assign_list ',' defparam_assign
506 delay1
507 : '#' delay_value_simple
508 { svector<PExpr*>*tmp = new svector<PExpr*>(1);
509 (*tmp)[0] = $2;
510 $$ = tmp;
512 | '#' '(' delay_value ')'
513 { svector<PExpr*>*tmp = new svector<PExpr*>(1);
514 (*tmp)[0] = $3;
515 $$ = tmp;
519 delay3
520 : '#' delay_value_simple
521 { svector<PExpr*>*tmp = new svector<PExpr*>(1);
522 (*tmp)[0] = $2;
523 $$ = tmp;
525 | '#' '(' delay_value ')'
526 { svector<PExpr*>*tmp = new svector<PExpr*>(1);
527 (*tmp)[0] = $3;
528 $$ = tmp;
530 | '#' '(' delay_value ',' delay_value ')'
531 { svector<PExpr*>*tmp = new svector<PExpr*>(2);
532 (*tmp)[0] = $3;
533 (*tmp)[1] = $5;
534 $$ = tmp;
536 | '#' '(' delay_value ',' delay_value ',' delay_value ')'
537 { svector<PExpr*>*tmp = new svector<PExpr*>(3);
538 (*tmp)[0] = $3;
539 (*tmp)[1] = $5;
540 (*tmp)[2] = $7;
541 $$ = tmp;
545 delay3_opt
546 : delay3 { $$ = $1; }
547 | { $$ = 0; }
550 delay_value_list
551 : delay_value
552 { svector<PExpr*>*tmp = new svector<PExpr*>(1);
553 (*tmp)[0] = $1;
554 $$ = tmp;
556 | delay_value_list ',' delay_value
557 { svector<PExpr*>*tmp = new svector<PExpr*>(*$1, $3);
558 delete $1;
559 $$ = tmp;
563 delay_value
564 : expression
565 { PExpr*tmp = $1;
566 $$ = tmp;
568 | expression ':' expression ':' expression
569 { $$ = pform_select_mtm_expr($1, $3, $5); }
573 delay_value_simple
574 : DEC_NUMBER
575 { verinum*tmp = $1;
576 if (tmp == 0) {
577 yyerror(@1, "internal error: delay.");
578 $$ = 0;
579 } else {
580 $$ = new PENumber(tmp);
581 $$->set_file(@1.text);
582 $$->set_lineno(@1.first_line);
585 | REALTIME
586 { verireal*tmp = $1;
587 if (tmp == 0) {
588 yyerror(@1, "internal error: delay.");
589 $$ = 0;
590 } else {
591 $$ = new PEFNumber(tmp);
592 $$->set_file(@1.text);
593 $$->set_lineno(@1.first_line);
596 | IDENTIFIER
597 { PEIdent*tmp = new PEIdent(lex_strings.make($1));
598 tmp->set_file(@1.text);
599 tmp->set_lineno(@1.first_line);
600 $$ = tmp;
601 delete $1;
605 description
606 : module
607 | udp_primitive
608 | KK_attribute '(' IDENTIFIER ',' STRING ',' STRING ')'
609 { perm_string tmp3 = lex_strings.make($3);
610 pform_set_type_attrib(tmp3, $5, $7);
611 delete $3;
612 delete $5;
616 drive_strength
617 : '(' dr_strength0 ',' dr_strength1 ')'
618 { $$.str0 = $2.str0;
619 $$.str1 = $4.str1;
621 | '(' dr_strength1 ',' dr_strength0 ')'
622 { $$.str0 = $4.str0;
623 $$.str1 = $2.str1;
625 | '(' dr_strength0 ',' K_highz1 ')'
626 { $$.str0 = $2.str0;
627 $$.str1 = PGate::HIGHZ;
629 | '(' dr_strength1 ',' K_highz0 ')'
630 { $$.str0 = PGate::HIGHZ;
631 $$.str1 = $2.str1;
633 | '(' K_highz1 ',' dr_strength0 ')'
634 { $$.str0 = $4.str0;
635 $$.str1 = PGate::HIGHZ;
637 | '(' K_highz0 ',' dr_strength1 ')'
638 { $$.str0 = PGate::HIGHZ;
639 $$.str1 = $4.str1;
643 drive_strength_opt
644 : drive_strength { $$ = $1; }
645 | { $$.str0 = PGate::STRONG; $$.str1 = PGate::STRONG; }
648 dr_strength0
649 : K_supply0 { $$.str0 = PGate::SUPPLY; }
650 | K_strong0 { $$.str0 = PGate::STRONG; }
651 | K_pull0 { $$.str0 = PGate::PULL; }
652 | K_weak0 { $$.str0 = PGate::WEAK; }
655 dr_strength1
656 : K_supply1 { $$.str1 = PGate::SUPPLY; }
657 | K_strong1 { $$.str1 = PGate::STRONG; }
658 | K_pull1 { $$.str1 = PGate::PULL; }
659 | K_weak1 { $$.str1 = PGate::WEAK; }
662 event_control
663 : '@' heirarchy_identifier
664 { PEIdent*tmpi = new PEIdent(*$2);
665 PEEvent*tmpe = new PEEvent(PEEvent::ANYEDGE, tmpi);
666 PEventStatement*tmps = new PEventStatement(tmpe);
667 tmps->set_file(@1.text);
668 tmps->set_lineno(@1.first_line);
669 $$ = tmps;
670 delete $2;
672 | '@' '(' event_expression_list ')'
673 { PEventStatement*tmp = new PEventStatement(*$3);
674 tmp->set_file(@1.text);
675 tmp->set_lineno(@1.first_line);
676 delete $3;
677 $$ = tmp;
679 | '@' '(' error ')'
680 { yyerror(@1, "error: Malformed event control expression.");
681 $$ = 0;
685 event_expression_list
686 : event_expression
687 { $$ = $1; }
688 | event_expression_list K_or event_expression
689 { svector<PEEvent*>*tmp = new svector<PEEvent*>(*$1, *$3);
690 delete $1;
691 delete $3;
692 $$ = tmp;
694 | event_expression_list ',' event_expression
695 { svector<PEEvent*>*tmp = new svector<PEEvent*>(*$1, *$3);
696 delete $1;
697 delete $3;
698 $$ = tmp;
702 event_expression
703 : K_posedge expression
704 { PEEvent*tmp = new PEEvent(PEEvent::POSEDGE, $2);
705 tmp->set_file(@1.text);
706 tmp->set_lineno(@1.first_line);
707 svector<PEEvent*>*tl = new svector<PEEvent*>(1);
708 (*tl)[0] = tmp;
709 $$ = tl;
711 | K_negedge expression
712 { PEEvent*tmp = new PEEvent(PEEvent::NEGEDGE, $2);
713 tmp->set_file(@1.text);
714 tmp->set_lineno(@1.first_line);
715 svector<PEEvent*>*tl = new svector<PEEvent*>(1);
716 (*tl)[0] = tmp;
717 $$ = tl;
719 | expression
720 { PEEvent*tmp = new PEEvent(PEEvent::ANYEDGE, $1);
721 tmp->set_file(@1.text);
722 tmp->set_lineno(@1.first_line);
723 svector<PEEvent*>*tl = new svector<PEEvent*>(1);
724 (*tl)[0] = tmp;
725 $$ = tl;
729 expression
730 : expr_primary
731 { $$ = $1; }
732 | '+' expr_primary %prec UNARY_PREC
733 { $$ = $2; }
734 | '-' expr_primary %prec UNARY_PREC
735 { PEUnary*tmp = new PEUnary('-', $2);
736 tmp->set_file(@2.text);
737 tmp->set_lineno(@2.first_line);
738 $$ = tmp;
740 | '~' expr_primary %prec UNARY_PREC
741 { PEUnary*tmp = new PEUnary('~', $2);
742 tmp->set_file(@2.text);
743 tmp->set_lineno(@2.first_line);
744 $$ = tmp;
746 | '&' expr_primary %prec UNARY_PREC
747 { PEUnary*tmp = new PEUnary('&', $2);
748 tmp->set_file(@2.text);
749 tmp->set_lineno(@2.first_line);
750 $$ = tmp;
752 | '!' expr_primary %prec UNARY_PREC
753 { PEUnary*tmp = new PEUnary('!', $2);
754 tmp->set_file(@2.text);
755 tmp->set_lineno(@2.first_line);
756 $$ = tmp;
758 | '|' expr_primary %prec UNARY_PREC
759 { PEUnary*tmp = new PEUnary('|', $2);
760 tmp->set_file(@2.text);
761 tmp->set_lineno(@2.first_line);
762 $$ = tmp;
764 | '^' expr_primary %prec UNARY_PREC
765 { PEUnary*tmp = new PEUnary('^', $2);
766 tmp->set_file(@2.text);
767 tmp->set_lineno(@2.first_line);
768 $$ = tmp;
770 | K_NAND expr_primary %prec UNARY_PREC
771 { PEUnary*tmp = new PEUnary('A', $2);
772 tmp->set_file(@2.text);
773 tmp->set_lineno(@2.first_line);
774 $$ = tmp;
776 | K_NOR expr_primary %prec UNARY_PREC
777 { PEUnary*tmp = new PEUnary('N', $2);
778 tmp->set_file(@2.text);
779 tmp->set_lineno(@2.first_line);
780 $$ = tmp;
782 | K_NXOR expr_primary %prec UNARY_PREC
783 { PEUnary*tmp = new PEUnary('X', $2);
784 tmp->set_file(@2.text);
785 tmp->set_lineno(@2.first_line);
786 $$ = tmp;
788 | '!' error %prec UNARY_PREC
789 { yyerror(@1, "error: Operand of unary ! "
790 "is not a primary expression.");
791 $$ = 0;
793 | '^' error %prec UNARY_PREC
794 { yyerror(@1, "error: Operand of reduction ^ "
795 "is not a primary expression.");
796 $$ = 0;
798 | expression '^' expression
799 { PEBinary*tmp = new PEBinary('^', $1, $3);
800 tmp->set_file(@2.text);
801 tmp->set_lineno(@2.first_line);
802 $$ = tmp;
804 | expression K_POW expression
805 { PEBinary*tmp = new PEBinary('p', $1, $3);
806 tmp->set_file(@2.text);
807 tmp->set_lineno(@2.first_line);
808 $$ = tmp;
810 | expression '*' expression
811 { PEBinary*tmp = new PEBinary('*', $1, $3);
812 tmp->set_file(@2.text);
813 tmp->set_lineno(@2.first_line);
814 $$ = tmp;
816 | expression '/' expression
817 { PEBinary*tmp = new PEBinary('/', $1, $3);
818 tmp->set_file(@2.text);
819 tmp->set_lineno(@2.first_line);
820 $$ = tmp;
822 | expression '%' expression
823 { PEBinary*tmp = new PEBinary('%', $1, $3);
824 tmp->set_file(@2.text);
825 tmp->set_lineno(@2.first_line);
826 $$ = tmp;
828 | expression '+' expression
829 { PEBinary*tmp = new PEBinary('+', $1, $3);
830 tmp->set_file(@2.text);
831 tmp->set_lineno(@2.first_line);
832 $$ = tmp;
834 | expression '-' expression
835 { PEBinary*tmp = new PEBinary('-', $1, $3);
836 tmp->set_file(@2.text);
837 tmp->set_lineno(@2.first_line);
838 $$ = tmp;
840 | expression '&' expression
841 { PEBinary*tmp = new PEBinary('&', $1, $3);
842 tmp->set_file(@2.text);
843 tmp->set_lineno(@2.first_line);
844 $$ = tmp;
846 | expression '|' expression
847 { PEBinary*tmp = new PEBinary('|', $1, $3);
848 tmp->set_file(@2.text);
849 tmp->set_lineno(@2.first_line);
850 $$ = tmp;
852 | expression K_NAND expression
853 { PEBinary*tmp = new PEBinary('A', $1, $3);
854 tmp->set_file(@2.text);
855 tmp->set_lineno(@2.first_line);
856 $$ = tmp;
858 | expression K_NOR expression
859 { PEBinary*tmp = new PEBinary('O', $1, $3);
860 tmp->set_file(@2.text);
861 tmp->set_lineno(@2.first_line);
862 $$ = tmp;
864 | expression K_NXOR expression
865 { PEBinary*tmp = new PEBinary('X', $1, $3);
866 tmp->set_file(@2.text);
867 tmp->set_lineno(@2.first_line);
868 $$ = tmp;
870 | expression '<' expression
871 { PEBinary*tmp = new PEBComp('<', $1, $3);
872 tmp->set_file(@2.text);
873 tmp->set_lineno(@2.first_line);
874 $$ = tmp;
876 | expression '>' expression
877 { PEBinary*tmp = new PEBComp('>', $1, $3);
878 tmp->set_file(@2.text);
879 tmp->set_lineno(@2.first_line);
880 $$ = tmp;
882 | expression K_LS expression
883 { PEBinary*tmp = new PEBShift('l', $1, $3);
884 tmp->set_file(@2.text);
885 tmp->set_lineno(@2.first_line);
886 $$ = tmp;
888 | expression K_RS expression
889 { PEBinary*tmp = new PEBShift('r', $1, $3);
890 tmp->set_file(@2.text);
891 tmp->set_lineno(@2.first_line);
892 $$ = tmp;
894 | expression K_RSS expression
895 { PEBinary*tmp = new PEBShift('R', $1, $3);
896 tmp->set_file(@2.text);
897 tmp->set_lineno(@2.first_line);
898 $$ = tmp;
900 | expression K_EQ expression
901 { PEBinary*tmp = new PEBComp('e', $1, $3);
902 tmp->set_file(@2.text);
903 tmp->set_lineno(@2.first_line);
904 $$ = tmp;
906 | expression K_CEQ expression
907 { PEBinary*tmp = new PEBComp('E', $1, $3);
908 tmp->set_file(@2.text);
909 tmp->set_lineno(@2.first_line);
910 $$ = tmp;
912 | expression K_LE expression
913 { PEBinary*tmp = new PEBComp('L', $1, $3);
914 tmp->set_file(@2.text);
915 tmp->set_lineno(@2.first_line);
916 $$ = tmp;
918 | expression K_GE expression
919 { PEBinary*tmp = new PEBComp('G', $1, $3);
920 tmp->set_file(@2.text);
921 tmp->set_lineno(@2.first_line);
922 $$ = tmp;
924 | expression K_NE expression
925 { PEBinary*tmp = new PEBComp('n', $1, $3);
926 tmp->set_file(@2.text);
927 tmp->set_lineno(@2.first_line);
928 $$ = tmp;
930 | expression K_CNE expression
931 { PEBinary*tmp = new PEBComp('N', $1, $3);
932 tmp->set_file(@2.text);
933 tmp->set_lineno(@2.first_line);
934 $$ = tmp;
936 | expression K_LOR expression
937 { PEBinary*tmp = new PEBinary('o', $1, $3);
938 tmp->set_file(@2.text);
939 tmp->set_lineno(@2.first_line);
940 $$ = tmp;
942 | expression K_LAND expression
943 { PEBinary*tmp = new PEBinary('a', $1, $3);
944 tmp->set_file(@2.text);
945 tmp->set_lineno(@2.first_line);
946 $$ = tmp;
948 | expression '?' expression ':' expression
949 { PETernary*tmp = new PETernary($1, $3, $5);
950 tmp->set_file(@2.text);
951 tmp->set_lineno(@2.first_line);
952 $$ = tmp;
957 /* Many contexts take a comma separated list of expressions. Null
958 expressions can happen anywhere in the list, so there are two
959 extra rules in expression_list_with_nuls for parsing and
960 installing those nulls.
962 The expression_list_proper rules do not allow null items in the
963 expression list, so can be used where nul expressions are not allowed. */
965 expression_list_with_nuls
966 : expression_list_with_nuls ',' expression
967 { svector<PExpr*>*tmp = new svector<PExpr*>(*$1, $3);
968 delete $1;
969 $$ = tmp;
971 | expression
972 { svector<PExpr*>*tmp = new svector<PExpr*>(1);
973 (*tmp)[0] = $1;
974 $$ = tmp;
977 { svector<PExpr*>*tmp = new svector<PExpr*>(1);
978 (*tmp)[0] = 0;
979 $$ = tmp;
982 | expression_list_with_nuls ','
983 { svector<PExpr*>*tmp = new svector<PExpr*>(*$1, 0);
984 delete $1;
985 $$ = tmp;
989 expression_list_proper
990 : expression_list_proper ',' expression
991 { svector<PExpr*>*tmp = new svector<PExpr*>(*$1, $3);
992 delete $1;
993 $$ = tmp;
995 | expression
996 { svector<PExpr*>*tmp = new svector<PExpr*>(1);
997 (*tmp)[0] = $1;
998 $$ = tmp;
1002 expr_primary
1003 : number
1004 { assert($1);
1005 PENumber*tmp = new PENumber($1);
1006 tmp->set_file(@1.text);
1007 tmp->set_lineno(@1.first_line);
1008 $$ = tmp;
1010 | REALTIME
1011 { PEFNumber*tmp = new PEFNumber($1);
1012 tmp->set_file(@1.text);
1013 tmp->set_lineno(@1.first_line);
1014 $$ = tmp;
1016 | STRING
1017 { PEString*tmp = new PEString($1);
1018 tmp->set_file(@1.text);
1019 tmp->set_lineno(@1.first_line);
1020 $$ = tmp;
1022 | SYSTEM_IDENTIFIER
1023 { perm_string tn = lex_strings.make($1);
1024 PECallFunction*tmp = new PECallFunction(tn);
1025 tmp->set_file(@1.text);
1026 tmp->set_lineno(@1.first_line);
1027 $$ = tmp;
1028 delete $1;
1031 /* The heirarchy_identifier rule matches simple identifiers as well as
1032 indexed arrays and part selects */
1034 | heirarchy_identifier
1035 { PEIdent*tmp = new PEIdent(*$1);
1036 tmp->set_file(@1.text);
1037 tmp->set_lineno(@1.first_line);
1038 $$ = tmp;
1039 delete $1;
1042 /* An identifer followed by an expression list in parentheses is a
1043 function call. If a system identifier, then a system function
1044 call. */
1046 | heirarchy_identifier '(' expression_list_proper ')'
1047 { PECallFunction*tmp = new PECallFunction(*$1, *$3);
1048 tmp->set_file(@1.text);
1049 tmp->set_lineno(@1.first_line);
1050 delete $1;
1051 $$ = tmp;
1053 | SYSTEM_IDENTIFIER '(' expression_list_proper ')'
1054 { perm_string tn = lex_strings.make($1);
1055 PECallFunction*tmp = new PECallFunction(tn, *$3);
1056 tmp->set_file(@1.text);
1057 tmp->set_lineno(@1.first_line);
1058 $$ = tmp;
1061 /* Parenthesized expressions are primaries. */
1063 | '(' expression ')'
1064 { $$ = $2; }
1066 /* Various kinds of concatenation expressions. */
1068 | '{' expression_list_proper '}'
1069 { PEConcat*tmp = new PEConcat(*$2);
1070 tmp->set_file(@1.text);
1071 tmp->set_lineno(@1.first_line);
1072 delete $2;
1073 $$ = tmp;
1075 | '{' expression '{' expression_list_proper '}' '}'
1076 { PExpr*rep = $2;
1077 PEConcat*tmp = new PEConcat(*$4, rep);
1078 tmp->set_file(@1.text);
1079 tmp->set_lineno(@1.first_line);
1080 delete $4;
1081 $$ = tmp;
1083 | '{' expression '{' expression_list_proper '}' error '}'
1084 { PExpr*rep = $2;
1085 PEConcat*tmp = new PEConcat(*$4, rep);
1086 tmp->set_file(@1.text);
1087 tmp->set_lineno(@1.first_line);
1088 delete $4;
1089 $$ = tmp;
1090 yyerror(@5, "error: Syntax error between internal '}' "
1091 "and closing '}' of repeat concatenation.");
1092 yyerrok;
1096 /* A function_item is either a block item (i.e. a reg or integer
1097 declaration) or an input declaration. There are no output or
1098 inout ports. */
1099 function_item
1100 : K_input signed_opt range_opt list_of_identifiers ';'
1101 { svector<PWire*>*tmp
1102 = pform_make_task_ports(NetNet::PINPUT,
1103 IVL_VT_NO_TYPE, $2,
1104 $3, $4,
1105 @1.text, @1.first_line);
1106 $$ = tmp;
1108 | K_output signed_opt range_opt list_of_identifiers ';'
1109 { svector<PWire*>*tmp
1110 = pform_make_task_ports(NetNet::PINPUT,
1111 IVL_VT_NO_TYPE, $2,
1112 $3, $4,
1113 @1.text, @1.first_line);
1114 $$ = tmp;
1115 yyerror(@1, "Functions may not have output ports.");
1117 | K_inout signed_opt range_opt list_of_identifiers ';'
1118 { svector<PWire*>*tmp
1119 = pform_make_task_ports(NetNet::PINPUT,
1120 IVL_VT_NO_TYPE, $2,
1121 $3, $4,
1122 @1.text, @1.first_line);
1123 $$ = tmp;
1124 yyerror(@1, "Functions may not have inout ports.");
1127 /* When the port is an integer, infer a signed vector of the integer
1128 shape. Generate a range to make it work. */
1130 | K_input K_integer list_of_identifiers ';'
1131 { svector<PExpr*>*range_stub
1132 = new svector<PExpr*>(2);
1133 PExpr*re;
1134 re = new PENumber(new verinum(integer_width-1,
1135 integer_width));
1136 (*range_stub)[0] = re;
1137 re = new PENumber(new verinum((uint64_t)0, integer_width));
1138 (*range_stub)[1] = re;
1139 svector<PWire*>*tmp
1140 = pform_make_task_ports(NetNet::PINPUT,
1141 IVL_VT_LOGIC, true,
1142 range_stub, $3,
1143 @1.text, @1.first_line);
1144 $$ = tmp;
1147 /* Ports can be real. */
1149 | K_input K_real list_of_identifiers ';'
1150 { svector<PWire*>*tmp
1151 = pform_make_task_ports(NetNet::PINPUT,
1152 IVL_VT_REAL, false,
1153 0, $3,
1154 @1.text, @1.first_line);
1155 $$ = tmp;
1158 | block_item_decl
1159 { $$ = 0; }
1162 /* A function_item_list only lists the input/output/inout
1163 declarations. The integer and reg declarations are handled in
1164 place, so are not listed. The list builder needs to account for
1165 the possibility that the various parts may be NULL. */
1166 function_item_list
1167 : function_item
1168 { $$ = $1; }
1169 | function_item_list function_item
1170 { if ($1 && $2) {
1171 svector<PWire*>*tmp = new svector<PWire*>(*$1, *$2);
1172 delete $1;
1173 delete $2;
1174 $$ = tmp;
1175 } else if ($1) {
1176 $$ = $1;
1177 } else {
1178 $$ = $2;
1183 /* A gate_instance is a module instantiation or a built in part
1184 type. In any case, the gate has a set of connections to ports. */
1185 gate_instance
1186 : IDENTIFIER '(' expression_list_with_nuls ')'
1187 { lgate*tmp = new lgate;
1188 tmp->name = $1;
1189 tmp->parms = $3;
1190 tmp->file = @1.text;
1191 tmp->lineno = @1.first_line;
1192 delete $1;
1193 $$ = tmp;
1196 | IDENTIFIER range '(' expression_list_with_nuls ')'
1197 { lgate*tmp = new lgate;
1198 svector<PExpr*>*rng = $2;
1199 tmp->name = $1;
1200 tmp->parms = $4;
1201 tmp->range[0] = (*rng)[0];
1202 tmp->range[1] = (*rng)[1];
1203 tmp->file = @1.text;
1204 tmp->lineno = @1.first_line;
1205 delete $1;
1206 delete rng;
1207 $$ = tmp;
1209 | '(' expression_list_with_nuls ')'
1210 { lgate*tmp = new lgate;
1211 tmp->name = "";
1212 tmp->parms = $2;
1213 tmp->file = @1.text;
1214 tmp->lineno = @1.first_line;
1215 $$ = tmp;
1218 /* Degenerate modules can have no ports. */
1220 | IDENTIFIER range
1221 { lgate*tmp = new lgate;
1222 svector<PExpr*>*rng = $2;
1223 tmp->name = $1;
1224 tmp->parms = 0;
1225 tmp->parms_by_name = 0;
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;
1235 /* Modules can also take ports by port-name expressions. */
1237 | IDENTIFIER '(' port_name_list ')'
1238 { lgate*tmp = new lgate;
1239 tmp->name = $1;
1240 tmp->parms = 0;
1241 tmp->parms_by_name = $3;
1242 tmp->file = @1.text;
1243 tmp->lineno = @1.first_line;
1244 delete $1;
1245 $$ = tmp;
1248 | IDENTIFIER range '(' port_name_list ')'
1249 { lgate*tmp = new lgate;
1250 svector<PExpr*>*rng = $2;
1251 tmp->name = $1;
1252 tmp->parms = 0;
1253 tmp->parms_by_name = $4;
1254 tmp->range[0] = (*rng)[0];
1255 tmp->range[1] = (*rng)[1];
1256 tmp->file = @1.text;
1257 tmp->lineno = @1.first_line;
1258 delete $1;
1259 delete rng;
1260 $$ = tmp;
1264 gate_instance_list
1265 : gate_instance_list ',' gate_instance
1266 { svector<lgate>*tmp1 = $1;
1267 lgate*tmp2 = $3;
1268 svector<lgate>*out = new svector<lgate> (*tmp1, *tmp2);
1269 delete tmp1;
1270 delete tmp2;
1271 $$ = out;
1273 | gate_instance
1274 { svector<lgate>*tmp = new svector<lgate>(1);
1275 (*tmp)[0] = *$1;
1276 delete $1;
1277 $$ = tmp;
1281 gatetype
1282 : K_and { $$ = PGBuiltin::AND; }
1283 | K_nand { $$ = PGBuiltin::NAND; }
1284 | K_or { $$ = PGBuiltin::OR; }
1285 | K_nor { $$ = PGBuiltin::NOR; }
1286 | K_xor { $$ = PGBuiltin::XOR; }
1287 | K_xnor { $$ = PGBuiltin::XNOR; }
1288 | K_buf { $$ = PGBuiltin::BUF; }
1289 | K_bufif0 { $$ = PGBuiltin::BUFIF0; }
1290 | K_bufif1 { $$ = PGBuiltin::BUFIF1; }
1291 | K_not { $$ = PGBuiltin::NOT; }
1292 | K_notif0 { $$ = PGBuiltin::NOTIF0; }
1293 | K_notif1 { $$ = PGBuiltin::NOTIF1; }
1294 | K_nmos { $$ = PGBuiltin::NMOS; }
1295 | K_rnmos { $$ = PGBuiltin::RNMOS; }
1296 | K_pmos { $$ = PGBuiltin::PMOS; }
1297 | K_rpmos { $$ = PGBuiltin::RPMOS; }
1298 | K_cmos { $$ = PGBuiltin::CMOS; }
1299 | K_rcmos { $$ = PGBuiltin::RCMOS; }
1300 | K_tran { $$ = PGBuiltin::TRAN; }
1301 | K_rtran { $$ = PGBuiltin::RTRAN; }
1302 | K_tranif0 { $$ = PGBuiltin::TRANIF0; }
1303 | K_tranif1 { $$ = PGBuiltin::TRANIF1; }
1304 | K_rtranif0 { $$ = PGBuiltin::RTRANIF0; }
1305 | K_rtranif1 { $$ = PGBuiltin::RTRANIF1; }
1309 /* A general identifier is a hierarchical name, with the right most
1310 name the base of the identifier. This rule builds up a
1311 hierarchical name from the left to the right, forming a list of
1312 names. */
1314 heirarchy_identifier
1315 : IDENTIFIER
1316 { $$ = new pform_name_t;
1317 $$->push_back(name_component_t(lex_strings.make($1)));
1318 delete $1;
1320 | heirarchy_identifier '.' IDENTIFIER
1321 { pform_name_t * tmp = $1;
1322 tmp->push_back(name_component_t(lex_strings.make($3)));
1323 delete $3;
1324 $$ = tmp;
1326 | heirarchy_identifier '[' expression ']'
1327 { pform_name_t * tmp = $1;
1328 name_component_t&tail = tmp->back();
1329 index_component_t itmp;
1330 itmp.sel = index_component_t::SEL_BIT;
1331 itmp.msb = $3;
1332 tail.index.push_back(itmp);
1333 $$ = tmp;
1335 | heirarchy_identifier '[' expression ':' expression ']'
1336 { pform_name_t * tmp = $1;
1337 name_component_t&tail = tmp->back();
1338 index_component_t itmp;
1339 itmp.sel = index_component_t::SEL_PART;
1340 itmp.msb = $3;
1341 itmp.lsb = $5;
1342 tail.index.push_back(itmp);
1343 $$ = tmp;
1345 | heirarchy_identifier '[' expression K_PO_POS expression ']'
1346 { pform_name_t * tmp = $1;
1347 name_component_t&tail = tmp->back();
1348 index_component_t itmp;
1349 itmp.sel = index_component_t::SEL_IDX_UP;
1350 itmp.msb = $3;
1351 itmp.lsb = $5;
1352 tail.index.push_back(itmp);
1353 $$ = tmp;
1355 | heirarchy_identifier '[' expression K_PO_NEG expression ']'
1356 { pform_name_t * tmp = $1;
1357 name_component_t&tail = tmp->back();
1358 index_component_t itmp;
1359 itmp.sel = index_component_t::SEL_IDX_DO;
1360 itmp.msb = $3;
1361 itmp.lsb = $5;
1362 tail.index.push_back(itmp);
1363 $$ = tmp;
1367 /* This is a list of identifiers. The result is a list of strings,
1368 each one of the identifiers in the list. These are simple,
1369 non-hierarchical names separated by ',' characters. */
1370 list_of_identifiers
1371 : IDENTIFIER
1372 { $$ = list_from_identifier($1); }
1373 | list_of_identifiers ',' IDENTIFIER
1374 { $$ = list_from_identifier($1, $3); }
1378 /* The list_of_ports and list_of_port_declarations rules are the
1379 port list formats for module ports. The list_of_ports_opt rule is
1380 only used by the module start rule.
1382 The first, the list_of_ports, is the 1364-1995 format, a list of
1383 port names, including .name() syntax.
1385 The list_of_port_declarations the 1364-2001 format, an in-line
1386 declaration of the ports.
1388 In both cases, the list_of_ports and list_of_port_declarations
1389 returns an array of Module::port_t* items that include the name
1390 of the port internally and externally. The actual creation of the
1391 nets/variables is done in the declaration, whether internal to
1392 the port list or in amongst the module items. */
1394 list_of_ports
1395 : port_opt
1396 { svector<Module::port_t*>*tmp
1397 = new svector<Module::port_t*>(1);
1398 (*tmp)[0] = $1;
1399 $$ = tmp;
1401 | list_of_ports ',' port_opt
1402 { svector<Module::port_t*>*tmp
1403 = new svector<Module::port_t*>(*$1, $3);
1404 delete $1;
1405 $$ = tmp;
1409 list_of_port_declarations
1410 : port_declaration
1411 { svector<Module::port_t*>*tmp
1412 = new svector<Module::port_t*>(1);
1413 (*tmp)[0] = $1;
1415 * Uncommenting this makes lopd always fully specified.
1416 * Some wanted an implicit net to not be fully defined.
1418 * pform_set_net_range($1[0].name);
1420 $$ = tmp;
1422 | list_of_port_declarations ',' port_declaration
1423 { svector<Module::port_t*>*tmp
1424 = new svector<Module::port_t*>(*$1, $3);
1425 delete $1;
1427 * Same as above.
1429 * pform_set_net_range($3[0].name);
1431 $$ = tmp;
1433 | list_of_port_declarations ',' IDENTIFIER
1434 { Module::port_t*ptmp;
1435 ptmp = pform_module_port_reference($3, @3.text,
1436 @3.first_line);
1437 svector<Module::port_t*>*tmp
1438 = new svector<Module::port_t*>(*$1, ptmp);
1440 /* Get the port declaration details, the port type
1441 and what not, from context data stored by the
1442 last port_declaration rule. */
1443 pform_module_define_port(@3, $3,
1444 port_declaration_context.port_type,
1445 port_declaration_context.port_net_type,
1446 port_declaration_context.sign_flag,
1447 port_declaration_context.range, 0);
1448 delete $1;
1450 * Same as above.
1452 * pform_set_net_range($3);
1454 $$ = tmp;
1458 port_declaration
1459 : attribute_list_opt
1460 K_input net_type_opt signed_opt range_opt IDENTIFIER
1461 { Module::port_t*ptmp;
1462 ptmp = pform_module_port_reference($6, @2.text,
1463 @2.first_line);
1464 pform_module_define_port(@2, $6, NetNet::PINPUT,
1465 $3, $4, $5, $1);
1466 port_declaration_context.port_type = NetNet::PINPUT;
1467 port_declaration_context.port_net_type = $3;
1468 port_declaration_context.sign_flag = $4;
1469 port_declaration_context.range = $5;
1470 delete $1;
1471 delete $6;
1472 $$ = ptmp;
1474 | attribute_list_opt
1475 K_inout net_type_opt signed_opt range_opt IDENTIFIER
1476 { Module::port_t*ptmp;
1477 ptmp = pform_module_port_reference($6, @2.text,
1478 @2.first_line);
1479 pform_module_define_port(@2, $6, NetNet::PINOUT,
1480 $3, $4, $5, $1);
1481 port_declaration_context.port_type = NetNet::PINOUT;
1482 port_declaration_context.port_net_type = $3;
1483 port_declaration_context.sign_flag = $4;
1484 port_declaration_context.range = $5;
1485 delete $1;
1486 delete $6;
1487 $$ = ptmp;
1489 | attribute_list_opt
1490 K_output net_type_opt signed_opt range_opt IDENTIFIER
1491 { Module::port_t*ptmp;
1492 ptmp = pform_module_port_reference($6, @2.text,
1493 @2.first_line);
1494 pform_module_define_port(@2, $6, NetNet::POUTPUT,
1495 $3, $4, $5, $1);
1496 port_declaration_context.port_type = NetNet::POUTPUT;
1497 port_declaration_context.port_net_type = $3;
1498 port_declaration_context.sign_flag = $4;
1499 port_declaration_context.range = $5;
1500 delete $1;
1501 delete $6;
1502 $$ = ptmp;
1504 | attribute_list_opt
1505 K_output var_type signed_opt range_opt IDENTIFIER
1506 { Module::port_t*ptmp;
1507 ptmp = pform_module_port_reference($6, @2.text,
1508 @2.first_line);
1509 pform_module_define_port(@2, $6, NetNet::POUTPUT,
1510 $3, $4, $5, $1);
1511 port_declaration_context.port_type = NetNet::POUTPUT;
1512 port_declaration_context.port_net_type = $3;
1513 port_declaration_context.sign_flag = $4;
1514 port_declaration_context.range = $5;
1515 delete $1;
1516 delete $6;
1517 $$ = ptmp;
1519 | attribute_list_opt
1520 K_output var_type signed_opt range_opt IDENTIFIER '=' expression
1521 { Module::port_t*ptmp;
1522 ptmp = pform_module_port_reference($6, @2.text,
1523 @2.first_line);
1524 pform_module_define_port(@2, $6, NetNet::POUTPUT,
1525 $3, $4, $5, $1);
1526 port_declaration_context.port_type = NetNet::POUTPUT;
1527 port_declaration_context.port_net_type = $3;
1528 port_declaration_context.sign_flag = $4;
1529 port_declaration_context.range = $5;
1531 if (! pform_expression_is_constant($8))
1532 yyerror(@8, "error: register declaration assignment"
1533 " value must be a constant expression.");
1534 pform_make_reginit(@6, $6, $8);
1536 delete $1;
1537 delete $6;
1538 $$ = ptmp;
1544 net_type_opt
1545 : net_type { $$ = $1; }
1546 | { $$ = NetNet::IMPLICIT; }
1549 signed_opt : K_signed { $$ = true; } | {$$ = false; } ;
1551 /* An lpvalue is the expression that can go on the left side of a
1552 procedural assignment. This rule handles only procedural
1553 assignments. It is more limited then the general expr_primary
1554 rule to reflect the rules for assignment l-values. */
1555 lpvalue
1556 : heirarchy_identifier
1557 { PEIdent*tmp = new PEIdent(*$1);
1558 tmp->set_file(@1.text);
1559 tmp->set_lineno(@1.first_line);
1560 $$ = tmp;
1561 delete $1;
1563 | '{' expression_list_proper '}'
1564 { PEConcat*tmp = new PEConcat(*$2);
1565 tmp->set_file(@1.text);
1566 tmp->set_lineno(@1.first_line);
1567 delete $2;
1568 $$ = tmp;
1573 /* Continuous assignments have a list of individual assignments. */
1575 cont_assign
1576 : lpvalue '=' expression
1577 { svector<PExpr*>*tmp = new svector<PExpr*>(2);
1578 (*tmp)[0] = $1;
1579 (*tmp)[1] = $3;
1580 $$ = tmp;
1584 cont_assign_list
1585 : cont_assign_list ',' cont_assign
1586 { svector<PExpr*>*tmp = new svector<PExpr*>(*$1, *$3);
1587 delete $1;
1588 delete $3;
1589 $$ = tmp;
1591 | cont_assign
1592 { $$ = $1; }
1596 /* This is the global structure of a module. A module in a start
1597 section, with optional ports, then an optional list of module
1598 items, and finally an end marker. */
1600 module : attribute_list_opt module_start IDENTIFIER
1601 { pform_startmodule($3, @2.text, @2.first_line, $1); }
1602 module_parameter_port_list_opt
1603 module_port_list_opt ';'
1604 { pform_module_set_ports($6); }
1605 module_item_list_opt
1606 K_endmodule
1607 { pform_endmodule($3);
1608 delete $3;
1613 module_start : K_module | K_macromodule ;
1615 module_port_list_opt
1616 : '(' list_of_ports ')' { $$ = $2; }
1617 | '(' list_of_port_declarations ')' { $$ = $2; }
1618 | { $$ = 0; }
1621 /* Module declarations include optional ANSII style module parameter
1622 ports. These are simply advance ways to declare parameters, so
1623 that the port declarations may use them. */
1624 module_parameter_port_list_opt
1626 | '#' '(' module_parameter_port_list ')'
1629 module_parameter_port_list
1630 : K_parameter parameter_assign
1631 | module_parameter_port_list ',' parameter_assign
1632 | module_parameter_port_list ',' K_parameter parameter_assign
1635 module_item
1637 /* This rule detects net declarations that possibly include a
1638 primitive type, an optional vector range and signed flag. This
1639 also includes an optional delay set. The values are then applied
1640 to a list of names. If the primitive type is not specified, then
1641 resort to the default type LOGIC. */
1643 : attribute_list_opt net_type
1644 primitive_type_opt signed_opt range_opt
1645 delay3_opt
1646 net_variable_list ';'
1648 { ivl_variable_type_t dtype = $3;
1649 if (dtype == IVL_VT_NO_TYPE)
1650 dtype = IVL_VT_LOGIC;
1651 pform_makewire(@2, $5, $4, $7, $2,
1652 NetNet::NOT_A_PORT, dtype, $1);
1653 if ($6 != 0) {
1654 yyerror(@6, "sorry: net delays not supported.");
1655 delete $6;
1657 if ($1) delete $1;
1660 /* Very similar to the rule above, but this takes a list of
1661 net_decl_assigns, which are <name> = <expr> assignment
1662 declarations. */
1664 | attribute_list_opt net_type
1665 primitive_type_opt signed_opt range_opt
1666 delay3_opt net_decl_assigns ';'
1668 { ivl_variable_type_t dtype = $3;
1669 if (dtype == IVL_VT_NO_TYPE)
1670 dtype = IVL_VT_LOGIC;
1671 pform_makewire(@2, $5, $4, $6,
1672 str_strength, $7, $2, dtype);
1673 if ($1) {
1674 yyerror(@2, "sorry: Attributes not supported "
1675 "on net declaration assignments.");
1676 delete $1;
1680 /* This form doesn't have the range, but does have strengths. This
1681 gives strength to the assignment drivers. */
1683 | attribute_list_opt net_type
1684 primitive_type_opt signed_opt
1685 drive_strength net_decl_assigns ';'
1687 { ivl_variable_type_t dtype = $3;
1688 if (dtype == IVL_VT_NO_TYPE)
1689 dtype = IVL_VT_LOGIC;
1690 pform_makewire(@2, 0, $4, 0, $5, $6, $2, dtype);
1691 if ($1) {
1692 yyerror(@2, "sorry: Attributes not supported "
1693 "on net declaration assignments.");
1694 delete $1;
1698 | K_trireg charge_strength_opt range_opt delay3_opt list_of_identifiers ';'
1699 { yyerror(@1, "sorry: trireg nets not supported.");
1700 delete $3;
1701 delete $4;
1704 | port_type signed_opt range_opt delay3_opt list_of_identifiers ';'
1705 { pform_set_port_type(@1, $5, $3, $2, $1);
1708 /* The next two rules handle Verilog 2001 statements of the form:
1709 input wire signed [h:l] <list>;
1710 This creates the wire and sets the port type all at once. */
1712 | port_type net_type signed_opt range_opt list_of_identifiers ';'
1713 { pform_makewire(@1, $4, $3, $5, $2, $1, IVL_VT_NO_TYPE, 0,
1714 SR_BOTH);
1717 | K_output var_type signed_opt range_opt list_of_identifiers ';'
1718 { pform_makewire(@1, $4, $3, $5, $2, NetNet::POUTPUT,
1719 IVL_VT_NO_TYPE, 0, SR_BOTH);
1722 /* var_type declaration (reg variables) cannot be input or output,
1723 because the port declaration implies an external driver, which
1724 cannot be attached to a reg. These rules catch that error early. */
1726 | K_input var_type signed_opt range_opt list_of_identifiers ';'
1727 { pform_makewire(@1, $4, $3, $5, $2, NetNet::PINPUT,
1728 IVL_VT_NO_TYPE, 0);
1729 yyerror(@2, "error: reg variables cannot be inputs.");
1732 | K_inout var_type signed_opt range_opt list_of_identifiers ';'
1733 { pform_makewire(@1, $4, $3, $5, $2, NetNet::PINOUT,
1734 IVL_VT_NO_TYPE, 0);
1735 yyerror(@2, "error: reg variables cannot be inouts.");
1738 | port_type signed_opt range_opt delay3_opt error ';'
1739 { yyerror(@1, "error: Invalid variable list"
1740 " in port declaration.");
1741 if ($3) delete $3;
1742 if ($4) delete $4;
1743 yyerrok;
1746 /* block_item_decl rule is shared with task blocks and named
1747 begin/end. */
1749 | block_item_decl
1751 /* */
1753 | K_defparam defparam_assign_list ';'
1754 | K_event list_of_identifiers ';'
1755 { pform_make_events($2, @1.text, @1.first_line);
1758 /* Most gate types have an optional drive strength and optional
1759 three-value delay. These rules handle the different cases. */
1761 | attribute_list_opt gatetype gate_instance_list ';'
1762 { pform_makegates($2, str_strength, 0, $3, $1);
1765 | attribute_list_opt gatetype delay3 gate_instance_list ';'
1766 { pform_makegates($2, str_strength, $3, $4, $1);
1769 | attribute_list_opt gatetype drive_strength gate_instance_list ';'
1770 { pform_makegates($2, $3, 0, $4, $1);
1773 | attribute_list_opt gatetype drive_strength delay3 gate_instance_list ';'
1774 { pform_makegates($2, $3, $4, $5, $1);
1777 /* Pullup and pulldown devices cannot have delays, and their
1778 strengths are limited. */
1780 | K_pullup gate_instance_list ';'
1781 { pform_makegates(PGBuiltin::PULLUP, pull_strength, 0,
1782 $2, 0);
1784 | K_pulldown gate_instance_list ';'
1785 { pform_makegates(PGBuiltin::PULLDOWN, pull_strength,
1786 0, $2, 0);
1789 | K_pullup '(' dr_strength1 ')' gate_instance_list ';'
1790 { pform_makegates(PGBuiltin::PULLUP, $3, 0, $5, 0);
1793 | K_pulldown '(' dr_strength0 ')' gate_instance_list ';'
1794 { pform_makegates(PGBuiltin::PULLDOWN, $3, 0, $5, 0);
1797 /* This rule handles instantiations of modules and user defined
1798 primitives. These devices to not have delay lists or strengths,
1799 but then can have parameter lists. */
1801 | attribute_list_opt
1802 IDENTIFIER parameter_value_opt gate_instance_list ';'
1803 { perm_string tmp1 = lex_strings.make($2);
1804 pform_make_modgates(tmp1, $3, $4);
1805 delete $2;
1806 if ($1) delete $1;
1809 | attribute_list_opt
1810 IDENTIFIER parameter_value_opt error ';'
1811 { yyerror(@2, "error: Invalid module instantiation");
1812 if ($1) delete $1;
1815 /* Continuous assignment can have an optional drive strength, then
1816 an optional delay3 that applies to all the assignments in the
1817 cont_assign_list. */
1819 | K_assign drive_strength_opt delay3_opt cont_assign_list ';'
1820 { pform_make_pgassign_list($4, $3, $2, @1.text, @1.first_line); }
1822 /* Always and initial items are behavioral processes. */
1824 | attribute_list_opt K_always statement
1825 { PProcess*tmp = pform_make_behavior(PProcess::PR_ALWAYS,
1826 $3, $1);
1827 tmp->set_file(@2.text);
1828 tmp->set_lineno(@2.first_line);
1830 | attribute_list_opt K_initial statement
1831 { PProcess*tmp = pform_make_behavior(PProcess::PR_INITIAL,
1832 $3, $1);
1833 tmp->set_file(@2.text);
1834 tmp->set_lineno(@2.first_line);
1837 /* The task declaration rule matches the task declaration
1838 header, then pushes the function scope. This causes the
1839 definitions in the task_body to take on the scope of the task
1840 instead of the module. Note that these runs accept for the task
1841 body statement_or_null, although the standard does not allow null
1842 statements in the task body. But we continue to accept it as an
1843 extension. */
1845 | K_task IDENTIFIER ';'
1846 { pform_push_scope($2); }
1847 task_item_list_opt
1848 statement_or_null
1849 K_endtask
1850 { PTask*tmp = new PTask;
1851 perm_string tmp2 = lex_strings.make($2);
1852 tmp->set_file(@1.text);
1853 tmp->set_lineno(@1.first_line);
1854 tmp->set_ports($5);
1855 tmp->set_statement($6);
1856 pform_set_task(tmp2, tmp);
1857 pform_pop_scope();
1858 delete $2;
1861 | K_task IDENTIFIER
1862 { pform_push_scope($2); }
1863 '(' task_port_decl_list ')' ';'
1864 task_item_list_opt
1865 statement_or_null
1866 K_endtask
1867 { PTask*tmp = new PTask;
1868 perm_string tmp2 = lex_strings.make($2);
1869 tmp->set_file(@1.text);
1870 tmp->set_lineno(@1.first_line);
1871 tmp->set_ports($5);
1872 tmp->set_statement($9);
1873 pform_set_task(tmp2, tmp);
1874 pform_pop_scope();
1875 delete $2;
1878 /* The function declaration rule matches the function declaration
1879 header, then pushes the function scope. This causes the
1880 definitions in the func_body to take on the scope of the function
1881 instead of the module. */
1883 | K_function function_range_or_type_opt IDENTIFIER ';'
1884 { pform_push_scope($3); }
1885 function_item_list statement
1886 K_endfunction
1887 { perm_string name = lex_strings.make($3);
1888 PFunction *tmp = new PFunction(name);
1889 tmp->set_file(@1.text);
1890 tmp->set_lineno(@1.first_line);
1891 tmp->set_ports($6);
1892 tmp->set_statement($7);
1893 tmp->set_return($2);
1894 pform_set_function(name, tmp);
1895 pform_pop_scope();
1896 delete $3;
1899 /* A generate region can contain further module items. Actually, it
1900 is supposed to be limited to certain kinds of module items, but
1901 the semantic tests will check that for us. */
1903 | K_generate module_item_list_opt K_endgenerate
1905 | K_genvar list_of_identifiers ';'
1906 { pform_genvars($2); }
1908 | K_for '(' IDENTIFIER '=' expression ';'
1909 expression ';'
1910 IDENTIFIER '=' expression ')'
1911 { pform_start_generate_for(@1, $3, $5, $7, $9, $11); }
1912 generate_block
1913 { pform_endgenerate(); }
1915 | generate_if
1916 generate_block_opt
1917 K_else
1918 { pform_start_generate_else(@1); }
1919 generate_block
1920 { pform_endgenerate(); }
1922 | generate_if
1923 generate_block_opt %prec less_than_K_else
1924 { pform_endgenerate(); }
1926 /* specify blocks are parsed but ignored. */
1928 | K_specify K_endspecify
1929 { /* empty lists are legal syntax. */ }
1931 | K_specify specify_item_list K_endspecify
1935 | K_specify error K_endspecify
1936 { yyerror(@1, "error: syntax error in specify block");
1937 yyerrok;
1940 /* These rules match various errors that the user can type into
1941 module items. These rules try to catch them at a point where a
1942 reasonable error message can be produced. */
1944 | K_module error ';'
1945 { yyerror(@2, "error: missing endmodule or attempt to "
1946 "nest modules.");
1947 pform_error_nested_modules();
1948 yyerrok;
1951 | error ';'
1952 { yyerror(@2, "error: invalid module item.");
1953 yyerrok;
1956 | K_assign error '=' expression ';'
1957 { yyerror(@1, "error: syntax error in left side "
1958 "of continuous assignment.");
1959 yyerrok;
1962 | K_assign error ';'
1963 { yyerror(@1, "error: syntax error in "
1964 "continuous assignment");
1965 yyerrok;
1968 | K_function error K_endfunction
1969 { yyerror(@1, "error: I give up on this "
1970 "function definition.");
1971 yyerrok;
1974 /* These rules are for the Icarus Verilog specific $attribute
1975 extensions. Then catch the parameters of the $attribute keyword. */
1977 | KK_attribute '(' IDENTIFIER ',' STRING ',' STRING ')' ';'
1978 { perm_string tmp3 = lex_strings.make($3);
1979 perm_string tmp5 = lex_strings.make($5);
1980 pform_set_attrib(tmp3, tmp5, $7);
1981 delete $3;
1982 delete $5;
1984 | KK_attribute '(' error ')' ';'
1985 { yyerror(@1, "error: Malformed $attribute parameter list."); }
1988 generate_if : K_if '(' expression ')' { pform_start_generate_if(@1, $3); }
1990 module_item_list
1991 : module_item_list module_item
1992 | module_item
1995 module_item_list_opt
1996 : module_item_list
2000 /* A generate block is the thing within a generate scheme. It may be
2001 a single module item, an anonymous block of module items, or a
2002 named module item. In all cases, the meat is in the module items
2003 inside, and the processing is done by the module_item rules. We
2004 only need to take note here of the scope name, if any. */
2006 generate_block
2007 : module_item
2008 | K_begin module_item_list_opt K_end
2009 | K_begin ':' IDENTIFIER module_item_list_opt K_end
2010 { pform_generate_block_name($3); }
2013 generate_block_opt : generate_block | ';' ;
2016 /* A net declaration assignment allows the programmer to combine the
2017 net declaration and the continuous assignment into a single
2018 statement.
2020 Note that the continuous assignment statement is generated as a
2021 side effect, and all I pass up is the name of the l-value. */
2023 net_decl_assign
2024 : IDENTIFIER '=' expression
2025 { net_decl_assign_t*tmp = new net_decl_assign_t;
2026 tmp->next = tmp;
2027 tmp->name = $1;
2028 tmp->expr = $3;
2029 $$ = tmp;
2033 net_decl_assigns
2034 : net_decl_assigns ',' net_decl_assign
2035 { net_decl_assign_t*tmp = $1;
2036 $3->next = tmp->next;
2037 tmp->next = $3;
2038 $$ = tmp;
2040 | net_decl_assign
2041 { $$ = $1;
2045 primitive_type
2046 : K_logic { $$ = IVL_VT_LOGIC; }
2047 | K_bool { $$ = IVL_VT_BOOL; }
2048 | K_real { $$ = IVL_VT_REAL; }
2051 primitive_type_opt : primitive_type { $$ = $1; } | { $$ = IVL_VT_NO_TYPE; } ;
2053 net_type
2054 : K_wire { $$ = NetNet::WIRE; }
2055 | K_tri { $$ = NetNet::TRI; }
2056 | K_tri1 { $$ = NetNet::TRI1; }
2057 | K_supply0 { $$ = NetNet::SUPPLY0; }
2058 | K_wand { $$ = NetNet::WAND; }
2059 | K_triand { $$ = NetNet::TRIAND; }
2060 | K_tri0 { $$ = NetNet::TRI0; }
2061 | K_supply1 { $$ = NetNet::SUPPLY1; }
2062 | K_wor { $$ = NetNet::WOR; }
2063 | K_trior { $$ = NetNet::TRIOR; }
2064 | K_wone { $$ = NetNet::WONE; }
2067 var_type
2068 : K_reg { $$ = NetNet::REG; }
2071 /* In this rule we have matched the "parameter" keyword. The rule
2072 generates a type (optional) and a list of assignments. */
2074 parameter_assign_decl
2075 : parameter_assign_list
2076 | range { active_range = $1; active_signed = false; }
2077 parameter_assign_list
2078 { active_range = 0;
2079 active_signed = false;
2081 | K_signed range { active_range = $2; active_signed = true; }
2082 parameter_assign_list
2083 { active_range = 0;
2084 active_signed = false;
2086 | K_integer { active_range = 0; active_signed = true; }
2087 parameter_assign_list
2088 { active_range = 0;
2089 active_signed = false;
2093 parameter_assign_list
2094 : parameter_assign
2095 | parameter_assign_list ',' parameter_assign
2098 parameter_assign
2099 : IDENTIFIER '=' expression
2100 { PExpr*tmp = $3;
2101 if (!pform_expression_is_constant(tmp)) {
2102 yyerror(@3, "error: parameter value "
2103 "must be a constant expression.");
2104 delete tmp;
2105 tmp = 0;
2106 } else {
2107 pform_set_parameter(lex_strings.make($1),
2108 active_signed,
2109 active_range, tmp);
2111 delete $1;
2115 /* Localparam assignments and assignment lists are broken into
2116 separate BNF so that I can call slightly different parameter
2117 handling code. They parse the same as parameters, they just
2118 behave differently when someone tries to override them. */
2120 localparam_assign
2121 : IDENTIFIER '=' expression
2122 { PExpr*tmp = $3;
2123 if (!pform_expression_is_constant(tmp)) {
2124 yyerror(@3, "error: parameter value "
2125 "must be constant.");
2126 delete tmp;
2127 tmp = 0;
2128 } else {
2129 pform_set_localparam(lex_strings.make($1),
2130 active_signed,
2131 active_range, tmp);
2133 delete $1;
2137 localparam_assign_decl
2138 : localparam_assign_list
2139 | range { active_range = $1; active_signed = false; }
2140 localparam_assign_list
2141 { active_range = 0;
2142 active_signed = false;
2144 | K_signed range { active_range = $2; active_signed = true; }
2145 localparam_assign_list
2146 { active_range = 0;
2147 active_signed = false;
2151 localparam_assign_list
2152 : localparam_assign
2153 | localparam_assign_list ',' localparam_assign
2158 /* The parameters of a module instance can be overridden by writing
2159 a list of expressions in a syntax much like a delay list. (The
2160 difference being the list can have any length.) The pform that
2161 attaches the expression list to the module checks that the
2162 expressions are constant.
2164 Although the BNF in IEEE1364-1995 implies that parameter value
2165 lists must be in parentheses, in practice most compilers will
2166 accept simple expressions outside of parentheses if there is only
2167 one value, so I'll accept simple numbers here.
2169 The parameter value by name syntax is OVI enhancement BTF-B06 as
2170 approved by WG1364 on 6/28/1998. */
2172 parameter_value_opt
2173 : '#' '(' expression_list_with_nuls ')'
2174 { struct parmvalue_t*tmp = new struct parmvalue_t;
2175 tmp->by_order = $3;
2176 tmp->by_name = 0;
2177 $$ = tmp;
2179 | '#' '(' parameter_value_byname_list ')'
2180 { struct parmvalue_t*tmp = new struct parmvalue_t;
2181 tmp->by_order = 0;
2182 tmp->by_name = $3;
2183 $$ = tmp;
2185 | '#' DEC_NUMBER
2186 { assert($2);
2187 PENumber*tmp = new PENumber($2);
2188 tmp->set_file(@1.text);
2189 tmp->set_lineno(@1.first_line);
2191 struct parmvalue_t*lst = new struct parmvalue_t;
2192 lst->by_order = new svector<PExpr*>(1);
2193 (*lst->by_order)[0] = tmp;
2194 lst->by_name = 0;
2195 $$ = lst;
2197 | '#' error
2198 { yyerror(@1, "error: syntax error in parameter value "
2199 "assignment list.");
2200 $$ = 0;
2203 { $$ = 0; }
2206 parameter_value_byname
2207 : '.' IDENTIFIER '(' expression ')'
2208 { named_pexpr_t*tmp = new named_pexpr_t;
2209 tmp->name = lex_strings.make($2);
2210 tmp->parm = $4;
2211 free($2);
2212 $$ = tmp;
2214 | '.' IDENTIFIER '(' ')'
2215 { named_pexpr_t*tmp = new named_pexpr_t;
2216 tmp->name = lex_strings.make($2);
2217 tmp->parm = 0;
2218 free($2);
2219 $$ = tmp;
2223 parameter_value_byname_list
2224 : parameter_value_byname
2225 { svector<named_pexpr_t*>*tmp = new svector<named_pexpr_t*>(1);
2226 (*tmp)[0] = $1;
2227 $$ = tmp;
2229 | parameter_value_byname_list ',' parameter_value_byname
2230 { svector<named_pexpr_t*>*tmp =
2231 new svector<named_pexpr_t*>(*$1,$3);
2232 delete $1;
2233 $$ = tmp;
2238 /* The port (of a module) is a fairly complex item. Each port is
2239 handled as a Module::port_t object. A simple port reference has a
2240 name and a PExpr object, but more complex constructs are possible
2241 where the name can be attached to a list of PWire objects.
2243 The port_reference returns a Module::port_t, and so does the
2244 port_reference_list. The port_reference_list may have built up a
2245 list of PWires in the port_t object, but it is still a single
2246 Module::port_t object.
2248 The port rule below takes the built up Module::port_t object and
2249 tweaks its name as needed. */
2251 port
2252 : port_reference
2253 { $$ = $1; }
2255 /* This syntax attaches an external name to the port reference so
2256 that the caller can bind by name to non-trivial port
2257 references. The port_t object gets its PWire from the
2258 port_reference, but its name from the IDENTIFIER. */
2260 | '.' IDENTIFIER '(' port_reference ')'
2261 { Module::port_t*tmp = $4;
2262 tmp->name = lex_strings.make($2);
2263 delete $2;
2264 $$ = tmp;
2267 /* A port can also be a concatenation of port references. In this
2268 case the port does not have a name available to the outside, only
2269 positional parameter passing is possible here. */
2271 | '{' port_reference_list '}'
2272 { Module::port_t*tmp = $2;
2273 tmp->name = perm_string();
2274 $$ = tmp;
2277 /* This attaches a name to a port reference concatenation list so
2278 that parameter passing be name is possible. */
2280 | '.' IDENTIFIER '(' '{' port_reference_list '}' ')'
2281 { Module::port_t*tmp = $5;
2282 tmp->name = lex_strings.make($2);
2283 delete $2;
2284 $$ = tmp;
2288 port_opt
2289 : port { $$ = $1; }
2290 | { $$ = 0; }
2294 /* A port reference is an internal (to the module) name of the port,
2295 possibly with a part of bit select to attach it to specific bits
2296 of a signal fully declared inside the module.
2298 The parser creates a PEIdent for every port reference, even if the
2299 signal is bound to different ports. The elaboration figures out
2300 the mess that this creates. The port_reference (and the
2301 port_reference_list below) puts the port reference PEIdent into the
2302 port_t object to pass it up to the module declaration code. */
2304 port_reference
2306 : IDENTIFIER
2307 { Module::port_t*ptmp;
2308 ptmp = pform_module_port_reference($1, @1.text, @1.first_line);
2309 delete $1;
2310 $$ = ptmp;
2313 | IDENTIFIER '[' expression ':' expression ']'
2314 { if (!pform_expression_is_constant($3)) {
2315 yyerror(@3, "error: msb expression of "
2316 "port part select must be constant.");
2318 if (!pform_expression_is_constant($5)) {
2319 yyerror(@5, "error: lsb expression of "
2320 "port part select must be constant.");
2322 index_component_t itmp;
2323 itmp.sel = index_component_t::SEL_PART;
2324 itmp.msb = $3;
2325 itmp.lsb = $5;
2327 name_component_t ntmp (lex_strings.make($1));
2328 ntmp.index.push_back(itmp);
2330 pform_name_t pname;
2331 pname.push_back(ntmp);
2333 PEIdent*wtmp = new PEIdent(pname);
2334 wtmp->set_file(@1.text);
2335 wtmp->set_lineno(@1.first_line);
2337 Module::port_t*ptmp = new Module::port_t;
2338 ptmp->name = perm_string();
2339 ptmp->expr = svector<PEIdent*>(1);
2340 ptmp->expr[0] = wtmp;
2342 delete $1;
2343 $$ = ptmp;
2346 | IDENTIFIER '[' expression ']'
2347 { if (!pform_expression_is_constant($3)) {
2348 yyerror(@3, "error: port bit select "
2349 "must be constant.");
2351 index_component_t itmp;
2352 itmp.sel = index_component_t::SEL_BIT;
2353 itmp.msb = $3;
2354 itmp.lsb = 0;
2356 name_component_t ntmp (lex_strings.make($1));
2357 ntmp.index.push_back(itmp);
2359 pform_name_t pname;
2360 pname.push_back(ntmp);
2362 PEIdent*tmp = new PEIdent(pname);
2363 tmp->set_file(@1.text);
2364 tmp->set_lineno(@1.first_line);
2366 Module::port_t*ptmp = new Module::port_t;
2367 ptmp->name = perm_string();
2368 ptmp->expr = svector<PEIdent*>(1);
2369 ptmp->expr[0] = tmp;
2370 delete $1;
2371 $$ = ptmp;
2374 | IDENTIFIER '[' error ']'
2375 { yyerror(@1, "error: invalid port bit select");
2376 Module::port_t*ptmp = new Module::port_t;
2377 PEIdent*wtmp = new PEIdent(lex_strings.make($1));
2378 wtmp->set_file(@1.text);
2379 wtmp->set_lineno(@1.first_line);
2380 ptmp->name = lex_strings.make($1);
2381 ptmp->expr = svector<PEIdent*>(1);
2382 ptmp->expr[0] = wtmp;
2383 delete $1;
2384 $$ = ptmp;
2389 port_reference_list
2390 : port_reference
2391 { $$ = $1; }
2392 | port_reference_list ',' port_reference
2393 { Module::port_t*tmp = $1;
2394 tmp->expr = svector<PEIdent*>(tmp->expr, $3->expr);
2395 delete $3;
2396 $$ = tmp;
2400 /* The port_name rule is used with a module is being *instantiated*,
2401 and not when it is being declared. See the port rule if you are
2402 looking for the ports of a module declaration. */
2404 port_name
2405 : '.' IDENTIFIER '(' expression ')'
2406 { named_pexpr_t*tmp = new named_pexpr_t;
2407 tmp->name = lex_strings.make($2);
2408 tmp->parm = $4;
2409 delete $2;
2410 $$ = tmp;
2412 | '.' IDENTIFIER '(' error ')'
2413 { yyerror(@4, "error: invalid port connection expression.");
2414 named_pexpr_t*tmp = new named_pexpr_t;
2415 tmp->name = lex_strings.make($2);
2416 tmp->parm = 0;
2417 delete $2;
2418 $$ = tmp;
2420 | '.' IDENTIFIER '(' ')'
2421 { named_pexpr_t*tmp = new named_pexpr_t;
2422 tmp->name = lex_strings.make($2);
2423 tmp->parm = 0;
2424 delete $2;
2425 $$ = tmp;
2429 port_name_list
2430 : port_name_list ',' port_name
2431 { svector<named_pexpr_t*>*tmp;
2432 tmp = new svector<named_pexpr_t*>(*$1, $3);
2433 delete $1;
2434 $$ = tmp;
2436 | port_name
2437 { svector<named_pexpr_t*>*tmp = new svector<named_pexpr_t*>(1);
2438 (*tmp)[0] = $1;
2439 $$ = tmp;
2443 port_type
2444 : K_input { $$ = NetNet::PINPUT; }
2445 | K_output { $$ = NetNet::POUTPUT; }
2446 | K_inout { $$ = NetNet::PINOUT; }
2449 range
2450 : '[' expression ':' expression ']'
2451 { svector<PExpr*>*tmp = new svector<PExpr*> (2);
2452 if (!pform_expression_is_constant($2))
2453 yyerror(@2, "error: msb of range must be constant.");
2455 (*tmp)[0] = $2;
2457 if (!pform_expression_is_constant($4))
2458 yyerror(@4, "error: lsb of range must be constant.");
2460 (*tmp)[1] = $4;
2462 $$ = tmp;
2466 range_opt
2467 : range
2468 | { $$ = 0; }
2471 /* This is used to express the return type of a function. */
2472 function_range_or_type_opt
2473 : range { $$.range = $1; $$.type = PTF_REG; }
2474 | K_signed range { $$.range = $2; $$.type = PTF_REG_S; }
2475 | K_integer { $$.range = 0; $$.type = PTF_INTEGER; }
2476 | K_real { $$.range = 0; $$.type = PTF_REAL; }
2477 | K_realtime { $$.range = 0; $$.type = PTF_REALTIME; }
2478 | K_time { $$.range = 0; $$.type = PTF_TIME; }
2479 | { $$.range = 0; $$.type = PTF_REG; }
2482 /* The register_variable rule is matched only when I am parsing
2483 variables in a "reg" definition. I therefore know that I am
2484 creating registers and I do not need to let the containing rule
2485 handle it. The register variable list simply packs them together
2486 so that bit ranges can be assigned. */
2487 register_variable
2488 : IDENTIFIER
2489 { pform_makewire(@1, $1, NetNet::REG,
2490 NetNet::NOT_A_PORT,
2491 IVL_VT_NO_TYPE, 0);
2492 $$ = $1;
2494 | IDENTIFIER '=' expression
2495 { pform_makewire(@1, $1, NetNet::REG,
2496 NetNet::NOT_A_PORT,
2497 IVL_VT_NO_TYPE, 0);
2498 if (! pform_expression_is_constant($3))
2499 yyerror(@3, "error: register declaration assignment"
2500 " value must be a constant expression.");
2501 pform_make_reginit(@1, $1, $3);
2502 $$ = $1;
2504 | IDENTIFIER '[' expression ':' expression ']'
2505 { pform_makewire(@1, $1, NetNet::REG,
2506 NetNet::NOT_A_PORT,
2507 IVL_VT_NO_TYPE, 0);
2508 if (! pform_expression_is_constant($3))
2509 yyerror(@3, "error: msb of register range must be constant.");
2510 if (! pform_expression_is_constant($5))
2511 yyerror(@3, "error: lsb of register range must be constant.");
2512 pform_set_reg_idx($1, $3, $5);
2513 $$ = $1;
2517 register_variable_list
2518 : register_variable
2519 { list<perm_string>*tmp = new list<perm_string>;
2520 tmp->push_back(lex_strings.make($1));
2521 $$ = tmp;
2522 delete[]$1;
2524 | register_variable_list ',' register_variable
2525 { list<perm_string>*tmp = $1;
2526 tmp->push_back(lex_strings.make($3));
2527 $$ = tmp;
2528 delete[]$3;
2532 real_variable
2533 : IDENTIFIER
2534 { pform_makewire(@1, $1, NetNet::REG, NetNet::NOT_A_PORT, IVL_VT_REAL, 0);
2535 $$ = $1;
2537 | IDENTIFIER '=' expression
2538 { pform_makewire(@1, $1, NetNet::REG, NetNet::NOT_A_PORT, IVL_VT_REAL, 0);
2539 pform_make_reginit(@1, $1, $3);
2540 $$ = $1;
2544 real_variable_list
2545 : real_variable
2546 { list<perm_string>*tmp = new list<perm_string>;
2547 tmp->push_back(lex_strings.make($1));
2548 $$ = tmp;
2549 delete[]$1;
2551 | real_variable_list ',' real_variable
2552 { list<perm_string>*tmp = $1;
2553 tmp->push_back(lex_strings.make($3));
2554 $$ = tmp;
2555 delete[]$3;
2559 net_variable
2560 : IDENTIFIER
2561 { pform_makewire(@1, $1, NetNet::IMPLICIT,
2562 NetNet::NOT_A_PORT,
2563 IVL_VT_NO_TYPE, 0);
2564 $$ = $1;
2566 | IDENTIFIER '[' expression ':' expression ']'
2567 { pform_makewire(@1, $1, NetNet::IMPLICIT,
2568 NetNet::NOT_A_PORT,
2569 IVL_VT_NO_TYPE, 0);
2570 if (! pform_expression_is_constant($3))
2571 yyerror(@3, "error: msb of net range must be constant.");
2572 if (! pform_expression_is_constant($5))
2573 yyerror(@3, "error: lsb of net range must be constant.");
2574 pform_set_reg_idx($1, $3, $5);
2575 $$ = $1;
2578 net_variable_list
2579 : net_variable
2580 { list<perm_string>*tmp = new list<perm_string>;
2581 tmp->push_back(lex_strings.make($1));
2582 $$ = tmp;
2583 delete[]$1;
2585 | net_variable_list ',' net_variable
2586 { list<perm_string>*tmp = $1;
2587 tmp->push_back(lex_strings.make($3));
2588 $$ = tmp;
2589 delete[]$3;
2593 specify_item
2594 : K_specparam specparam_list ';'
2595 | specify_simple_path_decl ';'
2596 { pform_module_specify_path($1);
2598 | specify_edge_path_decl ';'
2599 { pform_module_specify_path($1);
2601 | K_if '(' expression ')' specify_simple_path_decl ';'
2602 { PSpecPath*tmp = $5;
2603 if (tmp) {
2604 tmp->conditional = true;
2605 tmp->condition = $3;
2607 pform_module_specify_path(tmp);
2609 | K_if '(' expression ')' specify_edge_path_decl ';'
2610 { PSpecPath*tmp = $5;
2611 if (tmp) {
2612 tmp->conditional = true;
2613 tmp->condition = $3;
2615 pform_module_specify_path(tmp);
2617 | K_ifnone specify_simple_path_decl ';'
2618 { PSpecPath*tmp = $2;
2619 if (tmp) {
2620 tmp->conditional = true;
2621 tmp->condition = 0;
2623 pform_module_specify_path(tmp);
2625 | K_Shold '(' spec_reference_event ',' spec_reference_event
2626 ',' delay_value spec_notifier_opt ')' ';'
2627 { delete $7;
2629 | K_Speriod '(' spec_reference_event ',' delay_value
2630 spec_notifier_opt ')' ';'
2631 { delete $5;
2633 | K_Srecovery '(' spec_reference_event ',' spec_reference_event
2634 ',' delay_value spec_notifier_opt ')' ';'
2635 { delete $7;
2637 | K_Ssetup '(' spec_reference_event ',' spec_reference_event
2638 ',' delay_value spec_notifier_opt ')' ';'
2639 { delete $7;
2641 | K_Ssetuphold '(' spec_reference_event ',' spec_reference_event
2642 ',' delay_value ',' delay_value spec_notifier_opt ')' ';'
2643 { delete $7;
2644 delete $9;
2646 | K_Srecrem '(' spec_reference_event ',' spec_reference_event
2647 ',' delay_value ',' delay_value spec_notifier_opt ')' ';'
2648 { delete $7;
2649 delete $9;
2651 | K_Swidth '(' spec_reference_event ',' delay_value ',' expression
2652 spec_notifier_opt ')' ';'
2653 { delete $5;
2654 delete $7;
2656 | K_Swidth '(' spec_reference_event ',' delay_value ')' ';'
2657 { delete $5;
2661 specify_item_list
2662 : specify_item
2663 | specify_item_list specify_item
2666 specify_edge_path_decl
2667 : specify_edge_path '=' '(' delay_value_list ')'
2668 { $$ = pform_assign_path_delay($1, $4); }
2669 | specify_edge_path '=' delay_value_simple
2670 { svector<PExpr*>*tmp = new svector<PExpr*>(1);
2671 (*tmp)[0] = $3;
2672 $$ = pform_assign_path_delay($1, tmp);
2676 edge_operator : K_posedge { $$ = true; } | K_negedge { $$ = false; } ;
2678 specify_edge_path
2679 : '(' specify_path_identifiers spec_polarity
2680 K_EG '(' specify_path_identifiers polarity_operator expression ')' ')'
2681 { int edge_flag = 0;
2682 $$ = pform_make_specify_edge_path(@1, edge_flag, $2, $3, false, $6, $8); }
2683 | '(' edge_operator specify_path_identifiers spec_polarity
2684 K_EG '(' specify_path_identifiers polarity_operator expression ')' ')'
2685 { int edge_flag = $2? 1 : -1;
2686 $$ = pform_make_specify_edge_path(@1, edge_flag, $3, $4, false, $7, $9);}
2687 | '(' specify_path_identifiers spec_polarity
2688 K_SG '(' specify_path_identifiers polarity_operator expression ')' ')'
2689 { int edge_flag = 0;
2690 $$ = pform_make_specify_edge_path(@1, edge_flag, $2, $3, true, $6, $8); }
2691 | '(' edge_operator specify_path_identifiers spec_polarity
2692 K_SG '(' specify_path_identifiers polarity_operator expression ')' ')'
2693 { int edge_flag = $2? 1 : -1;
2694 $$ = pform_make_specify_edge_path(@1, edge_flag, $3, $4, true, $7, $9); }
2697 polarity_operator
2698 : K_PO_POS
2699 | K_PO_NEG
2700 | ':'
2703 specify_simple_path_decl
2704 : specify_simple_path '=' '(' delay_value_list ')'
2705 { $$ = pform_assign_path_delay($1, $4); }
2706 | specify_simple_path '=' delay_value_simple
2707 { svector<PExpr*>*tmp = new svector<PExpr*>(1);
2708 (*tmp)[0] = $3;
2709 $$ = pform_assign_path_delay($1, tmp);
2711 | specify_simple_path '=' '(' error ')'
2712 { yyerror(@2, "Syntax error in delay value list.");
2713 yyerrok;
2714 $$ = 0;
2718 specify_simple_path
2719 : '(' specify_path_identifiers spec_polarity
2720 K_EG specify_path_identifiers ')'
2721 { $$ = pform_make_specify_path(@1, $2, $3, false, $5); }
2722 | '(' specify_path_identifiers spec_polarity
2723 K_SG specify_path_identifiers ')'
2724 { $$ = pform_make_specify_path(@1, $2, $3, true, $5); }
2725 | '(' error ')'
2726 { yyerror(@2, "Invalid simple path");
2727 yyerrok;
2731 specify_path_identifiers
2732 : IDENTIFIER
2733 { list<perm_string>*tmp = new list<perm_string>;
2734 tmp->push_back(lex_strings.make($1));
2735 $$ = tmp;
2736 delete[]$1;
2738 | IDENTIFIER '[' expr_primary ']'
2739 { list<perm_string>*tmp = new list<perm_string>;
2740 tmp->push_back(lex_strings.make($1));
2741 $$ = tmp;
2742 delete[]$1;
2744 | specify_path_identifiers ',' IDENTIFIER
2745 { list<perm_string>*tmp = $1;
2746 tmp->push_back(lex_strings.make($3));
2747 $$ = tmp;
2748 delete[]$3;
2750 | specify_path_identifiers ',' IDENTIFIER '[' expr_primary ']'
2751 { list<perm_string>*tmp = $1;
2752 tmp->push_back(lex_strings.make($3));
2753 $$ = tmp;
2754 delete[]$3;
2758 specparam
2759 : IDENTIFIER '=' expression
2760 { PExpr*tmp = $3;
2761 pform_set_specparam(lex_strings.make($1), tmp);
2762 delete $1;
2764 | IDENTIFIER '=' expression ':' expression ':' expression
2765 { PExpr*tmp = 0;
2766 switch (min_typ_max_flag) {
2767 case MIN:
2768 tmp = $3;
2769 delete $5;
2770 delete $7;
2771 break;
2772 case TYP:
2773 delete $3;
2774 tmp = $5;
2775 delete $7;
2776 break;
2777 case MAX:
2778 delete $3;
2779 delete $5;
2780 tmp = $7;
2781 break;
2783 pform_set_specparam(lex_strings.make($1), tmp);
2784 delete $1;
2786 | PATHPULSE_IDENTIFIER '=' expression
2787 { delete $1;
2788 delete $3;
2790 | PATHPULSE_IDENTIFIER '=' '(' expression ',' expression ')'
2791 { delete $1;
2792 delete $4;
2793 delete $6;
2797 specparam_list
2798 : specparam
2799 | specparam_list ',' specparam
2802 spec_polarity
2803 : '+' { $$ = '+'; }
2804 | '-' { $$ = '-'; }
2805 | { $$ = 0; }
2808 spec_reference_event
2809 : K_posedge expression
2810 { delete $2; }
2811 | K_negedge expression
2812 { delete $2; }
2813 | K_posedge expr_primary K_TAND expression
2814 { delete $2;
2815 delete $4;
2817 | K_negedge expr_primary K_TAND expression
2818 { delete $2;
2819 delete $4;
2821 | K_edge '[' edge_descriptor_list ']' expr_primary K_TAND expression
2822 { delete $5;
2823 delete $7;
2825 | expr_primary K_TAND expression
2826 { delete $1;
2827 delete $3;
2829 | expr_primary
2830 { delete $1; }
2833 /* The edge_descriptor is detected by the lexor as the various
2834 2-letter edge sequences that are supported here. For now, we
2835 don't care what they are, because we do not yet support specify
2836 edge events. */
2837 edge_descriptor_list
2838 : edge_descriptor_list ',' K_edge_descriptor
2839 | K_edge_descriptor
2842 spec_notifier_opt
2843 : /* empty */
2845 | spec_notifier
2848 spec_notifier
2849 : ','
2851 | ',' heirarchy_identifier
2852 { delete $2; }
2853 | spec_notifier ','
2855 | spec_notifier ',' heirarchy_identifier
2856 { delete $3; }
2857 | IDENTIFIER
2858 { delete $1; }
2862 statement
2864 /* assign and deassign statements are procedural code to do
2865 structural assignments, and to turn that structural assignment
2866 off. This stronger then any other assign, but weaker then the
2867 force assignments. */
2869 : K_assign lpvalue '=' expression ';'
2870 { PCAssign*tmp = new PCAssign($2, $4);
2871 tmp->set_file(@1.text);
2872 tmp->set_lineno(@1.first_line);
2873 $$ = tmp;
2876 | K_deassign lpvalue ';'
2877 { PDeassign*tmp = new PDeassign($2);
2878 tmp->set_file(@1.text);
2879 tmp->set_lineno(@1.first_line);
2880 $$ = tmp;
2884 /* Force and release statements are similar to assignments,
2885 syntactically, but they will be elaborated differently. */
2887 | K_force lpvalue '=' expression ';'
2888 { PForce*tmp = new PForce($2, $4);
2889 tmp->set_file(@1.text);
2890 tmp->set_lineno(@1.first_line);
2891 $$ = tmp;
2893 | K_release lpvalue ';'
2894 { PRelease*tmp = new PRelease($2);
2895 tmp->set_file(@1.text);
2896 tmp->set_lineno(@1.first_line);
2897 $$ = tmp;
2900 /* begin-end blocks come in a variety of forms, including named and
2901 anonymous. The named blocks can also carry their own reg
2902 variables, which are placed in the scope created by the block
2903 name. These are handled by pushing the scope name then matching
2904 the declarations. The scope is popped at the end of the block. */
2906 | K_begin statement_list K_end
2907 { PBlock*tmp = new PBlock(PBlock::BL_SEQ, *$2);
2908 tmp->set_file(@1.text);
2909 tmp->set_lineno(@1.first_line);
2910 delete $2;
2911 $$ = tmp;
2913 | K_begin ':' IDENTIFIER
2914 { pform_push_scope($3); }
2915 block_item_decls_opt
2916 statement_list K_end
2917 { pform_pop_scope();
2918 PBlock*tmp = new PBlock(lex_strings.make($3),
2919 PBlock::BL_SEQ, *$6);
2920 tmp->set_file(@1.text);
2921 tmp->set_lineno(@1.first_line);
2922 delete $3;
2923 delete $6;
2924 $$ = tmp;
2926 | K_begin K_end
2927 { PBlock*tmp = new PBlock(PBlock::BL_SEQ);
2928 tmp->set_file(@1.text);
2929 tmp->set_lineno(@1.first_line);
2930 $$ = tmp;
2932 | K_begin ':' IDENTIFIER K_end
2933 { PBlock*tmp = new PBlock(PBlock::BL_SEQ);
2934 tmp->set_file(@1.text);
2935 tmp->set_lineno(@1.first_line);
2936 $$ = tmp;
2938 | K_begin error K_end
2939 { yyerrok; }
2941 /* fork-join blocks are very similar to begin-end blocks. In fact,
2942 from the parser's perspective there is no real difference. All we
2943 need to do is remember that this is a parallel block so that the
2944 code generator can do the right thing. */
2946 | K_fork ':' IDENTIFIER
2947 { pform_push_scope($3); }
2948 block_item_decls_opt
2949 statement_list K_join
2950 { pform_pop_scope();
2951 PBlock*tmp = new PBlock(lex_strings.make($3),
2952 PBlock::BL_PAR, *$6);
2953 tmp->set_file(@1.text);
2954 tmp->set_lineno(@1.first_line);
2955 delete $3;
2956 delete $6;
2957 $$ = tmp;
2959 | K_fork K_join
2960 { PBlock*tmp = new PBlock(PBlock::BL_PAR);
2961 tmp->set_file(@1.text);
2962 tmp->set_lineno(@1.first_line);
2963 $$ = tmp;
2965 | K_fork ':' IDENTIFIER K_join
2966 { PBlock*tmp = new PBlock(PBlock::BL_PAR);
2967 tmp->set_file(@1.text);
2968 tmp->set_lineno(@1.first_line);
2969 delete $3;
2970 $$ = tmp;
2973 | K_disable heirarchy_identifier ';'
2974 { PDisable*tmp = new PDisable(*$2);
2975 tmp->set_file(@1.text);
2976 tmp->set_lineno(@1.first_line);
2977 delete $2;
2978 $$ = tmp;
2980 | K_TRIGGER heirarchy_identifier ';'
2981 { PTrigger*tmp = new PTrigger(*$2);
2982 tmp->set_file(@2.text);
2983 tmp->set_lineno(@2.first_line);
2984 delete $2;
2985 $$ = tmp;
2987 | K_forever statement
2988 { PForever*tmp = new PForever($2);
2989 tmp->set_file(@1.text);
2990 tmp->set_lineno(@1.first_line);
2991 $$ = tmp;
2993 | K_fork statement_list K_join
2994 { PBlock*tmp = new PBlock(PBlock::BL_PAR, *$2);
2995 tmp->set_file(@1.text);
2996 tmp->set_lineno(@1.first_line);
2997 delete $2;
2998 $$ = tmp;
3000 | K_repeat '(' expression ')' statement
3001 { PRepeat*tmp = new PRepeat($3, $5);
3002 tmp->set_file(@1.text);
3003 tmp->set_lineno(@1.first_line);
3004 $$ = tmp;
3006 | K_case '(' expression ')' case_items K_endcase
3007 { PCase*tmp = new PCase(NetCase::EQ, $3, $5);
3008 tmp->set_file(@1.text);
3009 tmp->set_lineno(@1.first_line);
3010 $$ = tmp;
3012 | K_casex '(' expression ')' case_items K_endcase
3013 { PCase*tmp = new PCase(NetCase::EQX, $3, $5);
3014 tmp->set_file(@1.text);
3015 tmp->set_lineno(@1.first_line);
3016 $$ = tmp;
3018 | K_casez '(' expression ')' case_items K_endcase
3019 { PCase*tmp = new PCase(NetCase::EQZ, $3, $5);
3020 tmp->set_file(@1.text);
3021 tmp->set_lineno(@1.first_line);
3022 $$ = tmp;
3024 | K_case '(' expression ')' error K_endcase
3025 { yyerrok; }
3026 | K_casex '(' expression ')' error K_endcase
3027 { yyerrok; }
3028 | K_casez '(' expression ')' error K_endcase
3029 { yyerrok; }
3030 | K_if '(' expression ')' statement_or_null %prec less_than_K_else
3031 { PCondit*tmp = new PCondit($3, $5, 0);
3032 tmp->set_file(@1.text);
3033 tmp->set_lineno(@1.first_line);
3034 $$ = tmp;
3036 | K_if '(' expression ')' statement_or_null K_else statement_or_null
3037 { PCondit*tmp = new PCondit($3, $5, $7);
3038 tmp->set_file(@1.text);
3039 tmp->set_lineno(@1.first_line);
3040 $$ = tmp;
3042 | K_if '(' error ')' statement_or_null %prec less_than_K_else
3043 { yyerror(@1, "error: Malformed conditional expression.");
3044 $$ = $5;
3046 | K_if '(' error ')' statement_or_null K_else statement_or_null
3047 { yyerror(@1, "error: Malformed conditional expression.");
3048 $$ = $5;
3050 | K_for '(' lpvalue '=' expression ';' expression ';'
3051 lpvalue '=' expression ')' statement
3052 { PForStatement*tmp = new PForStatement($3, $5, $7, $9, $11, $13);
3053 tmp->set_file(@1.text);
3054 tmp->set_lineno(@1.first_line);
3055 $$ = tmp;
3057 | K_for '(' lpvalue '=' expression ';' expression ';'
3058 error ')' statement
3059 { $$ = 0;
3060 yyerror(@9, "error: Error in for loop step assignment.");
3062 | K_for '(' lpvalue '=' expression ';' error ';'
3063 lpvalue '=' expression ')' statement
3064 { $$ = 0;
3065 yyerror(@7, "error: Error in for loop condition expression.");
3067 | K_for '(' error ')' statement
3068 { $$ = 0;
3069 yyerror(@3, "error: Incomprehensible for loop.");
3071 | K_while '(' expression ')' statement
3072 { PWhile*tmp = new PWhile($3, $5);
3073 $$ = tmp;
3075 | K_while '(' error ')' statement
3076 { $$ = 0;
3077 yyerror(@3, "error: Error in while loop condition.");
3079 | delay1 statement_or_null
3080 { PExpr*del = (*$1)[0];
3081 assert($1->count() == 1);
3082 PDelayStatement*tmp = new PDelayStatement(del, $2);
3083 tmp->set_file(@1.text);
3084 tmp->set_lineno(@1.first_line);
3085 $$ = tmp;
3087 | event_control statement_or_null
3088 { PEventStatement*tmp = $1;
3089 if (tmp == 0) {
3090 yyerror(@1, "error: Invalid event control.");
3091 $$ = 0;
3092 } else {
3093 tmp->set_statement($2);
3094 $$ = tmp;
3097 | '@' '*' statement_or_null
3098 { PEventStatement*tmp = new PEventStatement;
3099 tmp->set_file(@1.text);
3100 tmp->set_lineno(@1.first_line);
3101 tmp->set_statement($3);
3102 $$ = tmp;
3104 | '@' '(' '*' ')' statement_or_null
3105 { PEventStatement*tmp = new PEventStatement;
3106 tmp->set_file(@1.text);
3107 tmp->set_lineno(@1.first_line);
3108 tmp->set_statement($5);
3109 $$ = tmp;
3111 | lpvalue '=' expression ';'
3112 { PAssign*tmp = new PAssign($1,$3);
3113 tmp->set_file(@1.text);
3114 tmp->set_lineno(@1.first_line);
3115 $$ = tmp;
3117 | error '=' expression ';'
3118 { yyerror(@1, "Syntax in assignment statement l-value.");
3119 yyerrok;
3120 $$ = new PNoop;
3122 | lpvalue K_LE expression ';'
3123 { PAssignNB*tmp = new PAssignNB($1,$3);
3124 tmp->set_file(@1.text);
3125 tmp->set_lineno(@1.first_line);
3126 $$ = tmp;
3128 | error K_LE expression ';'
3129 { yyerror(@1, "Syntax in assignment statement l-value.");
3130 yyerrok;
3131 $$ = new PNoop;
3133 | lpvalue '=' delay1 expression ';'
3134 { assert($3->count() == 1);
3135 PExpr*del = (*$3)[0];
3136 PAssign*tmp = new PAssign($1,del,$4);
3137 tmp->set_file(@1.text);
3138 tmp->set_lineno(@1.first_line);
3139 $$ = tmp;
3141 | lpvalue K_LE delay1 expression ';'
3142 { assert($3->count() == 1);
3143 PExpr*del = (*$3)[0];
3144 PAssignNB*tmp = new PAssignNB($1,del,$4);
3145 tmp->set_file(@1.text);
3146 tmp->set_lineno(@1.first_line);
3147 $$ = tmp;
3149 | lpvalue '=' event_control expression ';'
3150 { PAssign*tmp = new PAssign($1,$3,$4);
3151 tmp->set_file(@1.text);
3152 tmp->set_lineno(@1.first_line);
3153 $$ = tmp;
3155 | lpvalue '=' K_repeat '(' expression ')' event_control expression ';'
3156 { PAssign*tmp = new PAssign($1,$7,$8);
3157 tmp->set_file(@1.text);
3158 tmp->set_lineno(@1.first_line);
3159 yyerror(@3, "sorry: repeat event control not supported.");
3160 delete $5;
3161 $$ = tmp;
3163 | lpvalue K_LE event_control expression ';'
3164 { yyerror(@1, "sorry: Event controls not supported here.");
3165 PAssignNB*tmp = new PAssignNB($1,$4);
3166 tmp->set_file(@1.text);
3167 tmp->set_lineno(@1.first_line);
3168 $$ = tmp;
3170 | lpvalue K_LE K_repeat '(' expression ')' event_control expression ';'
3171 { yyerror(@1, "sorry: Event controls not supported here.");
3172 delete $5;
3173 PAssignNB*tmp = new PAssignNB($1,$8);
3174 tmp->set_file(@1.text);
3175 tmp->set_lineno(@1.first_line);
3176 $$ = tmp;
3178 | K_wait '(' expression ')' statement_or_null
3179 { PEventStatement*tmp;
3180 PEEvent*etmp = new PEEvent(PEEvent::POSITIVE, $3);
3181 tmp = new PEventStatement(etmp);
3182 tmp->set_file(@1.text);
3183 tmp->set_lineno(@1.first_line);
3184 tmp->set_statement($5);
3185 $$ = tmp;
3187 | SYSTEM_IDENTIFIER '(' expression_list_with_nuls ')' ';'
3188 { PCallTask*tmp = new PCallTask(lex_strings.make($1), *$3);
3189 tmp->set_file(@1.text);
3190 tmp->set_lineno(@1.first_line);
3191 delete $1;
3192 delete $3;
3193 $$ = tmp;
3195 | SYSTEM_IDENTIFIER ';'
3196 { svector<PExpr*>pt (0);
3197 PCallTask*tmp = new PCallTask(lex_strings.make($1), pt);
3198 tmp->set_file(@1.text);
3199 tmp->set_lineno(@1.first_line);
3200 delete $1;
3201 $$ = tmp;
3203 | heirarchy_identifier '(' expression_list_proper ')' ';'
3204 { PCallTask*tmp = new PCallTask(*$1, *$3);
3205 tmp->set_file(@1.text);
3206 tmp->set_lineno(@1.first_line);
3207 delete $1;
3208 delete $3;
3209 $$ = tmp;
3212 /* NOTE: The standard doesn't really support an empty argument list
3213 between parentheses, but it seems natural, and people commonly
3214 want it. So accept it explicitly. */
3216 | heirarchy_identifier '(' ')' ';'
3217 { svector<PExpr*>pt (0);
3218 PCallTask*tmp = new PCallTask(*$1, pt);
3219 tmp->set_file(@1.text);
3220 tmp->set_lineno(@1.first_line);
3221 delete $1;
3222 $$ = tmp;
3224 | heirarchy_identifier ';'
3225 { svector<PExpr*>pt (0);
3226 PCallTask*tmp = new PCallTask(*$1, pt);
3227 tmp->set_file(@1.text);
3228 tmp->set_lineno(@1.first_line);
3229 delete $1;
3230 $$ = tmp;
3232 | error ';'
3233 { yyerror(@1, "error: malformed statement");
3234 yyerrok;
3235 $$ = new PNoop;
3239 statement_list
3240 : statement_list statement
3241 { svector<Statement*>*tmp = new svector<Statement*>(*$1, $2);
3242 delete $1;
3243 $$ = tmp;
3245 | statement
3246 { svector<Statement*>*tmp = new svector<Statement*>(1);
3247 (*tmp)[0] = $1;
3248 $$ = tmp;
3252 statement_or_null
3253 : statement
3254 | ';' { $$ = 0; }
3257 /* Task items are, other than the statement, task port items and
3258 other block items. */
3259 task_item
3260 : block_item_decl { $$ = new svector<PWire*>(0); }
3261 | task_port_item { $$ = $1; }
3264 task_port_item
3266 : K_input signed_opt range_opt list_of_identifiers ';'
3267 { svector<PWire*>*tmp
3268 = pform_make_task_ports(NetNet::PINPUT,
3269 IVL_VT_LOGIC, $2,
3270 $3, $4,
3271 @1.text, @1.first_line);
3272 $$ = tmp;
3274 | K_output signed_opt range_opt list_of_identifiers ';'
3275 { svector<PWire*>*tmp
3276 = pform_make_task_ports(NetNet::POUTPUT,
3277 IVL_VT_LOGIC, $2,
3278 $3, $4,
3279 @1.text, @1.first_line);
3280 $$ = tmp;
3282 | K_inout signed_opt range_opt list_of_identifiers ';'
3283 { svector<PWire*>*tmp
3284 = pform_make_task_ports(NetNet::PINOUT,
3285 IVL_VT_LOGIC, $2,
3286 $3, $4,
3287 @1.text, @1.first_line);
3288 $$ = tmp;
3291 /* When the port is an integer, infer a signed vector of the integer
3292 shape. Generate a range to make it work. */
3294 | K_input K_integer list_of_identifiers ';'
3295 { svector<PExpr*>*range_stub
3296 = new svector<PExpr*>(2);
3297 PExpr*re;
3298 re = new PENumber(new verinum(integer_width-1,
3299 integer_width));
3300 (*range_stub)[0] = re;
3301 re = new PENumber(new verinum((uint64_t)0, integer_width));
3302 (*range_stub)[1] = re;
3303 svector<PWire*>*tmp
3304 = pform_make_task_ports(NetNet::PINPUT,
3305 IVL_VT_LOGIC, true,
3306 range_stub, $3,
3307 @1.text, @1.first_line);
3308 $$ = tmp;
3310 | K_output K_integer list_of_identifiers ';'
3311 { svector<PExpr*>*range_stub
3312 = new svector<PExpr*>(2);
3313 PExpr*re;
3314 re = new PENumber(new verinum(integer_width-1,
3315 integer_width));
3316 (*range_stub)[0] = re;
3317 re = new PENumber(new verinum((uint64_t)0, integer_width));
3318 (*range_stub)[1] = re;
3319 svector<PWire*>*tmp
3320 = pform_make_task_ports(NetNet::POUTPUT,
3321 IVL_VT_LOGIC, true,
3322 range_stub, $3,
3323 @1.text, @1.first_line);
3324 $$ = tmp;
3326 | K_inout K_integer list_of_identifiers ';'
3327 { svector<PExpr*>*range_stub
3328 = new svector<PExpr*>(2);
3329 PExpr*re;
3330 re = new PENumber(new verinum(integer_width-1,
3331 integer_width));
3332 (*range_stub)[0] = re;
3333 re = new PENumber(new verinum((uint64_t)0, integer_width));
3334 (*range_stub)[1] = re;
3335 svector<PWire*>*tmp
3336 = pform_make_task_ports(NetNet::PINOUT,
3337 IVL_VT_LOGIC, true,
3338 range_stub, $3,
3339 @1.text, @1.first_line);
3340 $$ = tmp;
3343 /* Ports can be real. */
3345 | K_input K_real list_of_identifiers ';'
3346 { svector<PWire*>*tmp
3347 = pform_make_task_ports(NetNet::PINPUT,
3348 IVL_VT_REAL, false,
3349 0, $3,
3350 @1.text, @1.first_line);
3351 $$ = tmp;
3353 | K_output K_real list_of_identifiers ';'
3354 { svector<PWire*>*tmp
3355 = pform_make_task_ports(NetNet::POUTPUT,
3356 IVL_VT_REAL, true,
3357 0, $3,
3358 @1.text, @1.first_line);
3359 $$ = tmp;
3361 | K_inout K_real list_of_identifiers ';'
3362 { svector<PWire*>*tmp
3363 = pform_make_task_ports(NetNet::PINOUT,
3364 IVL_VT_REAL, true,
3365 0, $3,
3366 @1.text, @1.first_line);
3367 $$ = tmp;
3371 task_item_list
3372 : task_item_list task_item
3373 { svector<PWire*>*tmp = new svector<PWire*>(*$1, *$2);
3374 delete $1;
3375 delete $2;
3376 $$ = tmp;
3378 | task_item
3379 { $$ = $1; }
3382 task_item_list_opt
3383 : task_item_list
3384 { $$ = $1; }
3386 { $$ = 0; }
3389 task_port_decl
3391 : K_input signed_opt range_opt IDENTIFIER
3392 { svector<PWire*>*tmp
3393 = pform_make_task_ports(NetNet::PINPUT,
3394 IVL_VT_LOGIC, $2,
3395 $3, list_from_identifier($4),
3396 @1.text, @1.first_line);
3397 $$ = tmp;
3400 | K_output signed_opt range_opt IDENTIFIER
3401 { svector<PWire*>*tmp
3402 = pform_make_task_ports(NetNet::POUTPUT,
3403 IVL_VT_LOGIC, $2,
3404 $3, list_from_identifier($4),
3405 @1.text, @1.first_line);
3406 $$ = tmp;
3408 | K_inout signed_opt range_opt IDENTIFIER
3409 { svector<PWire*>*tmp
3410 = pform_make_task_ports(NetNet::PINOUT,
3411 IVL_VT_LOGIC, $2,
3412 $3, list_from_identifier($4),
3413 @1.text, @1.first_line);
3414 $$ = tmp;
3417 | K_input K_integer IDENTIFIER
3418 { svector<PExpr*>*range_stub
3419 = new svector<PExpr*>(2);
3420 PExpr*re;
3421 re = new PENumber(new verinum(integer_width-1,
3422 integer_width));
3423 (*range_stub)[0] = re;
3424 re = new PENumber(new verinum((uint64_t)0, integer_width));
3425 (*range_stub)[1] = re;
3426 svector<PWire*>*tmp
3427 = pform_make_task_ports(NetNet::PINPUT,
3428 IVL_VT_LOGIC, true,
3429 range_stub,
3430 list_from_identifier($3),
3431 @1.text, @1.first_line);
3432 $$ = tmp;
3434 | K_output K_integer IDENTIFIER
3435 { svector<PExpr*>*range_stub
3436 = new svector<PExpr*>(2);
3437 PExpr*re;
3438 re = new PENumber(new verinum(integer_width-1,
3439 integer_width));
3440 (*range_stub)[0] = re;
3441 re = new PENumber(new verinum((uint64_t)0, integer_width));
3442 (*range_stub)[1] = re;
3443 svector<PWire*>*tmp
3444 = pform_make_task_ports(NetNet::POUTPUT,
3445 IVL_VT_LOGIC, true,
3446 range_stub,
3447 list_from_identifier($3),
3448 @1.text, @1.first_line);
3449 $$ = tmp;
3451 | K_inout K_integer IDENTIFIER
3452 { svector<PExpr*>*range_stub
3453 = new svector<PExpr*>(2);
3454 PExpr*re;
3455 re = new PENumber(new verinum(integer_width-1,
3456 integer_width));
3457 (*range_stub)[0] = re;
3458 re = new PENumber(new verinum((uint64_t)0, integer_width));
3459 (*range_stub)[1] = re;
3460 svector<PWire*>*tmp
3461 = pform_make_task_ports(NetNet::PINOUT,
3462 IVL_VT_LOGIC, true,
3463 range_stub,
3464 list_from_identifier($3),
3465 @1.text, @1.first_line);
3466 $$ = tmp;
3469 /* Ports can be real. */
3471 | K_input K_real IDENTIFIER
3472 { svector<PWire*>*tmp
3473 = pform_make_task_ports(NetNet::PINPUT,
3474 IVL_VT_REAL, false,
3475 0, list_from_identifier($3),
3476 @1.text, @1.first_line);
3477 $$ = tmp;
3479 | K_output K_real IDENTIFIER
3480 { svector<PWire*>*tmp
3481 = pform_make_task_ports(NetNet::POUTPUT,
3482 IVL_VT_REAL, false,
3483 0, list_from_identifier($3),
3484 @1.text, @1.first_line);
3485 $$ = tmp;
3487 | K_inout K_real IDENTIFIER
3488 { svector<PWire*>*tmp
3489 = pform_make_task_ports(NetNet::PINOUT,
3490 IVL_VT_REAL, false,
3491 0, list_from_identifier($3),
3492 @1.text, @1.first_line);
3493 $$ = tmp;
3497 task_port_decl_list
3498 : task_port_decl_list ',' task_port_decl
3499 { svector<PWire*>*tmp = new svector<PWire*>(*$1, *$3);
3500 delete $1;
3501 delete $3;
3502 $$ = tmp;
3504 | task_port_decl
3505 { $$ = $1; }
3508 udp_body
3509 : K_table { lex_start_table(); }
3510 udp_entry_list
3511 K_endtable { lex_end_table(); $$ = $3; }
3514 udp_entry_list
3515 : udp_comb_entry_list
3516 | udp_sequ_entry_list
3519 udp_comb_entry
3520 : udp_input_list ':' udp_output_sym ';'
3521 { char*tmp = new char[strlen($1)+3];
3522 strcpy(tmp, $1);
3523 char*tp = tmp+strlen(tmp);
3524 *tp++ = ':';
3525 *tp++ = $3;
3526 *tp++ = 0;
3527 delete[]$1;
3528 $$ = tmp;
3532 udp_comb_entry_list
3533 : udp_comb_entry
3534 { list<string>*tmp = new list<string>;
3535 tmp->push_back($1);
3536 delete $1;
3537 $$ = tmp;
3539 | udp_comb_entry_list udp_comb_entry
3540 { list<string>*tmp = $1;
3541 tmp->push_back($2);
3542 delete $2;
3543 $$ = tmp;
3547 udp_sequ_entry_list
3548 : udp_sequ_entry
3549 { list<string>*tmp = new list<string>;
3550 tmp->push_back($1);
3551 delete $1;
3552 $$ = tmp;
3554 | udp_sequ_entry_list udp_sequ_entry
3555 { list<string>*tmp = $1;
3556 tmp->push_back($2);
3557 delete $2;
3558 $$ = tmp;
3562 udp_sequ_entry
3563 : udp_input_list ':' udp_input_sym ':' udp_output_sym ';'
3564 { char*tmp = new char[strlen($1)+5];
3565 strcpy(tmp, $1);
3566 char*tp = tmp+strlen(tmp);
3567 *tp++ = ':';
3568 *tp++ = $3;
3569 *tp++ = ':';
3570 *tp++ = $5;
3571 *tp++ = 0;
3572 $$ = tmp;
3576 udp_initial
3577 : K_initial IDENTIFIER '=' number ';'
3578 { PExpr*etmp = new PENumber($4);
3579 PEIdent*itmp = new PEIdent(lex_strings.make($2));
3580 PAssign*atmp = new PAssign(itmp, etmp);
3581 atmp->set_file(@2.text);
3582 atmp->set_lineno(@2.first_line);
3583 delete $2;
3584 $$ = atmp;
3588 udp_init_opt
3589 : udp_initial { $$ = $1; }
3590 | { $$ = 0; }
3593 udp_input_list
3594 : udp_input_sym
3595 { char*tmp = new char[2];
3596 tmp[0] = $1;
3597 tmp[1] = 0;
3598 $$ = tmp;
3600 | udp_input_list udp_input_sym
3601 { char*tmp = new char[strlen($1)+2];
3602 strcpy(tmp, $1);
3603 char*tp = tmp+strlen(tmp);
3604 *tp++ = $2;
3605 *tp++ = 0;
3606 delete[]$1;
3607 $$ = tmp;
3611 udp_input_sym
3612 : '0' { $$ = '0'; }
3613 | '1' { $$ = '1'; }
3614 | 'x' { $$ = 'x'; }
3615 | '?' { $$ = '?'; }
3616 | 'b' { $$ = 'b'; }
3617 | '*' { $$ = '*'; }
3618 | '%' { $$ = '%'; }
3619 | 'f' { $$ = 'f'; }
3620 | 'F' { $$ = 'F'; }
3621 | 'l' { $$ = 'l'; }
3622 | 'h' { $$ = 'H'; }
3623 | 'B' { $$ = 'B'; }
3624 | 'r' { $$ = 'r'; }
3625 | 'R' { $$ = 'R'; }
3626 | 'M' { $$ = 'M'; }
3627 | 'n' { $$ = 'n'; }
3628 | 'N' { $$ = 'N'; }
3629 | 'p' { $$ = 'p'; }
3630 | 'P' { $$ = 'P'; }
3631 | 'Q' { $$ = 'Q'; }
3632 | 'q' { $$ = 'q'; }
3633 | '_' { $$ = '_'; }
3634 | '+' { $$ = '+'; }
3637 udp_output_sym
3638 : '0' { $$ = '0'; }
3639 | '1' { $$ = '1'; }
3640 | 'x' { $$ = 'x'; }
3641 | '-' { $$ = '-'; }
3644 /* Port declarations create wires for the inputs and the output. The
3645 makes for these ports are scoped within the UDP, so there is no
3646 heirarchy involved. */
3647 udp_port_decl
3648 : K_input list_of_identifiers ';'
3649 { $$ = pform_make_udp_input_ports($2); }
3650 | K_output IDENTIFIER ';'
3651 { pform_name_t pname;
3652 pname.push_back(name_component_t(lex_strings.make($2)));
3653 PWire*pp = new PWire(pname, NetNet::IMPLICIT, NetNet::POUTPUT, IVL_VT_LOGIC);
3654 svector<PWire*>*tmp = new svector<PWire*>(1);
3655 (*tmp)[0] = pp;
3656 $$ = tmp;
3657 delete $2;
3659 | K_reg IDENTIFIER ';'
3660 { pform_name_t pname;
3661 pname.push_back(name_component_t(lex_strings.make($2)));
3662 PWire*pp = new PWire(pname, NetNet::REG, NetNet::PIMPLICIT, IVL_VT_LOGIC);
3663 svector<PWire*>*tmp = new svector<PWire*>(1);
3664 (*tmp)[0] = pp;
3665 $$ = tmp;
3666 delete $2;
3668 | K_reg K_output IDENTIFIER ';'
3669 { pform_name_t pname;
3670 pname.push_back(name_component_t(lex_strings.make($3)));
3671 PWire*pp = new PWire(pname, NetNet::REG, NetNet::POUTPUT, IVL_VT_LOGIC);
3672 svector<PWire*>*tmp = new svector<PWire*>(1);
3673 (*tmp)[0] = pp;
3674 $$ = tmp;
3675 delete $3;
3679 udp_port_decls
3680 : udp_port_decl
3681 { $$ = $1; }
3682 | udp_port_decls udp_port_decl
3683 { svector<PWire*>*tmp = new svector<PWire*>(*$1, *$2);
3684 delete $1;
3685 delete $2;
3686 $$ = tmp;
3690 udp_port_list
3691 : IDENTIFIER
3692 { list<string>*tmp = new list<string>;
3693 tmp->push_back($1);
3694 delete $1;
3695 $$ = tmp;
3697 | udp_port_list ',' IDENTIFIER
3698 { list<string>*tmp = $1;
3699 tmp->push_back($3);
3700 delete $3;
3701 $$ = tmp;
3705 udp_reg_opt: K_reg { $$ = true; } | { $$ = false; };
3707 udp_initial_expr_opt
3708 : '=' expression { $$ = $2; }
3709 | { $$ = 0; }
3712 udp_input_declaration_list
3713 : K_input IDENTIFIER
3714 { list<perm_string>*tmp = new list<perm_string>;
3715 tmp->push_back(lex_strings.make($2));
3716 $$ = tmp;
3717 delete[]$2;
3719 | udp_input_declaration_list ',' K_input IDENTIFIER
3720 { list<perm_string>*tmp = $1;
3721 tmp->push_back(lex_strings.make($4));
3722 $$ = tmp;
3723 delete[]$4;
3727 udp_primitive
3728 /* This is the syntax for primitives that uses the IEEE1364-1995
3729 format. The ports are simply names in the port list, and the
3730 declarations are in the body. */
3732 : K_primitive IDENTIFIER '(' udp_port_list ')' ';'
3733 udp_port_decls
3734 udp_init_opt
3735 udp_body
3736 K_endprimitive
3738 { perm_string tmp2 = lex_strings.make($2);
3739 pform_make_udp(tmp2, $4, $7, $9, $8,
3740 @2.text, @2.first_line);
3741 delete[]$2;
3744 /* This is the syntax for IEEE1364-2001 format definitions. The port
3745 names and declarations are all in the parameter list. */
3747 | K_primitive IDENTIFIER
3748 '(' K_output udp_reg_opt IDENTIFIER udp_initial_expr_opt ','
3749 udp_input_declaration_list ')' ';'
3750 udp_body
3751 K_endprimitive
3753 { perm_string tmp2 = lex_strings.make($2);
3754 perm_string tmp6 = lex_strings.make($6);
3755 pform_make_udp(tmp2, $5, tmp6, $7, $9, $12,
3756 @2.text, @2.first_line);
3757 delete[]$2;
3758 delete[]$6;