Add support for text macros with arguments.
[iverilog.git] / Statement.h
blob21864a8315fe1c458ec6426b8be4fc027913b408
1 #ifndef __Statement_H
2 #define __Statement_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: Statement.h,v 1.44 2007/05/24 04:07:11 steve Exp $"
23 #endif
25 # include <string>
26 # include "svector.h"
27 # include "StringHeap.h"
28 # include "PDelays.h"
29 # include "PExpr.h"
30 # include "HName.h"
31 # include "LineInfo.h"
32 class PExpr;
33 class Statement;
34 class PEventStatement;
35 class Design;
36 class NetAssign_;
37 class NetCAssign;
38 class NetDeassign;
39 class NetForce;
40 class NetScope;
43 * The PProcess is the root of a behavioral process. Each process gets
44 * one of these, which contains its type (initial or always) and a
45 * pointer to the single statement that is the process. A module may
46 * have several concurrent processes.
48 class PProcess : public LineInfo {
50 public:
51 enum Type { PR_INITIAL, PR_ALWAYS };
53 PProcess(Type t, Statement*st)
54 : type_(t), statement_(st) { }
56 virtual ~PProcess();
58 bool elaborate(Design*des, NetScope*scope) const;
60 Type type() const { return type_; }
61 Statement*statement() { return statement_; }
63 map<perm_string,PExpr*> attributes;
65 virtual void dump(ostream&out, unsigned ind) const;
67 private:
68 Type type_;
69 Statement*statement_;
73 * The PProcess is a process, the Statement is the actual action. In
74 * fact, the Statement class is abstract and represents all the
75 * possible kinds of statements that exist in Verilog.
77 class Statement : public LineInfo {
79 public:
80 Statement() { }
81 virtual ~Statement() =0;
83 virtual void dump(ostream&out, unsigned ind) const;
84 virtual NetProc* elaborate(Design*des, NetScope*scope) const;
85 virtual void elaborate_scope(Design*des, NetScope*scope) const;
89 * Assignment statements of the various forms are handled by this
90 * type. The rvalue is an expression. The lvalue needs to be figured
91 * out by the parser as much as possible.
93 class PAssign_ : public Statement {
94 public:
95 explicit PAssign_(PExpr*lval, PExpr*ex);
96 explicit PAssign_(PExpr*lval, PExpr*de, PExpr*ex);
97 explicit PAssign_(PExpr*lval, PEventStatement*de, PExpr*ex);
98 virtual ~PAssign_() =0;
100 const PExpr* lval() const { return lval_; }
101 const PExpr* rval() const { return rval_; }
103 protected:
104 NetAssign_* elaborate_lval(Design*, NetScope*scope) const;
106 PExpr* delay_;
107 PEventStatement*event_;
109 private:
110 PExpr* lval_;
111 PExpr* rval_;
114 class PAssign : public PAssign_ {
116 public:
117 explicit PAssign(PExpr*lval, PExpr*ex);
118 explicit PAssign(PExpr*lval, PExpr*de, PExpr*ex);
119 explicit PAssign(PExpr*lval, PEventStatement*de, PExpr*ex);
120 ~PAssign();
122 virtual void dump(ostream&out, unsigned ind) const;
123 virtual NetProc* elaborate(Design*des, NetScope*scope) const;
125 private:
128 class PAssignNB : public PAssign_ {
130 public:
131 explicit PAssignNB(PExpr*lval, PExpr*ex);
132 explicit PAssignNB(PExpr*lval, PExpr*de, PExpr*ex);
133 ~PAssignNB();
135 virtual void dump(ostream&out, unsigned ind) const;
136 virtual NetProc* elaborate(Design*des, NetScope*scope) const;
138 private:
139 NetProc*assign_to_memory_(class NetMemory*, PExpr*,
140 Design*des, NetScope*scope) const;
144 * A block statement is an ordered list of statements that make up the
145 * block. The block can be sequential or parallel, which only affects
146 * how the block is interpreted. The parser collects the list of
147 * statements before constructing this object, so it knows a priori
148 * what is contained.
150 class PBlock : public Statement {
152 public:
153 enum BL_TYPE { BL_SEQ, BL_PAR };
155 explicit PBlock(perm_string n, BL_TYPE t, const svector<Statement*>&st);
156 explicit PBlock(BL_TYPE t, const svector<Statement*>&st);
157 explicit PBlock(BL_TYPE t);
158 ~PBlock();
160 BL_TYPE bl_type() const { return bl_type_; }
163 virtual void dump(ostream&out, unsigned ind) const;
164 virtual NetProc* elaborate(Design*des, NetScope*scope) const;
165 virtual void elaborate_scope(Design*des, NetScope*scope) const;
167 private:
168 perm_string name_;
169 const BL_TYPE bl_type_;
170 svector<Statement*>list_;
173 class PCallTask : public Statement {
175 public:
176 explicit PCallTask(const pform_name_t&n, const svector<PExpr*>&parms);
177 explicit PCallTask(perm_string n, const svector<PExpr*>&parms);
178 ~PCallTask();
180 const pform_name_t& path() const;
182 unsigned nparms() const { return parms_.count(); }
184 PExpr*&parm(unsigned idx)
185 { assert(idx < parms_.count());
186 return parms_[idx];
189 PExpr* parm(unsigned idx) const
190 { assert(idx < parms_.count());
191 return parms_[idx];
194 virtual void dump(ostream&out, unsigned ind) const;
195 virtual NetProc* elaborate(Design*des, NetScope*scope) const;
197 private:
198 NetProc* elaborate_sys(Design*des, NetScope*scope) const;
199 NetProc* elaborate_usr(Design*des, NetScope*scope) const;
201 pform_name_t path_;
202 svector<PExpr*> parms_;
205 class PCase : public Statement {
207 public:
208 struct Item {
209 svector<PExpr*>expr;
210 Statement*stat;
213 PCase(NetCase::TYPE, PExpr*ex, svector<Item*>*);
214 ~PCase();
216 virtual NetProc* elaborate(Design*des, NetScope*scope) const;
217 virtual void elaborate_scope(Design*des, NetScope*scope) const;
218 virtual void dump(ostream&out, unsigned ind) const;
220 private:
221 NetCase::TYPE type_;
222 PExpr*expr_;
224 svector<Item*>*items_;
226 private: // not implemented
227 PCase(const PCase&);
228 PCase& operator= (const PCase&);
231 class PCAssign : public Statement {
233 public:
234 explicit PCAssign(PExpr*l, PExpr*r);
235 ~PCAssign();
237 virtual NetCAssign* elaborate(Design*des, NetScope*scope) const;
238 virtual void dump(ostream&out, unsigned ind) const;
240 private:
241 PExpr*lval_;
242 PExpr*expr_;
245 class PCondit : public Statement {
247 public:
248 PCondit(PExpr*ex, Statement*i, Statement*e);
249 ~PCondit();
251 virtual NetProc* elaborate(Design*des, NetScope*scope) const;
252 virtual void elaborate_scope(Design*des, NetScope*scope) const;
253 virtual void dump(ostream&out, unsigned ind) const;
255 private:
256 PExpr*expr_;
257 Statement*if_;
258 Statement*else_;
260 private: // not implemented
261 PCondit(const PCondit&);
262 PCondit& operator= (const PCondit&);
265 class PDeassign : public Statement {
267 public:
268 explicit PDeassign(PExpr*l);
269 ~PDeassign();
271 virtual NetDeassign* elaborate(Design*des, NetScope*scope) const;
272 virtual void dump(ostream&out, unsigned ind) const;
274 private:
275 PExpr*lval_;
278 class PDelayStatement : public Statement {
280 public:
281 PDelayStatement(PExpr*d, Statement*st);
282 ~PDelayStatement();
284 virtual void dump(ostream&out, unsigned ind) const;
285 virtual NetProc* elaborate(Design*des, NetScope*scope) const;
286 virtual void elaborate_scope(Design*des, NetScope*scope) const;
288 private:
289 PExpr*delay_;
290 Statement*statement_;
295 * This represents the parsing of a disable <scope> statement.
297 class PDisable : public Statement {
299 public:
300 explicit PDisable(const pform_name_t&sc);
301 ~PDisable();
303 virtual void dump(ostream&out, unsigned ind) const;
304 virtual NetProc* elaborate(Design*des, NetScope*scope) const;
306 private:
307 pform_name_t scope_;
311 * The event statement represents the event delay in behavioral
312 * code. It comes from such things as:
314 * @name <statement>;
315 * @(expr) <statement>;
316 * @* <statement>;
318 class PEventStatement : public Statement {
320 public:
322 explicit PEventStatement(const svector<PEEvent*>&ee);
323 explicit PEventStatement(PEEvent*ee);
324 // Make an @* statement.
325 explicit PEventStatement(void);
327 ~PEventStatement();
329 void set_statement(Statement*st);
331 virtual void dump(ostream&out, unsigned ind) const;
332 virtual NetProc* elaborate(Design*des, NetScope*scope) const;
333 virtual void elaborate_scope(Design*des, NetScope*scope) const;
335 // This method is used to elaborate, but attach a previously
336 // elaborated statement to the event.
337 NetProc* elaborate_st(Design*des, NetScope*scope, NetProc*st) const;
339 NetProc* elaborate_wait(Design*des, NetScope*scope, NetProc*st) const;
341 private:
342 svector<PEEvent*>expr_;
343 Statement*statement_;
346 class PForce : public Statement {
348 public:
349 explicit PForce(PExpr*l, PExpr*r);
350 ~PForce();
352 virtual NetForce* elaborate(Design*des, NetScope*scope) const;
353 virtual void dump(ostream&out, unsigned ind) const;
355 private:
356 PExpr*lval_;
357 PExpr*expr_;
360 class PForever : public Statement {
361 public:
362 explicit PForever(Statement*s);
363 ~PForever();
365 virtual NetProc* elaborate(Design*des, NetScope*scope) const;
366 virtual void elaborate_scope(Design*des, NetScope*scope) const;
367 virtual void dump(ostream&out, unsigned ind) const;
369 private:
370 Statement*statement_;
373 class PForStatement : public Statement {
375 public:
376 PForStatement(PExpr*n1, PExpr*e1, PExpr*cond,
377 PExpr*n2, PExpr*e2, Statement*st);
378 ~PForStatement();
380 virtual NetProc* elaborate(Design*des, NetScope*scope) const;
381 virtual void elaborate_scope(Design*des, NetScope*scope) const;
382 virtual void dump(ostream&out, unsigned ind) const;
384 private:
385 PExpr* name1_;
386 PExpr* expr1_;
388 PExpr*cond_;
390 PExpr* name2_;
391 PExpr* expr2_;
393 Statement*statement_;
396 class PNoop : public Statement {
398 public:
399 PNoop() { }
400 ~PNoop() { }
403 class PRepeat : public Statement {
404 public:
405 explicit PRepeat(PExpr*expr, Statement*s);
406 ~PRepeat();
408 virtual NetProc* elaborate(Design*des, NetScope*scope) const;
409 virtual void elaborate_scope(Design*des, NetScope*scope) const;
410 virtual void dump(ostream&out, unsigned ind) const;
412 private:
413 PExpr*expr_;
414 Statement*statement_;
417 class PRelease : public Statement {
419 public:
420 explicit PRelease(PExpr*l);
421 ~PRelease();
423 virtual NetProc* elaborate(Design*des, NetScope*scope) const;
424 virtual void dump(ostream&out, unsigned ind) const;
426 private:
427 PExpr*lval_;
431 * The PTrigger statement sends a trigger to a named event. Take the
432 * name here.
434 class PTrigger : public Statement {
436 public:
437 explicit PTrigger(const pform_name_t&ev);
438 ~PTrigger();
440 virtual NetProc* elaborate(Design*des, NetScope*scope) const;
441 virtual void dump(ostream&out, unsigned ind) const;
443 private:
444 pform_name_t event_;
447 class PWhile : public Statement {
449 public:
450 PWhile(PExpr*e1, Statement*st);
451 ~PWhile();
453 virtual NetProc* elaborate(Design*des, NetScope*scope) const;
454 virtual void elaborate_scope(Design*des, NetScope*scope) const;
455 virtual void dump(ostream&out, unsigned ind) const;
457 private:
458 PExpr*cond_;
459 Statement*statement_;
463 * $Log: Statement.h,v $
464 * Revision 1.44 2007/05/24 04:07:11 steve
465 * Rework the heirarchical identifier parse syntax and pform
466 * to handle more general combinations of heirarch and bit selects.
468 * Revision 1.43 2007/03/05 05:59:10 steve
469 * Handle processes within generate loops.
471 * Revision 1.42 2005/12/05 21:21:18 steve
472 * Fixes for stubborn compilers.
474 * Revision 1.41 2004/12/11 02:31:25 steve
475 * Rework of internals to carry vectors through nexus instead
476 * of single bits. Make the ivl, tgt-vvp and vvp initial changes
477 * down this path.
479 * Revision 1.40 2004/02/20 18:53:33 steve
480 * Addtrbute keys are perm_strings.
482 * Revision 1.39 2004/02/18 17:11:54 steve
483 * Use perm_strings for named langiage items.
485 * Revision 1.38 2003/05/19 02:50:58 steve
486 * Implement the wait statement behaviorally instead of as nets.
488 * Revision 1.37 2003/01/30 16:23:07 steve
489 * Spelling fixes.
491 * Revision 1.36 2002/08/12 01:34:58 steve
492 * conditional ident string using autoconfig.
494 * Revision 1.35 2002/06/04 05:38:44 steve
495 * Add support for memory words in l-value of
496 * blocking assignments, and remove the special
497 * NetAssignMem class.
499 * Revision 1.34 2002/05/26 01:39:02 steve
500 * Carry Verilog 2001 attributes with processes,
501 * all the way through to the ivl_target API.
503 * Divide signal reference counts between rval
504 * and lval references.
506 * Revision 1.33 2002/04/21 22:31:02 steve
507 * Redo handling of assignment internal delays.
508 * Leave it possible for them to be calculated
509 * at run time.
511 * Revision 1.32 2002/04/21 04:59:07 steve
512 * Add support for conbinational events by finding
513 * the inputs to expressions and some statements.
514 * Get case and assignment statements working.
516 * Revision 1.31 2001/12/03 04:47:14 steve
517 * Parser and pform use hierarchical names as hname_t
518 * objects instead of encoded strings.
520 * Revision 1.30 2001/11/22 06:20:59 steve
521 * Use NetScope instead of string for scope path.
523 * Revision 1.29 2000/09/09 15:21:26 steve
524 * move lval elaboration to PExpr virtual methods.
526 * Revision 1.28 2000/09/03 17:58:35 steve
527 * Change elaborate_lval to return NetAssign_ objects.
529 * Revision 1.27 2000/07/26 05:08:07 steve
530 * Parse disable statements to pform.
532 * Revision 1.26 2000/05/11 23:37:26 steve
533 * Add support for procedural continuous assignment.
535 * Revision 1.25 2000/04/22 04:20:19 steve
536 * Add support for force assignment.
538 * Revision 1.24 2000/04/12 04:23:57 steve
539 * Named events really should be expressed with PEIdent
540 * objects in the pform,
542 * Handle named events within the mix of net events
543 * and edges. As a unified lot they get caught together.
544 * wait statements are broken into more complex statements
545 * that include a conditional.
547 * Do not generate NetPEvent or NetNEvent objects in
548 * elaboration. NetEvent, NetEvWait and NetEvProbe
549 * take over those functions in the netlist.
551 #endif