Fix for assertion error when expanding macro.
[iverilog.git] / netlist.h
bloba9a1fd4a0971ff786b3de812fb2cbc138f261ae4
1 #ifndef __netlist_H
2 #define __netlist_H
3 /*
4 * Copyright (c) 1998-2006 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: netlist.h,v 1.380 2007/06/02 03:42:13 steve Exp $"
23 #endif
26 * The netlist types, as described in this header file, are intended
27 * to be the output from elaboration of the source design. The design
28 * can be passed around in this form to the various stages and design
29 * processors.
31 # include <string>
32 # include <map>
33 # include <list>
34 # include <vector>
35 # include "ivl_target.h"
36 # include "pform_types.h"
37 # include "config.h"
38 # include "verinum.h"
39 # include "verireal.h"
40 # include "StringHeap.h"
41 # include "HName.h"
42 # include "LineInfo.h"
43 # include "svector.h"
44 # include "Attrib.h"
46 #ifdef HAVE_IOSFWD
47 # include <iosfwd>
48 #else
49 class ostream;
50 #endif
52 class Design;
53 class Link;
54 class Nexus;
55 class NetNet;
56 class NetNode;
57 class NetProc;
58 class NetProcTop;
59 class NetRelease;
60 class NetScope;
61 class NetEvProbe;
62 class NetExpr;
63 class NetESignal;
64 class NetFuncDef;
65 class NetRamDq;
66 class NetEvTrig;
67 class NetEvWait;
70 struct target;
71 struct functor_t;
73 ostream& operator << (ostream&o, ivl_variable_type_t val);
75 /* =========
76 * A NetObj is anything that has any kind of behavior in the
77 * netlist. Nodes can be gates, registers, etc. and are linked
78 * together to form a design web.
80 * The web of nodes that makes up a circuit is held together by the
81 * Link class. There is a link for each pin. All mutually connected
82 * pins form a ring of links.
84 * A link can be INPUT, OUTPUT or PASSIVE. An input never drives the
85 * signal, and PASSIVE never receives the value of the signal. Wires
86 * are PASSIVE, for example.
88 * A NetObj also has delays specified as rise_time, fall_time and
89 * decay_time. The rise and fall time are the times to transition to 1
90 * or 0 values. The decay_time is the time needed to decay to a 'bz
91 * value, or to decay of the net is a trireg. The exact and precise
92 * interpretation of the rise/fall/decay times is typically left to
93 * the target to properly interpret.
95 class NetObj : public Attrib, public virtual LineInfo {
97 public:
98 public:
99 // The name of the object must be a permallocated string. A
100 // lex_strings string, for example.
101 explicit NetObj(NetScope*s, perm_string n, unsigned npins);
102 virtual ~NetObj();
104 NetScope* scope();
105 const NetScope* scope() const;
107 perm_string name() const { return name_; }
109 unsigned pin_count() const { return npins_; }
111 const NetExpr* rise_time() const { return delay1_; }
112 const NetExpr* fall_time() const { return delay2_; }
113 const NetExpr* decay_time() const { return delay3_; }
115 void rise_time(const NetExpr* d) { delay1_ = d; }
116 void fall_time(const NetExpr* d) { delay2_ = d; }
117 void decay_time(const NetExpr* d) { delay3_ = d; }
119 Link&pin(unsigned idx);
120 const Link&pin(unsigned idx) const;
122 void dump_node_pins(ostream&, unsigned) const;
123 void dump_obj_attr(ostream&, unsigned) const;
125 private:
126 NetScope*scope_;
127 perm_string name_;
128 Link*pins_;
129 const unsigned npins_;
130 const NetExpr* delay1_;
131 const NetExpr* delay2_;
132 const NetExpr* delay3_;
135 class Link {
137 friend void connect(Link&, Link&);
138 friend void connect(Nexus*, Link&);
139 friend class NetObj;
140 friend class Nexus;
142 public:
143 enum DIR { PASSIVE, INPUT, OUTPUT };
145 enum strength_t { HIGHZ, WEAK, PULL, STRONG, SUPPLY };
147 Link();
148 ~Link();
150 // Manipulate the link direction.
151 void set_dir(DIR d);
152 DIR get_dir() const;
154 // A link has a drive strength for 0 and 1 values. The drive0
155 // strength is for when the link has the value 0, and drive1
156 // strength is for when the link has a value 1.
157 void drive0(strength_t);
158 void drive1(strength_t);
160 strength_t drive0() const;
161 strength_t drive1() const;
163 // A link has an initial value that is used by the nexus to
164 // figure out its initial value. Normally, only the object
165 // that contains the link sets the initial value, and only the
166 // attached Nexus gets it. The default link value is Vx.
167 void set_init(verinum::V val);
168 verinum::V get_init() const;
170 void cur_link(NetObj*&net, unsigned &pin);
171 void cur_link(const NetObj*&net, unsigned &pin) const;
173 // Get a pointer to the nexus that represents all the links
174 // connected to me.
175 Nexus* nexus();
176 const Nexus* nexus()const;
178 // Return a pointer to the next link in the nexus.
179 Link* next_nlink();
180 const Link* next_nlink() const;
182 // Remove this link from the set of connected pins. The
183 // destructor will automatically do this if needed.
184 void unlink();
186 // Return true if this link is connected to anything else.
187 bool is_linked() const;
189 // Return true if these pins are connected.
190 bool is_linked(const Link&that) const;
192 // Return true if this is the same pin of the same object of
193 // that link.
194 bool is_equal(const Link&that) const;
196 // Return information about the object that this link is
197 // a part of.
198 const NetObj*get_obj() const;
199 NetObj*get_obj();
200 unsigned get_pin() const;
202 // A link of an object (sometimes called a "pin") has a
203 // name. It is convenient for the name to have a string and an
204 // integer part.
205 void set_name(perm_string, unsigned inst =0);
206 perm_string get_name() const;
207 unsigned get_inst() const;
209 private:
210 // The NetNode manages these. They point back to the
211 // NetNode so that following the links can get me here.
212 NetObj *node_;
213 unsigned pin_;
215 DIR dir_;
216 strength_t drive0_, drive1_;
217 verinum::V init_;
219 // These members name the pin of the link. If the name
220 // has width, then the inst_ member is the index of the
221 // pin.
222 perm_string name_;
223 unsigned inst_;
225 private:
226 Link *next_;
227 Nexus*nexus_;
229 private: // not implemented
230 Link(const Link&);
231 Link& operator= (const Link&);
236 * The Nexus represents a collection of links that are joined
237 * together. Each link has its own properties, this class holds the
238 * properties of the group.
240 * The links in a nexus are grouped into a singly linked list, with
241 * the nexus pointing to the first Link. Each link in turn points to
242 * the next link in the nexus, with the last link pointing to 0.
244 * The t_cookie() is a void* that targets can use to store information
245 * in a Nexus. ivl guarantees that the t_cookie will be 0 when the
246 * target is invoked.
248 class Nexus {
250 friend void connect(Link&, Link&);
251 friend void connect(Nexus*, Link&);
252 friend class Link;
254 public:
255 explicit Nexus();
256 ~Nexus();
258 const char* name() const;
259 verinum::V get_init() const;
261 Link*first_nlink();
262 const Link* first_nlink()const;
264 /* Get the width of the Nexus, or 0 if there are no vectors
265 (in the form of NetNet objects) linked. */
266 unsigned vector_width() const;
268 NetNet* pick_any_net();
270 /* This method returns true if all the possible drivers of
271 this nexus are constant. It will also return true if there
272 are no drivers at all. */
273 bool drivers_constant() const;
275 /* Given the nexus has constant drivers, this method returns
276 the value that has been driven. */
277 verinum::V driven_value() const;
279 ivl_nexus_t t_cookie() const;
280 ivl_nexus_t t_cookie(ivl_nexus_t) const;
282 private:
283 Link*list_;
284 void unlink(Link*);
285 void relink(Link*);
287 mutable char* name_; /* Cache the calculated name for the Nexus. */
288 mutable ivl_nexus_t t_cookie_;
290 enum VALUE { NO_GUESS, V0, V1, Vx, Vz, VAR };
291 mutable VALUE driven_;
293 private: // not implemented
294 Nexus(const Nexus&);
295 Nexus& operator= (const Nexus&);
298 class NexusSet {
300 public:
301 ~NexusSet();
302 NexusSet();
304 unsigned count() const;
306 // Add the nexus to the set, if it is not already present.
307 void add(Nexus*that);
308 void add(const NexusSet&that);
310 // Remove the nexus from the set, if it is present.
311 void rem(Nexus*that);
312 void rem(const NexusSet&that);
314 Nexus* operator[] (unsigned idx) const;
316 // Return true if this set contains every nexus in that set.
317 bool contains(const NexusSet&that) const;
319 // Return true if this set contains any nexus in that set.
320 bool intersect(const NexusSet&that) const;
322 private:
323 Nexus**items_;
324 unsigned nitems_;
326 unsigned bsearch_(Nexus*that) const;
328 private: // not implemented
329 NexusSet(const NexusSet&);
330 NexusSet& operator= (const NexusSet&);
334 * A NetBus is a transparent device that is merely a bunch of pins
335 * used to tie some pins to. It is a convenient way to collect a
336 * bundle of pins and pass that bundle around.
338 class NetBus : public NetObj {
340 public:
341 NetBus(NetScope*scope, unsigned pin_count);
342 ~NetBus();
344 private: // not implemented
345 NetBus(const NetBus&);
346 NetBus& operator= (const NetBus&);
350 * A NetNode is a device of some sort, where each pin has a different
351 * meaning. (i.e., pin(0) is the output to an and gate.) NetNode
352 * objects are listed in the nodes_ of the Design object.
354 class NetNode : public NetObj {
356 public:
357 // The name parameter must be a permallocated string.
358 explicit NetNode(NetScope*s, perm_string n, unsigned npins);
360 virtual ~NetNode();
362 virtual bool emit_node(struct target_t*) const;
363 virtual void dump_node(ostream&, unsigned) const;
365 // This is used to scan a modifiable netlist, one node at a time.
366 virtual void functor_node(Design*, functor_t*);
368 private:
369 friend class Design;
370 NetNode*node_next_, *node_prev_;
371 Design*design_;
375 * A NetDelaySrc is an input-only device that calculates a path delay
376 * based on the time that the inputs change. This class is used by the
377 * NetNet class, and NetDelaySrc objects cannot exist outside of its
378 * association with NetNet objects.
380 class NetDelaySrc : public NetObj {
382 public:
383 explicit NetDelaySrc(NetScope*s, perm_string n,
384 unsigned nsrc, bool condit_src);
385 ~NetDelaySrc();
387 // These functions set the delays from the values in the
388 // source. These set_delays functions implement the various
389 // rules wrt collections of transitions.
391 // One transition specified.
392 void set_delays(uint64_t del);
393 // Two transitions: rise and fall
394 void set_delays(uint64_t rise, uint64_t fall);
395 // Three transitions
396 void set_delays(uint64_t rise, uint64_t fall, uint64_t tz);
397 void set_delays(uint64_t t01, uint64_t t10, uint64_t t0z,
398 uint64_t tz1, uint64_t t1z, uint64_t tz0);
399 void set_delays(uint64_t t01, uint64_t t10, uint64_t t0z,
400 uint64_t tz1, uint64_t t1z, uint64_t tz0,
401 uint64_t t0x, uint64_t tx1, uint64_t t1x,
402 uint64_t tx0, uint64_t txz, uint64_t tzx);
404 uint64_t get_delay(unsigned pe) const;
406 void set_posedge();
407 void set_negedge();
408 bool is_posedge() const;
409 bool is_negedge() const;
411 unsigned src_count() const;
412 Link&src_pin(unsigned);
413 const Link&src_pin(unsigned) const;
415 bool is_condit() const;
416 Link&condit_pin();
417 const Link&condit_pin() const;
419 void dump(ostream&, unsigned ind) const;
421 private:
422 uint64_t transition_delays_[12];
423 bool condit_flag_;
424 bool posedge_;
425 bool negedge_;
427 private: // Not implemented
428 NetDelaySrc(const NetDelaySrc&);
429 NetDelaySrc& operator= (const NetDelaySrc&);
433 * NetNet is a special kind of NetObj that doesn't really do anything,
434 * but carries the properties of the wire/reg/trireg, including its
435 * name. Scalers and vectors are all the same thing here, a NetNet
436 * with a single pin. The difference between a scaler and vector is
437 * the video of the atomic vector datum it carries.
439 * NetNet objects can also appear as side effects of synthesis or
440 * other abstractions.
442 * Note that INTEGER types are an alias for a ``reg signed [31:0]''.
444 * NetNet objects have a name and exist within a scope, so the
445 * constructor takes a pointer to the containing scope. The object
446 * automatically adds itself to the scope.
448 * NetNet objects are located by searching NetScope objects.
450 * The pin of a NetNet object are PASSIVE: they do not drive
451 * anything and they are not a data sink, per se. The pins follow the
452 * values on the nexus.
454 class NetNet : public NetObj {
456 public:
457 enum Type { NONE, IMPLICIT, IMPLICIT_REG, INTEGER, WIRE, TRI, TRI1,
458 SUPPLY0, SUPPLY1, WAND, TRIAND, TRI0, WOR, TRIOR, REG,
459 WONE };
461 enum PortType { NOT_A_PORT, PIMPLICIT, PINPUT, POUTPUT, PINOUT };
463 // The width in this case is a shorthand for ms=width-1 and
464 // ls=0. Only one pin is created, the width is of the vector
465 // that passed through.
466 explicit NetNet(NetScope*s, perm_string n, Type t, unsigned width =1);
468 // This form supports an array of vectors. The [ms:ls] define
469 // the base vector, and the [s0:e0] define the array
470 // dimensions. If s0==e0, then this is not an array after
471 // all.
472 explicit NetNet(NetScope*s, perm_string n, Type t,
473 long ms, long ls);
474 explicit NetNet(NetScope*s, perm_string n, Type t,
475 long ms, long ls, long s0, long e0);
477 virtual ~NetNet();
479 Type type() const;
480 void type(Type t);
482 PortType port_type() const;
483 void port_type(PortType t);
485 ivl_variable_type_t data_type() const;
486 void data_type(ivl_variable_type_t t);
488 /* If a NetNet is signed, then its value is to be treated as
489 signed. Otherwise, it is unsigned. */
490 bool get_signed() const;
491 void set_signed(bool);
493 /* Used to maintain original type of net since integers are
494 implemented as 'reg signed [31:0]' in Icarus */
495 bool get_isint() const;
496 void set_isint(bool);
498 /* These methods return the msb and lsb indices for the most
499 significant and least significant bits. These are signed
500 longs, and may be different from pin numbers. For example,
501 reg [1:8] has 8 bits, msb==1 and lsb==8. */
502 long msb() const;
503 long lsb() const;
504 unsigned long vector_width() const;
506 /* This method converts a signed index (the type that might be
507 found in the verilog source) to a pin number. It accounts
508 for variation in the definition of the reg/wire/whatever. */
509 unsigned sb_to_idx(long sb) const;
511 /* This method checks that the signed index is valid for this
512 signal. If it is, the above sb_to_idx can be used to get
513 the pin# from the index. */
514 bool sb_is_valid(long sb) const;
516 /* This method returns 0 for scalers and vectors, and greater
517 for arrays. The value is the number of array
518 indices. (Currently only one array index is supported.) */
519 unsigned array_dimensions() const;
520 long array_first() const;
522 // This is the number of array elements.
523 unsigned array_count() const;
525 // This method returns a 0 based address of an array entry as
526 // indexed by idx. The Verilog source may give index ranges
527 // that are not zero based.
528 bool array_index_is_valid(long idx) const;
529 unsigned array_index_to_address(long idx) const;
531 bool local_flag() const { return local_flag_; }
532 void local_flag(bool f) { local_flag_ = f; }
534 /* NetESignal objects may reference this object. Keep a
535 reference count so that I keep track of them. */
536 void incr_eref();
537 void decr_eref();
538 unsigned peek_eref() const;
540 /* Assignment statements count their lrefs here. */
541 void incr_lref();
542 void decr_lref();
543 unsigned peek_lref() const;
545 unsigned get_refs() const;
547 /* Manage path delays */
548 void add_delay_path(class NetDelaySrc*path);
549 unsigned delay_paths(void) const;
550 const class NetDelaySrc*delay_path(unsigned idx) const;
552 virtual void dump_net(ostream&, unsigned) const;
554 private:
555 // The NetScope class uses this for listing signals.
556 friend class NetScope;
557 NetNet*sig_next_, *sig_prev_;
559 private:
560 Type type_;
561 PortType port_type_;
562 ivl_variable_type_t data_type_;
563 bool signed_;
564 bool isint_; // original type of integer
566 long msb_, lsb_;
567 const unsigned dimensions_;
568 long s0_, e0_;
570 bool local_flag_;
571 unsigned eref_count_;
572 unsigned lref_count_;
574 vector<class NetDelaySrc*> delay_paths_;
578 * This class implements the LPM_ADD_SUB component as described in the
579 * EDIF LPM Version 2 1 0 standard. It is used as a structural
580 * implementation of the + and - operators.
582 class NetAddSub : public NetNode {
584 public:
585 NetAddSub(NetScope*s, perm_string n, unsigned width);
586 ~NetAddSub();
588 // Get the width of the device (that is, the width of the
589 // operands and results.)
590 unsigned width() const;
592 Link& pin_Aclr();
593 Link& pin_Add_Sub();
594 Link& pin_Clock();
595 Link& pin_Cin();
596 Link& pin_Cout();
597 Link& pin_Overflow();
599 Link& pin_DataA();
600 Link& pin_DataB();
601 Link& pin_Result();
603 const Link& pin_Cout() const;
604 const Link& pin_DataA() const;
605 const Link& pin_DataB() const;
606 const Link& pin_Result() const;
608 virtual void dump_node(ostream&, unsigned ind) const;
609 virtual bool emit_node(struct target_t*) const;
610 virtual void functor_node(Design*des, functor_t*fun);
612 private:
613 unsigned width_;
617 * The NetArrayDq node represents an array dereference. The NetNet
618 * that this object refers to is an array, and the Address pin selects
619 * which word of the array to place on the Result.
621 class NetArrayDq : public NetNode {
623 public:
624 NetArrayDq(NetScope*s, perm_string name, NetNet*mem, unsigned awid);
625 ~NetArrayDq();
627 unsigned width() const;
628 unsigned awidth() const;
629 unsigned size() const;
630 const NetNet*mem() const;
632 Link& pin_Address();
633 Link& pin_Result();
635 const Link& pin_Address() const;
636 const Link& pin_Result() const;
638 virtual void dump_node(ostream&, unsigned ind) const;
639 virtual bool emit_node(struct target_t*) const;
641 private:
642 NetNet*mem_;
643 unsigned awidth_;
648 * This type represents the LPM_CLSHIFT device.
650 class NetCLShift : public NetNode {
652 public:
653 NetCLShift(NetScope*s, perm_string n, unsigned width,
654 unsigned width_dist, bool right_flag, bool signed_flag);
655 ~NetCLShift();
657 unsigned width() const;
658 unsigned width_dist() const;
660 bool right_flag() const;
661 bool signed_flag() const;
663 Link& pin_Data();
664 Link& pin_Result();
665 Link& pin_Distance();
667 const Link& pin_Data() const;
668 const Link& pin_Result() const;
669 const Link& pin_Distance() const;
671 virtual void dump_node(ostream&, unsigned ind) const;
672 virtual bool emit_node(struct target_t*) const;
674 private:
675 unsigned width_;
676 unsigned width_dist_;
677 bool right_flag_;
678 bool signed_flag_;
682 * This class supports the LPM_COMPARE device.
684 * The width of the device is the width of the inputs. If one of the
685 * inputs is narrower then the other, it is up to the generator to
686 * make sure all the data pins are properly driven.
688 * NOTE: This is not the same as the device used to support case
689 * compare. Case comparisons handle Vx and Vz values, whereas this
690 * device need not.
692 class NetCompare : public NetNode {
694 public:
695 NetCompare(NetScope*scope, perm_string n, unsigned width);
696 ~NetCompare();
698 unsigned width() const;
700 bool get_signed() const;
701 void set_signed(bool);
703 Link& pin_Aclr();
704 Link& pin_Clock();
705 Link& pin_AGB();
706 Link& pin_AGEB();
707 Link& pin_AEB();
708 Link& pin_ANEB();
709 Link& pin_ALB();
710 Link& pin_ALEB();
712 Link& pin_DataA();
713 Link& pin_DataB();
715 const Link& pin_Aclr() const;
716 const Link& pin_Clock() const;
717 const Link& pin_AGB() const;
718 const Link& pin_AGEB() const;
719 const Link& pin_AEB() const;
720 const Link& pin_ANEB() const;
721 const Link& pin_ALB() const;
722 const Link& pin_ALEB() const;
724 const Link& pin_DataA() const;
725 const Link& pin_DataB() const;
727 virtual void functor_node(Design*, functor_t*);
728 virtual void dump_node(ostream&, unsigned ind) const;
729 virtual bool emit_node(struct target_t*) const;
731 private:
732 unsigned width_;
733 bool signed_flag_;
738 * This node is a means to connect net inputs together to form a wider
739 * vector. The output (pin 0) is a concatenation of the input vectors,
740 * with pin-1 at the LSB, pin-2 next, and so on. This node is most
741 * like the NetLogic node, as it has one output at pin 0 and the
742 * remaining pins are the input that are combined to make the
743 * output. It is seperated out because it it generally a special case
744 * for the code generators.
746 * When constructing the node, the width is the vector_width of the
747 * output, and the cnt is the number of pins. (the number of input
748 * vectors.)
750 class NetConcat : public NetNode {
752 public:
753 NetConcat(NetScope*scope, perm_string n, unsigned wid, unsigned cnt);
754 ~NetConcat();
756 unsigned width() const;
758 void dump_node(ostream&, unsigned ind) const;
759 bool emit_node(struct target_t*) const;
761 private:
762 unsigned width_;
767 * This class represents a theoretical (though not necessarily
768 * practical) integer divider gate. This is not to represent any real
769 * hardware, but to support the / operator in Verilog, when it shows
770 * up in structural contexts.
772 * The operands of the operation are the DataA<i> and DataB<i> inputs,
773 * and the Result<i> output reflects the value DataA/DataB.
776 class NetDivide : public NetNode {
778 public:
779 NetDivide(NetScope*scope, perm_string n,
780 unsigned width, unsigned wa, unsigned wb);
781 ~NetDivide();
783 unsigned width_r() const;
784 unsigned width_a() const;
785 unsigned width_b() const;
787 void set_signed(bool);
788 bool get_signed() const;
790 Link& pin_DataA();
791 Link& pin_DataB();
792 Link& pin_Result();
794 const Link& pin_DataA() const;
795 const Link& pin_DataB() const;
796 const Link& pin_Result() const;
798 virtual void dump_node(ostream&, unsigned ind) const;
799 virtual bool emit_node(struct target_t*) const;
800 virtual void functor_node(Design*des, functor_t*fun);
802 private:
803 unsigned width_r_;
804 unsigned width_a_;
805 unsigned width_b_;
807 bool signed_flag_;
811 * This class represents a theoretical (though not necessarily
812 * practical) integer modulo gate. This is not to represent any real
813 * hardware, but to support the % operator in Verilog, when it shows
814 * up in structural contexts.
816 * The operands of the operation are the DataA<i> and DataB<i> inputs,
817 * and the Result<i> output reflects the value DataA%DataB.
820 class NetModulo : public NetNode {
822 public:
823 NetModulo(NetScope*s, perm_string n,
824 unsigned width, unsigned wa, unsigned wb);
825 ~NetModulo();
827 unsigned width_r() const;
828 unsigned width_a() const;
829 unsigned width_b() const;
831 Link& pin_DataA();
832 Link& pin_DataB();
833 Link& pin_Result();
835 const Link& pin_DataA() const;
836 const Link& pin_DataB() const;
837 const Link& pin_Result() const;
839 virtual void dump_node(ostream&, unsigned ind) const;
840 virtual bool emit_node(struct target_t*) const;
841 virtual void functor_node(Design*des, functor_t*fun);
843 private:
844 unsigned width_r_;
845 unsigned width_a_;
846 unsigned width_b_;
850 * This class represents an LPM_FF device. There is no literal gate
851 * type in Verilog that maps, but gates of this type can be inferred.
853 class NetFF : public NetNode {
855 public:
856 NetFF(NetScope*s, perm_string n, unsigned vector_width);
857 ~NetFF();
859 unsigned width() const;
861 Link& pin_Clock();
862 Link& pin_Enable();
863 Link& pin_Aset();
864 Link& pin_Aclr();
865 Link& pin_Sset();
866 Link& pin_Sclr();
867 Link& pin_Data();
868 Link& pin_Q();
870 const Link& pin_Clock() const;
871 const Link& pin_Enable() const;
872 const Link& pin_Aset() const;
873 const Link& pin_Aclr() const;
874 const Link& pin_Sset() const;
875 const Link& pin_Sclr() const;
876 const Link& pin_Data() const;
877 const Link& pin_Q() const;
879 void aset_value(const verinum&val);
880 const verinum& aset_value() const;
882 void sset_value(const verinum&val);
883 const verinum& sset_value() const;
885 virtual void dump_node(ostream&, unsigned ind) const;
886 virtual bool emit_node(struct target_t*) const;
887 virtual void functor_node(Design*des, functor_t*fun);
889 private:
890 unsigned width_;
891 verinum aset_value_;
892 verinum sset_value_;
896 * This class implements a basic LPM_MULT combinational multiplier. It
897 * is used as a structural representation of the * operator. The
898 * device has inputs A and B and output Result all with independent
899 * widths.
901 * NOTE: Check this width thing. I think that the independence of the
902 * widths is not necessary or even useful.
904 class NetMult : public NetNode {
906 public:
907 NetMult(NetScope*sc, perm_string n, unsigned width,
908 unsigned wa, unsigned wb);
909 ~NetMult();
911 bool get_signed() const;
912 void set_signed(bool);
914 // Get the width of the device bussed inputs. There are these
915 // parameterized widths:
916 unsigned width_r() const; // Result
917 unsigned width_a() const; // DataA
918 unsigned width_b() const; // DataB
920 Link& pin_DataA();
921 Link& pin_DataB();
922 Link& pin_Result();
924 const Link& pin_DataA() const;
925 const Link& pin_DataB() const;
926 const Link& pin_Result() const;
928 virtual void dump_node(ostream&, unsigned ind) const;
929 virtual bool emit_node(struct target_t*) const;
930 virtual void functor_node(Design*des, functor_t*fun);
932 private:
933 bool signed_;
934 unsigned width_r_;
935 unsigned width_a_;
936 unsigned width_b_;
941 * This class represents an LPM_MUX device. This device has some
942 * number of Result points (the width of the device) and some number
943 * of input choices. There is also a selector of some width. The
944 * parameters are:
946 * width -- Width of the result and each possible Data input
947 * size -- Number of Data input (each of width)
948 * selw -- Width in bits of the select input
950 * All the data inputs must have the same type, and are the type of
951 * the result. The actual type does not matter, as the mux does not
952 * process data, just selects alternatives.
954 * The select input must be an integral type of some sort. Not real.
956 class NetMux : public NetNode {
958 public:
959 NetMux(NetScope*scope, perm_string n,
960 unsigned width, unsigned size, unsigned selw);
961 ~NetMux();
963 unsigned width() const;
964 unsigned size() const;
965 unsigned sel_width() const;
967 Link& pin_Result();
968 Link& pin_Data(unsigned si);
969 Link& pin_Sel();
971 const Link& pin_Result() const;
972 const Link& pin_Data(unsigned) const;
973 const Link& pin_Sel() const;
975 virtual void dump_node(ostream&, unsigned ind) const;
976 virtual bool emit_node(struct target_t*) const;
977 virtual void functor_node(Design*des, functor_t*fun);
979 private:
980 unsigned width_;
981 unsigned size_;
982 unsigned swidth_;
987 * The NetReplicate node takes a vector input and makes it into a larger
988 * vector by repeating the input vector some number of times. The
989 * repeat count is a fixed value. This is just like the repeat
990 * concatenation of Verilog: {<repeat>{<vector>}}.
992 * When construction this node, the wid is the vector width of the
993 * output, and the rpt is the repeat count. The wid must be an even
994 * multiple of the cnt, and wid/cnt is the expected input width.
996 * The device has exacly 2 pins: pin(0) is the output and pin(1) the
997 * input.
999 class NetReplicate : public NetNode {
1001 public:
1002 NetReplicate(NetScope*scope, perm_string n, unsigned wid, unsigned rpt);
1003 ~NetReplicate();
1005 unsigned width() const;
1006 unsigned repeat() const;
1008 void dump_node(ostream&, unsigned ind) const;
1009 bool emit_node(struct target_t*) const;
1011 private:
1012 unsigned width_;
1013 unsigned repeat_;
1017 * This node represents the call of a user defined function in a
1018 * structural context. The pin count is the same as the port count,
1019 * with pin0 the return value.
1021 class NetUserFunc : public NetNode {
1023 public:
1024 NetUserFunc(NetScope*s, perm_string n, NetScope*def);
1025 ~NetUserFunc();
1027 unsigned port_width(unsigned port) const;
1029 const NetScope* def() const;
1031 virtual void dump_node(ostream&, unsigned ind) const;
1032 virtual bool emit_node(struct target_t*) const;
1034 private:
1035 NetScope*def_;
1039 * The number of ports includes the return value, so will always be at
1040 * least 1.
1042 class NetSysFunc : public NetNode {
1044 public:
1045 NetSysFunc(NetScope*s, perm_string n,
1046 const struct sfunc_return_type*def,
1047 unsigned ports);
1048 ~NetSysFunc();
1050 unsigned vector_width() const;
1051 const char* func_name() const;
1053 virtual void dump_node(ostream&, unsigned ind) const;
1054 virtual bool emit_node(struct target_t*) const;
1056 private:
1057 const struct sfunc_return_type*def_;
1060 /* =========
1061 * There are cases where expressions need to be represented. The
1062 * NetExpr class is the root of a hierarchy that serves that purpose.
1064 * The expr_width() is the width of the expression, that accounts
1065 * for the widths of the sub-expressions I might have. It is up to the
1066 * derived classes to properly set the expr width, if need be. The
1067 * set_width() method is used to compel an expression to have a
1068 * certain width, and is used particularly when the expression is an
1069 * rvalue in an assignment statement.
1071 class NetExpr : public LineInfo {
1072 public:
1073 explicit NetExpr(unsigned w =0);
1074 virtual ~NetExpr() =0;
1076 virtual void expr_scan(struct expr_scan_t*) const =0;
1077 virtual void dump(ostream&) const;
1079 // Expressions have type.
1080 virtual ivl_variable_type_t expr_type() const;
1082 // How wide am I?
1083 unsigned expr_width() const { return width_; }
1085 // Coerce the expression to have a specific width. If the
1086 // coercion works, then return true. Otherwise, return false.
1087 // A coercion will work or not depending on the implementation
1088 // in the derived class. Normally, the width will be set if
1089 // the expression is:
1090 // - already the requested size, OR
1091 // - otherwise unsized.
1092 // Normally, the resize will not allow a width size that loses
1093 // data. For example, it will not reduce a constant expression
1094 // to the point where significant bits are lost. But if the
1095 // last_chance flag is true, then the method assumes that high
1096 // bits will be lost anyhow, so try harder. Loss will be
1097 // allowed, but it still won't resize fixed size expressions
1098 // such as vector signals. This flag is meant to be used by
1099 // elaboration of procedural assignment to set the expression
1100 // width to the l-value width, if possible.
1101 virtual bool set_width(unsigned wid, bool last_chance =false);
1103 // This method returns true if the expression is
1104 // signed. Unsigned expressions return false.
1105 bool has_sign() const;
1106 void cast_signed(bool flag);
1108 // This returns true if the expression has a definite
1109 // width. This is generally true, but in some cases the
1110 // expression is amorphous and desires a width from its
1111 // environment. For example, 'd5 has indefinite width, but
1112 // 5'd5 has a definite width.
1114 // This method is only really used within concatenation
1115 // expressions to check validity.
1116 virtual bool has_width() const;
1119 // This method evaluates the expression and returns an
1120 // equivalent expression that is reduced as far as compile
1121 // time knows how. Essentially, this is designed to fold
1122 // constants.
1124 // The prune_to_width is the maximum width that the result
1125 // should be. If it is 0 or -1, then do not prune the
1126 // result. If it is -1, go through special efforts to preserve
1127 // values that may expand. A width of 0 corresponds to a
1128 // self-determined context, and a width of -1 corresponds to
1129 // an infinitely wide context.
1130 virtual NetExpr*eval_tree(int prune_to_width = -1);
1132 // Make a duplicate of myself, and subexpressions if I have
1133 // any. This is a deep copy operation.
1134 virtual NetExpr*dup_expr() const =0;
1136 // Get the Nexus that are the input to this
1137 // expression. Normally this descends down to the reference to
1138 // a signal that reads from its input.
1139 virtual NexusSet* nex_input(bool rem_out = true) =0;
1141 // Return a version of myself that is structural. This is used
1142 // for converting expressions to gates.
1143 virtual NetNet*synthesize(Design*);
1146 protected:
1147 void expr_width(unsigned w) { width_ = w; }
1149 private:
1150 unsigned width_;
1151 bool signed_flag_;
1153 private: // not implemented
1154 NetExpr(const NetExpr&);
1155 NetExpr& operator=(const NetExpr&);
1159 * The expression constant is slightly special, and is sometimes
1160 * returned from other classes that can be evaluated at compile
1161 * time. This class represents constant values in expressions.
1163 class NetEConst : public NetExpr {
1165 public:
1166 explicit NetEConst(const verinum&val);
1167 ~NetEConst();
1169 const verinum&value() const;
1171 virtual bool set_width(unsigned w, bool last_chance =false);
1173 virtual bool has_width() const;
1174 virtual ivl_variable_type_t expr_type() const;
1176 virtual void expr_scan(struct expr_scan_t*) const;
1177 virtual void dump(ostream&) const;
1179 virtual NetEConst* dup_expr() const;
1180 virtual NetNet*synthesize(Design*);
1181 virtual NexusSet* nex_input(bool rem_out = true);
1183 private:
1184 verinum value_;
1187 class NetEConstParam : public NetEConst {
1189 public:
1190 explicit NetEConstParam(NetScope*scope, perm_string name,
1191 const verinum&val);
1192 ~NetEConstParam();
1194 perm_string name() const;
1195 const NetScope*scope() const;
1197 virtual bool set_width(unsigned w, bool last_chance);
1198 virtual void expr_scan(struct expr_scan_t*) const;
1199 virtual void dump(ostream&) const;
1201 virtual NetEConstParam* dup_expr() const;
1203 private:
1204 NetScope*scope_;
1205 perm_string name_;
1209 * This class represents a constant real value.
1211 class NetECReal : public NetExpr {
1213 public:
1214 explicit NetECReal(const verireal&val);
1215 ~NetECReal();
1217 const verireal&value() const;
1219 // Reals can be used in vector expressions. Conversions will
1220 // be done at the right time.
1221 virtual bool set_width(unsigned w, bool last_chance);
1223 // This type has no self-determined width. This is false.
1224 virtual bool has_width() const;
1226 // The type of this expression is ET_REAL
1227 ivl_variable_type_t expr_type() const;
1229 virtual void expr_scan(struct expr_scan_t*) const;
1230 virtual void dump(ostream&) const;
1232 virtual NetECReal* dup_expr() const;
1233 virtual NetNet*synthesize(Design*);
1234 virtual NexusSet* nex_input(bool rem_out = true);
1236 private:
1237 verireal value_;
1240 class NetECRealParam : public NetECReal {
1242 public:
1243 explicit NetECRealParam(NetScope*scope, perm_string name,
1244 const verireal&val);
1245 ~NetECRealParam();
1247 perm_string name() const;
1248 const NetScope*scope() const;
1250 virtual void expr_scan(struct expr_scan_t*) const;
1251 virtual void dump(ostream&) const;
1253 virtual NetECRealParam* dup_expr() const;
1255 private:
1256 NetScope*scope_;
1257 perm_string name_;
1261 * The NetPartSelect device represents a netlist part select of a
1262 * signal vector. Pin 0 is a vector that is a part select of pin 1,
1263 * which connected to the NetNet of the signal being selected from.
1265 * The part to be selected is the canonical (0-based) offset and the
1266 * specified number of bits (wid).
1268 * If the offset is non-constant, then pin(2) is the input vector for
1269 * the selector. If this pin is present, then use the non-constant
1270 * selector as the input.
1272 * The NetPartSelect can be output from the signal (i.e. reading a
1273 * part), input into the signal, or bi-directional. The DIR method
1274 * gives the type of the node.
1276 * VP (Vector-to-Part)
1277 * Output pin 0 is the part select, and input pin 1 is connected to
1278 * the NetNet object.
1280 * PV (Part-to-Vector)
1281 * Output pin 1 is connected to the NetNet, and input pin 0 is the
1282 * part select. In this case, the node is driving the NetNet.
1284 * BI (BI-directional)
1285 * Pin 0 is the part select and pin 1 is connected to the NetNet, but
1286 * the ports are intended to be bi-directional.
1288 * Note that whatever the direction that data is intended to flow,
1289 * pin-0 is the part select and pin-1 is connected to the NetNet.
1291 class NetPartSelect : public NetNode {
1293 public:
1294 // enum for the device direction
1295 enum dir_t { VP, PV, BI };
1297 explicit NetPartSelect(NetNet*sig,
1298 unsigned off, unsigned wid, dir_t dir);
1299 explicit NetPartSelect(NetNet*sig, NetNet*sel,
1300 unsigned wid);
1301 ~NetPartSelect();
1303 unsigned base() const;
1304 unsigned width() const;
1305 dir_t dir() const;
1307 virtual void dump_node(ostream&, unsigned ind) const;
1308 bool emit_node(struct target_t*tgt) const;
1310 private:
1311 unsigned off_;
1312 unsigned wid_;
1313 dir_t dir_;
1317 * The NetBUFZ is a magic device that represents the continuous
1318 * assign, with the output being the target register and the input
1319 * the logic that feeds it. The netlist preserves the directional
1320 * nature of that assignment with the BUFZ. The target may elide it if
1321 * that makes sense for the technology.
1323 class NetBUFZ : public NetNode {
1325 public:
1326 explicit NetBUFZ(NetScope*s, perm_string n, unsigned wid);
1327 ~NetBUFZ();
1329 unsigned width() const;
1331 virtual void dump_node(ostream&, unsigned ind) const;
1332 virtual bool emit_node(struct target_t*) const;
1334 private:
1335 unsigned width_;
1339 * This node is used to represent case equality in combinational
1340 * logic. Although this is not normally synthesizable, it makes sense
1341 * to support an abstract gate that can compare x and z. This node
1342 * always generates a single bit result, no matter the width of the
1343 * input. The elaboration, btw, needs to make sure the input widths
1344 * match.
1346 * This pins are assigned as:
1348 * 0 -- Output (always returns 0 or 1)
1349 * 1 -- Input
1350 * 2 -- Input
1352 class NetCaseCmp : public NetNode {
1354 public:
1355 explicit NetCaseCmp(NetScope*s, perm_string n, unsigned wid, bool eeq);
1356 ~NetCaseCmp();
1358 unsigned width() const;
1359 // true if this is ===, false if this is !==
1360 bool eeq() const;
1362 virtual void dump_node(ostream&, unsigned ind) const;
1363 virtual bool emit_node(struct target_t*) const;
1365 private:
1366 unsigned width_;
1367 bool eeq_;
1370 /* NOTE: This class should be replaced with the NetLiteral class
1371 * below, that is more general in that it supports different types of
1372 * values.
1374 * This class represents instances of the LPM_CONSTANT device. The
1375 * node has only outputs and a constant value. The width is available
1376 * by getting the pin_count(), and the value bits are available one at
1377 * a time. There is no meaning to the aggregation of bits to form a
1378 * wide NetConst object, although some targets may have an easier time
1379 * detecting interesting constructs if they are combined.
1381 class NetConst : public NetNode {
1383 public:
1384 explicit NetConst(NetScope*s, perm_string n, verinum::V v);
1385 explicit NetConst(NetScope*s, perm_string n, const verinum&val);
1386 ~NetConst();
1388 verinum::V value(unsigned idx) const;
1389 unsigned width() const;
1391 virtual bool emit_node(struct target_t*) const;
1392 virtual void functor_node(Design*, functor_t*);
1393 virtual void dump_node(ostream&, unsigned ind) const;
1395 private:
1396 unsigned width_;
1397 verinum::V*value_;
1401 * This class represents instances of the LPM_CONSTANT device. The
1402 * node has only outputs and a constant value. The width is available
1403 * by getting the pin_count(), and the value bits are available one at
1404 * a time. There is no meaning to the aggregation of bits to form a
1405 * wide NetConst object, although some targets may have an easier time
1406 * detecting interesting constructs if they are combined.
1408 class NetLiteral : public NetNode {
1410 public:
1411 // A read-valued literal.
1412 explicit NetLiteral(NetScope*s, perm_string n, const verireal&val);
1413 ~NetLiteral();
1415 ivl_variable_type_t data_type() const;
1417 const verireal& value_real() const;
1419 virtual bool emit_node(struct target_t*) const;
1420 virtual void functor_node(Design*, functor_t*);
1421 virtual void dump_node(ostream&, unsigned ind) const;
1423 private:
1424 verireal real_;
1428 * This class represents all manner of logic gates. Pin 0 is OUTPUT and
1429 * all the remaining pins are INPUT. The BUFIF[01] gates have the
1430 * more specific pinout as follows:
1432 * bufif<N>
1433 * 0 -- output
1434 * 1 -- input data
1435 * 2 -- enable
1437 * The pullup and pulldown gates have no inputs at all, and pin0 is
1438 * the output 1 or 0, depending on the gate type. It is the strength
1439 * of that value that is important.
1441 * All these devices process vectors bitwise, so each bit can be
1442 * logically seperated. The exception is the CONCAT gate, which is
1443 * really an abstract gate that takes the inputs and turns it into a
1444 * vector of bits.
1446 class NetLogic : public NetNode {
1448 public:
1449 enum TYPE { AND, BUF, BUFIF0, BUFIF1, CMOS, NAND, NMOS, NOR, NOT,
1450 NOTIF0, NOTIF1, OR, PULLDOWN, PULLUP, RCMOS, RNMOS, RPMOS,
1451 PMOS, XNOR, XOR };
1453 explicit NetLogic(NetScope*s, perm_string n, unsigned pins,
1454 TYPE t, unsigned wid);
1456 TYPE type() const;
1457 unsigned width() const;
1459 virtual void dump_node(ostream&, unsigned ind) const;
1460 virtual bool emit_node(struct target_t*) const;
1461 virtual void functor_node(Design*, functor_t*);
1463 private:
1464 TYPE type_;
1465 unsigned width_;
1469 * This class represents a structural sign extension. The pin-0 is a
1470 * vector of the input pin-1 sign-extended. The input is taken to be
1471 * signed. This generally matches a hardware implementation of
1472 * replicating the top bit enough times to create the desired output
1473 * width.
1475 class NetSignExtend : public NetNode {
1477 public:
1478 explicit NetSignExtend(NetScope*s, perm_string n, unsigned wid);
1479 ~NetSignExtend();
1481 unsigned width() const;
1483 virtual void dump_node(ostream&, unsigned ind) const;
1484 virtual bool emit_node(struct target_t*) const;
1485 virtual void functor_node(Design*, functor_t*);
1487 private:
1488 unsigned width_;
1492 * This class represents *reduction* logic operators. Certain boolean
1493 * logic operators have reduction forms which take in a vector and
1494 * return a single bit that is calculated by applying the logic
1495 * operation through the width of the input vector. These correspond
1496 * to reduction unary operators in Verilog.
1498 class NetUReduce : public NetNode {
1500 public:
1501 enum TYPE {NONE, AND, OR, XOR, NAND, NOR, XNOR};
1503 NetUReduce(NetScope*s, perm_string n, TYPE t, unsigned wid);
1505 TYPE type() const;
1506 unsigned width() const;
1508 virtual void dump_node(ostream&, unsigned ind) const;
1509 virtual bool emit_node(struct target_t*) const;
1510 virtual void functor_node(Design*, functor_t*);
1512 private:
1513 TYPE type_;
1514 unsigned width_;
1518 * The UDP is a User Defined Primitive from the Verilog source. Do not
1519 * expand it out any further then this in the netlist, as this can be
1520 * used to represent target device primitives.
1522 * The UDP can be combinational or sequential. The sequential UDP
1523 * includes the current output in the truth table, and supports edges,
1524 * whereas the combinational does not and is entirely level sensitive.
1525 * In any case, pin 0 is an output, and all the remaining pins are
1526 * inputs.
1528 * Set_table takes as input a string with one letter per pin. The
1529 * parser translates the written sequences to one of these. The
1530 * valid characters are:
1532 * 0, 1, x -- The levels
1533 * r -- (01)
1534 * R -- (x1)
1535 * f -- (10)
1536 * F -- (x0)
1537 * P -- (0x)
1538 * N -- (1x)
1540 * It also takes one of the following glob letters to represent more
1541 * than one item.
1543 * p -- 01, 0x or x1 // check this with the lexer
1544 * n -- 10, 1x or x0 // check this with the lexer
1545 * ? -- 0, 1, or x
1546 * * -- any edge
1547 * + -- 01 or x1
1548 * _ -- 10 or x0 (Note that this is not the output '-'.)
1549 * % -- 0x or 1x
1551 * SEQUENTIAL
1552 * These objects have a single bit of memory. The logic table includes
1553 * an entry for the current value, and allows edges on the inputs. In
1554 * canonical form, only the entries that generate 0, 1 or - (no change)
1555 * are listed.
1557 * COMBINATIONAL
1558 * The logic table is a map between the input levels and the
1559 * output. Each input pin can have the value 0, 1 or x and the output
1560 * can have the values 0 or 1. If the input matches nothing, the
1561 * output is x. In canonical form, only the entries that generate 0 or
1562 * 1 are listed.
1565 #include "PUdp.h"
1567 class NetUDP : public NetNode {
1569 public:
1570 explicit NetUDP(NetScope*s, perm_string n, unsigned pins, PUdp*u);
1572 virtual bool emit_node(struct target_t*) const;
1573 virtual void dump_node(ostream&, unsigned ind) const;
1575 /* Use these methods to scan the truth table of the
1576 device. "first" returns the first item in the table, and
1577 "next" returns the next item in the table. The method will
1578 return false when the scan is done. */
1579 bool first(string&inp, char&out) const;
1580 bool next(string&inp, char&out) const;
1581 unsigned rows() const { return udp->tinput.count(); }
1583 unsigned nin() const { return pin_count()-1; }
1584 bool is_sequential() const { return udp->sequential; }
1585 perm_string udp_name() const { return udp->name_; }
1586 char get_initial() const;
1588 private:
1589 mutable unsigned table_idx;
1590 PUdp *udp;
1594 /* =========
1595 * A process is a behavioral-model description. A process is a
1596 * statement that may be compound. the various statement types may
1597 * refer to places in a netlist (by pointing to nodes) but is not
1598 * linked into the netlist. However, elaborating a process may cause
1599 * special nodes to be created to handle things like events.
1601 class NetProc : public virtual LineInfo {
1603 public:
1604 explicit NetProc();
1605 virtual ~NetProc();
1607 // Find the Nexa that are input by the statement. This is used
1608 // for example by @* to find the inputs to the process for the
1609 // sensitivity list.
1610 virtual NexusSet* nex_input(bool rem_out = true);
1612 // Find the nexa that are set by the statement. Add the output
1613 // values to the set passed as a parameter.
1614 virtual void nex_output(NexusSet&);
1616 // This method is called to emit the statement to the
1617 // target. The target returns true if OK, false for errors.
1618 virtual bool emit_proc(struct target_t*) const;
1620 // This method is called by functors that want to scan a
1621 // process in search of matchable patterns.
1622 virtual int match_proc(struct proc_match_t*);
1624 // Return true if this represents the root of a combinational
1625 // process. Most process types are not.
1626 virtual bool is_asynchronous();
1628 // Return true if this represents the root of a synchronous
1629 // process. Most process types are not.
1630 virtual bool is_synchronous();
1632 // synthesize as asynchronous logic, and return true.
1633 virtual bool synth_async(Design*des, NetScope*scope,
1634 const NetBus&nex_map, NetBus&nex_out);
1636 virtual bool synth_sync(Design*des, NetScope*scope, NetFF*ff,
1637 const NetBus&nex_map, NetBus&nex_out,
1638 const svector<NetEvProbe*>&events);
1640 virtual void dump(ostream&, unsigned ind) const;
1642 private:
1643 friend class NetBlock;
1644 NetProc*next_;
1646 private: // not implemented
1647 NetProc(const NetProc&);
1648 NetProc& operator= (const NetProc&);
1652 * Procedural assignment is broken into a suite of classes. These
1653 * classes represent the various aspects of the assignment statement
1654 * in behavioral code. (The continuous assignment is *not*
1655 * represented here.)
1657 * The NetAssignBase carries the common aspects of an assignment,
1658 * including the r-value. This class has no cares of blocking vs
1659 * non-blocking, however it carries nearly all the other properties
1660 * of the assignment statement. It is abstract because it does not
1661 * differentiate the virtual behaviors.
1663 * The NetAssign and NetAssignNB classes are the concrete classes that
1664 * give the assignment its final, precise meaning. These classes fill
1665 * in the NetProc behaviors.
1667 * The l-value of the assignment is a collection of NetAssign_
1668 * objects that are connected to the structural netlist where the
1669 * assignment has its effect. The NetAssign_ class is not to be
1670 * derived from.
1672 * The collection is arranged from lsb up to msb, and represents the
1673 * concatenation of l-values. The elaborator may collapse some
1674 * concatenations into a single NetAssign_. The "more" member of the
1675 * NetAssign_ object points to the next most significant bits of l-value.
1677 * NOTE: The elaborator will make an effort to match the width of the
1678 * r-value to the width of the l-value, but targets and functions
1679 * should know that this is not a guarantee.
1682 class NetAssign_ {
1684 public:
1685 NetAssign_(NetNet*sig);
1686 ~NetAssign_();
1688 // If this expression exists, then it is used to select a word
1689 // from an array/memory.
1690 NetExpr*word();
1691 const NetExpr*word() const;
1693 // Get the base index of the part select, or 0 if there is no
1694 // part select.
1695 const NetExpr* get_base() const;
1697 void set_word(NetExpr*);
1698 void set_part(NetExpr* loff, unsigned wid);
1700 // Get the width of the r-value that this node expects. This
1701 // method accounts for the presence of the mux, so it not
1702 // necessarily the same as the pin_count().
1703 unsigned lwidth() const;
1705 // Get the name of the underlying object.
1706 perm_string name() const;
1708 NetNet* sig() const;
1710 // Mark that the synthesizer has worked with this l-value, so
1711 // when it is released, the l-value signal should be turned
1712 // into a wire.
1713 void turn_sig_to_wire_on_release();
1715 // It is possible that l-values can have *inputs*, as well as
1716 // being outputs. For example foo[idx] = ... is the l-value
1717 // (NetAssign_ object) with a foo l-value and the input
1718 // expression idx.
1719 NexusSet* nex_input(bool rem_out = true);
1721 // This pointer is for keeping simple lists.
1722 NetAssign_* more;
1724 void dump_lval(ostream&o) const;
1726 private:
1727 NetNet *sig_;
1728 // Memory word index
1729 NetExpr*word_;
1731 bool turn_sig_to_wire_on_release_;
1732 // indexed part select base
1733 NetExpr*base_;
1734 unsigned lwid_;
1737 class NetAssignBase : public NetProc {
1739 public:
1740 NetAssignBase(NetAssign_*lv, NetExpr*rv);
1741 virtual ~NetAssignBase() =0;
1743 // This is the (procedural) value that is to be assigned when
1744 // the assignment is executed.
1745 NetExpr*rval();
1746 const NetExpr*rval() const;
1748 void set_rval(NetExpr*);
1750 NetAssign_* l_val(unsigned);
1751 const NetAssign_* l_val(unsigned) const;
1752 unsigned l_val_count() const;
1754 void set_delay(NetExpr*);
1755 const NetExpr* get_delay() const;
1757 virtual NexusSet* nex_input(bool rem_out = true);
1758 virtual void nex_output(NexusSet&o);
1761 // This returns the total width of the accumulated l-value. It
1762 // accounts for any grouping of NetAssign_ objects that might happen.
1763 unsigned lwidth() const;
1765 bool synth_async(Design*des, NetScope*scope,
1766 const NetBus&nex_map, NetBus&nex_out);
1768 // This dumps all the lval structures.
1769 void dump_lval(ostream&) const;
1770 virtual void dump(ostream&, unsigned ind) const;
1772 private:
1773 NetAssign_*lval_;
1774 NetExpr *rval_;
1775 NetExpr *delay_;
1778 class NetAssign : public NetAssignBase {
1780 public:
1781 explicit NetAssign(NetAssign_*lv, NetExpr*rv);
1782 ~NetAssign();
1784 bool is_asynchronous();
1786 virtual bool emit_proc(struct target_t*) const;
1787 virtual int match_proc(struct proc_match_t*);
1788 virtual void dump(ostream&, unsigned ind) const;
1790 private:
1793 class NetAssignNB : public NetAssignBase {
1794 public:
1795 explicit NetAssignNB(NetAssign_*lv, NetExpr*rv);
1796 ~NetAssignNB();
1799 virtual bool emit_proc(struct target_t*) const;
1800 virtual int match_proc(struct proc_match_t*);
1801 virtual void dump(ostream&, unsigned ind) const;
1803 private:
1807 * A block is stuff like begin-end blocks, that contain an ordered
1808 * list of NetProc statements.
1810 * NOTE: The emit method calls the target->proc_block function but
1811 * does not recurse. It is up to the target-supplied proc_block
1812 * function to call emit_recurse.
1814 class NetBlock : public NetProc {
1816 public:
1817 enum Type { SEQU, PARA };
1819 NetBlock(Type t, NetScope*subscope);
1820 ~NetBlock();
1822 Type type() const { return type_; }
1823 NetScope* subscope() const { return subscope_; }
1825 void append(NetProc*);
1827 const NetProc*proc_first() const;
1828 const NetProc*proc_next(const NetProc*cur) const;
1831 // synthesize as asynchronous logic, and return true.
1832 bool synth_async(Design*des, NetScope*scope,
1833 const NetBus&nex_map, NetBus&nex_out);
1835 bool synth_sync(Design*des, NetScope*scope, NetFF*ff,
1836 const NetBus&nex_map, NetBus&nex_out,
1837 const svector<NetEvProbe*>&events);
1839 // This version of emit_recurse scans all the statements of
1840 // the begin-end block sequentially. It is typically of use
1841 // for sequential blocks.
1842 void emit_recurse(struct target_t*) const;
1844 virtual NexusSet* nex_input(bool rem_out = true);
1845 virtual void nex_output(NexusSet&);
1846 virtual bool emit_proc(struct target_t*) const;
1847 virtual int match_proc(struct proc_match_t*);
1848 virtual void dump(ostream&, unsigned ind) const;
1850 private:
1851 const Type type_;
1852 NetScope*subscope_;
1854 NetProc*last_;
1858 * A CASE statement in the verilog source leads, eventually, to one of
1859 * these. This is different from a simple conditional because of the
1860 * way the comparisons are performed. Also, it is likely that the
1861 * target may be able to optimize differently.
1863 * Case can be one of three types:
1864 * EQ -- All bits must exactly match
1865 * EQZ -- z bits are don't care
1866 * EQX -- x and z bits are don't care.
1868 class NetCase : public NetProc {
1870 public:
1871 enum TYPE { EQ, EQX, EQZ };
1872 NetCase(TYPE c, NetExpr*ex, unsigned cnt);
1873 ~NetCase();
1875 void set_case(unsigned idx, NetExpr*ex, NetProc*st);
1877 TYPE type() const;
1878 const NetExpr*expr() const { return expr_; }
1879 unsigned nitems() const { return nitems_; }
1881 const NetExpr*expr(unsigned idx) const { return items_[idx].guard;}
1882 const NetProc*stat(unsigned idx) const { return items_[idx].statement; }
1884 virtual NexusSet* nex_input(bool rem_out = true);
1885 virtual void nex_output(NexusSet&out);
1887 bool synth_async(Design*des, NetScope*scope,
1888 const NetBus&nex_map, NetBus&nex_out);
1890 virtual bool emit_proc(struct target_t*) const;
1891 virtual void dump(ostream&, unsigned ind) const;
1893 private:
1895 TYPE type_;
1897 struct Item {
1898 NetExpr*guard;
1899 NetProc*statement;
1902 NetExpr* expr_;
1903 unsigned nitems_;
1904 Item*items_;
1908 * The cassign statement causes the r-val net to be forced onto the
1909 * l-val reg when it is executed. The code generator is expected to
1910 * know what that means.
1912 class NetCAssign : public NetAssignBase {
1914 public:
1915 explicit NetCAssign(NetAssign_*lv, NetExpr*rv);
1916 ~NetCAssign();
1918 virtual NexusSet* nex_input(bool rem_out = true);
1919 virtual void dump(ostream&, unsigned ind) const;
1920 virtual bool emit_proc(struct target_t*) const;
1922 private: // not implemented
1923 NetCAssign(const NetCAssign&);
1924 NetCAssign& operator= (const NetCAssign&);
1929 * A condit represents a conditional. It has an expression to test,
1930 * and a pair of statements to select from. If the original statement
1931 * has empty clauses, then the NetProc for it will be a null pointer.
1933 class NetCondit : public NetProc {
1935 public:
1936 explicit NetCondit(NetExpr*ex, NetProc*i, NetProc*e);
1937 ~NetCondit();
1939 const NetExpr*expr() const;
1940 NetExpr*expr();
1942 NetProc* if_clause();
1943 NetProc* else_clause();
1945 // Replace the condition expression.
1946 void set_expr(NetExpr*ex);
1948 bool emit_recurse_if(struct target_t*) const;
1949 bool emit_recurse_else(struct target_t*) const;
1951 virtual NexusSet* nex_input(bool rem_out = true);
1952 virtual void nex_output(NexusSet&o);
1954 bool is_asynchronous();
1955 bool synth_async(Design*des, NetScope*scope,
1956 const NetBus&nex_map, NetBus&nex_out);
1958 bool synth_sync(Design*des, NetScope*scope, NetFF*ff,
1959 const NetBus&nex_map, NetBus&nex_out,
1960 const svector<NetEvProbe*>&events);
1962 virtual bool emit_proc(struct target_t*) const;
1963 virtual int match_proc(struct proc_match_t*);
1964 virtual void dump(ostream&, unsigned ind) const;
1966 private:
1967 NetExpr* expr_;
1968 NetProc*if_;
1969 NetProc*else_;
1973 * The procedural deassign statement (the opposite of assign) releases
1974 * any assign expressions attached to the bits of the reg. The
1975 * lval is the expression of the "deassign <expr>;" statement with the
1976 * expr elaborated to a net.
1978 class NetDeassign : public NetAssignBase {
1980 public:
1981 explicit NetDeassign(NetAssign_*l);
1982 ~NetDeassign();
1984 virtual bool emit_proc(struct target_t*) const;
1985 virtual void dump(ostream&, unsigned ind) const;
1987 private: // not implemented
1988 NetDeassign(const NetDeassign&);
1989 NetDeassign& operator= (const NetDeassign&);
1993 * This node represents the behavioral disable statement. The Verilog
1994 * source that produces it looks like:
1996 * disable <scope>;
1998 * Where the scope is a named block or a task. It cannot be a module
1999 * instance scope because module instances cannot be disabled.
2001 class NetDisable : public NetProc {
2003 public:
2004 explicit NetDisable(NetScope*tgt);
2005 ~NetDisable();
2007 const NetScope*target() const;
2009 virtual bool emit_proc(struct target_t*) const;
2010 virtual void dump(ostream&, unsigned ind) const;
2012 private:
2013 NetScope*target_;
2015 private: // not implemented
2016 NetDisable(const NetDisable&);
2017 NetDisable& operator= (const NetDisable&);
2021 * A NetEvent is an object that represents an event object, that is
2022 * objects declared like so in Verilog:
2024 * event foo;
2026 * Once an object of this type exists, behavioral code can wait on the
2027 * event or trigger the event. Event waits refer to this object, as do
2028 * the event trigger statements. The NetEvent class may have a name and
2029 * a scope. The name is a simple name (no hierarchy) and the scope is
2030 * the NetScope that contains the object. The scope member is written
2031 * by the NetScope object when the NetEvent is stored.
2033 * The NetEvWait class represents a thread wait for an event. When
2034 * this statement is executed, it starts waiting on the
2035 * event. Conceptually, it puts itself on the event list for the
2036 * referenced event. When the event is triggered, the wait ends its
2037 * block and starts the associated statement.
2039 * The NetEvTrig class represents trigger statements. Executing this
2040 * statement causes the referenced event to be triggered, which it
2041 * turn awakens the waiting threads. Each NetEvTrig object references
2042 * exactly one event object.
2044 * The NetEvProbe class is the structural equivalent of the NetEvTrig,
2045 * in that it is a node and watches bit values that it receives. It
2046 * checks for edges then if appropriate triggers the associated
2047 * NetEvent. Each NetEvProbe references exactly one event object, and
2048 * the NetEvent objects have a list of NetEvProbe objects that
2049 * reference it.
2051 class NetEvent : public LineInfo {
2053 friend class NetScope;
2054 friend class NetEvProbe;
2055 friend class NetEvTrig;
2056 friend class NetEvWait;
2057 friend class NetEEvent;
2059 public:
2060 // The name of the event is the basename, and should not
2061 // include the scope. Also, the name passed here should be
2062 // perm-allocated.
2063 explicit NetEvent (perm_string n);
2064 ~NetEvent();
2066 perm_string name() const;
2068 // Get information about probes connected to me.
2069 unsigned nprobe() const;
2070 NetEvProbe* probe(unsigned);
2071 const NetEvProbe* probe(unsigned) const;
2073 // Return the number of NetEvWait nodes that reference me.
2074 unsigned nwait() const;
2075 unsigned ntrig() const;
2076 unsigned nexpr() const;
2078 NetScope* scope();
2079 const NetScope* scope() const;
2081 void nex_output(NexusSet&);
2083 // Locate the first event that matches my behavior and
2084 // monitors the same signals.
2085 void find_similar_event(list<NetEvent*>&);
2087 // This method replaces pointers to me with pointers to
2088 // that. It is typically used to replace similar events
2089 // located by the find_similar_event method.
2090 void replace_event(NetEvent*that);
2092 private:
2093 // This returns a nexus set if it represents possibly
2094 // asynchronous inputs, otherwise 0.
2095 NexusSet*nex_async_();
2097 private:
2098 perm_string name_;
2100 // The NetScope class uses these to list the events.
2101 NetScope*scope_;
2102 NetEvent*snext_;
2104 // Use these methods to list the probes attached to me.
2105 NetEvProbe*probes_;
2107 // Use these methods to list the triggers attached to me.
2108 NetEvTrig* trig_;
2110 // Use This member to count references by NetEvWait objects.
2111 unsigned waitref_;
2112 struct wcell_ {
2113 NetEvWait*obj;
2114 struct wcell_*next;
2116 struct wcell_ *wlist_;
2118 // expression references, ala. task/funcs
2119 unsigned exprref_;
2121 private: // not implemented
2122 NetEvent(const NetEvent&);
2123 NetEvent& operator= (const NetEvent&);
2126 class NetEvTrig : public NetProc {
2128 friend class NetEvent;
2130 public:
2131 explicit NetEvTrig(NetEvent*tgt);
2132 ~NetEvTrig();
2134 const NetEvent*event() const;
2136 virtual bool emit_proc(struct target_t*) const;
2137 virtual void dump(ostream&, unsigned ind) const;
2139 private:
2140 NetEvent*event_;
2141 // This is used to place me in the NetEvents lists of triggers.
2142 NetEvTrig*enext_;
2145 class NetEvWait : public NetProc {
2147 public:
2148 explicit NetEvWait(NetProc*st);
2149 ~NetEvWait();
2151 void add_event(NetEvent*tgt);
2152 void replace_event(NetEvent*orig, NetEvent*repl);
2154 unsigned nevents() const;
2155 const NetEvent*event(unsigned) const;
2156 NetEvent*event(unsigned);
2158 NetProc*statement();
2160 virtual bool emit_proc(struct target_t*) const;
2161 bool emit_recurse(struct target_t*) const;
2162 virtual int match_proc(struct proc_match_t*);
2164 // It is possible that this is the root of a combinational
2165 // process. This method checks.
2166 virtual bool is_asynchronous();
2168 // It is possible that this is the root of a synchronous
2169 // process? This method checks.
2170 virtual bool is_synchronous();
2172 virtual void nex_output(NexusSet&out);
2174 virtual bool synth_async(Design*des, NetScope*scope,
2175 const NetBus&nex_map, NetBus&nex_out);
2177 virtual bool synth_sync(Design*des, NetScope*scope, NetFF*ff,
2178 const NetBus&nex_map, NetBus&nex_out,
2179 const svector<NetEvProbe*>&events);
2181 virtual void dump(ostream&, unsigned ind) const;
2183 private:
2184 NetProc*statement_;
2186 unsigned nevents_;
2187 NetEvent**events_;
2190 class NetEvProbe : public NetNode {
2192 friend class NetEvent;
2194 public:
2195 enum edge_t { ANYEDGE, POSEDGE, NEGEDGE };
2197 explicit NetEvProbe(NetScope*s, perm_string n,
2198 NetEvent*tgt, edge_t t, unsigned p);
2199 ~NetEvProbe();
2201 edge_t edge() const;
2202 NetEvent* event();
2203 const NetEvent* event() const;
2205 void find_similar_probes(list<NetEvProbe*>&);
2207 virtual bool emit_node(struct target_t*) const;
2208 virtual void dump_node(ostream&, unsigned ind) const;
2210 private:
2211 NetEvent*event_;
2212 edge_t edge_;
2213 // The NetEvent class uses this to list me.
2214 NetEvProbe*enext_;
2218 * The force statement causes the r-val net to be forced onto the
2219 * l-val net when it is executed. The code generator is expected to
2220 * know what that means.
2222 class NetForce : public NetAssignBase {
2224 public:
2225 explicit NetForce(NetAssign_*l, NetExpr*r);
2226 ~NetForce();
2228 virtual NexusSet* nex_input(bool rem_out = true);
2230 virtual void dump(ostream&, unsigned ind) const;
2231 virtual bool emit_proc(struct target_t*) const;
2235 * A forever statement is executed over and over again forever. Or
2236 * until its block is disabled.
2238 class NetForever : public NetProc {
2240 public:
2241 explicit NetForever(NetProc*s);
2242 ~NetForever();
2244 void emit_recurse(struct target_t*) const;
2246 virtual NexusSet* nex_input(bool rem_out = true);
2247 virtual bool emit_proc(struct target_t*) const;
2248 virtual void dump(ostream&, unsigned ind) const;
2250 private:
2251 NetProc*statement_;
2255 * A function definition is elaborated just like a task, though by now
2256 * it is certain that the first parameter (a phantom parameter) is the
2257 * output and all the remaining parameters are the inputs. This makes
2258 * for easy code generation in targets that support behavioral
2259 * descriptions.
2261 * The NetNet array that is passed in as a parameter is the set of
2262 * signals that make up its parameter list. These are all internal to
2263 * the scope of the function.
2265 class NetFuncDef {
2267 public:
2268 NetFuncDef(NetScope*, NetNet*result, const svector<NetNet*>&po);
2269 ~NetFuncDef();
2271 void set_proc(NetProc*st);
2273 //const string name() const;
2274 const NetProc*proc() const;
2275 const NetScope*scope() const;
2276 NetScope*scope();
2278 unsigned port_count() const;
2279 const NetNet*port(unsigned idx) const;
2281 const NetNet*return_sig() const;
2283 void dump(ostream&, unsigned ind) const;
2285 private:
2286 NetScope*scope_;
2287 NetProc*statement_;
2288 NetNet*result_sig_;
2289 svector<NetNet*>ports_;
2293 * This class represents delay statements of the form:
2295 * #<expr> <statement>
2297 * Where the statement may be null. The delay is evaluated at
2298 * elaboration time to make a constant unsigned long that is the delay
2299 * in simulation ticks.
2301 * If the delay expression is non-constant, construct the NetPDelay
2302 * object with a NetExpr* instead of the d value, and use the expr()
2303 * method to get the expression. If expr() returns 0, use the delay()
2304 * method to get the constant delay.
2306 class NetPDelay : public NetProc {
2308 public:
2309 NetPDelay(uint64_t d, NetProc*st);
2310 NetPDelay(NetExpr* d, NetProc*st);
2311 ~NetPDelay();
2313 uint64_t delay() const;
2314 const NetExpr*expr() const;
2316 virtual NexusSet* nex_input(bool rem_out = true);
2317 virtual void nex_output(NexusSet&);
2319 virtual bool emit_proc(struct target_t*) const;
2320 virtual void dump(ostream&, unsigned ind) const;
2322 bool emit_proc_recurse(struct target_t*) const;
2324 private:
2325 uint64_t delay_;
2326 NetExpr*expr_;
2327 NetProc*statement_;
2331 * A repeat statement is executed some fixed number of times.
2333 class NetRepeat : public NetProc {
2335 public:
2336 explicit NetRepeat(NetExpr*e, NetProc*s);
2337 ~NetRepeat();
2339 const NetExpr*expr() const;
2340 void emit_recurse(struct target_t*) const;
2342 virtual NexusSet* nex_input(bool rem_out = true);
2343 virtual bool emit_proc(struct target_t*) const;
2344 virtual void dump(ostream&, unsigned ind) const;
2346 private:
2347 NetExpr*expr_;
2348 NetProc*statement_;
2352 * The procedural release statement (the opposite of force) releases
2353 * any force expressions attached to the bits of the wire or reg. The
2354 * lval is the expression of the "release <expr>;" statement with the
2355 * expr elaborated to a net.
2357 class NetRelease : public NetAssignBase {
2359 public:
2360 explicit NetRelease(NetAssign_*l);
2361 ~NetRelease();
2363 virtual bool emit_proc(struct target_t*) const;
2364 virtual void dump(ostream&, unsigned ind) const;
2366 private:
2371 * The NetSTask class is a call to a system task. These kinds of tasks
2372 * are generally handled very simply in the target. They certainly are
2373 * handled differently from user defined tasks because ivl knows all
2374 * about the user defined tasks.
2376 class NetSTask : public NetProc {
2378 public:
2379 NetSTask(const char*na, const svector<NetExpr*>&);
2380 ~NetSTask();
2382 const char* name() const;
2384 unsigned nparms() const;
2386 const NetExpr* parm(unsigned idx) const;
2388 virtual NexusSet* nex_input(bool rem_out = true);
2389 virtual void nex_output(NexusSet&);
2390 virtual bool emit_proc(struct target_t*) const;
2391 virtual void dump(ostream&, unsigned ind) const;
2393 private:
2394 const char* name_;
2395 svector<NetExpr*>parms_;
2399 * This class represents an elaborated class definition. NetUTask
2400 * classes may refer to objects of this type to get the meaning of the
2401 * defined task.
2403 * The task also introduces a scope, and the parameters are actually
2404 * reg objects in the new scope. The task is called by the calling
2405 * thread assigning (blocking assignment) to the in and inout
2406 * parameters, then invoking the thread, and finally assigning out the
2407 * output and inout variables. The variables accessible as ports are
2408 * also elaborated and accessible as ordinary reg objects.
2410 class NetTaskDef {
2412 public:
2413 NetTaskDef(NetScope*n, const svector<NetNet*>&po);
2414 ~NetTaskDef();
2416 void set_proc(NetProc*p);
2418 //const string& name() const;
2419 const NetScope* scope() const;
2420 const NetProc*proc() const;
2422 unsigned port_count() const;
2423 NetNet*port(unsigned idx);
2425 void dump(ostream&, unsigned) const;
2427 private:
2428 NetScope*scope_;
2429 NetProc*proc_;
2430 svector<NetNet*>ports_;
2432 private: // not implemented
2433 NetTaskDef(const NetTaskDef&);
2434 NetTaskDef& operator= (const NetTaskDef&);
2438 * This node represents a function call in an expression. The object
2439 * contains a pointer to the function definition, which is used to
2440 * locate the value register and input expressions.
2442 class NetEUFunc : public NetExpr {
2444 public:
2445 NetEUFunc(NetScope*, NetESignal*, svector<NetExpr*>&);
2446 ~NetEUFunc();
2448 const NetESignal*result_sig() const;
2450 unsigned parm_count() const;
2451 const NetExpr* parm(unsigned idx) const;
2453 const NetScope* func() const;
2455 virtual bool set_width(unsigned, bool last_chance);
2456 virtual ivl_variable_type_t expr_type() const;
2457 virtual void dump(ostream&) const;
2459 virtual void expr_scan(struct expr_scan_t*) const;
2460 virtual NetEUFunc*dup_expr() const;
2461 virtual NexusSet* nex_input(bool rem_out = true);
2463 private:
2464 NetScope*func_;
2465 NetESignal*result_sig_;
2466 svector<NetExpr*> parms_;
2468 private: // not implemented
2469 NetEUFunc(const NetEUFunc&);
2470 NetEUFunc& operator= (const NetEUFunc&);
2474 * A call to a user defined task is elaborated into this object. This
2475 * contains a pointer to the elaborated task definition, but is a
2476 * NetProc object so that it can be linked into statements.
2478 class NetUTask : public NetProc {
2480 public:
2481 NetUTask(NetScope*);
2482 ~NetUTask();
2484 const string name() const;
2486 const NetScope* task() const;
2488 virtual NexusSet* nex_input(bool rem_out = true);
2489 virtual void nex_output(NexusSet&);
2490 virtual bool emit_proc(struct target_t*) const;
2491 virtual void dump(ostream&, unsigned ind) const;
2493 private:
2494 NetScope*task_;
2498 * The while statement is a condition that is tested in the front of
2499 * each iteration, and a statement (a NetProc) that is executed as
2500 * long as the condition is true.
2502 class NetWhile : public NetProc {
2504 public:
2505 NetWhile(NetExpr*c, NetProc*p)
2506 : cond_(c), proc_(p) { }
2508 const NetExpr*expr() const { return cond_; }
2510 void emit_proc_recurse(struct target_t*) const;
2512 virtual NexusSet* nex_input(bool rem_out = true);
2513 virtual void nex_output(NexusSet&);
2514 virtual bool emit_proc(struct target_t*) const;
2515 virtual void dump(ostream&, unsigned ind) const;
2517 private:
2518 NetExpr* cond_;
2519 NetProc*proc_;
2524 * The is the top of any process. It carries the type (initial or
2525 * always) and a pointer to the statement, probably a block, that
2526 * makes up the process.
2528 class NetProcTop : public LineInfo, public Attrib {
2530 public:
2531 enum Type { KINITIAL, KALWAYS };
2533 NetProcTop(NetScope*s, Type t, class NetProc*st);
2534 ~NetProcTop();
2536 Type type() const { return type_; }
2537 NetProc*statement();
2538 const NetProc*statement() const;
2540 NetScope*scope();
2541 const NetScope*scope() const;
2543 /* Return true if this process represents combinational logic. */
2544 bool is_asynchronous();
2546 /* Create asynchronous logic from this thread and return true,
2547 or return false if that cannot be done. */
2548 bool synth_async(Design*des);
2550 /* Return true if this process represents synchronous logic. */
2551 bool is_synchronous();
2553 /* Create synchronous logic from this thread and return true,
2554 or return false if that cannot be done. */
2555 bool synth_sync(Design*des);
2557 void dump(ostream&, unsigned ind) const;
2558 bool emit(struct target_t*tgt) const;
2560 private:
2561 const Type type_;
2562 NetProc*const statement_;
2564 NetScope*scope_;
2565 friend class Design;
2566 NetProcTop*next_;
2570 * This class represents a binary operator, with the left and right
2571 * operands and a single character for the operator. The operator
2572 * values are:
2574 * ^ -- Bit-wise exclusive OR
2575 * + -- Arithmetic add
2576 * - -- Arithmetic minus
2577 * * -- Arithmetic multiply
2578 * / -- Arithmetic divide
2579 * % -- Arithmetic modulus
2580 * p -- Arithmetic power (**)
2581 * & -- Bit-wise AND
2582 * | -- Bit-wise OR
2583 * < -- Less then
2584 * > -- Greater then
2585 * e -- Logical equality (==)
2586 * E -- Case equality (===)
2587 * L -- Less or equal
2588 * G -- Greater or equal
2589 * n -- Logical inequality (!=)
2590 * N -- Case inequality (!==)
2591 * a -- Logical AND (&&)
2592 * A -- Bitwise NAND (~&)
2593 * o -- Logical OR (||)
2594 * O -- Bit-wise NOR (~|)
2595 * l -- Left shift (<<)
2596 * r -- Right shift (>>)
2597 * R -- signed right shift (>>>)
2598 * X -- Bitwise exclusive NOR (~^)
2600 class NetEBinary : public NetExpr {
2602 public:
2603 NetEBinary(char op, NetExpr*l, NetExpr*r);
2604 ~NetEBinary();
2606 const NetExpr*left() const { return left_; }
2607 const NetExpr*right() const { return right_; }
2609 char op() const { return op_; }
2611 virtual bool set_width(unsigned w, bool last_chance =false);
2613 // A binary expression node only has a definite
2614 // self-determinable width if the operands both have definite
2615 // widths.
2616 virtual bool has_width() const;
2618 virtual NetEBinary* dup_expr() const;
2619 virtual NexusSet* nex_input(bool rem_out = true);
2621 virtual void expr_scan(struct expr_scan_t*) const;
2622 virtual void dump(ostream&) const;
2624 protected:
2625 char op_;
2626 NetExpr* left_;
2627 NetExpr* right_;
2629 void eval_sub_tree_();
2630 bool get_real_arguments_(verireal&lv, verireal&rv);
2634 * The addition operators have slightly more complex width
2635 * calculations because there is the optional carry bit that can be
2636 * used. The operators covered by this class are:
2637 * + -- Arithmetic add
2638 * - -- Arithmetic minus
2640 class NetEBAdd : public NetEBinary {
2642 public:
2643 NetEBAdd(char op, NetExpr*l, NetExpr*r, bool lossless_flag =false);
2644 ~NetEBAdd();
2646 virtual ivl_variable_type_t expr_type() const;
2648 virtual bool set_width(unsigned w, bool last_chance);
2649 virtual NetEBAdd* dup_expr() const;
2650 virtual NetExpr* eval_tree(int prune_to_width = -1);
2651 virtual NetNet* synthesize(Design*);
2653 private:
2654 NetECReal* eval_tree_real_();
2658 * This class represents the integer division operators.
2659 * / -- Divide
2660 * % -- Modulus
2662 class NetEBDiv : public NetEBinary {
2664 public:
2665 NetEBDiv(char op, NetExpr*l, NetExpr*r);
2666 ~NetEBDiv();
2668 virtual ivl_variable_type_t expr_type() const;
2670 virtual bool set_width(unsigned w, bool last_chance);
2671 virtual NetEBDiv* dup_expr() const;
2672 virtual NetExpr* eval_tree(int prune_to_width = -1);
2673 virtual NetNet* synthesize(Design*);
2677 * The bitwise binary operators are represented by this class. This is
2678 * a specialization of the binary operator, so is derived from
2679 * NetEBinary. The particular constraints on these operators are that
2680 * operand and result widths match exactly, and each bit slice of the
2681 * operation can be represented by a simple gate. The operators
2682 * covered by this class are:
2684 * ^ -- Bit-wise exclusive OR
2685 * & -- Bit-wise AND
2686 * | -- Bit-wise OR
2687 * O -- Bit-wise NOR
2688 * X -- Bit-wise XNOR (~^)
2690 class NetEBBits : public NetEBinary {
2692 public:
2693 NetEBBits(char op, NetExpr*l, NetExpr*r);
2694 ~NetEBBits();
2696 virtual bool set_width(unsigned w, bool last_chance);
2697 virtual NetEBBits* dup_expr() const;
2698 virtual NetEConst* eval_tree(int prune_to_width = -1);
2700 virtual NetNet* synthesize(Design*);
2704 * The binary comparison operators are handled by this class. This
2705 * this case the bit width of the expression is 1 bit, and the
2706 * operands take their natural widths. The supported operators are:
2708 * < -- Less then
2709 * > -- Greater then
2710 * e -- Logical equality (==)
2711 * E -- Case equality (===)
2712 * L -- Less or equal (<=)
2713 * G -- Greater or equal (>=)
2714 * n -- Logical inequality (!=)
2715 * N -- Case inequality (!==)
2717 class NetEBComp : public NetEBinary {
2719 public:
2720 NetEBComp(char op, NetExpr*l, NetExpr*r);
2721 ~NetEBComp();
2723 virtual bool set_width(unsigned w, bool last_chance);
2725 /* A compare expression has a definite width. */
2726 virtual bool has_width() const;
2727 virtual ivl_variable_type_t expr_type() const;
2728 virtual NetEBComp* dup_expr() const;
2729 virtual NetEConst* eval_tree(int prune_to_width = -1);
2731 virtual NetNet* synthesize(Design*);
2733 private:
2734 NetEConst*eval_eqeq_(bool ne_flag);
2735 NetEConst*eval_less_();
2736 NetEConst*eval_leeq_();
2737 NetEConst*eval_leeq_real_();
2738 NetEConst*eval_gt_();
2739 NetEConst*eval_gteq_();
2740 NetEConst*eval_eqeqeq_();
2741 NetEConst*eval_neeqeq_();
2745 * The binary logical operators are those that return boolean
2746 * results. The supported operators are:
2748 * a -- Logical AND (&&)
2749 * o -- Logical OR (||)
2751 class NetEBLogic : public NetEBinary {
2753 public:
2754 NetEBLogic(char op, NetExpr*l, NetExpr*r);
2755 ~NetEBLogic();
2757 virtual bool set_width(unsigned w, bool last_chance);
2758 virtual NetEBLogic* dup_expr() const;
2759 virtual NetEConst* eval_tree(int prune_to_width = -1);
2760 virtual NetNet* synthesize(Design*);
2762 private:
2767 * Support the binary multiplication (*) operator.
2769 class NetEBMult : public NetEBinary {
2771 public:
2772 NetEBMult(char op, NetExpr*l, NetExpr*r);
2773 ~NetEBMult();
2775 virtual ivl_variable_type_t expr_type() const;
2777 virtual bool set_width(unsigned w, bool last_chance);
2778 virtual NetEBMult* dup_expr() const;
2779 virtual NetExpr* eval_tree(int prune_to_width = -1);
2780 virtual NetNet* synthesize(Design*);
2782 private:
2784 NetExpr* eval_tree_real_();
2789 * Support the binary multiplication (*) operator.
2791 class NetEBPow : public NetEBinary {
2793 public:
2794 NetEBPow(char op, NetExpr*l, NetExpr*r);
2795 ~NetEBPow();
2797 virtual ivl_variable_type_t expr_type() const;
2799 virtual bool set_width(unsigned w, bool last_chance);
2800 virtual NetEBPow* dup_expr() const;
2801 virtual NetExpr* eval_tree(int prune_to_width = -1);
2802 virtual NetNet* synthesize(Design*);
2804 private:
2806 NetExpr* eval_tree_real_();
2812 * The binary logical operators are those that return boolean
2813 * results. The supported operators are:
2815 * l -- left shift (<<)
2816 * r -- right shift (>>)
2817 * R -- right shift arithmetic (>>>)
2819 class NetEBShift : public NetEBinary {
2821 public:
2822 NetEBShift(char op, NetExpr*l, NetExpr*r);
2823 ~NetEBShift();
2825 virtual bool set_width(unsigned w, bool last_chance);
2827 // A shift expression only needs the left expression to have a
2828 // definite width to give the expression a definite width.
2829 virtual bool has_width() const;
2831 virtual NetEBShift* dup_expr() const;
2832 virtual NetEConst* eval_tree(int prune_to_width = -1);
2834 virtual NetNet* synthesize(Design*);
2836 private:
2841 * This expression node supports the concat expression. This is an
2842 * operator that just glues the results of many expressions into a
2843 * single value.
2845 * Note that the class stores the parameter expressions in source code
2846 * order. That is, the parm(0) is placed in the most significant
2847 * position of the result.
2849 class NetEConcat : public NetExpr {
2851 public:
2852 NetEConcat(unsigned cnt, NetExpr* repeat =0);
2853 ~NetEConcat();
2855 // Manipulate the parameters.
2856 void set(unsigned idx, NetExpr*e);
2858 unsigned repeat();
2859 unsigned repeat() const;
2860 unsigned nparms() const { return parms_.count() ; }
2861 NetExpr* parm(unsigned idx) const { return parms_[idx]; }
2863 virtual NexusSet* nex_input(bool rem_out = true);
2864 virtual bool has_width() const;
2865 virtual bool set_width(unsigned w, bool last_chance =false);
2866 virtual NetEConcat* dup_expr() const;
2867 virtual NetEConst* eval_tree(int prune_to_width = -1);
2868 virtual NetNet*synthesize(Design*);
2869 virtual void expr_scan(struct expr_scan_t*) const;
2870 virtual void dump(ostream&) const;
2872 private:
2873 svector<NetExpr*>parms_;
2874 NetExpr* repeat_;
2875 unsigned repeat_value_;
2876 bool repeat_calculated_;
2881 * This class is a placeholder for a parameter expression. When
2882 * parameters are first created, an instance of this object is used to
2883 * hold the place where the parameter expression goes. Then, when the
2884 * parameters are resolved, these objects are removed.
2886 * If the parameter object is created with a path and name, then the
2887 * object represents a reference to a parameter that is known to exist.
2889 class NetEParam : public NetExpr {
2890 public:
2891 NetEParam();
2892 NetEParam(class Design*des, NetScope*scope, perm_string name);
2893 ~NetEParam();
2895 virtual NexusSet* nex_input(bool rem_out = true);
2896 virtual bool set_width(unsigned w, bool last_chance);
2897 virtual bool has_width() const;
2898 virtual void expr_scan(struct expr_scan_t*) const;
2899 virtual NetExpr* eval_tree(int prune_to_width = -1);
2900 virtual NetEParam* dup_expr() const;
2902 virtual void dump(ostream&) const;
2904 private:
2905 Design*des_;
2906 NetScope*scope_;
2907 perm_string name_;
2912 * This expression node supports bit/part selects from general
2913 * expressions. The sub-expression is self-sized, and has bits
2914 * selected from it. The base is the expression that identifies the
2915 * lsb of the expression, and the wid is the width of the part select,
2916 * or 1 for a bit select. No matter what the subexpression is, the
2917 * base is translated in canonical bits. It is up to the elaborator
2918 * to figure this out and adjust the expression if the subexpression
2919 * has a non-canonical base or direction.
2921 * If the base expression is null, then this expression node can be
2922 * used to express width expansion, signed or unsigned depending on
2923 * the has_sign() flag.
2925 class NetESelect : public NetExpr {
2927 public:
2928 NetESelect(NetExpr*exp, NetExpr*base, unsigned wid);
2929 ~NetESelect();
2931 const NetExpr*sub_expr() const;
2932 const NetExpr*select() const;
2934 virtual NexusSet* nex_input(bool rem_out = true);
2935 virtual bool set_width(unsigned w, bool last_chance =false);
2936 virtual bool has_width() const;
2937 virtual void expr_scan(struct expr_scan_t*) const;
2938 virtual NetEConst* eval_tree(int prune_to_width = -1);
2939 virtual NetESelect* dup_expr() const;
2940 virtual NetNet*synthesize(Design*des);
2941 virtual void dump(ostream&) const;
2943 private:
2944 NetExpr*expr_;
2945 NetExpr*base_;
2949 * This node is for representation of named events.
2951 class NetEEvent : public NetExpr {
2953 public:
2954 NetEEvent(NetEvent*);
2955 ~NetEEvent();
2957 const NetEvent* event() const;
2959 virtual void expr_scan(struct expr_scan_t*) const;
2960 virtual NetEEvent* dup_expr() const;
2961 virtual NexusSet* nex_input(bool rem_out = true);
2963 virtual void dump(ostream&os) const;
2965 private:
2966 NetEvent*event_;
2970 * This class is a special (and magical) expression node type that
2971 * represents scope names. These can only be found as parameters to
2972 * NetSTask objects.
2974 class NetEScope : public NetExpr {
2976 public:
2977 NetEScope(NetScope*);
2978 ~NetEScope();
2980 const NetScope* scope() const;
2982 virtual void expr_scan(struct expr_scan_t*) const;
2983 virtual NetEScope* dup_expr() const;
2984 virtual NexusSet* nex_input(bool rem_out = true);
2986 virtual void dump(ostream&os) const;
2988 private:
2989 NetScope*scope_;
2993 * This node represents a system function call in an expression. The
2994 * object contains the name of the system function, which the backend
2995 * uses to do VPI matching.
2997 class NetESFunc : public NetExpr {
2999 public:
3000 NetESFunc(const char*name, ivl_variable_type_t t,
3001 unsigned width, unsigned nprms);
3002 ~NetESFunc();
3004 const char* name() const;
3006 unsigned nparms() const;
3007 void parm(unsigned idx, NetExpr*expr);
3008 NetExpr* parm(unsigned idx);
3009 const NetExpr* parm(unsigned idx) const;
3011 virtual ivl_variable_type_t expr_type() const;
3012 virtual NexusSet* nex_input(bool rem_out = true);
3013 virtual bool set_width(unsigned, bool last_chance);
3014 virtual void dump(ostream&) const;
3016 virtual void expr_scan(struct expr_scan_t*) const;
3017 virtual NetESFunc*dup_expr() const;
3019 private:
3020 const char* name_;
3021 ivl_variable_type_t type_;
3022 unsigned nparms_;
3023 NetExpr**parms_;
3025 private: // not implemented
3026 NetESFunc(const NetESFunc&);
3027 NetESFunc& operator= (const NetESFunc&);
3031 * This class represents the ternary (?:) operator. It has 3
3032 * expressions, one of which is a condition used to select which of
3033 * the other two expressions is the result.
3035 class NetETernary : public NetExpr {
3037 public:
3038 NetETernary(NetExpr*c, NetExpr*t, NetExpr*f);
3039 ~NetETernary();
3041 virtual bool set_width(unsigned w, bool last_chance);
3043 const NetExpr*cond_expr() const;
3044 const NetExpr*true_expr() const;
3045 const NetExpr*false_expr() const;
3047 virtual NetETernary* dup_expr() const;
3048 virtual NetExpr* eval_tree(int prune_to_width = -1);
3050 virtual ivl_variable_type_t expr_type() const;
3051 virtual NexusSet* nex_input(bool rem_out = true);
3052 virtual void expr_scan(struct expr_scan_t*) const;
3053 virtual void dump(ostream&) const;
3054 virtual NetNet*synthesize(Design*);
3056 private:
3057 NetExpr*cond_;
3058 NetExpr*true_val_;
3059 NetExpr*false_val_;
3063 * This class represents a unary operator, with the single operand
3064 * and a single character for the operator. The operator values are:
3066 * ~ -- Bit-wise negation
3067 * ! -- Logical negation
3068 * & -- Reduction AND
3069 * | -- Reduction OR
3070 * ^ -- Reduction XOR
3071 * + --
3072 * - --
3073 * A -- Reduction NAND (~&)
3074 * N -- Reduction NOR (~|)
3075 * X -- Reduction NXOR (~^ or ^~)
3077 class NetEUnary : public NetExpr {
3079 public:
3080 NetEUnary(char op, NetExpr*ex);
3081 ~NetEUnary();
3083 char op() const { return op_; }
3084 const NetExpr* expr() const { return expr_; }
3086 virtual bool set_width(unsigned w, bool last_chance);
3088 virtual NetEUnary* dup_expr() const;
3089 virtual NetEConst* eval_tree(int prune_to_width = -1);
3091 virtual ivl_variable_type_t expr_type() const;
3092 virtual NexusSet* nex_input(bool rem_out = true);
3093 virtual void expr_scan(struct expr_scan_t*) const;
3094 virtual void dump(ostream&) const;
3096 protected:
3097 char op_;
3098 NetExpr* expr_;
3100 void eval_expr_();
3103 class NetEUBits : public NetEUnary {
3105 public:
3106 NetEUBits(char op, NetExpr*ex);
3107 ~NetEUBits();
3109 virtual NetNet* synthesize(Design*);
3111 virtual NetEConst* eval_tree(int prune_to_width = -1);
3112 virtual ivl_variable_type_t expr_type() const;
3115 class NetEUReduce : public NetEUnary {
3117 public:
3118 NetEUReduce(char op, NetExpr*ex);
3119 ~NetEUReduce();
3121 virtual bool set_width(unsigned w, bool last_chance);
3122 virtual NetNet* synthesize(Design*);
3123 virtual NetEUReduce* dup_expr() const;
3124 virtual NetEConst* eval_tree(int prune_to_width = -1);
3125 virtual ivl_variable_type_t expr_type() const;
3129 * When a signal shows up in an expression, this type represents
3130 * it. From this the expression can get any kind of access to the
3131 * structural signal, including arrays.
3133 * The NetESignal may refer to an array, if the word_index is
3134 * included. This expression calculates the index of the word in the
3135 * array. It may only be nil if the expression refers to the whole
3136 * array, and that is legal only in limited situation.
3138 class NetESignal : public NetExpr {
3140 public:
3141 NetESignal(NetNet*n);
3142 NetESignal(NetNet*n, NetExpr*word_index);
3143 ~NetESignal();
3145 perm_string name() const;
3146 virtual bool set_width(unsigned, bool last_chance);
3148 virtual NetESignal* dup_expr() const;
3149 NetNet* synthesize(Design*des);
3150 NexusSet* nex_input(bool rem_out = true);
3152 // This is the expression for selecting an array word, if this
3153 // signal refers to an array.
3154 const NetExpr* word_index() const;
3156 // This is the width of the vector that this signal refers to.
3157 unsigned vector_width() const;
3158 // Point back to the signal that this expression node references.
3159 const NetNet* sig() const;
3160 NetNet* sig();
3161 // Declared vector dimensions for the signal.
3162 unsigned msi() const;
3163 unsigned lsi() const;
3165 virtual ivl_variable_type_t expr_type() const;
3167 virtual void expr_scan(struct expr_scan_t*) const;
3168 virtual void dump(ostream&) const;
3170 private:
3171 NetNet*net_;
3172 // Expression to select a word from the net.
3173 NetExpr*word_;
3178 * This object type is used to contain a logical scope within a
3179 * design. The scope doesn't represent any executable hardware, but is
3180 * just a handle that netlist processors can use to grab at the design.
3182 class NetScope : public Attrib {
3184 public:
3185 enum TYPE { MODULE, TASK, FUNC, BEGIN_END, FORK_JOIN, GENBLOCK };
3187 /* Create a new scope, and attach it to the given parent. The
3188 name is expected to have been permallocated. */
3189 NetScope(NetScope*up, const hname_t&name, TYPE t);
3190 ~NetScope();
3192 /* Rename the scope using the name generated by inserting as
3193 many pad characters as required between prefix and suffix
3194 to make the name unique in the parent scope. Return false
3195 if a unique name couldn't be generated. */
3196 bool auto_name(const char* prefix, char pad, const char* suffix);
3198 /* Parameters exist within a scope, and these methods allow
3199 one to manipulate the set. In these cases, the name is the
3200 *simple* name of the parameter, the hierarchy is implicit in
3201 the scope. The return value from set_parameter is the
3202 previous expression, if there was one. */
3204 NetExpr* set_parameter(perm_string name, NetExpr*val,
3205 NetExpr*msb, NetExpr*lsb, bool signed_flag);
3206 NetExpr* set_localparam(perm_string name, NetExpr*val);
3208 const NetExpr*get_parameter(const char* name,
3209 const NetExpr*&msb,
3210 const NetExpr*&lsb) const;
3212 /* These are used by defparam elaboration to replace the
3213 expression with a new expression, without affecting the
3214 range or signed_flag. Return false if the name does not
3215 exist. */
3216 bool replace_parameter(perm_string name, NetExpr*val);
3218 /* These methods set or access events that live in this
3219 scope. */
3221 void add_event(NetEvent*);
3222 void rem_event(NetEvent*);
3223 NetEvent*find_event(const char*name);
3226 /* These methods manage signals. The add_ and rem_signal
3227 methods are used by the NetNet objects to make themselves
3228 available to the scope, and the find_signal method can be
3229 used to locate signals within a scope. */
3231 void add_signal(NetNet*);
3232 void rem_signal(NetNet*);
3233 NetNet* find_signal(const char*name);
3235 /* The parent and child() methods allow users of NetScope
3236 objects to locate nearby scopes. */
3237 NetScope* parent();
3238 NetScope* child(const hname_t&name);
3239 const NetScope* parent() const;
3240 const NetScope* child(const hname_t&name) const;
3242 TYPE type() const;
3244 void set_task_def(NetTaskDef*);
3245 void set_func_def(NetFuncDef*);
3246 void set_module_name(perm_string);
3248 NetTaskDef* task_def();
3249 NetFuncDef* func_def();
3251 bool in_func();
3253 const NetTaskDef* task_def() const;
3254 const NetFuncDef* func_def() const;
3256 /* If the scope represents a module instance, the module_name
3257 is the name of the module itself. */
3258 perm_string module_name() const;
3260 /* Scopes have their own time units and time precision. The
3261 unit and precision are given as power of 10, i.e., -3 is
3262 units of milliseconds.
3264 If a NetScope is created with a parent scope, the new scope
3265 will initially inherit the unit and precision of the
3266 parent scope. */
3268 void time_unit(int);
3269 void time_precision(int);
3271 int time_unit() const;
3272 int time_precision() const;
3274 void default_nettype(NetNet::Type);
3275 NetNet::Type default_nettype() const;
3277 /* The name of the scope is the fully qualified hierarchical
3278 name, whereas the basename is just my name within my parent
3279 scope. */
3280 perm_string basename() const;
3281 const hname_t& fullname() const { return name_; }
3283 void run_defparams(class Design*);
3284 void evaluate_parameters(class Design*);
3286 /* This method generates a non-hierarchical name that is
3287 guaranteed to be unique within this scope. */
3288 perm_string local_symbol();
3290 void dump(ostream&) const;
3291 void emit_scope(struct target_t*tgt) const;
3292 bool emit_defs(struct target_t*tgt) const;
3294 /* This method runs the functor on me. Recurse through the
3295 children of this node as well. */
3296 void run_functor(Design*des, functor_t*fun);
3299 /* This member is used during elaboration to pass defparam
3300 assignments from the scope pass to the parameter evaluation
3301 step. After that, it is not used. */
3303 map<pform_name_t,NetExpr*>defparams;
3305 public:
3306 /* After everything is all set up, the code generators like
3307 access to these things to make up the parameter lists. */
3308 struct param_expr_t {
3309 NetExpr*expr;
3310 NetExpr*msb;
3311 NetExpr*lsb;
3312 bool signed_flag;
3314 map<perm_string,param_expr_t>parameters;
3315 map<perm_string,param_expr_t>localparams;
3317 struct spec_val_t {
3318 ivl_variable_type_t type;
3319 union {
3320 double real_val; // type == IVL_VT_REAL
3321 long integer; // type == IVL_VT_BOOL
3324 map<perm_string,spec_val_t>specparams;
3326 /* Module instance arrays are collected here for access during
3327 the multiple elaboration passes. */
3328 typedef svector<NetScope*> scope_vec_t;
3329 map<perm_string, scope_vec_t>instance_arrays;
3331 /* Loop generate uses this as scratch space during
3332 elaboration. Expression evaluation can use this to match
3333 names. */
3334 perm_string genvar_tmp;
3335 long genvar_tmp_val;
3337 private:
3338 TYPE type_;
3339 hname_t name_;
3341 signed char time_unit_, time_prec_;
3342 NetNet::Type default_nettype_;
3344 NetEvent *events_;
3345 NetNet *signals_;
3346 perm_string module_name_;
3347 union {
3348 NetTaskDef*task_;
3349 NetFuncDef*func_;
3352 NetScope*up_;
3353 NetScope*sib_;
3354 NetScope*sub_;
3356 unsigned lcounter_;
3360 * This class contains an entire design. It includes processes and a
3361 * netlist, and can be passed around from function to function.
3363 class Design {
3365 public:
3366 Design();
3367 ~Design();
3370 /* The flags are a generic way of accepting command line
3371 parameters/flags and passing them to the processing steps
3372 that deal with the design. The compilation driver sets the
3373 entire flags map after elaboration is done. Subsequent
3374 steps can then use the get_flag() function to get the value
3375 of an interesting key. */
3377 void set_flags(const map<string,const char*>&f) { flags_ = f; }
3379 const char* get_flag(const string&key) const;
3381 NetScope* make_root_scope(perm_string name);
3382 NetScope* find_root_scope();
3383 list<NetScope*> find_root_scopes();
3385 const list<NetScope*> find_root_scopes() const;
3387 /* Attempt to set the precision to the specified value. If the
3388 precision is already more precise, the keep the precise
3389 setting. This is intended to hold the simulation precision
3390 for use throughout the entire design. */
3392 void set_precision(int val);
3393 int get_precision() const;
3395 /* This function takes a delay value and a scope, and returns
3396 the delay value scaled to the precision of the design. */
3397 uint64_t scale_to_precision(uint64_t, const NetScope*)const;
3399 /* Look up a scope. If no starting scope is passed, then the
3400 path is taken as an absolute scope name. Otherwise, the
3401 scope is located starting at the passed scope and working
3402 up if needed. */
3403 NetScope* find_scope(const std::list<hname_t>&path) const;
3404 NetScope* find_scope(NetScope*, const std::list<hname_t>&path) const;
3406 // PARAMETERS
3408 void run_defparams();
3409 void evaluate_parameters();
3411 /* This method locates a signal, starting at a given
3412 scope. The name parameter may be partially hierarchical, so
3413 this method, unlike the NetScope::find_signal method,
3414 handles global name binding. */
3416 NetNet*find_signal(NetScope*scope, pform_name_t path);
3418 // Functions
3419 NetFuncDef* find_function(NetScope*scope, const pform_name_t&key);
3421 // Tasks
3422 NetScope* find_task(NetScope*scope, const pform_name_t&name);
3424 // NODES
3425 void add_node(NetNode*);
3426 void del_node(NetNode*);
3428 // PROCESSES
3429 void add_process(NetProcTop*);
3430 void delete_process(NetProcTop*);
3432 // Iterate over the design...
3433 void dump(ostream&) const;
3434 void functor(struct functor_t*);
3435 int emit(struct target_t*) const;
3437 // This is incremented by elaboration when an error is
3438 // detected. It prevents code being emitted.
3439 unsigned errors;
3441 public:
3442 string local_symbol(const string&path);
3444 private:
3445 // Keep a tree of scopes. The NetScope class handles the wide
3446 // tree and per-hop searches for me.
3447 list<NetScope*>root_scopes_;
3449 // List the nodes in the design.
3450 NetNode*nodes_;
3451 // These are in support of the node functor iterator.
3452 NetNode*nodes_functor_cur_;
3453 NetNode*nodes_functor_nxt_;
3455 // List the processes in the design.
3456 NetProcTop*procs_;
3457 NetProcTop*procs_idx_;
3459 map<string,const char*> flags_;
3461 int des_precision_;
3463 unsigned lcounter_;
3465 private: // not implemented
3466 Design(const Design&);
3467 Design& operator= (const Design&);
3471 /* =======
3474 inline bool operator == (const Link&l, const Link&r)
3475 { return l.is_equal(r); }
3477 inline bool operator != (const Link&l, const Link&r)
3478 { return ! l.is_equal(r); }
3480 /* Connect the pins of two nodes together. Either may already be
3481 connected to other things, connect is transitive. */
3482 extern void connect(Link&, Link&);
3484 /* Return true if l and r are connected. */
3485 inline bool connected(const Link&l, const Link&r)
3486 { return l.is_linked(r); }
3488 /* Return the number of links in the ring that are of the specified
3489 type. */
3490 extern unsigned count_inputs(const Link&pin);
3491 extern unsigned count_outputs(const Link&pin);
3492 extern unsigned count_signals(const Link&pin);
3494 /* Find the next link that is an output into the nexus. */
3495 extern Link* find_next_output(Link*lnk);
3497 /* Find the signal connected to the given node pin. There should
3498 always be exactly one signal. The bidx parameter gets filled with
3499 the signal index of the Net, in case it is a vector. */
3500 const NetNet* find_link_signal(const NetObj*net, unsigned pin,
3501 unsigned&bidx);
3503 inline ostream& operator << (ostream&o, const NetExpr&exp)
3504 { exp.dump(o); return o; }
3506 extern ostream& operator << (ostream&, NetNet::Type);
3509 * Manipulator to dump a scope complete path to the output. The
3510 * manipulator is "scope_path" and works like this:
3512 * out << .... << scope_path(sc) << ... ;
3514 struct __ScopePathManip { const NetScope*scope; };
3515 inline __ScopePathManip scope_path(const NetScope*scope)
3516 { __ScopePathManip tmp; tmp.scope = scope; return tmp; }
3518 extern ostream& operator << (ostream&o, __ScopePathManip);
3520 #endif