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)
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
22 #ident "$Id: netlist.h,v 1.380 2007/06/02 03:42:13 steve Exp $"
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
35 # include "ivl_target.h"
36 # include "pform_types.h"
39 # include "verireal.h"
40 # include "StringHeap.h"
42 # include "LineInfo.h"
73 ostream
& operator << (ostream
&o
, ivl_variable_type_t val
);
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
{
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
);
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;
129 const unsigned npins_
;
130 const NetExpr
* delay1_
;
131 const NetExpr
* delay2_
;
132 const NetExpr
* delay3_
;
137 friend void connect(Link
&, Link
&);
138 friend void connect(Nexus
*, Link
&);
143 enum DIR { PASSIVE
, INPUT
, OUTPUT
};
145 enum strength_t
{ HIGHZ
, WEAK
, PULL
, STRONG
, SUPPLY
};
150 // Manipulate the link direction.
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
176 const Nexus
* nexus()const;
178 // Return a pointer to the next link in the nexus.
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.
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
194 bool is_equal(const Link
&that
) const;
196 // Return information about the object that this link is
198 const NetObj
*get_obj() const;
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
205 void set_name(perm_string
, unsigned inst
=0);
206 perm_string
get_name() const;
207 unsigned get_inst() const;
210 // The NetNode manages these. They point back to the
211 // NetNode so that following the links can get me here.
216 strength_t drive0_
, drive1_
;
219 // These members name the pin of the link. If the name
220 // has width, then the inst_ member is the index of the
229 private: // not implemented
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
250 friend void connect(Link
&, Link
&);
251 friend void connect(Nexus
*, Link
&);
258 const char* name() const;
259 verinum::V
get_init() const;
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;
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
295 Nexus
& operator= (const Nexus
&);
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;
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
{
341 NetBus(NetScope
*scope
, unsigned pin_count
);
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
{
357 // The name parameter must be a permallocated string.
358 explicit NetNode(NetScope
*s
, perm_string n
, unsigned npins
);
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
*);
370 NetNode
*node_next_
, *node_prev_
;
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
{
383 explicit NetDelaySrc(NetScope
*s
, perm_string n
,
384 unsigned nsrc
, bool condit_src
);
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
);
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;
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;
417 const Link
&condit_pin() const;
419 void dump(ostream
&, unsigned ind
) const;
422 uint64_t transition_delays_
[12];
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
{
457 enum Type
{ NONE
, IMPLICIT
, IMPLICIT_REG
, INTEGER
, WIRE
, TRI
, TRI1
,
458 SUPPLY0
, SUPPLY1
, WAND
, TRIAND
, TRI0
, WOR
, TRIOR
, REG
,
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
472 explicit NetNet(NetScope
*s
, perm_string n
, Type t
,
474 explicit NetNet(NetScope
*s
, perm_string n
, Type t
,
475 long ms
, long ls
, long s0
, long e0
);
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. */
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. */
538 unsigned peek_eref() const;
540 /* Assignment statements count their lrefs here. */
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;
555 // The NetScope class uses this for listing signals.
556 friend class NetScope
;
557 NetNet
*sig_next_
, *sig_prev_
;
562 ivl_variable_type_t data_type_
;
564 bool isint_
; // original type of integer
567 const unsigned dimensions_
;
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
{
585 NetAddSub(NetScope
*s
, perm_string n
, unsigned width
);
588 // Get the width of the device (that is, the width of the
589 // operands and results.)
590 unsigned width() const;
597 Link
& pin_Overflow();
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
);
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
{
624 NetArrayDq(NetScope
*s
, perm_string name
, NetNet
*mem
, unsigned awid
);
627 unsigned width() const;
628 unsigned awidth() const;
629 unsigned size() const;
630 const NetNet
*mem() const;
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;
648 * This type represents the LPM_CLSHIFT device.
650 class NetCLShift
: public NetNode
{
653 NetCLShift(NetScope
*s
, perm_string n
, unsigned width
,
654 unsigned width_dist
, bool right_flag
, bool signed_flag
);
657 unsigned width() const;
658 unsigned width_dist() const;
660 bool right_flag() const;
661 bool signed_flag() const;
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;
676 unsigned width_dist_
;
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
692 class NetCompare
: public NetNode
{
695 NetCompare(NetScope
*scope
, perm_string n
, unsigned width
);
698 unsigned width() const;
700 bool get_signed() const;
701 void set_signed(bool);
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;
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
750 class NetConcat
: public NetNode
{
753 NetConcat(NetScope
*scope
, perm_string n
, unsigned wid
, unsigned cnt
);
756 unsigned width() const;
758 void dump_node(ostream
&, unsigned ind
) const;
759 bool emit_node(struct target_t
*) const;
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
{
779 NetDivide(NetScope
*scope
, perm_string n
,
780 unsigned width
, unsigned wa
, unsigned wb
);
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;
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
);
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
{
823 NetModulo(NetScope
*s
, perm_string n
,
824 unsigned width
, unsigned wa
, unsigned wb
);
827 unsigned width_r() const;
828 unsigned width_a() const;
829 unsigned width_b() const;
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
);
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
{
856 NetFF(NetScope
*s
, perm_string n
, unsigned vector_width
);
859 unsigned width() const;
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
);
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
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
{
907 NetMult(NetScope
*sc
, perm_string n
, unsigned width
,
908 unsigned wa
, unsigned wb
);
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
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
);
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
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
{
959 NetMux(NetScope
*scope
, perm_string n
,
960 unsigned width
, unsigned size
, unsigned selw
);
963 unsigned width() const;
964 unsigned size() const;
965 unsigned sel_width() const;
968 Link
& pin_Data(unsigned si
);
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
);
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
999 class NetReplicate
: public NetNode
{
1002 NetReplicate(NetScope
*scope
, perm_string n
, unsigned wid
, unsigned rpt
);
1005 unsigned width() const;
1006 unsigned repeat() const;
1008 void dump_node(ostream
&, unsigned ind
) const;
1009 bool emit_node(struct target_t
*) const;
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
{
1024 NetUserFunc(NetScope
*s
, perm_string n
, NetScope
*def
);
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;
1039 * The number of ports includes the return value, so will always be at
1042 class NetSysFunc
: public NetNode
{
1045 NetSysFunc(NetScope
*s
, perm_string n
,
1046 const struct sfunc_return_type
*def
,
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;
1057 const struct sfunc_return_type
*def_
;
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
{
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;
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
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
*);
1147 void expr_width(unsigned w
) { width_
= w
; }
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
{
1166 explicit NetEConst(const verinum
&val
);
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);
1187 class NetEConstParam
: public NetEConst
{
1190 explicit NetEConstParam(NetScope
*scope
, perm_string name
,
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;
1209 * This class represents a constant real value.
1211 class NetECReal
: public NetExpr
{
1214 explicit NetECReal(const verireal
&val
);
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);
1240 class NetECRealParam
: public NetECReal
{
1243 explicit NetECRealParam(NetScope
*scope
, perm_string name
,
1244 const verireal
&val
);
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;
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
{
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
,
1303 unsigned base() const;
1304 unsigned width() const;
1307 virtual void dump_node(ostream
&, unsigned ind
) const;
1308 bool emit_node(struct target_t
*tgt
) const;
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
{
1326 explicit NetBUFZ(NetScope
*s
, perm_string n
, unsigned wid
);
1329 unsigned width() const;
1331 virtual void dump_node(ostream
&, unsigned ind
) const;
1332 virtual bool emit_node(struct target_t
*) const;
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
1346 * This pins are assigned as:
1348 * 0 -- Output (always returns 0 or 1)
1352 class NetCaseCmp
: public NetNode
{
1355 explicit NetCaseCmp(NetScope
*s
, perm_string n
, unsigned wid
, bool eeq
);
1358 unsigned width() const;
1359 // true if this is ===, false if this is !==
1362 virtual void dump_node(ostream
&, unsigned ind
) const;
1363 virtual bool emit_node(struct target_t
*) const;
1370 /* NOTE: This class should be replaced with the NetLiteral class
1371 * below, that is more general in that it supports different types of
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
{
1384 explicit NetConst(NetScope
*s
, perm_string n
, verinum::V v
);
1385 explicit NetConst(NetScope
*s
, perm_string n
, const verinum
&val
);
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;
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
{
1411 // A read-valued literal.
1412 explicit NetLiteral(NetScope
*s
, perm_string n
, const verireal
&val
);
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;
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:
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
1446 class NetLogic
: public NetNode
{
1449 enum TYPE
{ AND
, BUF
, BUFIF0
, BUFIF1
, CMOS
, NAND
, NMOS
, NOR
, NOT
,
1450 NOTIF0
, NOTIF1
, OR
, PULLDOWN
, PULLUP
, RCMOS
, RNMOS
, RPMOS
,
1453 explicit NetLogic(NetScope
*s
, perm_string n
, unsigned pins
,
1454 TYPE t
, unsigned wid
);
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
*);
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
1475 class NetSignExtend
: public NetNode
{
1478 explicit NetSignExtend(NetScope
*s
, perm_string n
, unsigned wid
);
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
*);
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
{
1501 enum TYPE
{NONE
, AND
, OR
, XOR
, NAND
, NOR
, XNOR
};
1503 NetUReduce(NetScope
*s
, perm_string n
, TYPE t
, unsigned wid
);
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
*);
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
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
1540 * It also takes one of the following glob letters to represent more
1543 * p -- 01, 0x or x1 // check this with the lexer
1544 * n -- 10, 1x or x0 // check this with the lexer
1548 * _ -- 10 or x0 (Note that this is not the output '-'.)
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)
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
1567 class NetUDP
: public NetNode
{
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;
1589 mutable unsigned table_idx
;
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
{
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;
1643 friend class NetBlock
;
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
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.
1685 NetAssign_(NetNet
*sig
);
1688 // If this expression exists, then it is used to select a word
1689 // from an array/memory.
1691 const NetExpr
*word() const;
1693 // Get the base index of the part select, or 0 if there is no
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
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
1719 NexusSet
* nex_input(bool rem_out
= true);
1721 // This pointer is for keeping simple lists.
1724 void dump_lval(ostream
&o
) const;
1728 // Memory word index
1731 bool turn_sig_to_wire_on_release_
;
1732 // indexed part select base
1737 class NetAssignBase
: public NetProc
{
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.
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;
1778 class NetAssign
: public NetAssignBase
{
1781 explicit NetAssign(NetAssign_
*lv
, NetExpr
*rv
);
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;
1793 class NetAssignNB
: public NetAssignBase
{
1795 explicit NetAssignNB(NetAssign_
*lv
, NetExpr
*rv
);
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;
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
{
1817 enum Type
{ SEQU
, PARA
};
1819 NetBlock(Type t
, NetScope
*subscope
);
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;
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
{
1871 enum TYPE
{ EQ
, EQX
, EQZ
};
1872 NetCase(TYPE c
, NetExpr
*ex
, unsigned cnt
);
1875 void set_case(unsigned idx
, NetExpr
*ex
, NetProc
*st
);
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;
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
{
1915 explicit NetCAssign(NetAssign_
*lv
, NetExpr
*rv
);
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
{
1936 explicit NetCondit(NetExpr
*ex
, NetProc
*i
, NetProc
*e
);
1939 const NetExpr
*expr() const;
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;
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
{
1981 explicit NetDeassign(NetAssign_
*l
);
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:
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
{
2004 explicit NetDisable(NetScope
*tgt
);
2007 const NetScope
*target() const;
2009 virtual bool emit_proc(struct target_t
*) const;
2010 virtual void dump(ostream
&, unsigned ind
) const;
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:
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
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
;
2060 // The name of the event is the basename, and should not
2061 // include the scope. Also, the name passed here should be
2063 explicit NetEvent (perm_string n
);
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;
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
);
2093 // This returns a nexus set if it represents possibly
2094 // asynchronous inputs, otherwise 0.
2095 NexusSet
*nex_async_();
2100 // The NetScope class uses these to list the events.
2104 // Use these methods to list the probes attached to me.
2107 // Use these methods to list the triggers attached to me.
2110 // Use This member to count references by NetEvWait objects.
2116 struct wcell_
*wlist_
;
2118 // expression references, ala. task/funcs
2121 private: // not implemented
2122 NetEvent(const NetEvent
&);
2123 NetEvent
& operator= (const NetEvent
&);
2126 class NetEvTrig
: public NetProc
{
2128 friend class NetEvent
;
2131 explicit NetEvTrig(NetEvent
*tgt
);
2134 const NetEvent
*event() const;
2136 virtual bool emit_proc(struct target_t
*) const;
2137 virtual void dump(ostream
&, unsigned ind
) const;
2141 // This is used to place me in the NetEvents lists of triggers.
2145 class NetEvWait
: public NetProc
{
2148 explicit NetEvWait(NetProc
*st
);
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;
2190 class NetEvProbe
: public NetNode
{
2192 friend class NetEvent
;
2195 enum edge_t
{ ANYEDGE
, POSEDGE
, NEGEDGE
};
2197 explicit NetEvProbe(NetScope
*s
, perm_string n
,
2198 NetEvent
*tgt
, edge_t t
, unsigned p
);
2201 edge_t
edge() const;
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;
2213 // The NetEvent class uses this to list me.
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
{
2225 explicit NetForce(NetAssign_
*l
, NetExpr
*r
);
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
{
2241 explicit NetForever(NetProc
*s
);
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;
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
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.
2268 NetFuncDef(NetScope
*, NetNet
*result
, const svector
<NetNet
*>&po
);
2271 void set_proc(NetProc
*st
);
2273 //const string name() const;
2274 const NetProc
*proc() const;
2275 const NetScope
*scope() const;
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;
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
{
2309 NetPDelay(uint64_t d
, NetProc
*st
);
2310 NetPDelay(NetExpr
* d
, NetProc
*st
);
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;
2331 * A repeat statement is executed some fixed number of times.
2333 class NetRepeat
: public NetProc
{
2336 explicit NetRepeat(NetExpr
*e
, NetProc
*s
);
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;
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
{
2360 explicit NetRelease(NetAssign_
*l
);
2363 virtual bool emit_proc(struct target_t
*) const;
2364 virtual void dump(ostream
&, unsigned ind
) const;
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
{
2379 NetSTask(const char*na
, const svector
<NetExpr
*>&);
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;
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
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.
2413 NetTaskDef(NetScope
*n
, const svector
<NetNet
*>&po
);
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;
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
{
2445 NetEUFunc(NetScope
*, NetESignal
*, svector
<NetExpr
*>&);
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);
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
{
2481 NetUTask(NetScope
*);
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;
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
{
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;
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
{
2531 enum Type
{ KINITIAL
, KALWAYS
};
2533 NetProcTop(NetScope
*s
, Type t
, class NetProc
*st
);
2536 Type
type() const { return type_
; }
2537 NetProc
*statement();
2538 const NetProc
*statement() const;
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;
2562 NetProc
*const statement_
;
2565 friend class Design
;
2570 * This class represents a binary operator, with the left and right
2571 * operands and a single character for the operator. The operator
2574 * ^ -- Bit-wise exclusive OR
2575 * + -- Arithmetic add
2576 * - -- Arithmetic minus
2577 * * -- Arithmetic multiply
2578 * / -- Arithmetic divide
2579 * % -- Arithmetic modulus
2580 * p -- Arithmetic power (**)
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
{
2603 NetEBinary(char op
, NetExpr
*l
, NetExpr
*r
);
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
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;
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
{
2643 NetEBAdd(char op
, NetExpr
*l
, NetExpr
*r
, bool lossless_flag
=false);
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
*);
2654 NetECReal
* eval_tree_real_();
2658 * This class represents the integer division operators.
2662 class NetEBDiv
: public NetEBinary
{
2665 NetEBDiv(char op
, NetExpr
*l
, NetExpr
*r
);
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
2688 * X -- Bit-wise XNOR (~^)
2690 class NetEBBits
: public NetEBinary
{
2693 NetEBBits(char op
, NetExpr
*l
, NetExpr
*r
);
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:
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
{
2720 NetEBComp(char op
, NetExpr
*l
, NetExpr
*r
);
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
*);
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
{
2754 NetEBLogic(char op
, NetExpr
*l
, NetExpr
*r
);
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
*);
2767 * Support the binary multiplication (*) operator.
2769 class NetEBMult
: public NetEBinary
{
2772 NetEBMult(char op
, NetExpr
*l
, NetExpr
*r
);
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
*);
2784 NetExpr
* eval_tree_real_();
2789 * Support the binary multiplication (*) operator.
2791 class NetEBPow
: public NetEBinary
{
2794 NetEBPow(char op
, NetExpr
*l
, NetExpr
*r
);
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
*);
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
{
2822 NetEBShift(char op
, NetExpr
*l
, NetExpr
*r
);
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
*);
2841 * This expression node supports the concat expression. This is an
2842 * operator that just glues the results of many expressions into a
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
{
2852 NetEConcat(unsigned cnt
, NetExpr
* repeat
=0);
2855 // Manipulate the parameters.
2856 void set(unsigned idx
, NetExpr
*e
);
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;
2873 svector
<NetExpr
*>parms_
;
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
{
2892 NetEParam(class Design
*des
, NetScope
*scope
, perm_string name
);
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;
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
{
2928 NetESelect(NetExpr
*exp
, NetExpr
*base
, unsigned wid
);
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;
2949 * This node is for representation of named events.
2951 class NetEEvent
: public NetExpr
{
2954 NetEEvent(NetEvent
*);
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;
2970 * This class is a special (and magical) expression node type that
2971 * represents scope names. These can only be found as parameters to
2974 class NetEScope
: public NetExpr
{
2977 NetEScope(NetScope
*);
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;
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
{
3000 NetESFunc(const char*name
, ivl_variable_type_t t
,
3001 unsigned width
, unsigned nprms
);
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;
3021 ivl_variable_type_t type_
;
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
{
3038 NetETernary(NetExpr
*c
, NetExpr
*t
, NetExpr
*f
);
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
*);
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
3070 * ^ -- Reduction XOR
3073 * A -- Reduction NAND (~&)
3074 * N -- Reduction NOR (~|)
3075 * X -- Reduction NXOR (~^ or ^~)
3077 class NetEUnary
: public NetExpr
{
3080 NetEUnary(char op
, NetExpr
*ex
);
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;
3103 class NetEUBits
: public NetEUnary
{
3106 NetEUBits(char op
, NetExpr
*ex
);
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
{
3118 NetEUReduce(char op
, NetExpr
*ex
);
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
{
3141 NetESignal(NetNet
*n
);
3142 NetESignal(NetNet
*n
, NetExpr
*word_index
);
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;
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;
3172 // Expression to select a word from the net.
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
{
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
);
3192 /* Parameters exist within a scope, and these methods allow
3193 one to manipulate the set. In these cases, the name is the
3194 *simple* name of the parameter, the hierarchy is implicit in
3195 the scope. The return value from set_parameter is the
3196 previous expression, if there was one. */
3198 NetExpr
* set_parameter(perm_string name
, NetExpr
*val
,
3199 NetExpr
*msb
, NetExpr
*lsb
, bool signed_flag
);
3200 NetExpr
* set_localparam(perm_string name
, NetExpr
*val
);
3202 const NetExpr
*get_parameter(const char* name
,
3204 const NetExpr
*&lsb
) const;
3206 /* These are used by defparam elaboration to replace the
3207 expression with a new expression, without affecting the
3208 range or signed_flag. Return false if the name does not
3210 bool replace_parameter(perm_string name
, NetExpr
*val
);
3212 /* These methods set or access events that live in this
3215 void add_event(NetEvent
*);
3216 void rem_event(NetEvent
*);
3217 NetEvent
*find_event(const char*name
);
3220 /* These methods manage signals. The add_ and rem_signal
3221 methods are used by the NetNet objects to make themselves
3222 available to the scope, and the find_signal method can be
3223 used to locate signals within a scope. */
3225 void add_signal(NetNet
*);
3226 void rem_signal(NetNet
*);
3227 NetNet
* find_signal(const char*name
);
3229 /* The parent and child() methods allow users of NetScope
3230 objects to locate nearby scopes. */
3232 NetScope
* child(const hname_t
&name
);
3233 const NetScope
* parent() const;
3234 const NetScope
* child(const hname_t
&name
) const;
3238 void set_task_def(NetTaskDef
*);
3239 void set_func_def(NetFuncDef
*);
3240 void set_module_name(perm_string
);
3242 NetTaskDef
* task_def();
3243 NetFuncDef
* func_def();
3247 const NetTaskDef
* task_def() const;
3248 const NetFuncDef
* func_def() const;
3250 /* If the scope represents a module instance, the module_name
3251 is the name of the module itself. */
3252 perm_string
module_name() const;
3254 /* Scopes have their own time units and time precision. The
3255 unit and precision are given as power of 10, i.e., -3 is
3256 units of milliseconds.
3258 If a NetScope is created with a parent scope, the new scope
3259 will initially inherit the unit and precision of the
3262 void time_unit(int);
3263 void time_precision(int);
3265 int time_unit() const;
3266 int time_precision() const;
3268 void default_nettype(NetNet::Type
);
3269 NetNet::Type
default_nettype() const;
3271 /* The name of the scope is the fully qualified hierarchical
3272 name, whereas the basename is just my name within my parent
3274 perm_string
basename() const;
3275 const hname_t
& fullname() const { return name_
; }
3277 void run_defparams(class Design
*);
3278 void evaluate_parameters(class Design
*);
3280 /* This method generates a non-hierarchical name that is
3281 guaranteed to be unique within this scope. */
3282 perm_string
local_symbol();
3284 void dump(ostream
&) const;
3285 void emit_scope(struct target_t
*tgt
) const;
3286 bool emit_defs(struct target_t
*tgt
) const;
3288 /* This method runs the functor on me. Recurse through the
3289 children of this node as well. */
3290 void run_functor(Design
*des
, functor_t
*fun
);
3293 /* This member is used during elaboration to pass defparam
3294 assignments from the scope pass to the parameter evaluation
3295 step. After that, it is not used. */
3297 map
<pform_name_t
,NetExpr
*>defparams
;
3300 /* After everything is all set up, the code generators like
3301 access to these things to make up the parameter lists. */
3302 struct param_expr_t
{
3308 map
<perm_string
,param_expr_t
>parameters
;
3309 map
<perm_string
,param_expr_t
>localparams
;
3312 ivl_variable_type_t type
;
3314 double real_val
; // type == IVL_VT_REAL
3315 long integer
; // type == IVL_VT_BOOL
3318 map
<perm_string
,spec_val_t
>specparams
;
3320 /* Module instance arrays are collected here for access during
3321 the multiple elaboration passes. */
3322 typedef svector
<NetScope
*> scope_vec_t
;
3323 map
<perm_string
, scope_vec_t
>instance_arrays
;
3325 /* Loop generate uses this as scratch space during
3326 elaboration. Expression evaluation can use this to match
3328 perm_string genvar_tmp
;
3329 long genvar_tmp_val
;
3335 signed char time_unit_
, time_prec_
;
3336 NetNet::Type default_nettype_
;
3340 perm_string module_name_
;
3354 * This class contains an entire design. It includes processes and a
3355 * netlist, and can be passed around from function to function.
3364 /* The flags are a generic way of accepting command line
3365 parameters/flags and passing them to the processing steps
3366 that deal with the design. The compilation driver sets the
3367 entire flags map after elaboration is done. Subsequent
3368 steps can then use the get_flag() function to get the value
3369 of an interesting key. */
3371 void set_flags(const map
<string
,const char*>&f
) { flags_
= f
; }
3373 const char* get_flag(const string
&key
) const;
3375 NetScope
* make_root_scope(perm_string name
);
3376 NetScope
* find_root_scope();
3377 list
<NetScope
*> find_root_scopes();
3379 const list
<NetScope
*> find_root_scopes() const;
3381 /* Attempt to set the precision to the specified value. If the
3382 precision is already more precise, the keep the precise
3383 setting. This is intended to hold the simulation precision
3384 for use throughout the entire design. */
3386 void set_precision(int val
);
3387 int get_precision() const;
3389 /* This function takes a delay value and a scope, and returns
3390 the delay value scaled to the precision of the design. */
3391 uint64_t scale_to_precision(uint64_t, const NetScope
*)const;
3393 /* Look up a scope. If no starting scope is passed, then the
3394 path is taken as an absolute scope name. Otherwise, the
3395 scope is located starting at the passed scope and working
3397 NetScope
* find_scope(const std::list
<hname_t
>&path
) const;
3398 NetScope
* find_scope(NetScope
*, const std::list
<hname_t
>&path
) const;
3402 void run_defparams();
3403 void evaluate_parameters();
3405 /* This method locates a signal, starting at a given
3406 scope. The name parameter may be partially hierarchical, so
3407 this method, unlike the NetScope::find_signal method,
3408 handles global name binding. */
3410 NetNet
*find_signal(NetScope
*scope
, pform_name_t path
);
3413 NetFuncDef
* find_function(NetScope
*scope
, const pform_name_t
&key
);
3416 NetScope
* find_task(NetScope
*scope
, const pform_name_t
&name
);
3419 void add_node(NetNode
*);
3420 void del_node(NetNode
*);
3423 void add_process(NetProcTop
*);
3424 void delete_process(NetProcTop
*);
3426 // Iterate over the design...
3427 void dump(ostream
&) const;
3428 void functor(struct functor_t
*);
3429 int emit(struct target_t
*) const;
3431 // This is incremented by elaboration when an error is
3432 // detected. It prevents code being emitted.
3436 string
local_symbol(const string
&path
);
3439 // Keep a tree of scopes. The NetScope class handles the wide
3440 // tree and per-hop searches for me.
3441 list
<NetScope
*>root_scopes_
;
3443 // List the nodes in the design.
3445 // These are in support of the node functor iterator.
3446 NetNode
*nodes_functor_cur_
;
3447 NetNode
*nodes_functor_nxt_
;
3449 // List the processes in the design.
3451 NetProcTop
*procs_idx_
;
3453 map
<string
,const char*> flags_
;
3459 private: // not implemented
3460 Design(const Design
&);
3461 Design
& operator= (const Design
&);
3468 inline bool operator == (const Link
&l
, const Link
&r
)
3469 { return l
.is_equal(r
); }
3471 inline bool operator != (const Link
&l
, const Link
&r
)
3472 { return ! l
.is_equal(r
); }
3474 /* Connect the pins of two nodes together. Either may already be
3475 connected to other things, connect is transitive. */
3476 extern void connect(Link
&, Link
&);
3478 /* Return true if l and r are connected. */
3479 inline bool connected(const Link
&l
, const Link
&r
)
3480 { return l
.is_linked(r
); }
3482 /* Return the number of links in the ring that are of the specified
3484 extern unsigned count_inputs(const Link
&pin
);
3485 extern unsigned count_outputs(const Link
&pin
);
3486 extern unsigned count_signals(const Link
&pin
);
3488 /* Find the next link that is an output into the nexus. */
3489 extern Link
* find_next_output(Link
*lnk
);
3491 /* Find the signal connected to the given node pin. There should
3492 always be exactly one signal. The bidx parameter gets filled with
3493 the signal index of the Net, in case it is a vector. */
3494 const NetNet
* find_link_signal(const NetObj
*net
, unsigned pin
,
3497 inline ostream
& operator << (ostream
&o
, const NetExpr
&exp
)
3498 { exp
.dump(o
); return o
; }
3500 extern ostream
& operator << (ostream
&, NetNet::Type
);
3503 * Manipulator to dump a scope complete path to the output. The
3504 * manipulator is "scope_path" and works like this:
3506 * out << .... << scope_path(sc) << ... ;
3508 struct __ScopePathManip
{ const NetScope
*scope
; };
3509 inline __ScopePathManip
scope_path(const NetScope
*scope
)
3510 { __ScopePathManip tmp
; tmp
.scope
= scope
; return tmp
; }
3512 extern ostream
& operator << (ostream
&o
, __ScopePathManip
);