1 #ifndef IVL_ivl_target_H
2 #define IVL_ivl_target_H
3 /*
4  * Copyright (c) 2000-2020 Stephen Williams (steve@icarus.com)
5  *
6  *    This source code is free software; you can redistribute it
7  *    and/or modify it in source code form under the terms of the GNU
8  *    General Public License as published by the Free Software
9  *    Foundation; either version 2 of the License, or (at your option)
10  *    any later version.
11  *
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.
16  *
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  */
21 
22 # include  <inttypes.h>
23 # include  <stddef.h>
24 
25 /* Re the _CLASS define: clang++ wants this to be class to match the
26  * definition, but clang (the C) compiler needs it to be a struct
27  * since class is not defined in C. They are effectively both pointers
28  * to an object so everything works out. */
29 
30 #ifdef __cplusplus
31 #define _BEGIN_DECL extern "C" {
32 #define _END_DECL }
33 #define _CLASS class
34 #else
35 #define _BEGIN_DECL
36 #define _END_DECL
37 #define _CLASS struct
38 #endif
39 
40 #ifndef __GNUC__
41 # define __attribute__(x)
42 #endif
43 
44 #if defined(__cplusplus) && defined(_MSC_VER)
45 # define ENUM_UNSIGNED_INT : unsigned int
46 #else
47 # define ENUM_UNSIGNED_INT
48 #endif
49 
50 _BEGIN_DECL
51 
52 /*
53  * This header file describes the API for the loadable target
54  * module. The main program can load these modules and access the
55  * functions within the loaded module to implement the backend
56  * behavior.
57  *
58  * The interface is divided into two parts: the entry points within
59  * the core that are called by the module, and the entry points in
60  * the module that are called by the core. It is the latter that
61  * causes the module to be invoked in the first place, but most of the
62  * interesting information about the design is accessed through the
63  * various access functions that the modules calls into the core.
64  */
65 
66 
67 /*
68  * In order to grab onto data in the design, the core passes cookies
69  * to the various functions of the module. These cookies can in turn
70  * be passed to access functions in the core to get more detailed
71  * information.
72  *
73  * The following typedefs list the various cookies that may be passed
74  * around.
75  *
76  * ivl_array_t
77  *    This object represents an array that can be a memory or a net
78  *    array. (They are the same from the perspective of ivl_target.h.)
79  *
80  * ivl_branch_t
81  *    this object represents an analog branch.
82  *
83  * ivl_design_t
84  *    This object represents the entire elaborated design. Various
85  *    global properties and methods are available from this.
86  *
87  * ivl_event_t
88  *    This object represents an event node. An event node stands for
89  *    named events written explicitly in the Verilog, and net events
90  *    that are implicit when @ statements are used.
91  *
92  * ivl_expr_t
93  *    This object represents a node of an expression. If the
94  *    expression has sub-expressions, they can be accessed from
95  *    various method described below. The ivl_expr_type method in
96  *    particular gets the type of the node in the form of an
97  *    ivl_expr_type_t enumeration value.
98  *
99  *    Objects of this type represent expressions in processes.
100  *    Structural expressions are instead treated as logic gates.
101  *
102  * ivl_island_t
103  *    Certain types of objects may belong to islands. The island that
104  *    they belong to is represented by the ivl_island_t cookie. To
105  *    know if objects belong to the same island, it is sufficient to
106  *    compare island cookies. If a==b, then island a is the same as
107  *    island b.
108  *
109  * ivl_lpm_t
110  *    This object is the base class for all the various LPM type
111  *    device nodes. This object carries a few base properties
112  *    (including a type) including a handle to the specific type.
113  *
114  * ivl_net_logic_t
115  *    This object represents various built in logic devices. In fact,
116  *    this includes just about every directional device that has a
117  *    single output, including logic gates and nmos, pmos and cmos
118  *    devices. There is also the occasional Icarus Verilog creation.
119  *    What is common about these devices is that they are
120  *    bitwise. That is, when fed a vector, they produce a vector
121  *    result where each bit of the output is made only from the same
122  *    bits in the vector inputs.
123  *
124  * ivl_nexus_t
125  *    Structural links within an elaborated design are connected
126  *    together at each bit. The connection point is a nexus, so pins
127  *    of devices refer to an ivl_nexus_t. Furthermore, from a nexus
128  *    there are backward references to all the device pins that point
129  *    to it.
130  *
131  * ivl_parameter_t
132  *    Scopes have zero or more parameter objects that represent
133  *    parameters that the source defined. The parameter has a value
134  *    that is fully elaborated, with defparams and other parameter
135  *    overrides taken care of.
136  *
137  * ivl_process_t
138  *    A Verilog process is represented by one of these. A process may
139  *    be an "initial" or an "always" process. These come from initial
140  *    or always statements from the Verilog source.
141  *
142  * ivl_scope_t
143  *    Elaborated scopes within a design are represented by this
144  *    type. Objects of this type also act as containers for scoped
145  *    objects such as signals.
146  *
147  * ivl_statement_t
148  *    Statements within processes are represented by one of these. The
149  *    ivl_process_t object holds one of these, but a statement may in
150  *    turn contain other statements.
151  *
152  * ivl_switch_t
153  *    Switches are the tran/tranif devices in the design.
154  *
155  * -- A Note About Bit Sets --
156  * Some objects hold a value as an array of bits. In these cases there
157  * is some method that retrieves the width of the value and another
158  * that returns a "char*". The latter is a pointer to the least
159  * significant bit value. Bit values are represented by the characters
160  * '0', '1', 'x' and 'z'. Strengths are stored elsewhere.
161  *
162  * -- A Note About Names --
163  * The names of objects are complete, hierarchical names. That is,
164  * they include the instance name of the module that contains them.
165  *
166  * basenames are the name of the object without the containing
167  * scope. These names are unique within a scope, but not necessarily
168  * throughout the design.
169  */
170 typedef struct ivl_array_s    *ivl_array_t;
171 typedef struct ivl_branch_s   *ivl_branch_t;
172 typedef struct ivl_delaypath_s*ivl_delaypath_t;
173 typedef struct ivl_design_s   *ivl_design_t;
174 typedef _CLASS ivl_discipline_s*ivl_discipline_t;
175 typedef const _CLASS netenum_t*ivl_enumtype_t;
176 typedef struct ivl_event_s    *ivl_event_t;
177 typedef struct ivl_expr_s     *ivl_expr_t;
178 typedef struct ivl_island_s   *ivl_island_t;
179 typedef struct ivl_lpm_s      *ivl_lpm_t;
180 typedef struct ivl_lval_s     *ivl_lval_t;
181 typedef struct ivl_net_const_s*ivl_net_const_t;
182 typedef struct ivl_net_logic_s*ivl_net_logic_t;
183 typedef struct ivl_udp_s      *ivl_udp_t;
184 typedef _CLASS ivl_nature_s   *ivl_nature_t;
185 typedef struct ivl_net_probe_s*ivl_net_probe_t;
186 typedef struct ivl_nexus_s    *ivl_nexus_t;
187 typedef struct ivl_nexus_ptr_s*ivl_nexus_ptr_t;
188 typedef struct ivl_parameter_s*ivl_parameter_t;
189 typedef struct ivl_process_s  *ivl_process_t;
190 typedef struct ivl_scope_s    *ivl_scope_t;
191 typedef struct ivl_signal_s   *ivl_signal_t;
192 typedef struct ivl_port_info_s*ivl_port_info_t;
193 typedef struct ivl_switch_s   *ivl_switch_t;
194 typedef struct ivl_memory_s   *ivl_memory_t; //XXXX __attribute__((deprecated));
195 typedef struct ivl_statement_s*ivl_statement_t;
196 typedef const _CLASS ivl_type_s*ivl_type_t;
197 
198 /*
199  * These are types that are defined as enumerations. These have
200  * explicit values so that the binary API is a bit more resilient to
201  * changes and additions to the enumerations.
202  */
203 
204 typedef enum ivl_dis_domain_e {
205       IVL_DIS_NONE       = 0,
206       IVL_DIS_DISCRETE   = 1,
207       IVL_DIS_CONTINUOUS = 2
208 } ivl_dis_domain_t;
209 
210 typedef enum ivl_drive_e ENUM_UNSIGNED_INT {
211       IVL_DR_HiZ    = 0,
212       IVL_DR_SMALL  = 1,
213       IVL_DR_MEDIUM = 2,
214       IVL_DR_WEAK   = 3,
215       IVL_DR_LARGE  = 4,
216       IVL_DR_PULL   = 5,
217       IVL_DR_STRONG = 6,
218       IVL_DR_SUPPLY = 7
219 } ivl_drive_t;
220 
221 /* This is the type of an ivl_expr_t object. The explicit numbers
222    allow additions to the enumeration without causing values to shift
223    and incompatibilities to be introduced. */
224 typedef enum ivl_expr_type_e {
225       IVL_EX_NONE = 0,
226       IVL_EX_ARRAY = 18,
227       IVL_EX_BACCESS= 19,
228       IVL_EX_BINARY = 2,
229       IVL_EX_CONCAT = 3,
230       IVL_EX_DELAY = 20,
231       IVL_EX_ENUMTYPE = 21,
232       IVL_EX_EVENT  = 17,
233       IVL_EX_MEMORY = 4,
234       IVL_EX_NEW    = 23,
235       IVL_EX_NULL   = 22,
236       IVL_EX_NUMBER = 5,
237       IVL_EX_ARRAY_PATTERN  = 26,
238       IVL_EX_PROPERTY = 24,
239       IVL_EX_REALNUM  = 16,
240       IVL_EX_SCOPE  = 6,
241       IVL_EX_SELECT = 7,
242       IVL_EX_SFUNC  = 8,
243       IVL_EX_SHALLOWCOPY = 25,
244       IVL_EX_SIGNAL = 9,
245       IVL_EX_STRING = 10,
246       IVL_EX_TERNARY = 11,
247       IVL_EX_UFUNC = 12,
248       IVL_EX_ULONG = 13,
249       IVL_EX_UNARY = 14
250 } ivl_expr_type_t;
251 
252 typedef enum ivl_select_type_e ENUM_UNSIGNED_INT {
253       IVL_SEL_OTHER = 0,
254       IVL_SEL_IDX_UP = 1,
255       IVL_SEL_IDX_DOWN = 2
256 } ivl_select_type_t;
257 
258 /* This is the type code for an ivl_net_logic_t object. */
259 typedef enum ivl_logic_e {
260       IVL_LO_NONE   =  0,
261       IVL_LO_AND    =  1,
262       IVL_LO_BUF    =  2,
263       IVL_LO_BUFIF0 =  3,
264       IVL_LO_BUFIF1 =  4,
265       IVL_LO_BUFT   = 24, /* transparent bufz. (NOT "tri-state") */
266       IVL_LO_BUFZ   =  5,
267       IVL_LO_CMOS   = 22,
268       IVL_LO_EQUIV  = 25,
269       IVL_LO_IMPL   = 26,
270       IVL_LO_NAND   =  6,
271       IVL_LO_NMOS   =  7,
272       IVL_LO_NOR    =  8,
273       IVL_LO_NOT    =  9,
274       IVL_LO_NOTIF0 = 10,
275       IVL_LO_NOTIF1 = 11,
276       IVL_LO_OR     = 12,
277       IVL_LO_PMOS   = 17,
278       IVL_LO_PULLDOWN  = 13,
279       IVL_LO_PULLUP = 14,
280       IVL_LO_RCMOS  = 23,
281       IVL_LO_RNMOS  = 15,
282       IVL_LO_RPMOS  = 16,
283       IVL_LO_XNOR   = 18,
284       IVL_LO_XOR    = 19,
285       IVL_LO_UDP    = 21
286 } ivl_logic_t;
287 
288 /* This is the type of a ivl_switch_t object */
289 typedef enum ivl_switch_type_e {
290       IVL_SW_TRAN     = 0,
291       IVL_SW_TRANIF0  = 1,
292       IVL_SW_TRANIF1  = 2,
293       IVL_SW_RTRAN    = 3,
294       IVL_SW_RTRANIF0 = 4,
295       IVL_SW_RTRANIF1 = 5,
296       IVL_SW_TRAN_VP  = 6
297 } ivl_switch_type_t;
298 
299 /* This is the type of an LPM object. */
300 typedef enum ivl_lpm_type_e {
301       IVL_LPM_ABS    = 32,
302       IVL_LPM_ADD    =  0,
303       IVL_LPM_ARRAY  = 30,
304       IVL_LPM_CAST_INT  = 34,
305       IVL_LPM_CAST_INT2 = 35,
306       IVL_LPM_CAST_REAL = 33,
307       IVL_LPM_CONCAT = 16,
308       IVL_LPM_CONCATZ = 36, /* Transparent concat */
309       IVL_LPM_CMP_EEQ= 18, /* Case EQ (===) */
310       IVL_LPM_CMP_EQX= 37, /* Wildcard EQ (casex) */
311       IVL_LPM_CMP_EQZ= 38, /* casez EQ */
312       IVL_LPM_CMP_WEQ= 41,
313       IVL_LPM_CMP_WNE= 42,
314       IVL_LPM_CMP_EQ = 10,
315       IVL_LPM_CMP_GE =  1,
316       IVL_LPM_CMP_GT =  2,
317       IVL_LPM_CMP_NE = 11,
318       IVL_LPM_CMP_NEE= 19, /* Case NE (!==) */
319       IVL_LPM_DIVIDE = 12,
320       IVL_LPM_FF     =  3,
321       IVL_LPM_LATCH  = 40,
322       IVL_LPM_MOD    = 13,
323       IVL_LPM_MULT   =  4,
324       IVL_LPM_MUX    =  5,
325       /* IVL_LPM_PART_BI= 28, / obsolete */
326       IVL_LPM_PART_VP= 15, /* part select: vector to part */
327       IVL_LPM_PART_PV= 17, /* part select: part written to vector */
328       IVL_LPM_POW    = 31,
329       IVL_LPM_RE_AND = 20,
330       IVL_LPM_RE_NAND= 21,
331       IVL_LPM_RE_NOR = 22,
332       IVL_LPM_RE_OR  = 23,
333       IVL_LPM_RE_XNOR= 24,
334       IVL_LPM_RE_XOR = 25,
335       IVL_LPM_REPEAT = 26,
336       IVL_LPM_SFUNC  = 29,
337       IVL_LPM_SHIFTL =  6,
338       IVL_LPM_SHIFTR =  7,
339       IVL_LPM_SIGN_EXT=27,
340       IVL_LPM_SUB    =  8,
341       IVL_LPM_SUBSTITUTE=39,
342       /* IVL_LPM_RAM =  9, / obsolete */
343       IVL_LPM_UFUNC  = 14
344 } ivl_lpm_type_t;
345 
346 /* The path edge type is the edge type used to select a specific
347    delay. */
348 typedef enum ivl_path_edge_e {
349       IVL_PE_01 = 0, IVL_PE_10, IVL_PE_0z,
350       IVL_PE_z1,     IVL_PE_1z, IVL_PE_z0,
351       IVL_PE_0x,     IVL_PE_x1, IVL_PE_1x,
352       IVL_PE_x0,     IVL_PE_xz, IVL_PE_zx,
353       IVL_PE_COUNT
354 } ivl_path_edge_t;
355 
356 /* Processes are initial, always, or final blocks with a statement. This is
357    the type of the ivl_process_t object. */
358 typedef enum ivl_process_type_e ENUM_UNSIGNED_INT {
359       IVL_PR_INITIAL      = 0,
360       IVL_PR_ALWAYS       = 1,
361       IVL_PR_ALWAYS_COMB  = 3,
362       IVL_PR_ALWAYS_FF    = 4,
363       IVL_PR_ALWAYS_LATCH = 5,
364       IVL_PR_FINAL        = 2
365 } ivl_process_type_t;
366 
367 /* These are the sorts of reasons a scope may come to be. These types
368    are properties of ivl_scope_t objects. */
369 typedef enum ivl_scope_type_e {
370       IVL_SCT_MODULE  = 0,
371       IVL_SCT_FUNCTION= 1,
372       IVL_SCT_TASK    = 2,
373       IVL_SCT_BEGIN   = 3,
374       IVL_SCT_FORK    = 4,
375       IVL_SCT_GENERATE= 5,
376       IVL_SCT_PACKAGE = 6,
377       IVL_SCT_CLASS   = 7
378 } ivl_scope_type_t;
379 
380 /* Signals (ivl_signal_t) that are ports into the scope that contains
381    them have a port type. Otherwise, they are port IVL_SIP_NONE. */
382 typedef enum OUT {
383       IVL_SIP_NONE  = 0,
384       IVL_SIP_INPUT = 1,
385       IVL_SIP_OUTPUT= 2,
386       IVL_SIP_INOUT = 3
387 } ivl_signal_port_t;
388 
389 /* This is the type code for an ivl_signal_t object. Implicit types
390    are resolved by the core compiler, and integers are converted into
391    signed registers. */
392 typedef enum ivl_signal_type_e {
393       IVL_SIT_NONE = 0,
394       IVL_SIT_REG  = 1,
395       IVL_SIT_TRI  = 4,
396       IVL_SIT_TRI0 = 5,
397       IVL_SIT_TRI1 = 6,
398       IVL_SIT_TRIAND = 7,
399       IVL_SIT_TRIOR  = 8,
400       IVL_SIT_UWIRE  = 9
401 } ivl_signal_type_t;
402 
403 /* This is the type code for ivl_statement_t objects. */
404 typedef enum ivl_statement_type_e {
405       IVL_ST_NONE    = 0,
406       IVL_ST_NOOP    = 1,
407       IVL_ST_ALLOC   = 25,
408       IVL_ST_ASSIGN    = 2,
409       IVL_ST_ASSIGN_NB = 3,
410       IVL_ST_BLOCK   = 4,
411       IVL_ST_CASE    = 5,
412       IVL_ST_CASER   = 24, /* Case statement with real expressions. */
413       IVL_ST_CASEX   = 6,
414       IVL_ST_CASEZ   = 7,
415       IVL_ST_CASSIGN = 8,
416       IVL_ST_CONDIT  = 9,
417       IVL_ST_CONTRIB = 27,
418       IVL_ST_DEASSIGN = 10,
419       IVL_ST_DELAY   = 11,
420       IVL_ST_DELAYX  = 12,
421       IVL_ST_DISABLE = 13,
422       IVL_ST_DO_WHILE = 30,
423       IVL_ST_FORCE   = 14,
424       IVL_ST_FOREVER = 15,
425       IVL_ST_FORK    = 16,
426       IVL_ST_FORK_JOIN_ANY  = 28,
427       IVL_ST_FORK_JOIN_NONE = 29,
428       IVL_ST_FREE    = 26,
429       IVL_ST_RELEASE = 17,
430       IVL_ST_REPEAT  = 18,
431       IVL_ST_STASK   = 19,
432       IVL_ST_TRIGGER = 20,
433       IVL_ST_UTASK   = 21,
434       IVL_ST_WAIT    = 22,
435       IVL_ST_WHILE   = 23
436 } ivl_statement_type_t;
437 
438 /* Case statements can be tagged as unique/unique0/priority. */
439 typedef enum ivl_case_quality_t {
440       IVL_CASE_QUALITY_BASIC    = 0,  /* no quality flags */
441       IVL_CASE_QUALITY_UNIQUE   = 1,
442       IVL_CASE_QUALITY_UNIQUE0  = 2,
443       IVL_CASE_QUALITY_PRIORITY = 3
444 } ivl_case_quality_t;
445 
446 /* SystemVerilog allows a system function to be called as a task. */
447 typedef enum ivl_sfunc_as_task_e {
448       IVL_SFUNC_AS_TASK_ERROR   = 0,
449       IVL_SFUNC_AS_TASK_WARNING = 1,
450       IVL_SFUNC_AS_TASK_IGNORE  = 2
451 } ivl_sfunc_as_task_t;
452 
453 /* This is the type of a variable, and also used as the type for an
454    expression. */
455 typedef enum ivl_variable_type_e ENUM_UNSIGNED_INT {
456       IVL_VT_VOID    = 0,  /* Not used */
457       IVL_VT_NO_TYPE = 1,  /* Place holder for missing/unknown type. */
458       IVL_VT_REAL    = 2,
459       IVL_VT_BOOL    = 3,
460       IVL_VT_LOGIC   = 4,
461       IVL_VT_STRING  = 5,
462       IVL_VT_DARRAY  = 6,  /* Array (esp. dynamic array) */
463       IVL_VT_CLASS   = 7,  /* SystemVerilog class instances */
464       IVL_VT_QUEUE   = 8,  /* SystemVerilog queue instances */
465       IVL_VT_VECTOR = IVL_VT_LOGIC /* For compatibility */
466 } ivl_variable_type_t;
467 
468 /* This is the type of the function to apply to a process. */
469 typedef int (*ivl_process_f)(ivl_process_t net, void*cd);
470 
471 /* This is the type of a function to apply to a scope. The ivl_scope_t
472    parameter is the scope, and the cd parameter is client data that
473    the user passes to the scanner. */
474 typedef int (ivl_scope_f)(ivl_scope_t net, void*cd);
475 
476 /* Attributes, which can be attached to various object types, have
477    this form. */
478 typedef enum ivl_attribute_type_e {
479       IVL_ATT_VOID = 0,
480       IVL_ATT_STR,
481       IVL_ATT_NUM
482 } ivl_attribute_type_t;
483 
484 struct ivl_attribute_s {
485       const char*key;
486       ivl_attribute_type_t type;
487       union val_ {
488 	    const char*str;
489 	    long num;
490       } val;
491 };
492 typedef const struct ivl_attribute_s*ivl_attribute_t;
493 
494 /* BRANCH
495  * Branches are analog constructs, a pair of terminals that is used in
496  * branch access functions. Terminal-1 is the reference node (The
497  * "ground") for the purposes of the access function that accesses it.
498  *
499  * SEMANTIC NOTES
500  * All the branches in an island are connected by terminals or by
501  * expressions. The island is the connection of branches that must be
502  * solved together.
503  */
504   /* extern ivl_scope_t ivl_branch_scope(ivl_branch_t obj); */
505 extern ivl_nexus_t ivl_branch_terminal(ivl_branch_t obj, int idx);
506 extern ivl_island_t ivl_branch_island(ivl_branch_t obj);
507 
508 /* DELAYPATH
509  * Delaypath objects represent delay paths called out by a specify
510  * block in the Verilog source file. The destination signal references
511  * the path object, which in turn points to the source for the path.
512  *
513  * ivl_path_scope
514  *    This returns the scope of the delay path. This scope corresponds
515  *    to the scope of the specify-block that led to this path.
516  *
517  * ivl_path_source
518  *    This returns the nexus that is the source end of the delay
519  *    path. Transitions on the source are the start of the delay time
520  *    for this path.
521  *
522  * ivl_path_condit
523  *    This returns the nexus that tracks the condition for the
524  *    delay. If the delay path is unconditional, this returns nil.
525  * ivl_path_is_condit
526  *    Is this a conditional structure? Needed for ifnone.
527  *
528  * ivl_path_is_parallel
529  *    This returns true if the path is a parallel connection and
530  *    false if the path is a full connection.
531  *
532  * ivl_path_source_posedge
533  * ivl_path_source_negedge
534  *    These functions return true if the source is edge sensitive.
535  */
536 extern ivl_scope_t ivl_path_scope(ivl_delaypath_t obj);
537 extern ivl_nexus_t ivl_path_source(ivl_delaypath_t obj);
538 extern uint64_t ivl_path_delay(ivl_delaypath_t obj, ivl_path_edge_t pt);
539 extern ivl_nexus_t ivl_path_condit(ivl_delaypath_t obj);
540 extern int ivl_path_is_condit(ivl_delaypath_t obj);
541 
542 extern int ivl_path_is_parallel(ivl_delaypath_t obj);
543 
544 extern int ivl_path_source_posedge(ivl_delaypath_t obj);
545 extern int ivl_path_source_negedge(ivl_delaypath_t obj);
546 
547 /* DESIGN
548  * When handed a design (ivl_design_t) there are a few things that you
549  * can do with it. The Verilog program has one design that carries the
550  * entire program. Use the design methods to iterate over the elements
551  * of the design.
552  *
553  * ivl_design_delay_sel
554  *    Returns the tool delay selection: "MINIMUM", "TYPICAL" or "MAXIMUM"?
555  *
556  * ivl_design_flag
557  *    This function returns the string value of a named flag. Flags
558  *    come from the "-pkey=value" options to the iverilog command and
559  *    are stored in a map for this function. Given the key, this
560  *    function returns the value.
561  *
562  *    The special key "-o" is the argument to the -o flag of the
563  *    command line (or the default if the -o flag is not used) and is
564  *    generally how the target learns the name of the output file.
565  *
566  * ivl_design_process
567  *    This function scans the processes (threads) in the design. It
568  *    calls the user supplied function on each of the processes until
569  *    one of the functors returns non-0 or all the processes are
570  *    scanned. This function will return 0, or the non-zero value that
571  *    was returned from the last scanned process.
572  *
573  * ivl_design_root (ANACHRONISM)
574  *    A design has a root named scope that is an instance of the top
575  *    level module in the design. This is a hook for naming the
576  *    design, or for starting the scope scan.
577  *
578  * ivl_design_roots
579  *    A design has some number of root scopes. These are the starting
580  *    points for structural elaboration. This function returns to the
581  *    caller a pointer to an ivl_scope_t array, and the size of the
582  *    array.
583  *
584  * ivl_design_time_precision
585  *    A design as a time precision. This is the size in seconds (a
586  *    signed power of 10) of a simulation tick.
587  */
588 
589 extern const char* ivl_design_delay_sel(ivl_design_t des);
590 extern const char* ivl_design_flag(ivl_design_t des, const char*key);
591 extern int         ivl_design_process(ivl_design_t des,
592 				      ivl_process_f fun, void*cd);
593 extern ivl_scope_t ivl_design_root(ivl_design_t des);
594 extern void        ivl_design_roots(ivl_design_t des,
595 				    ivl_scope_t **scopes,
596 				    unsigned int *nscopes);
597 extern int         ivl_design_time_precision(ivl_design_t des);
598 
599 extern unsigned        ivl_design_consts(ivl_design_t des);
600 extern ivl_net_const_t ivl_design_const(ivl_design_t, unsigned idx);
601 
602 extern unsigned         ivl_design_disciplines(ivl_design_t des);
603 extern ivl_discipline_t ivl_design_discipline(ivl_design_t des, unsigned idx);
604 
605 /* LITERAL CONSTANTS
606  * Literal constants are nodes with no input and a single constant
607  * output. The form of the output depends on the type of the node.
608  * The output is an array of 4-value bits, using a single char
609  * value for each bit. The bits of the vector are in canonical (lsb
610  * first) order for the width of the constant.
611  *
612  * ivl_const_type
613  *    The is the type of the node.
614  *
615  * ivl_const_bits
616  *    This returns a pointer to an array of constant characters,
617  *    each byte a '0', '1', 'x' or 'z'. The array is *not* nul
618  *    terminated. This value is only value if ivl_const_type is
619  *    IVL_VT_LOGIC or IVL_VT_BOOL. It returns nil otherwise.
620  *
621  * ivl_const_nex
622  *    Return the ivl_nexus_t of the output for the constant.
623  *
624  * ivl_const_scope
625  *    Return the scope this constant was defined in.
626 
627  * ivl_const_signed
628  *    Return true (!0) if the constant is a signed value, 0 otherwise.
629  *
630  * ivl_const_width
631  *    Return the width, in logical bits, of the constant.
632  *
633  * ivl_const_delay
634  *    T0 delay for a transition (0, 1 and Z).
635  *
636  * SEMANTIC NOTES
637  *
638  * The const_type of the literal constant must match the
639  * ivl_signal_data_type if the signals that share the nexus of this
640  * node. The compiler makes sure it is so, converting constant values
641  * as needed.
642  *
643  * - IVL_VT_LOGIC
644  *
645  * - IVL_VT_REAL
646  * Real valued constants have a width of 1. The value emitted to the
647  * output is ivl_const_real.
648  */
649 extern ivl_variable_type_t ivl_const_type(ivl_net_const_t net);
650 extern const char* ivl_const_bits(ivl_net_const_t net);
651 extern ivl_expr_t  ivl_const_delay(ivl_net_const_t net, unsigned transition);
652 extern ivl_nexus_t ivl_const_nex(ivl_net_const_t net);
653 extern ivl_scope_t ivl_const_scope(ivl_net_const_t net);
654 extern int         ivl_const_signed(ivl_net_const_t net);
655 extern unsigned    ivl_const_width(ivl_net_const_t net);
656 extern double      ivl_const_real(ivl_net_const_t net);
657 
658 extern const char* ivl_const_file(ivl_net_const_t net);
659 extern unsigned ivl_const_lineno(ivl_net_const_t net);
660 
661 /* extern ivl_nexus_t ivl_const_pin(ivl_net_const_t net, unsigned idx); */
662 /* extern unsigned    ivl_const_pins(ivl_net_const_t net); */
663 
664 /* DISCIPLINES
665  *
666  * Disciplines are Verilog-AMS construct. A discipline is a collection
667  * of attributes that can be attached to a signal.
668  *
669  * FUNCTION SUMMARY
670  *
671  * ivl_discipline_name
672  *    This is the name of the discipline in the Verilog-AMS source.
673  *
674  * ivl_discipline_domain
675  *    This is the domain: continuous or discrete.
676  *
677  * SEMANTIC NOTES
678  *
679  * The discipline domain will not be IVL_DIS_NONE. The "none" domain
680  * is a place-holder internally for incomplete parsing, and is also
681  * available for code generators to use.
682  */
683 extern const char*ivl_discipline_name(ivl_discipline_t net);
684 extern ivl_dis_domain_t ivl_discipline_domain(ivl_discipline_t net);
685 extern ivl_nature_t ivl_discipline_potential(ivl_discipline_t net);
686 extern ivl_nature_t ivl_discipline_flow(ivl_discipline_t net);
687 
688 extern const char* ivl_nature_name(ivl_nature_t net);
689 
690 /* ENUMERATIONS
691  *
692  * Enumerations are a collections of symbolic names and vector
693  * values. The enumeration has a base type, and a list of names and
694  * values.
695  *
696  * FUNCTION SUMMARY
697  *
698  * ivl_enum_names
699  *    This is the number of enumeration names in the enum type.
700  *
701  * ivl_enum_name
702  *    Get the string name for an item in the enumeration
703  *
704  * ivl_enum_bits
705  *    Get the bits (lsb first) of the enumeration value. The width
706  *    of the enumeration should match the length of this string. Every
707  *    name also has bits that make up the value.
708  *
709  * ivl_enum_signed
710  *    Is the base type for the enum signed?
711  *
712  * ivl_enum_type
713  *    Get the data-type for the base type that the enum uses. This
714  *    will be either IVL_VT_BOOL or IVL_VT_LOGIC
715  *
716  * ivl_enum_width
717  *    Return the bit width of the base type for this enum type.
718  *
719  * SEMANTIC NOTES
720  */
721 extern unsigned ivl_enum_names(ivl_enumtype_t net);
722 extern const char*ivl_enum_name(ivl_enumtype_t net, unsigned idx);
723 extern const char*ivl_enum_bits(ivl_enumtype_t net, unsigned idx);
724 extern int ivl_enum_signed(ivl_enumtype_t net);
725 extern ivl_variable_type_t ivl_enum_type(ivl_enumtype_t net);
726 extern unsigned ivl_enum_width(ivl_enumtype_t net);
727 
728 extern const char*ivl_enum_file(ivl_enumtype_t net);
729 extern unsigned ivl_enum_lineno(ivl_enumtype_t net);
730 
731 /* EVENTS
732  *
733  * Events are a unification of named events and implicit events
734  * generated by the @ statements.
735  *
736  * FUNCTION SUMMARY
737  *
738  * ivl_event_name (Obsolete)
739  * ivl_event_basename
740  *    Return the name of the event. The basename is the name within
741  *    the scope, as declared by the user or generated by elaboration.
742  *
743  * ivl_event_scope
744  *    All events exist within a scope.
745  *
746  * SEMANTICS NOTES
747  *
748  * Named events (i.e. event objects declared by the Verilog
749  * declaration "event foo") are recognized by the fact that they have
750  * no edge sources. The name of the event as given in the Verilog
751  * source is available from the ivl_event_basename function.
752  *
753  * Named events are referenced in trigger statements.
754  *
755  * Named events have file and line number information.
756  *
757  * Edge events are created implicitly by the @(...) Verilog syntax to
758  * watch for the correct type of edge for the functor being
759  * watched. The nodes to watch are collected into groups based on the
760  * type of edge to be watched for on that node. For example, nodes to
761  * be watched for positive edges are accessed via the ivl_event_npos
762  * and ivl_event_pos functions.
763  */
764 extern const char* ivl_event_name(ivl_event_t net);
765 extern const char* ivl_event_basename(ivl_event_t net);
766 extern ivl_scope_t ivl_event_scope(ivl_event_t net);
767 
768 extern unsigned    ivl_event_nany(ivl_event_t net);
769 extern ivl_nexus_t ivl_event_any(ivl_event_t net, unsigned idx);
770 
771 extern unsigned    ivl_event_nneg(ivl_event_t net);
772 extern ivl_nexus_t ivl_event_neg(ivl_event_t net, unsigned idx);
773 
774 extern unsigned    ivl_event_npos(ivl_event_t net);
775 extern ivl_nexus_t ivl_event_pos(ivl_event_t net, unsigned idx);
776 
777 extern const char*ivl_event_file(ivl_event_t net);
778 extern unsigned ivl_event_lineno(ivl_event_t net);
779 
780 
781 /* EXPRESSIONS
782  *
783  * These methods operate on expression objects from the
784  * design. Expressions mainly exist in behavioral code. The
785  * ivl_expr_type() function returns the type of the expression node,
786  * and the remaining functions access value bits of the expression.
787  *
788  * ivl_expr_signed
789  *    This method returns true (!= 0) if the expression node
790  *    represents a signed expression. It is possible for sub-
791  *    expressions to be unsigned even if a node is signed, but the
792  *    IVL core figures all this out for you. At any rate, this method
793  *    can be applied to any expression node.
794  *
795  * ivl_expr_sized
796  *    This method returns false (0) if the expression node does not
797  *    have a defined size. This is unusual, but may happen for
798  *    constant expressions.
799  *
800  * ivl_expr_type
801  *    Get the type of the expression node. Every expression node has a
802  *    type, which can affect how some of the other expression methods
803  *    operate on the node
804  *
805  * ivl_expr_value
806  *    Get the data type of the expression node. This uses the variable
807  *    type enum to express the type of the expression node.
808  *
809  * ivl_expr_net_type
810  *    This is used in some cases to carry more advanced type
811  *    descriptions. Over the long run, all type information will be
812  *    moved into the ivl_type_t type description method.
813  *
814  * ivl_expr_width
815  *    This method returns the bit width of the expression at this
816  *    node. It can be applied to any expression node, and returns the
817  *    *output* width of the expression node.
818  *
819  * ivl_expr_parameter
820  *    This function returns the ivl_parameter_t object that represents
821  *    this object, or 0 (nil) if it is not a parameter value. This
822  *    function allows the code generator to detect the case where the
823  *    expression is a parameter. This will normally only return a
824  *    non-nil value for constants.
825  *
826  * ivl_expr_opcode
827  *    IVL_EX_BINARY and IVL_EX_UNARY expression nodes include an
828  *    opcode from this table:
829  *              &   -- AND
830  *              A   -- NAND (~&)
831  *              X   -- XNOR (~^)
832  *              *   -- Multiply
833  *
834  * SEMANTIC NOTES
835  *
836  * - IVL_EX_ARRAY
837  * This expression type is a special case of the IVL_EX_SIGNAL where
838  * the target is an array (ivl_signal_t with an array_count) but there
839  * is no index expression. This is used only in the special situation
840  * where the array is passed to a system task/function. The function
841  * ivl_expr_signal returns the ivl_signal_t of the array object, and
842  * from that all the properties of the array can be determined.
843  *
844  * - IVL_EX_BINARY
845  *
846  * - IVL_EX_PROPERTY
847  * This expression represents the property select from a class
848  * type, for example "foo.property" where "foo" is a class handle and
849  * "property" is the name of one of the properties of the class. The
850  * ivl_expr_signal function returns the ivl_signal_t for "foo" and the
851  * data_type for the signal will be IVL_VT_CLASS.
852  *
853  * The ivl_signal_net_type(sig) for the "foo" signal will be a class
854  * type and from there you can get access to the type information.
855  *
856  * Elaboration reduces the properties of a class to a vector numbered
857  * from 0 to the number of properties. The ivl_expr_property_idx()
858  * function gets the index of the selected property into the property
859  * table. That number can be passed to ivl_type_prop_*() functions to
860  * get details about the property.
861  *
862  * If the property is an array, then the ivl_expr_oper1() function
863  * returns the canonical expression for accessing the element of the
864  * property.
865  *
866  * - IVL_EX_NEW
867  * This expression takes one or two operands. The first operand,
868  * returned by ivl_expr_oper1() is the number of elements to create
869  * for the dynamic array. The second operand, if present, is returned
870  * by the ivl_expr_oper2() function. If this returns a non-nil
871  * expression, it is the initial value to be written to the elements
872  * of the array. If the expression is an IVL_EX_ARRAY_PATTERN, then
873  * this is the very special case of a list of values to be written to
874  * array elements.
875  *
876  * - IVL_EX_SELECT
877  * This expression takes two operands, oper1 is the expression to
878  * select from, and oper2 is the selection base. The ivl_expr_width
879  * value is the width of the bit/part select. The ivl_expr_oper1 value
880  * is the base of a vector. The compiler has already figured out any
881  * conversion from signal units to vector units, so the result of
882  * ivl_expr_oper1 should range from 0 to ivl_expr_width().
883  *
884  * This expression is also used to implement string substrings. If the
885  * sub-expression (oper1) is IVL_VT_STRING, then the base expression
886  * (oper2) is a character address, with 0 the first address of the
887  * string, 1 the second, and so on. This is OPPOSITE how a part select
888  * of a string cast to a vector works, to be aware. The size of the
889  * expression is an even multiple of 8, and is 8 times the number of
890  * characters to pick.
891  *
892  * - IVL_EX_SIGNAL
893  * This expression references a signal vector. The ivl_expr_signal
894  * function gets a handle for the signal that is referenced. The
895  * signal may be an array (see the ivl_signal_array_count function)
896  * that is addressed by the expression returned by the ivl_expr_oper1
897  * function. This expression returns a *canonical* address. The core
898  * compiler already corrected the expression to account for index
899  * bases.
900  *
901  * The ivl_expr_width function returns the vector width of the signal
902  * word. The ivl_expr_value returns the data type of the word.
903  *
904  * Bit and part selects are not done here. The IVL_EX_SELECT
905  * expression does bit/part selects on the word read from the signal.
906  *
907  * - IVL_EX_STRING
908  * This expression refers to a string constant. The ivl_expr_string
909  * function returns a pointer to the first byte of the string. The
910  * compiler has translated it to a "vvp escaped string" which has
911  * quoting and escapes eliminated. The string may contain octal
912  * escapes (\<oct>) so that the string text returned by
913  * ivl_expr_string will only contain graphical characters. It is up to
914  * the target to change the escaped \NNN to the proper byte value when
915  * using this string. No other escape sequences will appear in the
916  * string. Quote (") and slash (\) characters will be delivered in
917  * \NNN form.
918  */
919 
920 extern ivl_expr_type_t ivl_expr_type(ivl_expr_t net);
921 extern ivl_type_t ivl_expr_net_type(ivl_expr_t net);
922 extern ivl_variable_type_t ivl_expr_value(ivl_expr_t net);
923 extern const char*ivl_expr_file(ivl_expr_t net);
924 extern unsigned ivl_expr_lineno(ivl_expr_t net);
925 
926   /* IVL_EX_NUMBER */
927 extern const char* ivl_expr_bits(ivl_expr_t net);
928   /* IVL_EX_BACCESS */
929 extern ivl_branch_t ivl_expr_branch(ivl_expr_t net);
930   /* IVL_EX_UFUNC */
931 extern ivl_scope_t ivl_expr_def(ivl_expr_t net);
932   /* IVL_EX_DELAY */
933 extern uint64_t ivl_expr_delay_val(ivl_expr_t net);
934   /* IVL_EX_REALNUM */
935 extern double ivl_expr_dvalue(ivl_expr_t net);
936   /* IVL_EX_ENUMTYPE */
937 extern ivl_enumtype_t ivl_expr_enumtype(ivl_expr_t net);
938   /* IVL_EX_PROPERTY IVL_EX_SIGNAL IVL_EX_SFUNC IVL_EX_VARIABLE */
939 extern const char* ivl_expr_name(ivl_expr_t net);
940   /* IVL_EX_BACCESS */
941 extern ivl_nature_t ivl_expr_nature(ivl_expr_t net);
942   /* IVL_EX_BINARY IVL_EX_UNARY */
943 extern char        ivl_expr_opcode(ivl_expr_t net);
944   /* IVL_EX_BINARY  IVL_EX_UNARY, IVL_EX_MEMORY IVL_EX_NEW IVL_EX_TERNARY */
945 extern ivl_expr_t  ivl_expr_oper1(ivl_expr_t net);
946   /* IVL_EX_BINARY IVL_EX_NEW IVL_EX_TERNARY */
947 extern ivl_expr_t  ivl_expr_oper2(ivl_expr_t net);
948   /* IVL_EX_TERNARY */
949 extern ivl_expr_t  ivl_expr_oper3(ivl_expr_t net);
950   /* and expression */
951 extern ivl_parameter_t ivl_expr_parameter(ivl_expr_t net);
952   /* IVL_EX_ARRAY_PATTERN IVL_EX_CONCAT IVL_EX_UFUNC */
953 extern ivl_expr_t  ivl_expr_parm(ivl_expr_t net, unsigned idx);
954   /* IVL_EX_ARRAY_PATTERN IVL_EX_CONCAT IVL_EX_SFUNC IVL_EX_UFUNC */
955 extern unsigned    ivl_expr_parms(ivl_expr_t net);
956   /* IVL_EX_CONCAT */
957 extern unsigned    ivl_expr_repeat(ivl_expr_t net);
958   /* IVL_EX_SELECT */
959 extern ivl_select_type_t ivl_expr_sel_type(ivl_expr_t net);
960   /* IVL_EX_EVENT */
961 extern ivl_event_t ivl_expr_event(ivl_expr_t net);
962   /* IVL_EX_PROPERTY */
963 extern int ivl_expr_property_idx(ivl_expr_t net);
964   /* IVL_EX_SCOPE */
965 extern ivl_scope_t ivl_expr_scope(ivl_expr_t net);
966   /* IVL_EX_PROPERTY IVL_EX_SIGNAL */
967 extern ivl_signal_t ivl_expr_signal(ivl_expr_t net);
968   /* any expression */
969 extern int         ivl_expr_signed(ivl_expr_t net);
970   /* any expression */
971 extern int         ivl_expr_sized(ivl_expr_t net);
972   /* IVL_EX_STRING */
973 extern const char* ivl_expr_string(ivl_expr_t net);
974   /* IVL_EX_ULONG */
975 extern unsigned long ivl_expr_uvalue(ivl_expr_t net);
976   /* any expression */
977 extern unsigned    ivl_expr_width(ivl_expr_t net);
978 
979 extern const char* ivl_file_table_item(unsigned  idx);
980 extern unsigned ivl_file_table_index(const char *);
981 extern unsigned ivl_file_table_size(void);
982 
983 
984 /* ISLAND
985  *
986  * ivl_island_flag_set
987  * ivl_island_flag_test
988  *    Allow the user to test or set a boolean flag associated with the
989  *    island.
990  */
991 extern int ivl_island_flag_set(ivl_island_t net, unsigned flag, int value);
992 extern int ivl_island_flag_test(ivl_island_t net, unsigned flag);
993 
994 extern const char* ivl_logic_file(ivl_net_logic_t net);
995 extern unsigned ivl_logic_lineno(ivl_net_logic_t net);
996 
997 /* LOGIC
998  * These types and functions support manipulation of logic gates. The
999  * ivl_logic_t enumeration identifies the various kinds of gates that
1000  * the ivl_net_logic_t can represent. The various functions then
1001  * provide access to the bits of information for a given logic device.
1002  *
1003  * The ivl_net_logic_t nodes are bit-slice devices. That means that
1004  * the device may have width (and therefore processes vectors) but
1005  * each bit slice of the width is independent.
1006  *
1007  * ivl_logic_type
1008  *    This method returns the type of logic gate that the node
1009  *    represents. The logic type implies the meaning of the various pins.
1010  *
1011  * ivl_logic_name (obsolete)
1012  *    This method returns the complete name of the logic gate. Every
1013  *    gate has a complete name (that includes the scope) even if the
1014  *    Verilog source doesn't include one. The compiler will choose one
1015  *    if necessary.
1016  *
1017  * ivl_logic_basename
1018  *    This is the name of the gate without the scope part.
1019  *
1020  * ivl_logic_scope
1021  *    This is the scope that directly contains the logic device.
1022  *
1023  * ivl_logic_pins
1024  * ivl_logic_pin
1025  *    Return the nexus for the pin. If two pins are connected
1026  *    together, then these values are the same. Use the nexus
1027  *    functions to find other pins that are connected to this nexus.
1028  *
1029  * ivl_logic_width
1030  *    This returns the width of the logic array. This does not affect
1031  *    the number of pins, but implies the width of the vector at each
1032  *    pin.
1033  *
1034  * ivl_logic_delay
1035  *    Logic devices have a delay for each transition (0, 1 and Z).
1036  *
1037  * ivl_logic_attr (obsolete)
1038  *    Return the value of a specific attribute, given the key name as
1039  *    a string. If the key is not defined, then return 0 (null).
1040  *
1041  * ivl_logic_attr_cnt
1042  * ivl_logic_attr_val
1043  *    These support iterating over logic attributes. The _cnt method
1044  *    returns the number of attributes attached to the gate, and the
1045  *    ivl_logic_attr_val returns the value of the attribute.
1046  *
1047  * SEMANTIC NOTES
1048  * The ivl_logic_width applies to all the pins of a logic device. If a
1049  * logic device has width, that means that it is actually an array of
1050  * logic devices that each process a bit slice of the
1051  * inputs/output. That implies that the widths of all the inputs and
1052  * the output must be identical.
1053  *
1054  * The ivl_logic_width  and ivl_logic_pins are *not* related. A logic
1055  * device has a number of pins that is the number of inputs to a logic
1056  * array of identical gates, and the ivl_logic_width, is the width of
1057  * the vector into each input pin and out of the output pin.
1058  *
1059  * The output pin is pin-0. The ivl_logic_driveX functions return the
1060  * drive strengths for the output pin-0, and match the drive values
1061  * stored in the ivl_nexus_ptr_t object for the pin.
1062  *
1063  * Logic devices have a logic propagation delay. The delay can be any
1064  * expression, although the most common expression is an IVL_EX_NUMBER
1065  * for a number value. The expression already includes scaling for the
1066  * containing module, so the delay value is always taken to be in
1067  * simulation clock ticks.
1068  *
1069  * If the delay is present, then ivl_logic_delay returns a non-nil
1070  * object. If any of the three delays is present, then all three are
1071  * present, even if they are all the same. The compiler will translate
1072  * shorthands into a complete set of delay expressions.
1073  *
1074  * The ivl_logic_delay expression will always be an IVL_EX_NUMBER, an
1075  * IVL_EX_ULONG, or an IVL_EX_SIGNAL. These expressions can easily be
1076  * used in structural contexts. The compiler will take care of
1077  * elaborating more complex expressions to nets.
1078  *
1079  * - IVL_LO_PULLUP/IVL_LO_PULLDOWN
1080  * These devices are grouped as logic devices with zero inputs because
1081  * the outputs have the same characteristics as other logic
1082  * devices. They are special only in that they have zero inputs, and
1083  * their drivers typically have strength other than strong.
1084  *
1085  * - IVL_LO_UDP
1086  * User defined primitives (UDPs) are like any other logic devices, in
1087  * that they are bit-slice devices. If they have a width, then they
1088  * are repeated to accommodate that width, and that implies that the
1089  * output and all the inputs must have the same width.
1090  *
1091  * The IVL_LO_UDP represents instantiations of UDP devices. The
1092  * ivl_udp_t describes the implementation.
1093  */
1094 
1095 extern const char* ivl_logic_name(ivl_net_logic_t net);
1096 extern const char* ivl_logic_basename(ivl_net_logic_t net);
1097 extern ivl_scope_t ivl_logic_scope(ivl_net_logic_t net);
1098 extern ivl_logic_t ivl_logic_type(ivl_net_logic_t net);
1099 extern ivl_nexus_t ivl_logic_pin(ivl_net_logic_t net, unsigned pin);
1100 extern unsigned    ivl_logic_pins(ivl_net_logic_t net);
1101 extern ivl_udp_t   ivl_logic_udp(ivl_net_logic_t net);
1102 extern ivl_expr_t  ivl_logic_delay(ivl_net_logic_t net, unsigned transition);
1103 extern ivl_drive_t ivl_logic_drive0(ivl_net_logic_t net);
1104 extern ivl_drive_t ivl_logic_drive1(ivl_net_logic_t net);
1105 extern unsigned    ivl_logic_width(ivl_net_logic_t net);
1106 extern unsigned    ivl_logic_is_cassign(ivl_net_logic_t net);
1107 
1108   /* DEPRECATED */
1109 extern const char* ivl_logic_attr(ivl_net_logic_t net, const char*key);
1110 
1111 extern unsigned        ivl_logic_attr_cnt(ivl_net_logic_t net);
1112 extern ivl_attribute_t ivl_logic_attr_val(ivl_net_logic_t net, unsigned idx);
1113 
1114 /* UDP
1115  * These methods allow access to the ivl_udp_t definition of a UDP.
1116  * The UDP definition is accessed through the ivl_logic_udp method of
1117  * an ivl_net_logic_t object.
1118  *
1119  * ivl_udp_name
1120  *    This returns the name of the definition of the primitive.
1121  *
1122  * ivl_udp_nin
1123  *    This is the number of inputs for the UDP definition.
1124  *
1125  * ivl_udp_rows
1126  * ivl_udp_row
1127  *    These methods give access to the rows that define the table of
1128  *    the primitive.
1129  *
1130  * SEMANTIC NOTES
1131  *
1132  * - Combinational primitives
1133  * These devices have no edge dependencies, and have no table entry
1134  * for the current input value. These have ivl_udp_sequ return 0
1135  * (false) and the length of each row is the number of inputs plus 1.
1136  * The first N characters correspond to the N inputs of the
1137  * device. The next character, the last character, is the output for
1138  * that row.
1139  *
1140  * - Sequential primitives
1141  * These devices allow edge transitions, and the rows are 1+N+1
1142  * characters long. The first character is the current output, the
1143  * next N characters the current input and the last character is the
1144  * new output.
1145  *
1146  * The ivl_udp_init value is only valid if the device is
1147  * sequential. It is the initial value for the output of the storage
1148  * element.
1149  */
1150 
1151 extern int         ivl_udp_sequ(ivl_udp_t net);
1152 extern unsigned    ivl_udp_nin(ivl_udp_t net);
1153 extern char        ivl_udp_init(ivl_udp_t net);
1154 extern const char* ivl_udp_row(ivl_udp_t net, unsigned idx);
1155 extern unsigned    ivl_udp_rows(ivl_udp_t net);
1156 extern const char* ivl_udp_name(ivl_udp_t net);
1157 extern const char* ivl_udp_file(ivl_udp_t net);
1158 extern unsigned    ivl_udp_lineno(ivl_udp_t net);
1159 extern const char* ivl_udp_port(ivl_udp_t net, unsigned idx);
1160 
1161 extern const char* ivl_lpm_file(ivl_lpm_t net);
1162 extern unsigned    ivl_lpm_lineno(ivl_lpm_t net);
1163 
1164 /* LPM
1165  * These functions support access to the properties of LPM
1166  * devices. LPM devices are a variety of devices that handle more
1167  * complex structural semantics. They are based on EIA LPM standard
1168  * devices, but vary to suite the technical situation.
1169  *
1170  * These are the functions that apply to all LPM devices:
1171  *
1172  * ivl_lpm_name (Obsolete)
1173  * ivl_lpm_basename
1174  *    Return the name of the device. The name is the name of the
1175  *    device with the scope part, and the basename is without the scope.
1176  *
1177  * ivl_lpm_delay
1178  *    LPM devices have a delay for each transition (0, 1 and Z).
1179  *
1180  * ivl_lpm_scope
1181  *    LPM devices exist within a scope. Return the scope that contains
1182  *    this device.
1183  *
1184  * ivl_lpm_type
1185  *    Return the ivl_lpm_type_t of the specific LPM device.
1186  *
1187  * ivl_lpm_width
1188  *    Return the width of the LPM device. What this means depends on
1189  *    the LPM type, but it generally has to do with the width of the
1190  *    output data path.
1191  *
1192  *
1193  * These functions apply to a subset of the LPM devices, or may have
1194  * varying meaning depending on the device:
1195  *
1196  * ivl_lpm_base
1197  *    The IVL_LPM_PART objects use this value as the base (first bit)
1198  *    of the part select. The ivl_lpm_width is the size of the part.
1199  *
1200  * ivl_lpm_data
1201  *    Return the input data nexus for device types that have input
1202  *    vectors. The "idx" parameter selects which data input is selected.
1203  *
1204  * ivl_lpm_datab (ANACHRONISM)
1205  *    This is the same as ivl_lpm_data(net,1), in other words the
1206  *    second data input. Use the ivl_lpm_data method instead.
1207  *
1208  * ivl_lpm_q
1209  *    Return the output data nexus for device types that have a single
1210  *    output vector. This is most devices, it turns out.
1211  *
1212  * ivl_lpm_selects
1213  *    This is the size of the select input for a LPM_MUX device, or the
1214  *    address bus width of an LPM_RAM.
1215  *
1216  * ivl_lpm_signed
1217  *    Arithmetic LPM devices may be signed or unsigned if there is a
1218  *    distinction. For some devices this gives the signedness of the
1219  *    output, but not all devices.
1220  *
1221  * ivl_lpm_size
1222  *    In addition to a width, some devices have a size. The size is
1223  *    often the number of inputs per out, i.e., the number of inputs
1224  *    per bit for a MUX.
1225  *
1226  * ivl_lpm_trigger
1227  *    SFUNC and UFUNC devices may have a trigger that forces the
1228  *    function output to be re-evaluated.
1229  *
1230  * SEMANTIC NOTES
1231  *
1232  * - Concatenation (IVL_LPM_CONCAT)
1233  * These devices take vectors in and combine them to form a single
1234  * output the width specified by ivl_lpm_width.
1235  *
1236  * The ivl_lpm_q nexus is the output from the concatenation.
1237  *
1238  * The ivl_lpm_data function returns the connections for the inputs to
1239  * the concatenation. The ivl_lpm_size function returns the number of
1240  * inputs help by the device.
1241  *
1242  * - Divide (IVL_LPM_DIVIDE)
1243  * The divide operators take two inputs and generate an output. The
1244  * ivl_lpm_width returns the width of the result. The width of the
1245  * inputs are their own.
1246  *
1247  * - Multiply (IVL_LPM_MULT)
1248  * The multiply takes two inputs and generates an output. Unlike other
1249  * arithmetic nodes, the width only refers to the output. The inputs
1250  * have independent widths, to reflect the arithmetic truth that the
1251  * width of a general multiply is the sum of the widths of the
1252  * inputs. In fact, the compiler doesn't assure that the widths of the
1253  * inputs add up to the width of the output, but the possibility
1254  * exists. It is *not* an error for the sum of the input widths to be
1255  * more than the width of the output, although the possibility of
1256  * overflow exists at run time.
1257  *
1258  * The inputs are always treated as unsigned. If the expression is
1259  * supposed to be signed, elaboration will generate the necessary sign
1260  * extension, so the target need not (must not) consider signedness.
1261  *
1262  * - Power (IVL_LPM_POW)
1263  * The power takes two inputs and generates an output. Unlike other
1264  * arithmetic nodes, the width only refers to the output. The inputs
1265  * have independent widths, to reflect the arithmetic truth that the
1266  * width of a general power is the XXXX of the widths of the
1267  * inputs.
1268  *
1269  * Power may be signed. This indicates the type of the exponent. The
1270  * base will always be treated as unsigned. The compiler must ensure
1271  * the width of the base is equal to the width of the output to
1272  * obtain the correct result when the base is really a signed value.
1273  *
1274  * - Part Select (IVL_LPM_PART_VP and IVL_LPM_PART_PV)
1275  * There are two part select devices, one that extracts a part from a
1276  * vector, and another that writes a part of a vector. The _VP is
1277  * Vector-to-Part, and _PV is Part-to-Vector. The _VP form is meant to
1278  * model part/bin selects in r-value expressions, where the _PV from
1279  * is meant to model part selects in l-value nets.
1280  *
1281  * In both cases, ivl_lpm_data(0) is the input pin, and ivl_lpm_q is the
1282  * output. In the case of the _VP device, the vector is input and the
1283  * part is the output. In the case of the _PV device, the part is the
1284  * input and the vector is the output.
1285  *
1286  * If the base of the part select is non-constant, then
1287  * ivl_lpm_data(1) is non-nil and is the select, or base, address of
1288  * the part. If this pin is nil, then the constant base is used
1289  * instead.
1290  *
1291  * Also in both cases, the width of the device is the width of the
1292  * part. In the _VP case, this is obvious as the output nexus has the
1293  * part width. In the _PV case, this is a little less obvious, but
1294  * still correct. The output being written to the wider vector is
1295  * indeed the width of the part, even though it is written to a wider
1296  * gate. The target will need to handle this case specially.
1297  *
1298  * - Bi-directional Part Select (IVL_LPM_PART_BI)
1299  * This is not exactly a part select but a bi-directional partial link
1300  * of two nexa with different widths. This is used to implement tran
1301  * devices and inout ports in certain cases. The device width is the
1302  * width of the part. The ivl_lpm_q is the part end, and the
1303  * ivl_lpm_data(0) is the non-part end.
1304  *
1305  * - Comparisons (IVL_LPM_CMP_GT/GE/EQ/NE/EEQ/NEE/EQX/EQZ)
1306  * These devices have two inputs, available by the ivl_lpm_data()
1307  * function, and one output available by the ivl_lpm_q function. The
1308  * output width is always 1, but the ivl_lpm_width() returns the width
1309  * of the inputs. Both inputs must have the same width.
1310  *
1311  * The CMP_GE and CMP_GT nodes may also be signed or unsigned, with
1312  * the obvious implications. The widths are matched by the compiler
1313  * (so the target need not worry about sign extension) but when doing
1314  * magnitude compare, the signedness does matter. In any case, the
1315  * result of the compare is always unsigned.
1316  *
1317  * The EQX and EQZ nodes are wildcard compares, where xz bits (EQX) or
1318  * z bits (EQZ) in the data(1) operand are treated as wildcards. no
1319  * bits in the data(0) operand are wild. This matches the
1320  * SystemVerilog convention for the ==? operator.
1321  *
1322  * - Mux Device (IVL_LPM_MUX)
1323  * The MUX device has a q output, a select input, and a number of data
1324  * inputs. The ivl_lpm_q output and the ivl_lpm_data inputs all have
1325  * the width from the ivl_lpm_width() method. The Select input, from
1326  * ivl_lpm_select, has the width ivl_lpm_selects().
1327  *
1328  * The ivl_lpm_data() method returns the inputs of the MUX device. The
1329  * ivl_lpm_size() method returns the number of data inputs there
1330  * are. All the data inputs have the same width, the width of the
1331  * ivl_lpm_q output. The type of the device is divined from the
1332  * inputs and the Q. All the types must be exactly the same.
1333  *
1334  * - D-FlipFlop (IVL_LPM_FF)
1335  * This device is an edge sensitive register. The ivl_lpm_q output and
1336  * single ivl_lpm_data input are the same width, ivl_lpm_width. This
1337  * device carries a vector like other LPM devices.
1338  *
1339  * - Latch (IVL_LPM_LATCH)
1340  * This device is an asynchronous latch. The ivl_lpm_q output and
1341  * single ivl_lpm_data input are the same width, ivl_lpm_width. This
1342  * device carries a vector like other LPM devices.
1343  *
1344  * - Memory port (IVL_LPM_RAM) (deprecated in favor of IVL_LPM_ARRAY)
1345  * These are structural ports into a memory device. They represent
1346  * address/data ports of a memory device that the context can hook to
1347  * for read or write. Read devices have an ivl_lpm_q output port that
1348  * is the data being read.
1349  *
1350  * The ivl_lpm_memory function returns the ivl_memory_t for the memory
1351  * that the port access. The ivl_lpm_width for the port then must
1352  * match the ivl_memory_width of the memory device.
1353  *
1354  * Read or write, the ivl_lpm_select nexus is the address. The
1355  * ivl_lpm_selects function returns the vector width of the
1356  * address. The range of the address is always from 0 to the memory
1357  * size-1 -- the canonical form. It is up to the compiler to generate
1358  * offsets to correct for a range declaration.
1359  *
1360  * Read ports use the ivl_lpm_q as the data output, and write ports
1361  * use the ivl_lpm_data(0) as the input. In either case the width of
1362  * the vector matches the width of the memory itself.
1363  *
1364  * - Reduction operators (IVL_LPM_RE_*)
1365  * These devices have one input, a vector, and generate a single bit
1366  * result. The width from the ivl_lpm_width is the width of the input
1367  * vector.
1368  *
1369  * - Repeat Node (IVL_LPM_REPEAT)
1370  * This node takes as input a single vector, and outputs a single
1371  * vector. The ivl_lpm_width if this node is the width of the *output*
1372  * vector. The ivl_lpm_size() returns the number of times the input is
1373  * repeated to get the desired width. The ivl core assures that the
1374  * input vector is exactly ivl_lpm_width() / ivl_lpm_size() bits.
1375  *
1376  * - Sign Extend (IVL_LPM_SIGN_EXT)
1377  * This node takes a single input and generates a single output. The
1378  * input must be signed, and the output will be a vector sign extended
1379  * to the desired width. The ivl_lpm_width() value is the output
1380  * width, the input will be whatever it wants to be.
1381  *
1382  * - Shifts (IVL_LPM_SHIFTL/SHIFTR)
1383  * This node takes two inputs, a vector and a shift distance. The
1384  * ivl_lpm_data(0) nexus is the vector input, and the ivl_lpm_data(1)
1385  * the shift distance. The vector input is the same width as the
1386  * output, but the distance has its own width.
1387  *
1388  * The ivl_lpm_signed() flag means for IVL_LPM_SHIFTR that the right
1389  * shift is *signed*. For SHIFTL, then signed-ness is meaningless.
1390  *
1391  * - System function call (IVL_LPM_SFUNC)
1392  * This device represents a netlist call to a system function. The
1393  * inputs to the device are passed to a system function, and the
1394  * result is sent via the output. The ivl_lpm_q function returns the
1395  * output nexus.
1396  *
1397  * The ivl_lpm_size function returns the number of arguments, and the
1398  * ivl_lpm_data(net,N) returns the nexa for the argument.
1399  *
1400  * The ivl_lpm_string(net) function returns the name of the system
1401  * function (i.e. "$display") that was found in the source code. The
1402  * compiler does little checking of that name.
1403  *
1404  * The ivl_lpm_trigger function retrieves the trigger event that
1405  * indicates when the system function needs to be re-evaluated. If
1406  * there is no trigger event, the system function only needs to be
1407  * re-evaluated when a change is detected on its input ports.
1408  *
1409  * - User Function Call (IVL_LPM_UFUNC)
1410  * This device is special as it represents a call to a user defined
1411  * function (behavioral code) within a netlist. The inputs to the
1412  * function are connected to the net, as is the output.
1413  *
1414  * The function definition is associated with a scope, and the
1415  * ivl_lpm_define function returns the scope that is that definition.
1416  * See the ivl_scope_* functions for how to get at the actual
1417  * definition.
1418  *
1419  * As with many LPM nodes, the ivl_lpm_q function returns the nexus
1420  * for the signal function return value. The width of this nexus must
1421  * exactly match the width of the device from ivl_lpm_width.
1422  *
1423  * The ivl_lpm_data function retrieves the nexa for all the input
1424  * ports. The ivl_lpm_size function returns the number of inputs for
1425  * the device, and the ivl_lpm_data() function index argument selects
1426  * the port to retrieve. Each port is sized independently.
1427  *
1428  * The ivl_lpm_trigger function retrieves the trigger event that
1429  * indicates when the user function needs to be re-evaluated. If
1430  * there is no trigger event, the user function only needs to be
1431  * re-evaluated when a change is detected on its input ports.
1432  */
1433 
1434 extern const char*    ivl_lpm_name(ivl_lpm_t net); /* (Obsolete) */
1435 extern const char*    ivl_lpm_basename(ivl_lpm_t net);
1436 extern ivl_expr_t     ivl_lpm_delay(ivl_lpm_t net, unsigned transition);
1437 extern ivl_scope_t    ivl_lpm_scope(ivl_lpm_t net);
1438 extern int            ivl_lpm_signed(ivl_lpm_t net);
1439 extern ivl_lpm_type_t ivl_lpm_type(ivl_lpm_t net);
1440 extern unsigned       ivl_lpm_width(ivl_lpm_t net);
1441 extern ivl_event_t    ivl_lpm_trigger(ivl_lpm_t net);
1442 
1443   /* IVL_LPM_FF */
1444 extern ivl_nexus_t ivl_lpm_async_clr(ivl_lpm_t net);
1445 extern ivl_nexus_t ivl_lpm_async_set(ivl_lpm_t net);
1446 extern ivl_expr_t  ivl_lpm_aset_value(ivl_lpm_t net);
1447 extern ivl_nexus_t ivl_lpm_sync_clr(ivl_lpm_t net);
1448 extern ivl_nexus_t ivl_lpm_sync_set(ivl_lpm_t net);
1449 extern ivl_expr_t  ivl_lpm_sset_value(ivl_lpm_t net);
1450   /* IVL_LPM_ARRAY */
1451 extern ivl_signal_t ivl_lpm_array(ivl_lpm_t net);
1452   /* IVL_LPM_PART IVL_LPM_SUBSTITUTE */
1453 extern unsigned ivl_lpm_base(ivl_lpm_t net);
1454   /* IVL_LPM_FF */
1455 extern unsigned    ivl_lpm_negedge(ivl_lpm_t net);
1456 extern ivl_nexus_t ivl_lpm_clk(ivl_lpm_t net);
1457   /* IVL_LPM_UFUNC */
1458 extern ivl_scope_t  ivl_lpm_define(ivl_lpm_t net);
1459   /* IVL_LPM_FF IVL_LPM_LATCH*/
1460 extern ivl_nexus_t ivl_lpm_enable(ivl_lpm_t net);
1461   /* IVL_LPM_ADD IVL_LPM_CONCAT IVL_LPM_FF IVL_LPM_PART IVL_LPM_MULT
1462      IVL_LPM_MUX IVL_LPM_POW IVL_LPM_SHIFTL IVL_LPM_SHIFTR IVL_LPM_SUB
1463      IVL_LPM_UFUNC IVL_LPM_SUBSTITUTE IVL_LPM_LATCH */
1464 extern ivl_nexus_t ivl_lpm_data(ivl_lpm_t net, unsigned idx);
1465   /* IVL_LPM_ADD IVL_LPM_MULT IVL_LPM_POW IVL_LPM_SUB IVL_LPM_CMP_EQ
1466      IVL_LPM_CMP_EEQ IVL_LPM_CMP_EQX IVL_LPM_CMP_EQZ IVL_LPM_CMP_NEE */
1467 extern ivl_nexus_t ivl_lpm_datab(ivl_lpm_t net, unsigned idx);
1468   /* IVL_LPM_ADD IVL_LPM_FF IVL_LPM_MULT IVL_LPM_PART IVL_LPM_POW
1469      IVL_LPM_SUB IVL_LPM_UFUNC IVL_LPM_CMP_EEQ IVL_LPM_CMP_EQX
1470      IVL_LPM_CMP_EQZ IVL_LPM_CMP_NEE IVL_LPM_SUBSTITUTE IVL_LPM_LATCH */
1471 extern ivl_nexus_t ivl_lpm_q(ivl_lpm_t net);
1472 extern ivl_drive_t ivl_lpm_drive0(ivl_lpm_t net);
1473 extern ivl_drive_t ivl_lpm_drive1(ivl_lpm_t net);
1474   /* IVL_LPM_MUX */
1475 extern unsigned ivl_lpm_selects(ivl_lpm_t net);
1476   /* IVL_LPM_MUX */
1477 extern ivl_nexus_t ivl_lpm_select(ivl_lpm_t net);
1478   /* IVL_LPM_CONCAT IVL_LPM_MUX IVL_LPM_REPEAT IVL_LPM_UFUNC */
1479 extern unsigned ivl_lpm_size(ivl_lpm_t net);
1480   /* IVL_LPM_SFUNC */
1481 extern const char*ivl_lpm_string(ivl_lpm_t net);
1482 
1483 /* LVAL
1484  * The l-values of assignments are concatenation of ivl_lval_t
1485  * objects. Each lvi_lval_t object is an assignment to a var or a
1486  * memory, through a bit select, part select or word select.
1487  *
1488  * Var lvals are things like assignments to a part select or a bit
1489  * select. Assignment to the whole variable is a special case of a
1490  * part select, as is a bit select with a constant expression.
1491  *
1492  * ivl_lval_width
1493  *    The width of a vector that this lval can receive. This accounts
1494  *    for the local part selecting I might to in the lval object, as
1495  *    well as the target object width.
1496  *
1497  * ivl_lval_mux (* obsolete *)
1498  *
1499  * ivl_lval_nest
1500  *    If the l-value is an object more complex than a variable, then
1501  *    this returns the nested l-value (and ivl_lval_sig==0).
1502  *
1503  * ivl_lval_sig
1504  *    If the l-value is a variable, this method returns the signal
1505  *    object that is the target of the assign.
1506  *
1507  * ivl_lval_part_off
1508  *    The part select of the signal is based here. This is the
1509  *    canonical index of bit-0 of the part select. The return value is
1510  *    an ivl_expr_t. If the return value is nil, then take the offset
1511  *    as zero. Otherwise, evaluate the expression to get the offset.
1512  *
1513  * ivl_lval_idx
1514  *    If the l-value is a memory, this method returns an
1515  *    ivl_expr_t that represents the index expression.  Otherwise, it
1516  *    returns 0.
1517  *
1518  * ivl_lval_property_idx
1519  *    If the l-value is a class object, this is the name of a property
1520  *    to select from the object. If this property is not present (<0)
1521  *    then the l-value represents the class object itself.
1522  *
1523  * SEMANTIC NOTES
1524  * The ivl_lval_width is not necessarily the same as the width of the
1525  * signal or memory word it represents. It is the width of the vector
1526  * it receives and assigns. This may be less than the width of the
1527  * signal (or even 1) if only a part of the l-value signal is to be
1528  * assigned.
1529  *
1530  * The ivl_lval_part_off is the canonical base of a part or
1531  * bit select.
1532  *
1533  * - Array words
1534  * If the l-value is an array, then ivl_lval_idx function will return
1535  * an expression that calculates the address of the array word. If
1536  * the referenced signal has more than one word, this expression must
1537  * be present. If the signal has exactly one word (it is not an array)
1538  * then the ivl_lval_idx expression must *not* be present.
1539  *
1540  * For array words, the ivl_lval_width is the width of the word.
1541  *
1542  * - Arrayed properties
1543  * If the l-value is a class property, then the ivl_lval_idx function
1544  * will return an expression if the property is in fact arrayed. The
1545  * expression is the canonical index for elements in the property.
1546  */
1547 
1548 extern unsigned    ivl_lval_width(ivl_lval_t net);
1549 extern ivl_expr_t  ivl_lval_mux(ivl_lval_t net) __attribute__((deprecated)); /* XXXX Obsolete? */
1550 extern ivl_expr_t  ivl_lval_idx(ivl_lval_t net);
1551 extern ivl_expr_t  ivl_lval_part_off(ivl_lval_t net);
1552 extern ivl_select_type_t ivl_lval_sel_type(ivl_lval_t net);
1553 extern int ivl_lval_property_idx(ivl_lval_t net);
1554 extern ivl_signal_t ivl_lval_sig(ivl_lval_t net);
1555 extern ivl_lval_t  ivl_lval_nest(ivl_lval_t net);
1556 
1557 
1558 /* NEXUS
1559  * connections of signals and nodes is handled by single-bit
1560  * nexus. These functions manage the ivl_nexus_t object. They also
1561  * manage the ivl_nexus_ptr_t objects that are closely related to the
1562  * nexus.
1563  *
1564  * ivl_nexus_name
1565  *    Each nexus is given a name, typically derived from the signals
1566  *    connected to it, but completely made up if need be. The name of
1567  *    every nexus is unique.
1568  *
1569  * ivl_nexus_ptrs
1570  *    This function returns the number of pointers that are held by
1571  *    the nexus. It should always return at least 1. The pointer
1572  *    proper is accessed by index.
1573  *
1574  * ivl_nexus_ptr
1575  *    Return a nexus pointer given the nexus and an index.
1576  *
1577  * ivl_nexus_set_private
1578  * ivl_nexus_get_private
1579  *    The target module often needs to associate data with a nexus for
1580  *    later use when the nexus is encountered associated with a
1581  *    device. These methods allow the code generator to store to or
1582  *    retrieve from a nexus a void* of private data. This pointer is
1583  *    guaranteed to be 0 before the target module is invoked.
1584  *
1585  * Once an ivl_nexus_ptr_t is selected by the ivl_nexus_ptr method,
1586  * the properties of the pointer can be accessed by the following
1587  * methods:
1588  *
1589  * ivl_nexus_ptr_pin
1590  *    This returns the pin number of the device where this nexus
1591  *    points. It is the bit within the signal or logic device that is
1592  *    connected to the nexus.
1593  *
1594  *    If the target is an LPM device, then this value is zero, and it
1595  *    is up to the application to find the pin that refers to this
1596  *    nexus. The problem is that LPM devices do not have a pinout per
1597  *    se, the pins all have specific names.
1598  *
1599  * ivl_nexus_ptr_con
1600  *    If this is a pointer to a magic constant device, then this
1601  *    returns the net_const object.
1602  *
1603  * ivl_nexus_ptr_drive0
1604  * ivl_nexus_ptr_drive1
1605  *    These are the 0 and 1 strength values for the devices. For most
1606  *    devices, these values are fixed by the description in the
1607  *    original source, with the default as IVL_DR_STRONG. For pins
1608  *    that are input only, drive0 and drive1 are both IVL_DR_HiZ.
1609  *
1610  *    The strength of strength-aware devices (such as nmos devices)
1611  *    does not really matter, as long as the output is not
1612  *    IVL_DR_HiZ. Testing for HiZ drivers is how code generators
1613  *    detect inputs.
1614  *
1615  * ivl_nexus_ptr_log
1616  *    If the target object is an ivl_net_logic_t, this method returns
1617  *    the object. Otherwise, this method returns 0.
1618  *
1619  * ivl_nexus_ptr_lpm
1620  *    If the target object is an ivl_lpm_t, this method returns the
1621  *    object. Otherwise, this method returns 0.
1622  *
1623  * ivl_nexus_ptr_sig
1624  *    If the target object is an ivl_signal_t, this method returns the
1625  *    object. If the target is not a signal, this method returns 0.
1626  *
1627  * SEMANTIC NOTES
1628  * All the device pins that connect to a nexus have the same
1629  * type. That means, for example, that vector pins have the same
1630  * width. The compiler will insure this is so.
1631  */
1632 
1633 extern const char*     ivl_nexus_name(ivl_nexus_t net) __attribute__((deprecated));
1634 extern unsigned        ivl_nexus_ptrs(ivl_nexus_t net);
1635 extern ivl_nexus_ptr_t ivl_nexus_ptr(ivl_nexus_t net, unsigned idx);
1636 
1637 extern void  ivl_nexus_set_private(ivl_nexus_t net, void*data);
1638 extern void* ivl_nexus_get_private(ivl_nexus_t net);
1639 
1640 
1641 extern ivl_drive_t  ivl_nexus_ptr_drive0(ivl_nexus_ptr_t net);
1642 extern ivl_drive_t  ivl_nexus_ptr_drive1(ivl_nexus_ptr_t net);
1643 extern unsigned     ivl_nexus_ptr_pin(ivl_nexus_ptr_t net);
1644 extern ivl_branch_t ivl_nexus_ptr_branch(ivl_nexus_ptr_t net);
1645 extern ivl_net_const_t ivl_nexus_ptr_con(ivl_nexus_ptr_t net);
1646 extern ivl_net_logic_t ivl_nexus_ptr_log(ivl_nexus_ptr_t net);
1647 extern ivl_lpm_t    ivl_nexus_ptr_lpm(ivl_nexus_ptr_t net);
1648 extern ivl_switch_t ivl_nexus_ptr_switch(ivl_nexus_ptr_t net);
1649 extern ivl_signal_t ivl_nexus_ptr_sig(ivl_nexus_ptr_t net);
1650 
1651 /* PARAMETER
1652  * Parameters are named constants associated with a scope. The user
1653  * may set in the Verilog source the value of parameters, and that
1654  * leads to ivl_parameter_t objects contained in the ivl_scope_t
1655  * objects.
1656  *
1657  * Parameters are essentially named constants. These constant values
1658  * can be accessed by looking at the scope (using ivl_scope_param) or
1659  * they can be discovered when they are used, via the
1660  * ivl_expr_parameter function. The fact that a constant has a name
1661  * (i.e. is a parameter) does not otherwise impose on the value or
1662  * interpretation of the constant expression so far as ivl_target is
1663  * concerned. The target may need this information, or may choose to
1664  * completely ignore it.
1665  *
1666  * ivl_parameter_basename
1667  *    return the name of the parameter.
1668  *
1669  * ivl_parameter_scope
1670  *    Return the scope of the parameter. The parameter name is only
1671  *    unique within its scope.
1672  *
1673  * ivl_parameter_expr
1674  *    Return the value of the parameter. This should be a simple
1675  *    constant expression, an IVL_EX_STRING or IVL_EX_NUMBER.
1676  *
1677  * ivl_parameter_msb
1678  * ivl_parameter_lsb
1679  *    Returns the MSB and LSB for the parameter. For a parameter without
1680  *    a range the value is zero based and the width of the expression is
1681  *    used to determine the MSB.
1682  *
1683  * ivl_parameter_width
1684  *    return |MSB - LSB| + 1
1685  *
1686  * ivl_parameter_signed
1687  *    Returns if the parameter was declared to be signed.
1688  *
1689  * ivl_parameter_local
1690  *    Return whether parameter was local (localparam, implicit genvar etc)
1691  *    or not.
1692  *
1693  * ivl_parameter_file
1694  * ivl_parameter_lineno
1695  *    Returns the file and line where this parameter is defined
1696  */
1697 extern const char* ivl_parameter_basename(ivl_parameter_t net);
1698 extern ivl_scope_t ivl_parameter_scope(ivl_parameter_t net);
1699 extern ivl_expr_t  ivl_parameter_expr(ivl_parameter_t net);
1700 extern int         ivl_parameter_msb(ivl_parameter_t net);
1701 extern int         ivl_parameter_lsb(ivl_parameter_t net);
1702 extern unsigned    ivl_parameter_width(ivl_parameter_t net);
1703 extern int         ivl_parameter_signed(ivl_parameter_t net);
1704 extern int         ivl_parameter_local(ivl_parameter_t net);
1705 extern const char* ivl_parameter_file(ivl_parameter_t net);
1706 extern unsigned    ivl_parameter_lineno(ivl_parameter_t net);
1707 
1708 
1709 /* SCOPE
1710  * Scopes of various sort have these properties. Use these methods to
1711  * access them. Scopes come to exist in the elaborated design
1712  * generally when a module is instantiated, though they also come from
1713  * named blocks, tasks and functions.
1714  *
1715  * - module instances (IVL_SCT_MODULE)
1716  *    A module instance scope may contain events, logic gates, lpm
1717  *    nodes, signals, and possibly children. The children are further
1718  *    instances, or function/task scopes. Module instances do *not*
1719  *    contain a definition.
1720  *
1721  * - function scopes (IVL_SCT_FUNCTION)
1722  *    These scopes represent functions. A function may not be a root,
1723  *    so it is contained within a module instance scope. A function is
1724  *    required to have a definition (in the form of a statement) and a
1725  *    signal (IVL_SIG_REG) that is its return value.
1726  *
1727  *    A single function scope is created each time the module with the
1728  *    definition is instantiated.
1729  *
1730  *
1731  * - task scopes (IVL_SCT_TASK)
1732  *    [...]
1733  *
1734  * ivl_scope_attr_cnt
1735  * ivl_scope_attr_val
1736  *    A scope may have attributes attached to it. These functions
1737  *    allow the target to access the attributes values.
1738  *
1739  * ivl_scope_children
1740  *    A scope may in turn contain other scopes. This method iterates
1741  *    through all the child scopes of a given scope. If the function
1742  *    returns any value other than 0, the iteration stops and the
1743  *    method returns that value. Otherwise, iteration continues until
1744  *    the children run out.
1745  *
1746  *    If the scope has no children, this method will return 0 and
1747  *    otherwise do nothing.
1748  *
1749  * ivl_scope_childs
1750  * ivl_scope_child
1751  *    This is an alternative way of getting at the childs scopes of a
1752  *    given scope.
1753  *
1754  * ivl_scope_def
1755  *    Task definition scopes carry a task definition, in the form of
1756  *    a statement. This method accesses that definition. The
1757  *    ivl_scope_def function must return a statement for scopes that
1758  *    are type FUNCTION or TASK, and must return nil otherwise.
1759  *
1760  * ivl_scope_def_file
1761  * ivl_scope_def_lineno
1762  *    Returns the file and line where this scope is defined.
1763  *
1764  * ivl_scope_enumerate
1765  * ivl_scope_enumerates
1766  *    Scopes have 0 or more enumeration types in them.
1767  *
1768  * ivl_scope_event
1769  * ivl_scope_events
1770  *    Scopes have 0 or more event objects in them.
1771  *
1772  * ivl_scope_file
1773  * ivl_scope_lineno
1774  *    Returns the instantiation file and line for this scope.
1775  *
1776  * ivl_scope_func_type
1777  * ivl_scope_func_signed
1778  * ivl_scope_func_width
1779  *
1780  *    If the scope is a function, these function can be used to get
1781  *    the type of the return value.
1782  *
1783  * ivl_scope_is_auto
1784  *    Is the task or function declared to be automatic?
1785  *
1786  * ivl_scope_is_cell
1787  *    Is the module defined to be a cell?
1788  *
1789  * ivl_scope_var
1790  * ivl_scope_vars
1791  *    REMOVED
1792  *
1793  * ivl_scope_log
1794  * ivl_scope_logs
1795  *    Scopes have 0 or more logic devices in them. A logic device is
1796  *    represented by ivl_logic_t.
1797  *
1798  * ivl_scope_lpm
1799  * ivl_scope_lpms
1800  *    Scopes have 0 or more LPM devices in them. These functions access
1801  *    those devices.
1802  *
1803  * ivl_scope_name
1804  * ivl_scope_basename
1805  *    Every scope has a hierarchical name. This name is also a prefix
1806  *    of all the names of objects contained within the scope. The
1807  *    ivl_scope_basename is the name of the scope without the included
1808  *    hierarchy.
1809  *
1810  * ivl_scope_param
1811  * ivl_scope_params
1812  *    A scope has zero or more named parameters. These parameters have
1813  *    a name and an expression value.
1814  *
1815  * ivl_scope_parent
1816  *    If this is a non-root scope, then the parent is the scope that
1817  *    contains this scope. Otherwise, the parent is nil.
1818  *
1819  * ivl_scope_port
1820  * ivl_scope_ports
1821  *    Scopes that are functions or tasks have ports defined by
1822  *    signals. These methods access the ports by name.
1823  *
1824  *    If this scope represents a function, then the ports list
1825  *    includes the return value, as port 0. The remaining ports are
1826  *    the input ports in order.
1827  *
1828  * ivl_scope_sig
1829  * ivl_scope_sigs
1830  *    Scopes have 0 or more signals in them. These signals are
1831  *    anything that can become and ivl_signal_t, include synthetic
1832  *    signals generated by the compiler.
1833  *
1834  * ivl_scope_time_precision
1835  *    Scopes have their own intrinsic time precision, typically from
1836  *    the timescale compiler directive. This method returns the
1837  *    precision as a signed power of 10 value.
1838  *
1839  * ivl_scope_time_units
1840  *    Scopes have their own intrinsic time units, typically from the
1841  *    timescale compiler directive. This method returns the units as a
1842  *    signed power of 10 value.
1843  *
1844  * ivl_scope_type
1845  * ivl_scope_tname
1846  *    Scopes have a type and a type name. For example, if a scope is
1847  *    an instance of module foo, its type is IVL_SCT_MODULE and its
1848  *    type name is "foo". This is different from the instance name
1849  *    returned by ivl_scope_name above.
1850  */
1851 
1852 extern unsigned        ivl_scope_attr_cnt(ivl_scope_t net);
1853 extern ivl_attribute_t ivl_scope_attr_val(ivl_scope_t net, unsigned idx);
1854 
1855 extern int          ivl_scope_children(ivl_scope_t net,
1856 				       ivl_scope_f func, void*cd);
1857 
1858 extern ivl_statement_t ivl_scope_def(ivl_scope_t net);
1859 extern const char* ivl_scope_def_file(ivl_scope_t net);
1860 extern unsigned ivl_scope_def_lineno(ivl_scope_t net);
1861 
1862 extern size_t      ivl_scope_childs(ivl_scope_t net);
1863 extern ivl_scope_t ivl_scope_child(ivl_scope_t net, size_t idx);
1864 extern unsigned   ivl_scope_classes(ivl_scope_t net);
1865 extern ivl_type_t ivl_scope_class(ivl_scope_t net, unsigned idx);
1866 extern unsigned       ivl_scope_enumerates(ivl_scope_t net);
1867 extern ivl_enumtype_t ivl_scope_enumerate(ivl_scope_t net, unsigned idx);
1868 extern unsigned     ivl_scope_events(ivl_scope_t net);
1869 extern ivl_event_t  ivl_scope_event(ivl_scope_t net, unsigned idx);
1870 extern const char* ivl_scope_file(ivl_scope_t net);
1871 extern unsigned ivl_scope_is_auto(ivl_scope_t net);
1872 extern unsigned ivl_scope_is_cell(ivl_scope_t net);
1873 extern unsigned ivl_scope_lineno(ivl_scope_t net);
1874 extern unsigned     ivl_scope_logs(ivl_scope_t net);
1875 extern ivl_net_logic_t ivl_scope_log(ivl_scope_t net, unsigned idx);
1876 extern unsigned     ivl_scope_lpms(ivl_scope_t net);
1877 extern ivl_lpm_t    ivl_scope_lpm(ivl_scope_t, unsigned idx);
1878 extern const char*  ivl_scope_name(ivl_scope_t net);
1879 extern const char*  ivl_scope_basename(ivl_scope_t net);
1880 extern unsigned     ivl_scope_params(ivl_scope_t net);
1881 extern ivl_parameter_t ivl_scope_param(ivl_scope_t net, unsigned idx);
1882 extern ivl_scope_t  ivl_scope_parent(ivl_scope_t net);
1883 
1884 extern unsigned ivl_scope_mod_module_ports(ivl_scope_t net);
1885 extern const char *ivl_scope_mod_module_port_name(ivl_scope_t net, unsigned idx );
1886 extern ivl_signal_port_t ivl_scope_mod_module_port_type(ivl_scope_t net, unsigned idx );
1887 extern unsigned ivl_scope_mod_module_port_width(ivl_scope_t net, unsigned idx );
1888 
1889 extern unsigned     ivl_scope_ports(ivl_scope_t net);
1890 extern ivl_signal_t ivl_scope_port(ivl_scope_t net, unsigned idx);
1891 extern ivl_nexus_t  ivl_scope_mod_port(ivl_scope_t net, unsigned idx);
1892 extern unsigned     ivl_scope_sigs(ivl_scope_t net);
1893 extern ivl_signal_t ivl_scope_sig(ivl_scope_t net, unsigned idx);
1894 extern unsigned     ivl_scope_switches(ivl_scope_t net);
1895 extern ivl_switch_t ivl_scope_switch(ivl_scope_t net, unsigned idx);
1896 extern ivl_scope_type_t ivl_scope_type(ivl_scope_t net);
1897 extern const char*  ivl_scope_tname(ivl_scope_t net);
1898 extern int          ivl_scope_time_precision(ivl_scope_t net);
1899 extern int          ivl_scope_time_units(ivl_scope_t net);
1900 
1901 extern ivl_variable_type_t ivl_scope_func_type(ivl_scope_t net);
1902 extern int ivl_scope_func_signed(ivl_scope_t net);
1903 extern unsigned ivl_scope_func_width(ivl_scope_t net);
1904 
1905 /* SIGNALS
1906  * Signals are named things in the Verilog source, like wires and
1907  * regs, and also named things that are created as temporaries during
1908  * certain elaboration or optimization steps. A signal may also be a
1909  * port of a module or task.
1910  *
1911  * Signals have a name (obviously) and types. A signal may also be
1912  * signed or unsigned.
1913  *
1914  * ivl_signal_nex
1915  *    This is the nexus of the signal. This is used for managing
1916  *    connections to the rest of the net. There is exactly one pin for
1917  *    each word of a signal. Each word may in turn be a vector. The
1918  *    word address is the zero-based index for the word. It is up to
1919  *    the context to translate different bases to the canonical address.
1920  *
1921  * ivl_signal_array_base
1922  * ivl_signal_array_count
1923  * ivl_signal_array_addr_swapped
1924  *    The signal may be arrayed. If so, the array_count is >1. Each
1925  *    word of the array has its own nexus. The array_base is the
1926  *    address in the Verilog source for the canonical zero word. This
1927  *    may be negative, positive or zero. The array addresses may be
1928  *    reversed/swapped.
1929  *
1930  *    Note that arraying of the signal into words is distinct from the
1931  *    vectors. The width of a signal is the width of a WORD.
1932  *
1933  * ivl_signal_dimensions
1934  *    The signal may be an array (of vectors) in which case this
1935  *    function returns >0, the number of dimensions of the array.
1936  *
1937  * ivl_signal_discipline
1938  *    If the signal has been declared with a domain (Verilog-AMS) then
1939  *    this function will return a non-nil ivl_discipline_t.
1940  *
1941  * ivl_signal_msb (deprecated)
1942  * ivl_signal_lsb (deprecated)
1943  * ivl_signal_packed_dimensions
1944  * ivl_signal_packed_msb
1945  * ivl_signal_packed_lsb
1946  * ivl_signal_width
1947  *    These functions return the msb and lsb packed indices. The
1948  *    packed dimensions are declared differently from array
1949  *    dimensions, like so:
1950  *       reg [4:1][7:0] sig...
1951  *    which has two packed dimensions. The [4:1] dimension is the
1952  *    first, and so forth. If the signal is a scalar, it has 0
1953  *    dimension.
1954  *
1955  *    The ivl_signal_msb/ivl_signal_lsb functions are deprecated
1956  *    versions that only work with variables that have less than two
1957  *    dimensions. They will return msb==lsb==0 for scalars.
1958  *
1959  * ivl_signal_port
1960  *    If the signal is a port to a module, this function returns the
1961  *    port direction. If the signal is not a port, it returns
1962  *    IVL_SIP_NONE.
1963  *
1964  * ivl_signal_signed
1965  *    A signal, which is a vector, may be signed. In Verilog 2000, any
1966  *    net or variable may be signed. This function returns true if the
1967  *    signal is signed.
1968  *
1969  * ivl_signal_local
1970  *    A signal that was generated by the compiler as a place holder is
1971  *    marked as local.
1972  *
1973  * ivl_signal_forced_net
1974  *    Return whether the signal is a net that is the subject of a force
1975  *    statement.
1976  *
1977  * ivl_signal_type
1978  *    Return the type of the signal, i.e., reg, wire, tri0, etc.
1979  *
1980  * ivl_signal_data_type
1981  *    Return the data type of the signal, i.e. logic, real, bool,
1982  *    etc. All the signals connected to a nexus should have the same
1983  *    data type
1984  *
1985  * ivl_signal_npath
1986  * ivl_signal_path
1987  *    This function returns the delay path object for the signal. The
1988  *    delay path has this signal as the output, the source is attached
1989  *    to the delay path itself.
1990  *
1991  * ivl_signal_name (DEPRECATED)
1992  *    This function returns the fully scoped hierarchical name for the
1993  *    signal. The name refers to the entire vector that is the signal.
1994  *
1995  *    NOTE: This function is deprecated. The hierarchical name is too
1996  *    vague a construct when escaped names can have . characters in
1997  *    them. Do no use this function in new code, it will disappear.
1998  *
1999  * ivl_signal_basename
2000  *    This function returns the name of the signal, without the scope
2001  *    information. This is the tail of the signal name. Since Verilog
2002  *    has an escape syntax, this name can contain any ASCII
2003  *    characters, except NULL or white space. The leading \ and
2004  *    trailing ' ' of escaped names in Verilog source are not part of
2005  *    the name, so not included here.
2006  *
2007  * ivl_signal_attr
2008  *    Icarus Verilog supports attaching attributes to signals, with
2009  *    the attribute value (a string) associated with a key. This
2010  *    function returns the attribute value for the given key. If the
2011  *    key does not exist, the function returns 0.
2012  *
2013  * ivl_signal_file
2014  * ivl_signal_lineno
2015  *    Returns the file and line where this signal is defined.
2016  */
2017 
2018 extern ivl_scope_t ivl_signal_scope(ivl_signal_t net);
2019 extern ivl_nexus_t ivl_signal_nex(ivl_signal_t net, unsigned word);
2020 extern int         ivl_signal_array_base(ivl_signal_t net);
2021 extern unsigned    ivl_signal_array_count(ivl_signal_t net);
2022 extern unsigned    ivl_signal_array_addr_swapped(ivl_signal_t net);
2023 extern unsigned    ivl_signal_dimensions(ivl_signal_t net);
2024 extern ivl_discipline_t ivl_signal_discipline(ivl_signal_t net);
2025 extern unsigned    ivl_signal_packed_dimensions(ivl_signal_t net);
2026 extern int         ivl_signal_packed_msb(ivl_signal_t net, unsigned dim);
2027 extern int         ivl_signal_packed_lsb(ivl_signal_t net, unsigned dim);
2028 extern int         ivl_signal_msb(ivl_signal_t net) __attribute__((deprecated));
2029 extern int         ivl_signal_lsb(ivl_signal_t net) __attribute__((deprecated));
2030 extern unsigned    ivl_signal_width(ivl_signal_t net);
2031 extern ivl_signal_port_t ivl_signal_port(ivl_signal_t net);
2032 extern int         ivl_signal_module_port_index(ivl_signal_t net);
2033 extern int         ivl_signal_signed(ivl_signal_t net);
2034 extern int         ivl_signal_integer(ivl_signal_t net);
2035 extern int         ivl_signal_local(ivl_signal_t net);
2036 extern unsigned    ivl_signal_forced_net(ivl_signal_t net);
2037 extern unsigned    ivl_signal_npath(ivl_signal_t net);
2038 extern ivl_delaypath_t ivl_signal_path(ivl_signal_t net, unsigned idx);
2039 extern ivl_signal_type_t ivl_signal_type(ivl_signal_t net);
2040 extern ivl_variable_type_t ivl_signal_data_type(ivl_signal_t net);
2041 extern ivl_type_t  ivl_signal_net_type(ivl_signal_t net);
2042 extern const char* ivl_signal_name(ivl_signal_t net);
2043 extern const char* ivl_signal_basename(ivl_signal_t net);
2044 extern const char* ivl_signal_attr(ivl_signal_t net, const char*key);
2045 
2046 extern const char* ivl_signal_file(ivl_signal_t net);
2047 extern unsigned ivl_signal_lineno(ivl_signal_t net);
2048 
2049 extern unsigned        ivl_signal_attr_cnt(ivl_signal_t net);
2050 extern ivl_attribute_t ivl_signal_attr_val(ivl_signal_t net, unsigned idx);
2051 
2052 /* ivl_nexus_t ivl_signal_pin(ivl_signal_t net, unsigned idx); */
2053 /* unsigned    ivl_signal_pins(ivl_signal_t net); */
2054 
2055 /*
2056  * These functions get information about a process. A process is
2057  * an initial or always block within the original Verilog source, that
2058  * is translated into a type and a single statement. (The statement
2059  * may be a compound statement.)
2060  *
2061  * ivl_process_type
2062  * ivl_process_analog
2063  *    The ivl_process_type function returns the type of the process,
2064  *    an "initial" or "always" statement. The ivl_process_analog
2065  *    returns true if the process is analog.
2066  *
2067  * ivl_process_scope
2068  *    A process is placed in a scope. The statement within the process
2069  *    operates within the scope of the process unless there are calls
2070  *    outside the scope.
2071  *
2072  * The ivl_process_stmt function gets the statement that forms the
2073  * process. See the statement related functions for how to manipulate
2074  * statements.
2075  *
2076  * Processes can have attributes attached to them. the attr_cnt and
2077  * attr_val methods return those attributes.
2078  */
2079 extern ivl_process_type_t ivl_process_type(ivl_process_t net);
2080 extern int ivl_process_analog(ivl_process_t net);
2081 
2082 extern ivl_scope_t ivl_process_scope(ivl_process_t net);
2083 
2084 extern ivl_statement_t ivl_process_stmt(ivl_process_t net);
2085 
2086 extern unsigned        ivl_process_attr_cnt(ivl_process_t net);
2087 extern ivl_attribute_t ivl_process_attr_val(ivl_process_t net, unsigned idx);
2088 
2089 extern const char* ivl_process_file(ivl_process_t net);
2090 extern unsigned ivl_process_lineno(ivl_process_t net);
2091 
2092 /*
2093  * These functions manage statements of various type. This includes
2094  * all the different kinds of statements (as enumerated in
2095  * ivl_statement_type_t) that might occur in behavioral code.
2096  *
2097  * The ivl_statement_type() function returns the type code for the
2098  * statement. This is the major type, and implies which of the later
2099  * functions are applicable to the statement.
2100  *
2101  * the ivl_statement_file() and _lineno() functions return the source
2102  * file and line number of the statement in the Verilog source. This
2103  * information is useful for diagnostic information.
2104  */
2105 extern ivl_statement_type_t ivl_statement_type(ivl_statement_t net);
2106 
2107 extern const char* ivl_stmt_file(ivl_statement_t net);
2108 extern unsigned ivl_stmt_lineno(ivl_statement_t net);
2109 
2110 /*
2111  * The following functions retrieve specific single values from the
2112  * statement. These values are the bits of data and parameters that
2113  * make up the statement. Many of these functions apply to more than
2114  * one type of statement, so the comment in front of them tells which
2115  * statement types can be passed to the function.
2116  *
2117  * FUNCTION SUMMARY:
2118  *
2119  * ivl_stmt_block_scope
2120  *    If the block is named, then there is a scope associated with
2121  *    this. The code generator may need to know this in order to
2122  *    handle disable statements.
2123  *
2124  * ivl_stmt_events
2125  * ivl_stmt_needs_t0_trigger
2126  * ivl_stmt_nevent
2127  *    Statements that have event arguments (TRIGGER and WAIT) make
2128  *    those event objects available through these methods.
2129  *
2130 * ivl_stmt_lval
2131  * ivl_stmt_lvals
2132  *    Return the number of l-values for an assignment statement, or
2133  *    the specific l-value. If there is more than 1 l-value, then the
2134  *    l-values are presumed to be vector values concatenated together
2135  *    from msb (idx==0) to lsb.
2136  *
2137  * ivl_stmt_rval
2138  *    Return the rval expression of the assignment. This is the value
2139  *    that is to be calculated and assigned to the l-value in all the
2140  *    assignment statements.
2141  *
2142  * ivl_stmt_sub_stmt
2143  *    Some statements contain a single, subordinate statement. An
2144  *    example is the IVL_ST_WAIT, which contains the statement to be
2145  *    executed after the wait completes. This method retrieves that
2146  *    sub-statement.
2147  *
2148  * SEMANTIC NOTES:
2149  *
2150  * - Assignments: IVL_ST_ASSIGN, IVL_ST_ASSIGN_NB, IVL_CASSIGN, IVL_ST_FORCE
2151  *
2152  * The assignments support ivl_stmt_rval to get the r-value expression
2153  * that is to be assign to the l-value, and ivl_stmt_lval[s] to get
2154  * the l-value that receives the value. The compiler has already made
2155  * sure that the types (l-value and r-value) are compatible.
2156  *
2157  * If the l-value is a vector, then the compiler also makes sure the
2158  * expression width of the r-values matches. It handles padding or
2159  * operator sizing as needed to get the width exactly right.
2160  *
2161  * The blocking and non-blocking assignments may also have an internal
2162  * delay. These are of the form "lval = #<delay> rval;" and <delay> is
2163  * the internal delay expression. (It is internal because it is inside
2164  * the statement.) The ivl_stmt_delay_expr function returns the
2165  * expression for the delay, or nil if there is no delay expression.
2166  *
2167  * The blocking assignment (IVL_ST_ASSIGN) may have an associated
2168  * opcode, that can be extracted from ivl_stmt_opcode(). This opcode
2169  * is the compressed operator used it statements like this:
2170  *      foo += <expr>
2171  * The ivl_stmt_opcode() returns null (0) if this is not a compressed
2172  * assignment statement.
2173  *
2174  * - IVL_ST_CASSIGN
2175  * This reflects a procedural continuous assignment to an l-value. The
2176  * l-value is the same as any other assignment (use ivl_stmt_lval).
2177  *
2178  * The value to be assigned is an ivl_expr_t retrieved by the
2179  * ivl_stmt_rval function. The run time is expected to calculate the
2180  * value of the expression at the assignment, then continuous assign
2181  * that constant value. If the expression is non-constant, the code
2182  * generator is supposed to know what to do about that, too.
2183  *
2184  * - IVL_ST_CONTRIB
2185  * This is an analog contribution statement. The ivl_stmt_lexp
2186  * function returns the l-value expression which is guaranteed to be a
2187  * branch access expression. The ivl_stmt_rval returns the r-value
2188  * expression for the assignment.
2189  *
2190  * - IVL_ST_DELAY, IVL_ST_DELAYX
2191  * These statement types are delay statements. They are a way to
2192  * attach a delay to a statement. The ivl_stmt_sub_stmt() function
2193  * gets the statement to be executed after the delay. If this is
2194  * IVL_ST_DELAY, then the ivl_stmt_delay_val function gets the
2195  * constant delay. If this is IVL_ST_DELAYX, then the
2196  * ivl_stmt_delay_expr gets the expression of the delay. In this case,
2197  * the expression is not necessarily constant.
2198  *
2199  * Whether constant or calculated, the resulting delay is in units of
2200  * simulation ticks. The compiler has already taken care of converting
2201  * the delay to the time scale/precision of the scope.
2202  *
2203  * - IVL_ST_FORCE
2204  * This is very much like IVL_ST_CASSIGN, but adds that l-values can
2205  * include nets (tri, wire, etc). Memory words are restricted from
2206  * force l-values, and also non-constant bit or part selects. The
2207  * compiler will assure these constraints are met.
2208  *
2209  * - IVL_ST_TRIGGER
2210  * This represents the "-> name" statement that sends a trigger to a
2211  * named event. The ivl_stmt_nevent function should always return 1,
2212  * and the ivl_stmt_events(net,0) function returns the target event,
2213  * as an ivl_event_t. The only behavior of this statement is to send a
2214  * "trigger" to the target event.
2215  *
2216  * - IVL_ST_WAIT
2217  * This is the edge sensitive wait (for event) statement. The
2218  * statement contains an array of events that are to be tested, and a
2219  * single statement that is to be executed when any of the array of
2220  * events triggers.
2221  *
2222  * the ivl_stmt_events function accesses the array of events to wait
2223  * for, and the ivl_stmt_sub_stmt function gets the sub-statement,
2224  * which may be null, that is to be executed when an event
2225  * triggers. The statement waits even if the sub-statement is nul.
2226  */
2227 
2228   /* IVL_ST_BLOCK, IVL_ST_FORK, IVL_ST_FORK_JOIN_ANY, IVL_ST_FORK_JOIN_NONE */
2229 extern unsigned ivl_stmt_block_count(ivl_statement_t net);
2230   /* IVL_ST_BLOCK, IVL_ST_FORK, IVL_ST_FORK_JOIN_ANY, IVL_ST_FORK_JOIN_NONE */
2231 extern ivl_scope_t ivl_stmt_block_scope(ivl_statement_t net);
2232   /* IVL_ST_BLOCK, IVL_ST_FORK, IVL_ST_FORK_JOIN_ANY, IVL_ST_FORK_JOIN_NONE */
2233 extern ivl_statement_t ivl_stmt_block_stmt(ivl_statement_t net, unsigned i);
2234   /* IVL_ST_UTASK IVL_ST_DISABLE */
2235 extern ivl_scope_t ivl_stmt_call(ivl_statement_t net);
2236   /* IVL_ST_CASE,IVL_ST_CASER,IVL_ST_CASEX,IVL_ST_CASEZ */
2237 extern unsigned ivl_stmt_case_count(ivl_statement_t net);
2238   /* IVL_ST_CASE,IVL_ST_CASER,IVL_ST_CASEX,IVL_ST_CASEZ */
2239 extern ivl_expr_t ivl_stmt_case_expr(ivl_statement_t net, unsigned i);
2240   /* IVL+ST_CASE,IVL_ST_CASER,IVL_ST_CASEX,IVL_ST_CASEZ */
2241 extern ivl_case_quality_t ivl_stmt_case_quality(ivl_statement_t net);
2242   /* IVL_ST_CASE,IVL_ST_CASER,IVL_ST_CASEX,IVL_ST_CASEZ */
2243 extern ivl_statement_t ivl_stmt_case_stmt(ivl_statement_t net, unsigned i);
2244   /* IVL_ST_CONDIT IVL_ST_CASE IVL_ST_REPEAT IVL_ST_WHILE */
2245 extern ivl_expr_t      ivl_stmt_cond_expr(ivl_statement_t net);
2246   /* IVL_ST_CONDIT */
2247 extern ivl_statement_t ivl_stmt_cond_false(ivl_statement_t net);
2248   /* IVL_ST_CONDIT */
2249 extern ivl_statement_t ivl_stmt_cond_true(ivl_statement_t net);
2250   /* IVL_ST_ASSIGN IVL_ST_ASSIGN_NB IVL_ST_DELAYX */
2251 extern ivl_expr_t ivl_stmt_delay_expr(ivl_statement_t net);
2252   /* IVL_ST_DELAY */
2253 extern uint64_t ivl_stmt_delay_val(ivl_statement_t net);
2254   /* IVL_ST_WAIT IVL_ST_TRIGGER */
2255 extern unsigned    ivl_stmt_needs_t0_trigger(ivl_statement_t net);
2256 extern unsigned    ivl_stmt_nevent(ivl_statement_t net);
2257 extern ivl_event_t ivl_stmt_events(ivl_statement_t net, unsigned idx);
2258   /* IVL_ST_CONTRIB */
2259 extern ivl_expr_t ivl_stmt_lexp(ivl_statement_t net);
2260   /* IVL_ST_ASSIGN IVL_ST_ASSIGN_NB IVL_ST_CASSIGN IVL_ST_DEASSIGN
2261      IVL_ST_FORCE IVL_ST_RELEASE */
2262 extern ivl_lval_t ivl_stmt_lval(ivl_statement_t net, unsigned idx);
2263   /* IVL_ST_ASSIGN IVL_ST_ASSIGN_NB IVL_ST_CASSIGN IVL_ST_DEASSIGN
2264      IVL_ST_FORCE IVL_ST_RELEASE */
2265 extern unsigned ivl_stmt_lvals(ivl_statement_t net);
2266   /* IVL_ST_ASSIGN IVL_ST_ASSIGN_NB IVL_ST_CASSIGN */
2267 extern unsigned ivl_stmt_lwidth(ivl_statement_t net);
2268   /* IVL_ST_STASK */
2269 extern const char* ivl_stmt_name(ivl_statement_t net);
2270   /* IVL_ST_ASSIGN */
2271 extern char ivl_stmt_opcode(ivl_statement_t net);
2272   /* IVL_ST_STASK */
2273 extern ivl_expr_t ivl_stmt_parm(ivl_statement_t net, unsigned idx);
2274   /* IVL_ST_STASK */
2275 extern unsigned ivl_stmt_parm_count(ivl_statement_t net);
2276   /* IVL_ST_ASSIGN IVL_ST_ASSIGN_NB IVL_ST_CASSIGN IVL_ST_CONTRIB
2277      IVL_ST_FORCE */
2278 extern ivl_expr_t ivl_stmt_rval(ivl_statement_t net);
2279   /* IVL_ST_STASK */
2280 extern ivl_sfunc_as_task_t ivl_stmt_sfunc_as_task(ivl_statement_t net);
2281   /* IVL_ST_DELAY, IVL_ST_DELAYX, IVL_ST_FOREVER, IVL_ST_REPEAT
2282      IVL_ST_WAIT, IVL_ST_WHILE */
2283 extern ivl_statement_t ivl_stmt_sub_stmt(ivl_statement_t net);
2284 
2285 /* SWITCHES
2286  *
2287  * The switches represent the tran devices in the design.
2288  *
2289  * FUNCTION SUMMARY
2290  *
2291  * ivl_switch_type
2292  *    Return the enumerated value that is the type of the switch.
2293  *
2294  * ivl_switch_basename
2295  *    This is the name given to the device in the source code.
2296  *
2297  * ivl_switch_a
2298  * ivl_switch_b
2299  *    The a and b ports are the two ports of the switch.
2300  *
2301  * ivl_switch_enable
2302  *    If the device has an enable (tranifX) then this is the enable
2303  *    port.
2304  *
2305  * SEMANTIC NOTES
2306  * The a/b ports can be any type, but the types must exactly
2307  * match, including vector widths. The enable must be a scalar.
2308  *
2309  * The IVL_SW_TRAN_VP is an exception to the above. In this case,
2310  * the B side may be a different size, and the a side will have a
2311  * a fixed width. The unused bits are padded to Z on the A side.
2312  */
2313 extern ivl_switch_type_t ivl_switch_type(ivl_switch_t net);
2314 extern ivl_scope_t ivl_switch_scope(ivl_switch_t net);
2315 extern const char*ivl_switch_basename(ivl_switch_t net);
2316 extern ivl_nexus_t ivl_switch_a(ivl_switch_t net);
2317 extern ivl_nexus_t ivl_switch_b(ivl_switch_t net);
2318 extern ivl_nexus_t ivl_switch_enable(ivl_switch_t net);
2319 extern ivl_island_t ivl_switch_island(ivl_switch_t net);
2320 
2321   /* These are only support for IVL_SW_TRAN_VP switches. */
2322 extern unsigned ivl_switch_width(ivl_switch_t net);
2323 extern unsigned ivl_switch_part(ivl_switch_t net);
2324 extern unsigned ivl_switch_offset(ivl_switch_t net);
2325 extern ivl_expr_t ivl_switch_delay(ivl_switch_t net, unsigned transition);
2326 
2327 /* Not implemented yet
2328 extern unsigned        ivl_switch_attr_cnt(ivl_switch_t net);
2329 extern ivl_attribute_t ivl_switch_attr_val(ivl_switch_t net, unsigned idx);
2330 *** */
2331 extern const char* ivl_switch_file(ivl_switch_t net);
2332 extern unsigned ivl_switch_lineno(ivl_switch_t net);
2333 
2334 /* TYPES
2335  *
2336  * ivl_type_base
2337  *    This returns the base type for the type. See the
2338  *    ivl_variable_type_t definition for the various base types.
2339  *
2340  * ivl_type_element
2341  *    Return the type of the element of an array. This is only valid
2342  *    for array types.
2343  *
2344  * ivl_type_signed
2345  *    Return TRUE if the type represents a signed packed vector or
2346  *    signed atomic type, and FALSE otherwise.
2347  *
2348  * SEMANTIC NOTES
2349  *
2350  * Class types have names and properties.
2351  */
2352 extern ivl_variable_type_t ivl_type_base(ivl_type_t net);
2353 extern ivl_type_t ivl_type_element(ivl_type_t net);
2354 extern unsigned ivl_type_packed_dimensions(ivl_type_t net);
2355 extern int ivl_type_packed_lsb(ivl_type_t net, unsigned dim);
2356 extern int ivl_type_packed_msb(ivl_type_t net, unsigned dim);
2357 extern int ivl_type_signed(ivl_type_t net);
2358 extern const char* ivl_type_name(ivl_type_t net);
2359 extern int         ivl_type_properties(ivl_type_t net);
2360 extern const char* ivl_type_prop_name(ivl_type_t net, int idx);
2361 extern ivl_type_t  ivl_type_prop_type(ivl_type_t net, int idx);
2362 
2363 
2364 #if defined(__MINGW32__) || defined (__CYGWIN__)
2365 #  define DLLEXPORT __declspec(dllexport)
2366 #else
2367 #  define DLLEXPORT
2368 #endif
2369 
2370 extern DLLEXPORT int target_design(ivl_design_t des);
2371 extern DLLEXPORT const char* target_query(const char*key);
2372 
2373 /* target_design
2374 
2375    The "target_design" function is called once after the whole design
2376    is processed and available to the target. The target doesn't return
2377    from this function until it is finished with the design.
2378 
2379    The return value of this function should normally be zero. If the
2380    code generator detects errors, however, then the code generator
2381    returns a positive number to indicate the approximate number of
2382    errors detected (before it gave up.) Return values <0 are reserved
2383    for system and infrastructure errors.
2384 
2385    This function is implemented in the loaded target, and not in the
2386    ivl core. This function is how the target module is invoked. */
2387 
2388 typedef int  (*target_design_f)(ivl_design_t des);
2389 typedef const char* (*target_query_f) (const char*key);
2390 
2391 
2392 _END_DECL
2393 
2394 #undef ENUM_UNSIGNED_INT
2395 
2396 #endif /* IVL_ivl_target_H */
2397