forked from steveicarus/iverilog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnetlist.h
5334 lines (4262 loc) · 170 KB
/
netlist.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#ifndef IVL_netlist_H
#define IVL_netlist_H
/*
* Copyright (c) 1998-2024 Stephen Williams ([email protected])
* Copyright CERN 2013 / Stephen Williams ([email protected])
*
* This source code is free software; you can redistribute it
* and/or modify it in source code form under the terms of the GNU
* General Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
/*
* The netlist types, as described in this header file, are intended
* to be the output from elaboration of the source design. The design
* can be passed around in this form to the various stages and design
* processors.
*/
# include <string>
# include <map>
# include <list>
# include <memory>
# include <vector>
# include <set>
# include <utility>
# include "ivl_target.h"
# include "ivl_target_priv.h"
# include "pform_types.h"
# include "config.h"
# include "nettypes.h"
# include "verinum.h"
# include "verireal.h"
# include "StringHeap.h"
# include "HName.h"
# include "LineInfo.h"
# include "Attrib.h"
# include "PScope.h"
# include "PUdp.h"
#ifdef HAVE_IOSFWD
# include <iosfwd>
#else
# include <iostream>
#endif
class Design;
class Link;
class Nexus;
class NetEvent;
class NetNet;
class NetNode;
class NetObj;
class NetPins;
class NetProc;
class NetProcTop;
class NetRelease;
class NetScope;
class NetEvProbe;
class NetExpr;
class NetEAccess;
class NetEConstEnum;
class NetESignal;
class NetFuncDef;
class NetRamDq;
class NetTaskDef;
class NetEvTrig;
class NetEvNBTrig;
class NetEvWait;
class PClass;
class PExpr;
class PFunction;
class PPackage;
class PTaskFunc;
class PWire;
class data_type_t;
struct enum_type_t;
class netclass_t;
class netdarray_t;
class netparray_t;
class netuarray_t;
class netqueue_t;
class netenum_t;
class netstruct_t;
class netvector_t;
struct target;
struct functor_t;
#if defined(__cplusplus) && defined(_MSC_VER)
# define ENUM_UNSIGNED_INT : unsigned int
#else
# define ENUM_UNSIGNED_INT
#endif
std::ostream& operator << (std::ostream&o, ivl_variable_type_t val);
extern void join_island(NetPins*obj);
class Link {
friend void connect(Link&, Link&);
friend class NetPins;
friend class Nexus;
friend class NexusSet;
public:
enum DIR ENUM_UNSIGNED_INT { PASSIVE, INPUT, OUTPUT };
private: // Only NetPins can create/delete Link objects
Link();
~Link();
public:
// Manipulate the link direction.
void set_dir(DIR d);
DIR get_dir() const;
// Set the delay for all the drivers to this nexus.
void drivers_delays(NetExpr*rise, NetExpr*fall, NetExpr*decay);
// A link has a drive strength for 0 and 1 values. The drive0
// strength is for when the link has the value 0, and drive1
// strength is for when the link has a value 1.
void drive0(ivl_drive_t);
void drive1(ivl_drive_t);
// This sets the drives for all drivers of this link, and not
// just the current link.
void drivers_drive(ivl_drive_t d0, ivl_drive_t d1);
ivl_drive_t drive0() const;
ivl_drive_t drive1() const;
void cur_link(NetPins*&net, unsigned &pin);
void cur_link(const NetPins*&net, unsigned &pin) const;
// Get a pointer to the nexus that represents all the links
// connected to me.
Nexus* nexus();
const Nexus* nexus()const;
// Return a pointer to the next link in the nexus.
Link* next_nlink();
const Link* next_nlink() const;
// Remove this link from the set of connected pins. The
// destructor will automatically do this if needed.
void unlink();
// Return true if this link is connected to anything else.
bool is_linked() const;
// Return true if these pins are connected.
bool is_linked(const Link&that) const;
// Return true if this is the same pin of the same object of
// that link.
bool is_equal(const Link&that) const;
// Return information about the object that this link is
// a part of. Note that the get_obj() method can return NIL if
// this Link is part of a NexusSet. That should be OK, because
// they are collection variables, and not functional parts of
// a design.
const NetPins*get_obj() const;
NetPins*get_obj();
unsigned get_pin() const;
void dump_link(std::ostream&fd, unsigned ind) const;
private:
// The NetNode manages these. They point back to the
// NetNode so that following the links can get me here.
union {
NetPins *node_;
unsigned pin_;
};
bool pin_zero_ : 1;
DIR dir_ : 2;
ivl_drive_t drive0_ : 3;
ivl_drive_t drive1_ : 3;
private:
Nexus* find_nexus_() const;
private:
// The Nexus uses these to maintain its list of Link
// objects. If this link is not connected to anything,
// then these pointers are both nil.
Link *next_;
Nexus*nexus_;
private: // not implemented
Link(const Link&);
Link& operator= (const Link&);
};
class NetPins : public LineInfo {
public:
explicit NetPins(unsigned npins);
virtual ~NetPins();
unsigned pin_count() const { return npins_; }
Link&pin(unsigned idx);
const Link&pin(unsigned idx) const;
void dump_node_pins(std::ostream&, unsigned, const char**pin_names =0) const;
void set_default_dir(Link::DIR d);
bool is_linked() const;
bool pins_are_virtual(void) const;
void devirtualize_pins(void);
// This is for showing a brief description of the object to
// the stream. It is used for debug and diagnostics.
virtual void show_type(std::ostream&fd) const;
private:
Link*pins_;
const unsigned npins_;
Link::DIR default_dir_;
};
/* =========
* A NetObj is anything that has any kind of behavior in the
* netlist. Nodes can be gates, registers, etc. and are linked
* together to form a design web.
*
* The web of nodes that makes up a circuit is held together by the
* Link class. There is a link for each pin. All mutually connected
* pins form a ring of links.
*
* A link can be INPUT, OUTPUT or PASSIVE. An input never drives the
* signal, and PASSIVE never receives the value of the signal. Wires
* are PASSIVE, for example.
*
* A NetObj also has delays specified as rise_time, fall_time and
* decay_time. The rise and fall time are the times to transition to 1
* or 0 values. The decay_time is the time needed to decay to a 'bz
* value, or to decay of the net is a trireg. The exact and precise
* interpretation of the rise/fall/decay times is typically left to
* the target to properly interpret.
*/
class NetObj : public NetPins, public Attrib {
public:
// The name of the object must be a permallocated string. A
// lex_strings string, for example.
explicit NetObj(NetScope*s, perm_string n, unsigned npins);
virtual ~NetObj();
NetScope* scope();
const NetScope* scope() const;
perm_string name() const { return name_; }
void rename(perm_string n) { name_ = n; }
const NetExpr* rise_time() const { return delay1_; }
const NetExpr* fall_time() const { return delay2_; }
const NetExpr* decay_time() const { return delay3_; }
void rise_time(const NetExpr* d) { delay1_ = d; }
void fall_time(const NetExpr* d) { delay2_ = d; }
void decay_time(const NetExpr* d) { delay3_ = d; }
void dump_obj_attr(std::ostream&, unsigned) const;
virtual void show_type(std::ostream&fd) const;
private:
NetScope*scope_;
perm_string name_;
const NetExpr* delay1_;
const NetExpr* delay2_;
const NetExpr* delay3_;
};
/*
* Objects that can be island branches are derived from this. (It is
* possible for an object to be a NetObj and an IslandBranch.) This is
* used to collect island information about the node.
*/
class IslandBranch {
public:
explicit IslandBranch(ivl_discipline_t dis =0) : island_(0), discipline_(dis) { }
ivl_island_t get_island() const { return island_; }
friend void join_island(NetPins*);
private:
ivl_island_t island_;
ivl_discipline_t discipline_;
};
/*
* A NetBranch is a construct of Verilog-A that is a branch between
* two nodes. The branch has exactly 2 pins and a discipline.
*
* pin(0) is the source of flow through a branch and the plus side of
* potential. Pin(1) is the sink of flow and the minus (or ground) of
* potential.
*/
class NetBranch : public NetPins, public IslandBranch {
public:
explicit NetBranch(ivl_discipline_t dis);
explicit NetBranch(ivl_discipline_t dis, perm_string name);
~NetBranch();
// If the branch is named, this returns the name.
perm_string name() const { return name_; }
ivl_branch_s* target_obj() const { return &target_obj_; }
void dump(std::ostream&, unsigned) const;
private:
perm_string name_;
mutable ivl_branch_s target_obj_;
// The design class uses this member to list the branches.
friend class Design;
NetBranch*next_;
};
/*
* The Nexus represents a collection of links that are joined
* together. Each link has its own properties, this class holds the
* properties of the group.
*
* The links in a nexus are grouped into a circularly linked list,
* with the nexus pointing to the last Link. Each link in turn points
* to the next link in the nexus, with the last link pointing back to
* the first. The last link also has a non-nil nexus_ pointer back to
* this nexus.
*
* The t_cookie() is an ivl_nexus_t that the code generator uses to
* store data in the nexus. When a Nexus is created, this cookie is
* set to nil. The code generator may set the cookie once. This locks
* the nexus, and rewrites the Link list to be optimal for the code
* generator. In the process, *all* of the other methods are no longer
* functional.
*/
class Nexus {
friend void connect(Link&, Link&);
friend class Link;
private:
// Only Link objects can create (or delete) Nexus objects
explicit Nexus(Link&r);
~Nexus();
public:
void connect(Link&r);
const char* name() const;
void drivers_delays(NetExpr*rise, NetExpr*fall, NetExpr*decay);
void drivers_drive(ivl_drive_t d0, ivl_drive_t d1);
Link*first_nlink();
const Link* first_nlink()const;
/* Get the width of the Nexus, or 0 if there are no vectors
(in the form of NetNet objects) linked. */
unsigned vector_width() const;
NetNet* pick_any_net();
NetNode* pick_any_node();
/* This method counts the number of input and output links for
this nexus, and assigns the results to the output arguments. */
void count_io(unsigned&inp, unsigned&out) const;
/* This method returns true if there are any assignments that
use this nexus as an l-value. This can be true if the nexus
is a variable, but also if this is a net with a force. */
bool assign_lval() const;
/* This method returns true if there are any inputs
attached to this nexus but no drivers. */
bool has_floating_input() const;
/* This method returns true if there are any drivers
(including variables) attached to this nexus. */
bool drivers_present() const;
/* This method returns true if all the possible drivers of
this nexus are constant. It will also return true if there
are no drivers at all. */
bool drivers_constant() const;
/* Given the nexus has constant drivers, this method returns
the value that has been driven. */
verinum::V driven_value() const;
verinum driven_vector() const;
/* Return a mask of the bits of this vector that are
driven. This is usually all false or all true, but in
special cases it may be a blend. */
std::vector<bool> driven_mask(void)const;
/* The code generator sets an ivl_nexus_t to attach code
generation details to the nexus. */
ivl_nexus_t t_cookie() const { return t_cookie_; }
void t_cookie(ivl_nexus_t) const;
private:
Link*list_;
void unlink(Link*);
mutable char* name_; /* Cache the calculated name for the Nexus. */
mutable ivl_nexus_t t_cookie_;
enum VALUE { NO_GUESS, V0, V1, Vx, Vz, VAR };
mutable VALUE driven_;
private: // not implemented
Nexus(const Nexus&);
Nexus& operator= (const Nexus&);
};
inline void connect(Nexus*l, Link&r) { l->connect(r); }
class NexusSet {
public:
struct elem_t {
inline elem_t(Nexus*n, unsigned b, unsigned w)
: base(b), wid(w)
{
lnk.set_dir(Link::PASSIVE);
n->connect(lnk);
}
inline elem_t() : base(0), wid(0)
{
}
inline bool operator == (const struct elem_t&that) const
{ return lnk.is_linked(that.lnk) && base==that.base && wid==that.wid; }
bool contains(const struct elem_t&that) const;
Link lnk;
unsigned base;
unsigned wid;
private:
elem_t(const elem_t&);
elem_t& operator= (elem_t&);
};
public:
~NexusSet();
NexusSet();
size_t size() const;
// Add the nexus/part to the set, if it is not already present.
void add(Nexus*that, unsigned base, unsigned wid);
void add(NexusSet&that);
// Remove the nexus from the set, if it is present.
void rem(const NexusSet&that);
unsigned find_nexus(const elem_t&that) const;
elem_t& at(unsigned idx);
inline elem_t& operator[] (unsigned idx) { return at(idx); }
// Return true if this set contains every nexus/part in that
// set. That means that every bit of that set is accounted for
// this set.
bool contains(const NexusSet&that) const;
// Return true if this set contains any nexus in that set.
bool intersect(const NexusSet&that) const;
private:
// NexSet items are canonical part selects of vectors.
std::vector<struct elem_t*> items_;
size_t bsearch_(const struct elem_t&that) const;
void rem_(const struct elem_t*that);
bool contains_(const elem_t&that) const;
private: // not implemented
NexusSet(const NexusSet&);
NexusSet& operator= (const NexusSet&);
};
/*
* A NetBus is a transparent device that is merely a bunch of pins
* used to tie some pins to. It is a convenient way to collect a
* bundle of pins and pass that bundle around.
*/
class NetBus : public NetObj {
public:
NetBus(NetScope*scope, unsigned pin_count);
~NetBus();
unsigned find_link(const Link&that) const;
private: // not implemented
NetBus(const NetBus&);
NetBus& operator= (const NetBus&);
};
/*
* A NetNode is a device of some sort, where each pin has a different
* meaning. (i.e., pin(0) is the output to an and gate.) NetNode
* objects are listed in the nodes_ of the Design object.
*/
class NetNode : public NetObj {
public:
// The name parameter must be a permallocated string.
explicit NetNode(NetScope*s, perm_string n, unsigned npins);
virtual ~NetNode();
virtual bool emit_node(struct target_t*) const;
virtual void dump_node(std::ostream&, unsigned) const;
// This is used to scan a modifiable netlist, one node at a time.
virtual void functor_node(Design*, functor_t*);
private:
friend class Design;
NetNode*node_next_, *node_prev_;
Design*design_;
};
/*
* A NetDelaySrc is an input-only device that calculates a path delay
* based on the time that the inputs change. This class is used by the
* NetNet class, and NetDelaySrc objects cannot exist outside of its
* association with NetNet objects.
*/
class NetDelaySrc : public NetObj {
public:
explicit NetDelaySrc(NetScope*s, perm_string n, unsigned nsrc,
bool condit_src, bool conditional, bool parallel);
~NetDelaySrc();
// These functions set the delays from the values in the
// source. These set_delays functions implement the various
// rules wrt collections of transitions.
// One transition specified.
void set_delays(uint64_t del);
// Two transitions: rise and fall
void set_delays(uint64_t rise, uint64_t fall);
// Three transitions
void set_delays(uint64_t rise, uint64_t fall, uint64_t tz);
void set_delays(uint64_t t01, uint64_t t10, uint64_t t0z,
uint64_t tz1, uint64_t t1z, uint64_t tz0);
void set_delays(uint64_t t01, uint64_t t10, uint64_t t0z,
uint64_t tz1, uint64_t t1z, uint64_t tz0,
uint64_t t0x, uint64_t tx1, uint64_t t1x,
uint64_t tx0, uint64_t txz, uint64_t tzx);
uint64_t get_delay(unsigned pe) const;
void set_posedge();
void set_negedge();
bool is_posedge() const;
bool is_negedge() const;
unsigned src_count() const;
Link&src_pin(unsigned);
const Link&src_pin(unsigned) const;
bool is_condit() const;
bool has_condit() const;
Link&condit_pin();
const Link&condit_pin() const;
bool is_parallel() const;
void dump(std::ostream&, unsigned ind) const;
private:
uint64_t transition_delays_[12];
bool condit_flag_;
bool conditional_;
bool parallel_;
bool posedge_;
bool negedge_;
private: // Not implemented
NetDelaySrc(const NetDelaySrc&);
NetDelaySrc& operator= (const NetDelaySrc&);
};
/*
* NetNet is a special kind of NetObj that doesn't really do anything,
* but carries the properties of the wire/reg/trireg, including its
* name. Scalars and vectors are all the same thing here, a NetNet
* with a single pin. The difference between a scalar and vector is
* the width of the atomic vector datum it carries.
*
* NetNet objects can also appear as side effects of synthesis or
* other abstractions.
*
* Note that INTEGER types are an alias for a ``reg signed [31:0]''.
*
* NetNet objects have a name and exist within a scope, so the
* constructor takes a pointer to the containing scope. The object
* automatically adds itself to the scope.
*
* NetNet objects are located by searching NetScope objects.
*
* The pins of a NetNet object are usually PASSIVE: they do not drive
* anything and they are not a data sink, per se. The pins follow the
* values on the nexus. The exceptions are reg, trireg, tri0, tri1,
* supply0, and supply1 objects, whose pins are classed as OUTPUT.
*/
class PortType
{
public:
enum Enum ENUM_UNSIGNED_INT { NOT_A_PORT, PIMPLICIT, PINPUT, POUTPUT, PINOUT, PREF };
/*
* Merge Port types (used to construct a sane combined port-type
* for module ports with complex defining expressions).
*
*/
static Enum merged( Enum lhs, Enum rhs );
};
extern std::ostream& operator << (std::ostream&, PortType::Enum);
/*
* Information on actual ports (rather than port-connected signals) of
* module.
* N.b. must be POD as passed through a "C" interface in the t-dll-api.
*/
struct PortInfo
{
PortType::Enum type;
unsigned long width;
perm_string name;
ivl_net_logic_t buffer;
};
class NetNet : public NetObj, public PortType {
public:
enum Type ENUM_UNSIGNED_INT { NONE, IMPLICIT, IMPLICIT_REG, WIRE, TRI, TRI1,
SUPPLY0, SUPPLY1, WAND, TRIAND, TRI0, WOR, TRIOR, REG,
UNRESOLVED_WIRE };
typedef PortType::Enum PortType;
public:
// This form is the more generic form of the constructor. For
// now, the unpacked type is not buried into an ivl_type_s object.
explicit NetNet(NetScope*s, perm_string n, Type t,
const netranges_t &unpacked,
ivl_type_t type);
explicit NetNet(NetScope*s, perm_string n, Type t, ivl_type_t type);
virtual ~NetNet();
Type type() const;
void type(Type t);
// This method returns true if we have changed the net type from being
// a variable to being an unresolved wire. This happens in SystemVerilog
// when we find a continuous assignment to a variable.
bool coerced_to_uwire() { return coerced_to_uwire_; }
PortType port_type() const;
void port_type(PortType t);
unsigned lexical_pos() const { return lexical_pos_; }
void lexical_pos(unsigned lp) { lexical_pos_ = lp; }
// If this net net is a port (i.e. a *sub*port net of a module port)
// its port index is number of the module it connects through
int get_module_port_index() const; // -1 Not connected to port...
void set_module_port_index(unsigned idx);
ivl_variable_type_t data_type() const;
/* If a NetNet is signed, then its value is to be treated as
signed. Otherwise, it is unsigned. */
bool get_signed() const;
void set_const(bool is_const) { is_const_ = is_const; }
bool get_const() const { return is_const_; }
bool get_scalar() const;
inline const ivl_type_s* net_type(void) const { return net_type_; }
const netenum_t*enumeration(void) const;
const netstruct_t*struct_type(void) const;
const netdarray_t*darray_type(void) const;
const netqueue_t*queue_type(void) const;
const netclass_t*class_type(void) const;
const netarray_t*array_type(void) const;
/* Attach a discipline to the net. */
ivl_discipline_t get_discipline() const;
void set_discipline(ivl_discipline_t dis);
/* This method returns a reference to the packed dimensions
for the vector. These are arranged as a list where the
first range in the list (front) is the left-most range in
the Verilog declaration. These packed dims are compressed
to represent the dimensions of all the subtypes. */
const netranges_t& packed_dims() const { return slice_dims_; }
const netranges_t& unpacked_dims() const { return unpacked_dims_; }
/* The vector_width returns the bit width of the packed array,
vector or scalar that is this NetNet object. */
inline unsigned long vector_width() const { return slice_width(0); }
/* Given a prefix of indices, figure out how wide the
resulting slice would be. This is a generalization of the
vector_width(), where the depth would be 0. */
unsigned long slice_width(size_t depth) const;
/* This method converts a signed index (the type that might be
found in the Verilog source) to canonical. It accounts
for variation in the definition of the
reg/wire/whatever. Note that a canonical index of a
multi-dimensioned packed array is a single dimension. For
example, "reg [4:1][3:0]..." has the canonical dimension
[15:0] and the sb_to_idx() method will convert [2][2] to
the canonical index [6]. */
long sb_to_idx(const std::list<long>&prefix, long sb) const;
/* This method converts a partial packed indices list and a
tail index, and generates a canonical slice offset and
width. */
bool sb_to_slice(const std::list<long>&prefix, long sb, long&off, unsigned long&wid) const;
/* This method checks that the signed index is valid for this
signal. If it is, the above sb_to_idx can be used to get
the pin# from the index. */
bool sb_is_valid(const std::list<long>&prefix, long sb) const;
/* This method returns 0 for scalars and vectors, and greater
for arrays. The value is the number of array
indices. (Currently only one array index is supported.) */
inline unsigned unpacked_dimensions() const { return unpacked_dims_.size(); }
/* This method returns 0 for scalars, but vectors and other
PACKED arrays have packed dimensions. */
inline size_t packed_dimensions() const { return slice_dims_.size(); }
// This is the number of array elements.
unsigned unpacked_count() const;
bool local_flag() const { return local_flag_; }
void local_flag(bool f) { local_flag_ = f; }
// NetESignal objects may reference this object. Keep a
// reference count so that I keep track of them.
void incr_eref();
void decr_eref();
unsigned peek_eref() const;
// Assignment statements count their lrefs here. And by
// assignment statements, we mean BEHAVIORAL assignments.
void incr_lref();
void decr_lref();
unsigned peek_lref() const { return lref_count_; }
// Treating this node as a uwire, this function tests whether
// any bits in the canonical part are already driven. This is
// only useful for UNRESOLVED_WIRE objects. The msb and lsb
// are the part select of the signal, and the widx is the word
// index if this is an unpacked array.
bool test_part_driven(unsigned msb, unsigned lsb, int widx =0);
// Treating this node as a uwire, this function tests whether
// any bits in the canonical part are already driven and sets
// them if not. This is only useful for UNRESOLVED_WIRE objects.
// The msb and lsb are the part select of the signal, and the
// widx is the word index if this is an unpacked array.
bool test_and_set_part_driver(unsigned msb, unsigned lsb, int widx =0);
unsigned get_refs() const;
/* Manage path delays */
void add_delay_path(class NetDelaySrc*path);
unsigned delay_paths(void) const;
const class NetDelaySrc*delay_path(unsigned idx) const;
virtual void dump_net(std::ostream&, unsigned) const;
private:
void initialize_dir_();
private:
Type type_ : 5;
PortType port_type_ : 3;
bool coerced_to_uwire_: 1;
bool local_flag_: 1;
unsigned lexical_pos_;
ivl_type_t net_type_;
netuarray_t *array_type_ = nullptr;
ivl_discipline_t discipline_;
// Whether the net is variable declared with the const keyword.
bool is_const_ = false;
netranges_t unpacked_dims_;
// These are the widths of the various slice depths. There is
// one entry in this vector for each packed dimension. The
// value at N is the slice width if N indices are provided.
//
// For example: slice_wids_[0] is vector_width().
void calculate_slice_widths_from_packed_dims_(void);
netranges_t slice_dims_;
std::vector<unsigned long> slice_wids_;
unsigned eref_count_;
unsigned lref_count_;
// When the signal is an unresolved wire, we need more detail
// which bits are assigned. This mask is true for each bit
// that is known to be driven.
std::vector<bool> lref_mask_;
std::vector<class NetDelaySrc*> delay_paths_;
int port_index_ = -1;
};
/*
* This object type is used for holding local variable values when
* evaluating constant user functions.
*/
struct LocalVar {
int nwords; // zero for a simple variable, -1 for reference
union {
NetExpr* value; // a simple variable
NetExpr** array; // an array variable
LocalVar* ref; // A reference to a previous scope
};
};
class NetBaseDef {
public:
NetBaseDef(NetScope*n, const std::vector<NetNet*>&po,
const std::vector<NetExpr*>&pd);
virtual ~NetBaseDef();
const NetScope*scope() const;
NetScope*scope();
unsigned port_count() const;
NetNet*port(unsigned idx) const;
NetExpr*port_defe(unsigned idx) const;
void set_proc(NetProc*p);
//const string& name() const;
const NetProc*proc() const;
virtual bool check_synth(ivl_process_type_t pr_type, const NetScope*scope) const;
private:
NetScope*scope_;
std::vector<NetNet*>ports_;
std::vector<NetExpr*>pdefaults_;
protected:
NetProc*proc_;
};
/*
* Some definitions (and methods to manipulate them) are common to a
* couple of types. Keep them here.
*/
class Definitions {
public:
Definitions();
~Definitions();
// Add the enumeration to the set of enumerations in this
// scope. Include a key that the elaboration can use to look
// up this enumeration based on the pform type.
void add_enumeration_set(const enum_type_t*key, netenum_t*enum_set);
bool add_enumeration_name(netenum_t*enum_set, perm_string enum_name);
// Look up the enumeration set that was added with the given
// key. This is used by enum_type_t::elaborate_type to locate
// a previously elaborated enumeration.
netenum_t* enumeration_for_key(const enum_type_t*key) const;
// Look up an enumeration literal in this scope. If the
// literal is present, return the expression that defines its
// value.
const NetExpr* enumeration_expr(perm_string key);
// Definitions scopes can also hold classes, by name.
void add_class(netclass_t*class_type);
protected:
// Enumerations. The enum_sets_ is a list of all the
// enumerations present in this scope. The enum_names_ is a
// map of all the enumeration names back to the sets that
// contain them.
std::map<const enum_type_t*,netenum_t*> enum_sets_;
std::map<perm_string,NetEConstEnum*> enum_names_;
// This is a map of all the classes (by name) in this scope.
std::map<perm_string,netclass_t*> classes_;
};
/*
* This object type is used to contain a logical scope within a
* design. The scope doesn't represent any executable hardware, but is
* just a handle that netlist processors can use to grab at the design.
*/
class NetScope : public Definitions, public Attrib {
public:
enum TYPE { MODULE, CLASS, TASK, FUNC, BEGIN_END, FORK_JOIN, GENBLOCK, PACKAGE };
/* Create a new scope associated with a given compilation unit,
and attach it to the given parent. If no compilation unit is
specified, the parent's compilation unit is used. The name
is expected to have been permallocated. */
NetScope(NetScope*up, const hname_t&name, TYPE t, NetScope*in_unit=0,
bool nest=false, bool program=false, bool interface=false,
bool compilation_unit=false);
~NetScope();
/* Rename the scope using the name generated by inserting as
many pad characters as required between prefix and suffix
to make the name unique in the parent scope. Return false
if a unique name couldn't be generated. */
bool auto_name(const char* prefix, char pad, const char* suffix);
void add_imports(const std::map<perm_string,PPackage*>*imports);
NetScope*find_import(const Design*des, perm_string name);
void add_typedefs(const std::map<perm_string,typedef_t*>*typedefs);
/* Search the scope hierarchy for the scope where 'type' was defined. */
NetScope*find_typedef_scope(const Design*des, const typedef_t*type);
/* Parameters exist within a scope, and these methods allow
one to manipulate the set. In these cases, the name is the
*simple* name of the parameter, the hierarchy is implicit in
the scope. */
struct range_t;
void set_parameter(perm_string name, bool is_annotatable,
const LexicalScope::param_expr_t ¶m,
NetScope::range_t *range_list);
void set_parameter(perm_string name, NetExpr*val,
const LineInfo&file_line);
const NetExpr*get_parameter(Design*des, const char* name,
ivl_type_t&ivl_type);
const NetExpr*get_parameter(Design*des, perm_string name,
ivl_type_t&ivl_type);
/* These are used by defparam elaboration to replace the
expression with a new expression, without affecting the
range or signed_flag. Return false if the name does not
exist. */
void replace_parameter(Design *des, perm_string name, PExpr*val,
NetScope*scope, bool defparam = false);
/* This is used to ensure the value of a parameter cannot be
changed at run-time. This is required if a specparam is used