Logic gates can take part select inputs
[iverilog.git] / pform.h
blob8899b16e9920aa63aaec1782d89fb0cf77eb620b
1 #ifndef __pform_H
2 #define __pform_H
3 /*
4 * Copyright (c) 1998-2000 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: pform.h,v 1.91 2007/05/24 04:07:12 steve Exp $"
23 #endif
25 # include "netlist.h"
26 # include "HName.h"
27 # include "named.h"
28 # include "Module.h"
29 # include "Statement.h"
30 # include "PGate.h"
31 # include "PExpr.h"
32 # include "PTask.h"
33 # include "PUdp.h"
34 # include "PWire.h"
35 # include "verinum.h"
36 # include <iostream>
37 # include <string>
38 # include <list>
39 # include <stdio.h>
42 * These classes implement the parsed form (P-form for short) of the
43 * original verilog source. the parser generates the pform for the
44 * convenience of later processing steps.
49 * Wire objects represent the named wires (of various flavor) declared
50 * in the source.
52 * Gate objects are the functional modules that are connected together
53 * by wires.
55 * Wires and gates, connected by joints, represent a netlist. The
56 * netlist is therefore a representation of the desired circuit.
58 class PGate;
59 class PExpr;
60 class PSpecPath;
61 struct vlltype;
64 * The min:typ:max expression s selected at parse time using the
65 * enumeration. When the compiler makes a choice, it also prints a
66 * warning if min_typ_max_warn > 0.
68 extern enum MIN_TYP_MAX { MIN, TYP, MAX } min_typ_max_flag;
69 extern unsigned min_typ_max_warn;
70 PExpr* pform_select_mtm_expr(PExpr*min, PExpr*typ, PExpr*max);
73 * This flag is true if the lexor thinks we are in a library source
74 * file.
76 extern bool pform_library_flag;
79 * These type are lexical types -- that is, types that are used as
80 * lexical values to decorate the parse tree during parsing. They are
81 * not in any way preserved once parsing is done.
84 /* This is information about port name information for named port
85 connections. */
87 //typedef struct named<PExpr*> named_pexpr_t;
88 typedef named<PExpr*> named_pexpr_t;
90 struct parmvalue_t {
91 svector<PExpr*>*by_order;
92 svector<named_pexpr_t*>*by_name;
95 struct str_pair_t { PGate::strength_t str0, str1; };
97 struct net_decl_assign_t {
98 char*name;
99 PExpr*expr;
100 struct net_decl_assign_t*next;
103 /* The lgate is gate instantiation information. */
104 struct lgate {
105 lgate(int =0)
106 : parms(0), parms_by_name(0), lineno(0)
107 { range[0] = 0;
108 range[1] = 0;
111 string name;
112 svector<PExpr*>*parms;
113 svector<named_pexpr_t*>*parms_by_name;
115 PExpr*range[2];
117 const char* file;
118 unsigned lineno;
121 /* The lexor calls this function to change the default nettype. */
122 extern void pform_set_default_nettype(NetNet::Type net,
123 const char*file,
124 unsigned lineno);
127 * The parser uses startmodule and endmodule together to build up a
128 * module as it parses it. The startmodule tells the pform code that a
129 * module has been noticed in the source file and the following events
130 * are to apply to the scope of that module. The endmodule causes the
131 * pform to close up and finish the named module.
133 extern void pform_startmodule(const char*, const char*file, unsigned lineno,
134 svector<named_pexpr_t*>*attr);
135 extern void pform_module_set_ports(svector<Module::port_t*>*);
137 /* This function is used to support the port definition in a
138 port_definition_list. In this case, we have everything needed to
139 define the port, all in one place. */
140 extern void pform_module_define_port(const struct vlltype&li,
141 const char*name,
142 NetNet::PortType,
143 NetNet::Type type,
144 bool signed_flag,
145 svector<PExpr*>*range,
146 svector<named_pexpr_t*>*attr);
148 extern Module::port_t* pform_module_port_reference(char*name,
149 const char*file,
150 unsigned lineno);
151 extern void pform_endmodule(const char*);
153 extern void pform_make_udp(perm_string name, list<string>*parms,
154 svector<PWire*>*decl, list<string>*table,
155 Statement*init,
156 const char*file, unsigned lineno);
158 extern void pform_make_udp(perm_string name,
159 bool sync_flag, perm_string out_name,
160 PExpr*sync_init,
161 list<perm_string>*parms,
162 list<string>*table,
163 const char*file, unsigned lineno);
166 * Enter/exit name scopes. The push_scope function pushes the scope
167 * name string onto the scope hierarchy. The pop pulls it off and
168 * deletes it. Thus, the string pushed must be allocated.
170 extern void pform_push_scope(char*name);
171 extern void pform_pop_scope();
174 extern verinum* pform_verinum_with_size(verinum*s, verinum*val,
175 const char*file, unsigned loneno);
178 * This function takes the list of names as new genvars to declare in
179 * the current module scope.
181 extern void pform_genvars(list<perm_string>*names);
183 extern void pform_start_generate_for(const struct vlltype&li,
184 char*ident1,
185 PExpr*init,
186 PExpr*test,
187 char*ident2,
188 PExpr*next);
189 extern void pform_start_generate_if(const struct vlltype&li, PExpr*test);
190 extern void pform_start_generate_else(const struct vlltype&li);
191 extern void pform_generate_block_name(char*name);
192 extern void pform_endgenerate();
196 * The makewire functions announce to the pform code new wires. These
197 * go into a module that is currently opened.
199 extern void pform_makewire(const struct vlltype&li, const char*name,
200 NetNet::Type type,
201 NetNet::PortType pt,
202 ivl_variable_type_t,
203 svector<named_pexpr_t*>*attr);
205 /* This form handles simple declarations */
206 extern void pform_makewire(const struct vlltype&li,
207 svector<PExpr*>*range,
208 bool signed_flag,
209 list<perm_string>*names,
210 NetNet::Type type,
211 NetNet::PortType,
212 ivl_variable_type_t,
213 svector<named_pexpr_t*>*attr);
215 /* This form handles assignment declarations. */
216 extern void pform_makewire(const struct vlltype&li,
217 svector<PExpr*>*range,
218 bool signed_flag,
219 svector<PExpr*>*delay,
220 str_pair_t str,
221 net_decl_assign_t*assign_list,
222 NetNet::Type type,
223 ivl_variable_type_t);
225 extern void pform_make_reginit(const struct vlltype&li,
226 const char*name, PExpr*expr);
228 /* Look up the names of the wires, and set the port type,
229 i.e. input, output or inout. If the wire does not exist, create
230 it. The second form takes a single name. */
231 extern void pform_set_port_type(const struct vlltype&li,
232 list<perm_string>*names,
233 svector<PExpr*>*range,
234 bool signed_flag,
235 NetNet::PortType);
236 extern void pform_set_port_type(perm_string nm, NetNet::PortType pt,
237 const char*file, unsigned lineno);
239 extern void pform_set_net_range(list<perm_string>*names,
240 svector<PExpr*>*,
241 bool signed_flag,
242 ivl_variable_type_t);
243 extern void pform_set_reg_idx(const char*name, PExpr*l, PExpr*r);
244 extern void pform_set_reg_integer(list<perm_string>*names);
245 extern void pform_set_reg_time(list<perm_string>*names);
246 extern void pform_set_task(perm_string name, PTask*);
247 extern void pform_set_function(perm_string name, PFunction*);
249 /* pform_set_attrib and pform_set_type_attrib exist to support the
250 $attribute syntax, which can only set string values to
251 attributes. The functions keep the value strings that are
252 passed in. */
253 extern void pform_set_attrib(perm_string name, perm_string key,
254 char*value);
255 extern void pform_set_type_attrib(perm_string name, const string&key,
256 char*value);
258 extern void pform_set_parameter(perm_string name,
259 bool signed_flag,
260 svector<PExpr*>*range,
261 PExpr*expr);
262 extern void pform_set_localparam(perm_string name,
263 bool signed_flag,
264 svector<PExpr*>*range,
265 PExpr*expr);
266 extern void pform_set_defparam(const pform_name_t&name, PExpr*expr);
269 * Functions related to specify blocks.
271 extern void pform_set_specparam(perm_string name, PExpr*expr);
273 extern PSpecPath*pform_make_specify_path(const struct vlltype&li,
274 list<perm_string>*src, char pol,
275 bool full_flag, list<perm_string>*dst);
276 extern PSpecPath*pform_make_specify_edge_path(const struct vlltype&li,
277 int edge_flag, /*posedge==true */
278 list<perm_string>*src, char pol,
279 bool full_flag, list<perm_string>*dst,
280 PExpr*data_source_expression);
281 extern PSpecPath*pform_assign_path_delay(PSpecPath*obj, svector<PExpr*>*delays);
283 extern void pform_module_specify_path(PSpecPath*obj);
286 * pform_make_behavior creates processes that are declared with always
287 * or initial items.
289 extern PProcess* pform_make_behavior(PProcess::Type, Statement*,
290 svector<named_pexpr_t*>*attr);
292 extern svector<PWire*>* pform_make_udp_input_ports(list<perm_string>*);
294 extern bool pform_expression_is_constant(const PExpr*);
296 extern void pform_make_events(list<perm_string>*names,
297 const char*file, unsigned lineno);
299 * Make real datum objects.
301 extern void pform_make_reals(list<perm_string>*names,
302 const char*file, unsigned lineno);
305 * The makegate function creates a new gate (which need not have a
306 * name) and connects it to the specified wires.
308 extern void pform_makegates(PGBuiltin::Type type,
309 struct str_pair_t str,
310 svector<PExpr*>*delay,
311 svector<lgate>*gates,
312 svector<named_pexpr_t*>*attr);
314 extern void pform_make_modgates(perm_string type,
315 struct parmvalue_t*overrides,
316 svector<lgate>*gates);
318 /* Make a continuous assignment node, with optional bit- or part- select. */
319 extern void pform_make_pgassign_list(svector<PExpr*>*alist,
320 svector<PExpr*>*del,
321 struct str_pair_t str,
322 const char* fn, unsigned lineno);
324 /* Given a port type and a list of names, make a list of wires that
325 can be used as task port information. */
326 extern svector<PWire*>*pform_make_task_ports(NetNet::PortType pt,
327 ivl_variable_type_t vtype,
328 bool signed_flag,
329 svector<PExpr*>*range,
330 list<perm_string>*names,
331 const char* file,
332 unsigned lineno);
336 * These are functions that the outside-the-parser code uses the do
337 * interesting things to the verilog. The parse function reads and
338 * parses the source file and places all the modules it finds into the
339 * mod list. The dump function dumps a module to the output stream.
341 extern void pform_dump(ostream&out, Module*mod);
344 * $Log: pform.h,v $
345 * Revision 1.91 2007/05/24 04:07:12 steve
346 * Rework the heirarchical identifier parse syntax and pform
347 * to handle more general combinations of heirarch and bit selects.
349 * Revision 1.90 2007/04/19 02:52:53 steve
350 * Add support for -v flag in command file.
352 * Revision 1.89 2007/04/13 02:34:35 steve
353 * Parse edge sensitive paths without edge specifier.
355 * Revision 1.88 2007/02/12 01:52:21 steve
356 * Parse all specify paths to pform.
358 * Revision 1.87 2006/09/23 04:57:19 steve
359 * Basic support for specify timing.
361 * Revision 1.86 2006/04/10 00:37:42 steve
362 * Add support for generate loops w/ wires and gates.
364 * Revision 1.85 2006/03/30 05:22:34 steve
365 * task/function ports can have types.
367 * Revision 1.84 2005/12/05 21:21:18 steve
368 * Fixes for stubborn compilers.
370 * Revision 1.83 2005/07/07 16:22:49 steve
371 * Generalize signals to carry types.
373 * Revision 1.82 2004/12/11 02:31:27 steve
374 * Rework of internals to carry vectors through nexus instead
375 * of single bits. Make the ivl, tgt-vvp and vvp initial changes
376 * down this path.
378 * Revision 1.81 2004/08/26 04:02:04 steve
379 * Add support for localparam ranges.
381 * Revision 1.80 2004/06/13 04:56:56 steve
382 * Add support for the default_nettype directive.
384 * Revision 1.79 2004/05/31 23:34:39 steve
385 * Rewire/generalize parsing an elaboration of
386 * function return values to allow for better
387 * speed and more type support.
389 * Revision 1.78 2004/05/25 19:21:07 steve
390 * More identifier lists use perm_strings.
392 * Revision 1.77 2004/03/08 00:10:30 steve
393 * Verilog2001 new style port declartions for primitives.
395 * Revision 1.76 2004/02/20 18:53:35 steve
396 * Addtrbute keys are perm_strings.
398 * Revision 1.75 2004/02/20 06:22:58 steve
399 * parameter keys are per_strings.
401 * Revision 1.74 2004/02/18 17:11:57 steve
402 * Use perm_strings for named langiage items.
404 * Revision 1.73 2003/07/04 03:57:19 steve
405 * Allow attributes on Verilog 2001 port declarations.
407 * Revision 1.72 2003/06/20 00:53:19 steve
408 * Module attributes from the parser
409 * through to elaborated form.
411 * Revision 1.71 2003/06/13 00:27:09 steve
412 * Task/functions can have signed ports.
414 * Revision 1.70 2003/04/28 17:50:57 steve
415 * More 2001 port declaration support.
417 * Revision 1.69 2003/04/14 03:39:15 steve
418 * Break sized constants into a size token
419 * and a based numeric constant.
421 * Revision 1.68 2003/02/27 06:45:11 steve
422 * specparams as far as pform.
424 * Revision 1.67 2003/02/02 19:02:40 steve
425 * Add support for signed ports and nets.
427 * Revision 1.66 2003/01/30 16:23:08 steve
428 * Spelling fixes.
430 * Revision 1.65 2003/01/26 21:15:59 steve
431 * Rework expression parsing and elaboration to
432 * accommodate real/realtime values and expressions.
434 * Revision 1.64 2002/09/01 03:01:48 steve
435 * Properly cast signedness of parameters with ranges.
437 * Revision 1.63 2002/08/19 02:39:17 steve
438 * Support parameters with defined ranges.
440 * Revision 1.62 2002/08/12 01:35:00 steve
441 * conditional ident string using autoconfig.
443 * Revision 1.61 2002/06/06 18:57:18 steve
444 * Use standard name for iostream.
446 * Revision 1.60 2002/05/26 01:39:02 steve
447 * Carry Verilog 2001 attributes with processes,
448 * all the way through to the ivl_target API.
450 * Divide signal reference counts between rval
451 * and lval references.
453 * Revision 1.59 2002/05/24 04:36:23 steve
454 * Verilog 2001 attriubtes on nets/wires.
456 * Revision 1.58 2002/05/23 03:08:51 steve
457 * Add language support for Verilog-2001 attribute
458 * syntax. Hook this support into existing $attribute
459 * handling, and add number and void value types.
461 * Add to the ivl_target API new functions for access
462 * of complex attributes attached to gates.
464 * Revision 1.57 2002/05/20 02:06:01 steve
465 * Add ranges and signed to port list declarations.
467 * Revision 1.56 2002/05/19 23:37:28 steve
468 * Parse port_declaration_lists from the 2001 Standard.
470 * Revision 1.55 2002/01/12 04:03:39 steve
471 * Drive strengths for continuous assignments.
473 * Revision 1.54 2001/12/07 05:03:13 steve
474 * Support integer for function return value.
476 * Revision 1.53 2001/12/03 04:47:15 steve
477 * Parser and pform use hierarchical names as hname_t
478 * objects instead of encoded strings.
480 * Revision 1.52 2001/11/29 17:37:51 steve
481 * Properly parse net_decl assignments with delays.
483 * Revision 1.51 2001/11/10 02:08:49 steve
484 * Coerse input to inout when assigned to.
486 * Revision 1.50 2001/10/31 03:11:15 steve
487 * detect module ports not declared within the module.
489 * Revision 1.49 2001/10/21 01:55:25 steve
490 * Error messages for missing UDP port declarations.
492 * Revision 1.48 2001/10/21 00:42:48 steve
493 * Module types in pform are char* instead of string.
495 * Revision 1.47 2001/10/20 23:02:40 steve
496 * Add automatic module libraries.
498 * Revision 1.46 2001/10/20 05:21:51 steve
499 * Scope/module names are char* instead of string.
501 * Revision 1.45 2000/12/11 00:31:43 steve
502 * Add support for signed reg variables,
503 * simulate in t-vvm signed comparisons.
505 * Revision 1.44 2000/11/30 17:31:42 steve
506 * Change LineInfo to store const C strings.
508 * Revision 1.43 2000/10/31 17:49:02 steve
509 * Support time variables.
511 * Revision 1.42 2000/10/31 17:00:05 steve
512 * Remove C++ string from variable lists.
514 * Revision 1.41 2000/07/29 17:58:21 steve
515 * Introduce min:typ:max support.
517 * Revision 1.40 2000/05/08 05:30:20 steve
518 * Deliver gate output strengths to the netlist.
520 * Revision 1.39 2000/05/06 15:41:57 steve
521 * Carry assignment strength to pform.
523 * Revision 1.38 2000/04/01 19:31:57 steve
524 * Named events as far as the pform.
526 * Revision 1.37 2000/03/12 17:09:41 steve
527 * Support localparam.
529 * Revision 1.36 2000/03/08 04:36:54 steve
530 * Redesign the implementation of scopes and parameters.
531 * I now generate the scopes and notice the parameters
532 * in a separate pass over the pform. Once the scopes
533 * are generated, I can process overrides and evalutate
534 * paremeters before elaboration begins.
536 * Revision 1.35 2000/02/23 02:56:55 steve
537 * Macintosh compilers do not support ident.
539 * Revision 1.34 2000/01/10 22:16:24 steve
540 * minor type syntax fix for stubborn C++ compilers.
542 * Revision 1.33 2000/01/09 05:50:49 steve
543 * Support named parameter override lists.
545 * Revision 1.32 1999/12/30 19:06:14 steve
546 * Support reg initial assignment syntax.
548 * Revision 1.31 1999/09/10 05:02:09 steve
549 * Handle integers at task parameters.
551 * Revision 1.30 1999/08/27 15:08:37 steve
552 * continuous assignment lists.
554 * Revision 1.29 1999/08/25 22:22:41 steve
555 * elaborate some aspects of functions.
557 * Revision 1.28 1999/08/23 16:48:39 steve
558 * Parameter overrides support from Peter Monta
559 * AND and XOR support wide expressions.
561 * Revision 1.27 1999/08/03 04:14:49 steve
562 * Parse into pform arbitrarily complex module
563 * port declarations.
565 * Revision 1.26 1999/08/01 16:34:50 steve
566 * Parse and elaborate rise/fall/decay times
567 * for gates, and handle the rules for partial
568 * lists of times.
570 * Revision 1.25 1999/07/31 19:14:47 steve
571 * Add functions up to elaboration (Ed Carter)
573 * Revision 1.24 1999/07/24 02:11:20 steve
574 * Elaborate task input ports.
576 * Revision 1.23 1999/07/10 01:03:18 steve
577 * remove string from lexical phase.
579 * Revision 1.22 1999/07/03 02:12:52 steve
580 * Elaborate user defined tasks.
582 * Revision 1.21 1999/06/24 04:24:18 steve
583 * Handle expression widths for EEE and NEE operators,
584 * add named blocks and scope handling,
585 * add registers declared in named blocks.
587 * Revision 1.20 1999/06/15 03:44:53 steve
588 * Get rid of the STL vector template.
590 * Revision 1.19 1999/06/12 20:35:27 steve
591 * parse more verilog.
593 * Revision 1.18 1999/06/06 20:45:39 steve
594 * Add parse and elaboration of non-blocking assignments,
595 * Replace list<PCase::Item*> with an svector version,
596 * Add integer support.
598 * Revision 1.17 1999/06/02 15:38:46 steve
599 * Line information with nets.
601 * Revision 1.16 1999/05/29 02:36:17 steve
602 * module parameter bind by name.
604 * Revision 1.15 1999/05/20 04:31:45 steve
605 * Much expression parsing work,
606 * mark continuous assigns with source line info,
607 * replace some assertion failures with Sorry messages.
609 * Revision 1.14 1999/05/16 05:08:42 steve
610 * Redo constant expression detection to happen
611 * after parsing.
613 * Parse more operators and expressions.
615 * Revision 1.13 1999/05/10 00:16:58 steve
616 * Parse and elaborate the concatenate operator
617 * in structural contexts, Replace vector<PExpr*>
618 * and list<PExpr*> with svector<PExpr*>, evaluate
619 * constant expressions with parameters, handle
620 * memories as lvalues.
622 * Parse task declarations, integer types.
624 * Revision 1.12 1999/05/07 04:26:49 steve
625 * Parse more complex continuous assign lvalues.
627 * Revision 1.11 1999/05/06 04:37:17 steve
628 * Get rid of list<lgate> types.
630 * Revision 1.10 1999/05/06 04:09:28 steve
631 * Parse more constant expressions.
633 * Revision 1.9 1999/04/19 01:59:37 steve
634 * Add memories to the parse and elaboration phases.
636 * Revision 1.8 1999/02/21 17:01:57 steve
637 * Add support for module parameters.
639 * Revision 1.7 1999/02/15 02:06:15 steve
640 * Elaborate gate ranges.
642 * Revision 1.6 1999/01/25 05:45:56 steve
643 * Add the LineInfo class to carry the source file
644 * location of things. PGate, Statement and PProcess.
646 * elaborate handles module parameter mismatches,
647 * missing or incorrect lvalues for procedural
648 * assignment, and errors are propogated to the
649 * top of the elaboration call tree.
651 * Attach line numbers to processes, gates and
652 * assignment statements.
654 * Revision 1.5 1998/12/09 04:02:47 steve
655 * Support the include directive.
657 * Revision 1.4 1998/12/01 00:42:14 steve
658 * Elaborate UDP devices,
659 * Support UDP type attributes, and
660 * pass those attributes to nodes that
661 * are instantiated by elaboration,
662 * Put modules into a map instead of
663 * a simple list.
665 * Revision 1.3 1998/11/25 02:35:53 steve
666 * Parse UDP primitives all the way to pform.
668 * Revision 1.2 1998/11/23 00:20:23 steve
669 * NetAssign handles lvalues as pin links
670 * instead of a signal pointer,
671 * Wire attributes added,
672 * Ability to parse UDP descriptions added,
673 * XNF generates EXT records for signals with
674 * the PAD attribute.
676 * Revision 1.1 1998/11/03 23:29:04 steve
677 * Introduce verilog to CVS.
680 #endif