4 * Copyright (c) 2000-2004 Stephen Williams (steve@icarus.com)
6 * This source code is free software; you can redistribute it
7 * and/or modify it in source code form under the terms of the GNU
8 * General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
22 #ident "$Id: ivl_target.h,v 1.182 2007/04/02 01:12:34 steve Exp $"
25 # include <inttypes.h>
28 #define _BEGIN_DECL extern "C" {
39 * This header file describes the API for the loadable target
40 * module. The main program can load these modules and access the
41 * functions within the loaded module to implement the backend
44 * The interface is divided into two parts: the entry points within
45 * the core that are called by the module, and the entry points in
46 * the module that are called by the core. It is the latter that
47 * causes the module to be invoked in the first place, but most of the
48 * interesting information about the design is accessed through the
49 * various access functions that the modules calls into the core.
54 * In order to grab onto data in the design, the core passes cookies
55 * to the various functions of the module. These cookies can in turn
56 * be passed to access functions in the core to get more detailed
59 * The following typedefs list the various cookies that may be passed
63 * This object represent an array that can be a memory or a net
64 * array. (They are the same from the perspective of ivl_target.h.)
67 * This object represents the entire elaborated design. Various
68 * global properties and methods are available from this.
71 * This object represents an event node. An event node stands for
72 * named events written explicitly in the Verilog, and net events
73 * that are implicit when @ statements are used.
76 * This object represents a node of an expression. If the
77 * expression has sub-expressions, they can be accessed from
78 * various method described below. The ivl_expr_type method in
79 * particular gets the type of the node in the form of an
80 * ivl_expr_type_t enumeration value.
82 * Objects of this type represent expressions in
83 * processes. Structural expressions are instead treated as logic
87 * This object is the base class for all the various LPM type
88 * device nodes. This object carries a few base properties
89 * (including a type) including a handle to the specific type.
92 * This object represents various built in logic devices. In fact,
93 * this includes just about every directional device that has a
94 * single output, including logic gates and nmos, pmos and cmos
95 * devices. There is also the occasional Icarus Verilog creation.
96 * What is common about these devices is that they are
97 * bitwise. That is, when fed a vector, they produce a vector
98 * result where each bit of the output is made only from the same
99 * bits in the vector inputs.
102 * Structural links within an elaborated design are connected
103 * together at each bit. The connection point is a nexus, so pins
104 * of devices refer to an ivl_nexus_t. Furthermore, from a nexus
105 * there are backward references to all the device pins that point
109 * Scopes have zero or more parameter objects that represent
110 * parameters that the source defined. The parameter has a value
111 * that is fully elaborated, with defparams and other parameter
112 * overrides taken care of.
115 * A Verilog process is represented by one of these. A process may
116 * be an "initial" or an "always" process. These come from initial
117 * or always statements from the Verilog source.
120 * Elaborated scopes within a design are represented by this
121 * type. Objects of this type also act as containers for scoped
122 * objects such as signals.
125 * Statements within processes are represented by one of these. The
126 * ivl_process_t object holds one of these, but a statement may in
127 * turn contain other statements.
129 * -- A Note About Bit Sets --
130 * Some objects hold a value as an array of bits. In these cases there
131 * is some method that retrieves the width of the value and another
132 * that returns a "char*". The latter is a pointer to the least
133 * significant bit value. Bit values are represented by the characters
134 * '0', '1', 'x' and 'z'. Strengths are stored elsewhere.
136 * -- A Note About Names --
137 * The names of objects are complete, hierarchical names. That is,
138 * they include the instance name of the module that contains them.
140 * basenames are the name of the object without the containing
141 * scope. These names are unique within a scope, but not necessarily
142 * throughout the design.
144 typedef struct ivl_array_s
*ivl_array_t
;
145 typedef struct ivl_delaypath_s
*ivl_delaypath_t
;
146 typedef struct ivl_design_s
*ivl_design_t
;
147 typedef struct ivl_event_s
*ivl_event_t
;
148 typedef struct ivl_expr_s
*ivl_expr_t
;
149 typedef struct ivl_lpm_s
*ivl_lpm_t
;
150 typedef struct ivl_lval_s
*ivl_lval_t
;
151 typedef struct ivl_net_const_s
*ivl_net_const_t
;
152 typedef struct ivl_net_logic_s
*ivl_net_logic_t
;
153 typedef struct ivl_udp_s
*ivl_udp_t
;
154 typedef struct ivl_net_probe_s
*ivl_net_probe_t
;
155 typedef struct ivl_nexus_s
*ivl_nexus_t
;
156 typedef struct ivl_nexus_ptr_s
*ivl_nexus_ptr_t
;
157 typedef struct ivl_parameter_s
*ivl_parameter_t
;
158 typedef struct ivl_process_s
*ivl_process_t
;
159 typedef struct ivl_scope_s
*ivl_scope_t
;
160 typedef struct ivl_signal_s
*ivl_signal_t
;
161 typedef struct ivl_memory_s
*ivl_memory_t
; /* DEPRECATED */
162 typedef struct ivl_statement_s
*ivl_statement_t
;
165 * These are types that are defined as enumerations. These have
166 * explicit values so that the binary API is a bit more resilient to
167 * changes and additions to the enumerations.
170 typedef enum ivl_drive_e
{
181 /* This is the type of an ivl_expr_t object. The explicit numbers
182 allow additions to the enumeration without causing values to shift
183 and incompatibilities to be introduced. */
184 typedef enum ivl_expr_type_e
{
204 /* This is the type code for an ivl_net_logic_t object. */
205 typedef enum ivl_logic_e
{
219 IVL_LO_PULLDOWN
= 13,
230 /* This is the type of an LPM object. */
231 typedef enum ivl_lpm_type_e
{
235 IVL_LPM_CMP_EEQ
= 18, /* Case EQ (===) */
240 IVL_LPM_CMP_NEE
= 19, /* Case NE (!==) */
246 IVL_LPM_PART_BI
= 28, /* part select: bi-directional (part on 0) */
247 IVL_LPM_PART_VP
= 15, /* part select: vector to part */
248 IVL_LPM_PART_PV
= 17, /* part select: part written to vector */
261 /* IVL_LPM_RAM = 9, / obsolete */
265 /* The path edge type is the edge type used to select a specific
267 typedef enum ivl_path_edge_e
{
268 IVL_PE_01
= 0, IVL_PE_10
, IVL_PE_0z
,
269 IVL_PE_z1
, IVL_PE_1z
, IVL_PE_z0
,
270 IVL_PE_0x
, IVL_PE_x1
, IVL_PE_1x
,
271 IVL_PE_x0
, IVL_PE_xz
, IVL_PE_zx
,
275 /* Processes are initial or always blocks with a statement. This is
276 the type of the ivl_process_t object. */
277 typedef enum ivl_process_type_e
{
280 } ivl_process_type_t
;
282 /* These are the sorts of reasons a scope may come to be. These types
283 are properties of ivl_scope_t objects. */
284 typedef enum ivl_scope_type_e
{
293 /* Signals (ivl_signal_t) that are ports into the scope that contains
294 them have a port type. Otherwise, they are port IVL_SIP_NONE. */
295 typedef enum ivl_signal_port_e
{
302 /* This is the type code for an ivl_signal_t object. Implicit types
303 are resolved by the core compiler, and integers are converted into
305 typedef enum ivl_signal_type_e
{
315 /* This is the type code for ivl_statement_t objects. */
316 typedef enum ivl_statement_type_e
{
320 IVL_ST_ASSIGN_NB
= 3,
323 IVL_ST_CASER
= 24, /* Case statement with real expressions. */
328 IVL_ST_DEASSIGN
= 10,
342 } ivl_statement_type_t
;
344 /* This is the type of a variable, and also used as the type for an
346 typedef enum ivl_variable_type_e
{
347 IVL_VT_VOID
= 0, /* Not used */
348 IVL_VT_NO_TYPE
= 1, /* Place holder for missing/unknown type. */
352 IVL_VT_VECTOR
= IVL_VT_LOGIC
/* For compatibility */
353 } ivl_variable_type_t
;
355 /* This is the type of the function to apply to a process. */
356 typedef int (*ivl_process_f
)(ivl_process_t net
, void*cd
);
358 /* This is the type of a function to apply to a scope. The ivl_scope_t
359 parameter is the scope, and the cd parameter is client data that
360 the user passes to the scanner. */
361 typedef int (ivl_scope_f
)(ivl_scope_t net
, void*cd
);
363 /* Attributes, which can be attached to various object types, have
365 typedef enum ivl_attribute_type_e
{
369 } ivl_attribute_type_t
;
371 struct ivl_attribute_s
{
373 ivl_attribute_type_t type
;
379 typedef const struct ivl_attribute_s
*ivl_attribute_t
;
382 * Delaypath objects represent delay paths called out by a specify
383 * block in the verilog source file. The destination signal references
384 * the path object, which in turn points to the source for the path.
387 * This returns the nexus that is the source end of the delay
388 * path. Transitions on the source are the start of the delay time
392 * This returns the nexus that tracks the condition for the
393 * delay. If the delay path is unconditional, this returns nil.
395 * ivl_path_srouce_posedge
396 * ivl_path_source_negedge
397 * These functions return true if the source is edge sensitive.
399 extern ivl_nexus_t
ivl_path_source(ivl_delaypath_t obj
);
400 extern uint64_t ivl_path_delay(ivl_delaypath_t obj
, ivl_path_edge_t pt
);
401 extern ivl_nexus_t
ivl_path_condit(ivl_delaypath_t obj
);
403 extern int ivl_path_source_posedge(ivl_delaypath_t obj
);
404 extern int ivl_path_source_negedge(ivl_delaypath_t obj
);
407 * When handed a design (ivl_design_t) there are a few things that you
408 * can do with it. The Verilog program has one design that carries the
409 * entire program. Use the design methods to iterate over the elements
413 * This function returns the string value of a named flag. Flags
414 * come from the "-fkey=value" options to the iverilog command and
415 * are stored in a map for this function. Given the key, this
416 * function returns the value.
418 * The special key "-o" is the argument to the -o flag of the
419 * command line (or the default if the -o flag is not used) and is
420 * generally how the target learns the name of the output file.
423 * This function scans the processes (threads) in the design. It
424 * calls the user supplied function on each of the processes until
425 * one of the functors returns non-0 or all the processes are
426 * scanned. This function will return 0, or the non-zero value that
427 * was returned from the last scanned process.
429 * ivl_design_root (ANACHRONISM)
430 * A design has a root named scope that is an instance of the top
431 * level module in the design. This is a hook for naming the
432 * design, or for starting the scope scan.
435 * A design has some number of root scopes. These are the starting
436 * points for structural elaboration. This function returns to the
437 * caller a pointer to an ivl_scope_t array, and the size of the
440 * ivl_design_time_precision
441 * A design as a time precision. This is the size in seconds (a
442 * signed power of 10) of a simulation tick.
445 extern const char* ivl_design_flag(ivl_design_t des
, const char*key
);
446 extern int ivl_design_process(ivl_design_t des
,
447 ivl_process_f fun
, void*cd
);
448 extern ivl_scope_t
ivl_design_root(ivl_design_t des
);
449 extern void ivl_design_roots(ivl_design_t des
,
450 ivl_scope_t
**scopes
,
451 unsigned int *nscopes
);
452 extern int ivl_design_time_precision(ivl_design_t des
);
454 extern unsigned ivl_design_consts(ivl_design_t des
);
455 extern ivl_net_const_t
ivl_design_const(ivl_design_t
, unsigned idx
);
458 * Literal constants are nodes with no input and a single constant
459 * output. The form of the output depends on the type of the node.
460 * The output is an array of 4-value bits, using a single char
461 * value for each bit. The bits of the vector are in canonical (lsb
462 * first) order for the width of the constant.
465 * The is the type of the node.
468 * This returns a pointer to an array of conststant characters,
469 * each byte a '0', '1', 'x' or 'z'. The array is *not* nul
473 * Return the ivl_nexus_t of the output for the constant.
476 * Return true (!0) if the constant is a signed value, 0 otherwise.
479 * Return the width, in logical bits, of the constant.
483 * The const_type of the literal constant must match the
484 * ivl_signal_data_type if the signals that share the nexus of this
485 * node. The compiler makes sure it is so, converting constant values
491 * Real valued constants have a width of 1. The value emitted to the
492 * output is ivl_const_real.
494 extern ivl_variable_type_t
ivl_const_type(ivl_net_const_t net
);
495 extern const char* ivl_const_bits(ivl_net_const_t net
);
496 extern ivl_nexus_t
ivl_const_nex(ivl_net_const_t net
);
497 extern int ivl_const_signed(ivl_net_const_t net
);
498 extern unsigned ivl_const_width(ivl_net_const_t net
);
499 extern double ivl_const_real(ivl_net_const_t net
);
501 /* extern ivl_nexus_t ivl_const_pin(ivl_net_const_t net, unsigned idx); */
502 /* extern unsigned ivl_const_pins(ivl_net_const_t net); */
506 * Events are a unification of named events and implicit events
507 * generated by the @ statements.
511 * ivl_event_name (Obsolete)
513 * Return the name of the event. The basename is the name within
514 * the scope, as declared by the user or generated by elaboration.
517 * All events exist within a scope.
521 * Named events (i.e. event objects declared by the Verilog
522 * declaration "event foo") are recognized by the fact that they have
523 * no edge sources. The name of the event as given in the Verilog
524 * source is available from the ivl_event_basename function.
526 * Named events are referenced in trigger statements.
528 * Edge events are created implicitly by the @(...) Verilog syntax to
529 * watch for the correct type of edge for the functor being
530 * watched. The nodes to watch are collected into groups based on the
531 * type of edge to be watched for on that node. For example, nodes to
532 * be watched for positive edges are accessed via the ivl_event_npos
533 * and ivl_event_pos functions.
535 extern const char* ivl_event_name(ivl_event_t net
);
536 extern const char* ivl_event_basename(ivl_event_t net
);
537 extern ivl_scope_t
ivl_event_scope(ivl_event_t net
);
539 extern unsigned ivl_event_nany(ivl_event_t net
);
540 extern ivl_nexus_t
ivl_event_any(ivl_event_t net
, unsigned idx
);
542 extern unsigned ivl_event_nneg(ivl_event_t net
);
543 extern ivl_nexus_t
ivl_event_neg(ivl_event_t net
, unsigned idx
);
545 extern unsigned ivl_event_npos(ivl_event_t net
);
546 extern ivl_nexus_t
ivl_event_pos(ivl_event_t net
, unsigned idx
);
551 * These methods operate on expression objects from the
552 * design. Expressions mainly exist in behavioral code. The
553 * ivl_expr_type() function returns the type of the expression node,
554 * and the remaining functions access value bits of the expression.
557 * This method returns true (!= 0) if the expression node
558 * represents a signed expression. It is possible for sub-
559 * expressions to be unsigned even if a node is signed, but the
560 * IVL core figures all this out for you. At any rate, this method
561 * can be applied to any expression node.
564 * Get the type of the expression node. Every expression node has a
565 * type, which can affect how some of the other expression methods
566 * operate on the node
569 * Get the data type of the expression node. This uses the variable
570 * type enum to express the type of the expression node.
573 * This method returns the bit width of the expression at this
574 * node. It can be applied to any expression node, and returns the
575 * *output* width of the expression node.
578 * This function returns the ivl_parameter_t object that represents
579 * this object, or 0 (nil) if it is not a parameter value. This
580 * function allows the code generator to detect the case where the
581 * expression is a parameter. This will normally only return a
582 * non-nil value for constants.
585 * IVL_EX_BINARY and IVL_EX_UNARY expression nodes include an
586 * opcode from this table:
595 * This expression type is a special case of the IVL_EX_SIGNAL where
596 * the target is an array (ivl_signal_t with an array_count) but there
597 * is no index expression. This is used only in the special situation
598 * where the array is passed to a system task/function. The function
599 * ivl_expr_signal returns the ivl_signal_t of the array object, and
600 * from that all the properties of the array can be determined.
605 * This expression takes two operands, oper1 is the expression to
606 * select from, and oper2 is the selection base. The ivl_expr_width
607 * value is the width of the bit/part select. The ivl_expr_oper1 value
608 * is the base of a vector. The compiler has already figured out any
609 * conversion from signal units to vector units, so the result of
610 * ivl_expr_oper1 should range from 0 to ivl_expr_width().
613 * This expression references a signal vector. The ivl_expr_signal
614 * function gets a handle for the signal that is referenced. The
615 * signal may be an array (see the ivl_signal_array_count function)
616 * that is addressed by the expression returned by the ivl_expr_oper1
617 * function. This expression returns a *canonical* address. The core
618 * compiler already corrected the expression to account for index
621 * The ivl_expr_width function returns the vector width of the signal
622 * word. The ivl_expr_value returns the data type of the word.
624 * Bit and part selects are not done here. The IVL_EX_SELECT
625 * expression does bit/part selects on the word read from the signal.
628 * This expression refers to a string constant. The ivl_expr_string
629 * function returns a pointer to the first byte of the string. The
630 * compiler has translated it to a "vvp escaped string" which has
631 * quoting and escapes eliminated. The string may contain octal
632 * escapes (\<oct>) so that the string text returned by
633 * ivl_expr_string will only contain graphical characters. It is up to
634 * the target to change the escaped \NNN to the proper byte value when
635 * using this string. No other escape sequences will appear in the
636 * string. Quote (") and slash (\) characters will be delivered in
640 extern ivl_expr_type_t
ivl_expr_type(ivl_expr_t net
);
641 extern ivl_variable_type_t
ivl_expr_value(ivl_expr_t net
);
644 extern const char* ivl_expr_bits(ivl_expr_t net
);
646 extern ivl_scope_t
ivl_expr_def(ivl_expr_t net
);
648 extern double ivl_expr_dvalue(ivl_expr_t net
);
649 /* IVL_EX_SIGNAL, IVL_EX_SFUNC, IVL_EX_VARIABLE */
650 extern const char* ivl_expr_name(ivl_expr_t net
);
651 /* IVL_EX_BINARY IVL_EX_UNARY */
652 extern char ivl_expr_opcode(ivl_expr_t net
);
653 /* IVL_EX_BINARY IVL_EX_UNARY, IVL_EX_MEMORY IVL_EX_TERNARY */
654 extern ivl_expr_t
ivl_expr_oper1(ivl_expr_t net
);
655 /* IVL_EX_BINARY IVL_EX_TERNARY */
656 extern ivl_expr_t
ivl_expr_oper2(ivl_expr_t net
);
658 extern ivl_expr_t
ivl_expr_oper3(ivl_expr_t net
);
660 extern ivl_parameter_t
ivl_expr_parameter(ivl_expr_t net
);
661 /* IVL_EX_CONCAT IVL_EX_UFUNC */
662 extern ivl_expr_t
ivl_expr_parm(ivl_expr_t net
, unsigned idx
);
663 /* IVL_EX_CONCAT IVL_EX_SFUNC IVL_EX_UFUNC */
664 extern unsigned ivl_expr_parms(ivl_expr_t net
);
666 extern unsigned ivl_expr_repeat(ivl_expr_t net
);
668 extern ivl_event_t
ivl_expr_event(ivl_expr_t net
);
670 extern ivl_scope_t
ivl_expr_scope(ivl_expr_t net
);
672 extern ivl_signal_t
ivl_expr_signal(ivl_expr_t net
);
674 extern int ivl_expr_signed(ivl_expr_t net
);
676 extern const char* ivl_expr_string(ivl_expr_t net
);
678 extern unsigned long ivl_expr_uvalue(ivl_expr_t net
);
680 extern unsigned ivl_expr_width(ivl_expr_t net
);
685 * These types and functions support manipulation of logic gates. The
686 * ivl_logic_t enumeration identifies the various kinds of gates that
687 * the ivl_net_logic_t can represent. The various functions then
688 * provide access to the bits of information for a given logic device.
690 * The ivl_net_logic_t nodes are bit-slice devices. That means that
691 * the device may have width (and therefore processes vectors) but
692 * each bit slice of the width is independent.
695 * This method returns the type of logic gate that the node
696 * represents. The logic type implies the meaning of the various pins.
698 * ivl_logic_name (obsolete)
699 * This method returns the complete name of the logic gate. Every
700 * gate has a complete name (that includes the scope) even if the
701 * Verilog source doesn't include one. The compiler will choose one
705 * This is the name of the gate without the scope part.
708 * This is the scope that directly contains the logic device.
712 * Return the nexus for the pin. If two pins are connected
713 * together, then these values are the same. Use the nexus
714 * functions to find other pins that are connected to this nexus.
717 * This returns the width of the logic array. This does not affect
718 * the number of pins, but implies the width of the vector at each
722 * Logic devices have a delay for each transition (0, 1 and Z).
724 * ivl_logic_attr (obsolete)
725 * Return the value of a specific attribute, given the key name as
726 * a string. If the key is not defined, then return 0 (null).
730 * These support iterating over logic attributes. The _cnt method
731 * returns the number of attributes attached to the gate, and the
732 * ivl_logic_attr_val returns the value of the attribute.
735 * The ivl_logic_width applies to all the pins of a logic device. If a
736 * logic device has width, that means that it is actually an array of
737 * logic devices tha each process a bit slice of the
738 * inputs/output. That implies that the widths of all the inputs and
739 * the output must be identical.
741 * The ivl_logic_width and ivl_logic_pins are *not* related. A logic
742 * device has a number of pins that is the number of inputs to a logic
743 * array of identical gates, and the ivl_logic_width, is the width of
744 * the vector into each input pin and out of the output pin.
746 * The output pin is pin-0. The ivl_logic_driveX functions return the
747 * drive strengths for the output pin-0, and match the drive values
748 * stored in the ivl_nexus_ptr_t object for the pin.
750 * Logic devices have a logic propagation delay. The delay can be any
751 * expression, although the most common expression is an IVL_EX_NUMBER
752 * for a number value. The expression already includes scaling for the
753 * containing module, so the delay value is always taken to be in
754 * simulation clock ticks.
756 * If the delay is present, then ivl_logic_delay returns a non-nil
757 * object. If any of the three delays is present, then all three are
758 * present, even if they are all the same. The compiler will translate
759 * shorthands into a complete set of delay expressions.
761 * The ivl_logic_delay expression will always be an IVL_EX_NUMBER, an
762 * IVL_EX_ULONG, or an IVL_EX_SIGNAL. These expressions can easily be
763 * used in structural contexts. The compiler will take care of
764 * elaborating more complex expressions to nets.
766 * - IVL_LO_PULLUP/IVL_LO_PULLDOWN
767 * These devices are grouped as logic devices with zero inputs because
768 * the outputs have the same characteristics as other logic
769 * devices. They are special only in that they have zero inputs, and
770 * their drivers typically have strength other than strong.
773 * User defined primitives (UDPs) are like any other logic devices, in
774 * that they are bit-slice devices. If they have a width, then they
775 * are repeated to accommodate that width, and that implies that the
776 * output and all the inputs must have the same width.
778 * The IVL_LO_UDP represents instantiations of UDP devices. The
779 * ivl_udp_t describes the implementation.
782 extern const char* ivl_logic_name(ivl_net_logic_t net
);
783 extern const char* ivl_logic_basename(ivl_net_logic_t net
);
784 extern ivl_scope_t
ivl_logic_scope(ivl_net_logic_t net
);
785 extern ivl_logic_t
ivl_logic_type(ivl_net_logic_t net
);
786 extern ivl_nexus_t
ivl_logic_pin(ivl_net_logic_t net
, unsigned pin
);
787 extern unsigned ivl_logic_pins(ivl_net_logic_t net
);
788 extern ivl_udp_t
ivl_logic_udp(ivl_net_logic_t net
);
789 extern ivl_expr_t
ivl_logic_delay(ivl_net_logic_t net
, unsigned transition
);
790 extern ivl_drive_t
ivl_logic_drive0(ivl_net_logic_t net
);
791 extern ivl_drive_t
ivl_logic_drive1(ivl_net_logic_t net
);
792 extern unsigned ivl_logic_width(ivl_net_logic_t net
);
795 extern const char* ivl_logic_attr(ivl_net_logic_t net
, const char*key
);
797 extern unsigned ivl_logic_attr_cnt(ivl_net_logic_t net
);
798 extern ivl_attribute_t
ivl_logic_attr_val(ivl_net_logic_t net
, unsigned idx
);
801 * These methods allow access to the ivl_udp_t definition of a UDP.
802 * The UDP definition is accessed through the ivl_logic_udp method of
803 * an ivl_net_logic_t object.
806 * This returns the name of the definition of the primitive.
809 * This is the number of inputs for the UDP definition.
813 * These methods give access to the rows that define the table of
818 * - Combinational primitives
819 * These devices have no edge dependencies, and have no table entry
820 * for the current input value. These have ivl_udp_sequ return 0
821 * (false) and the length of each row is the number of inputs plus 1.
822 * The first N characters correspond to the N inputs of the
823 * device. The next character, the last character, is the output for
826 * - Sequential primitives
827 * These devices allow edge transitions, and the rows are 1+N+1
828 * characters long. The first character is the current output, the
829 * next N characters the current input and the last character is the
832 * The ivl_udp_init value is only valid if the device is
833 * sequential. It is the initial value for the output of the storage
837 extern int ivl_udp_sequ(ivl_udp_t net
);
838 extern unsigned ivl_udp_nin(ivl_udp_t net
);
839 extern unsigned ivl_udp_init(ivl_udp_t net
);
840 extern const char* ivl_udp_row(ivl_udp_t net
, unsigned idx
);
841 extern unsigned ivl_udp_rows(ivl_udp_t net
);
842 extern const char* ivl_udp_name(ivl_udp_t net
);
846 * These functions support access to the properties of LPM
847 * devices. LPM devices are a variety of devices that handle more
848 * complex structural semantics. They are based on EIA LPM standard
849 * devices, but vary to suite the technical situation.
851 * These are the functions that apply to all LPM devices:
853 * ivl_lpm_name (Obsolete)
855 * Return the name of the device. The name is the name of the
856 * device with the scope part, and the basename is without the scope.
859 * LPM devices exist within a scope. Return the scope that contains
863 * Return the ivl_lpm_type_t of the specific LPM device.
866 * Return the width of the LPM device. What this means depends on
867 * the LPM type, but it generally has to do with the width of the
871 * These functions apply to a subset of the LPM devices, or may have
872 * varying meaning depending on the device:
875 * The IVL_LPM_PART objects use this value as the base (first bit)
876 * of the part select. The ivl_lpm_width is the size of the part.
879 * Return the input data nexus for device types that have input
880 * vectors. The "idx" parameter selects which data input is selected.
882 * ivl_lpm_datab (ANACHRONISM)
883 * This is the same as ivl_lpm_data(net,1), in other words the
884 * second data input. Use the ivl_lpm_data method instead.
887 * Return the output data nexus for device types that have a single
888 * output vector. This is most devices, it turns out.
891 * This is the size of the select input for a LPM_MUX device, or the
892 * address bus width of an LPM_RAM.
895 * Arithmetic LPM devices may be signed or unsigned if there is a
896 * distinction. For some devices this gives the signedness of the
897 * output, but not all devices.
900 * In addition to a width, some devices have a size. The size is
901 * often the number of inputs per out, i.e., the number of inputs
906 * - Concatenation (IVL_LPM_CONCAT)
907 * These devices take vectors in and combine them to form a single
908 * output the width specified by ivl_lpm_width.
910 * The ivl_lpm_q nexus is the output from the concatenation.
912 * The ivl_lpm_data function returns the connections for the inputs to
913 * the concatentation. The ivl_lpm_size function returns the number of
914 * inputs help by the device.
916 * - Divide (IVL_LPM_DIVIDE)
917 * The divide operators take two inputs and generate an output. The
918 * ivl_lpm_width returns the width of the result. The width of the
919 * inputs are their own.
921 * - Multiply (IVL_LPM_MULT)
922 * The multiply takes two inputs and generates an output. Unlike other
923 * arithmetic nodes, the width only refers to the output. The inputs
924 * have independent widths, to reflect the arithmetic truth that the
925 * width of a general multiply is the sum of the widths of the
926 * inputs. In fact, the compiler doesn't assure that the widths of the
927 * inputs add up to the width of the output, but the possibility
928 * exists. It is *not* an error for the sum of the input widths to be
929 * more than the width of the output, although the possibility of
930 * overflow exists at run time.
932 * Multiply may be signed. If so, the output should be sign extended
933 * to fill in its result.
935 * - Part Select (IVL_LPM_PART_VP and IVL_LPM_PART_PV)
936 * There are two part select devices, one that extracts a part from a
937 * vector, and another that writes a part of a vector. The _VP is
938 * Vector-to-Part, and _PV is Part-to-Vector. The _VP form is meant to
939 * model part/bin selects in r-value expressions, where the _PV from
940 * is meant to model part selects in l-value nets.
942 * In both cases, ivl_lpm_data(0) is the input pin, and ivl_lpm_q is the
943 * output. In the case of the _VP device, the vector is input and the
944 * part is the output. In the case of the _PV device, the part is the
945 * input and the vector is the output.
947 * If the base of the part select is non-constant, then
948 * ivl_lpm_data(1) is non-nil and is the select, or base, address of
949 * the part. If this pin is nil, then the constant base is used
952 * Also in both cases, the width of the device is the width of the
953 * part. In the _VP case, this is obvious as the output nexus has the
954 * part width. In the _PV case, this is a little less obvious, but
955 * still correct. The output being written to the wider vector is
956 * indeed the width of the part, even though it is written to a wider
957 * gate. The target will need to handle this case specially.
959 * - Bi-directional Part Select (IVL_LPM_PART_BI)
960 * This is not exactly a part select but a bi-directional partial link
961 * of two nexa with different widths. This is used to implement tran
962 * devices and inout ports in certain cases. The device width is the
963 * width of the part. The ivl_lpm_q is the part end, and the
964 * ivl_lpm_data(0) is the non-part end.
966 * - Comparisons (IVL_LPM_CMP_GT/GE/EQ/NE/EEQ/NEE)
967 * These devices have two inputs, available by the ivl_lpm_data()
968 * function, and one output available by the ivl_lpm_q function. The
969 * output width is always 1, but the ivl_lpm_width() returns the width
970 * of the inputs. Both inputs must have the same width.
972 * The CMP_GE and CMP_GT nodes may also be signed or unsigned, with
973 * the obvious implications. The widths are matched by the compiler
974 * (so the target need not worry about sign extension) but when doing
975 * magnitude compare, the signedness does matter. In any case, the
976 * result of the compare is always unsigned.
978 * - Mux Device (IVL_LPM_MUX)
979 * The MUX device has a q output, a select input, and a number of data
980 * inputs. The ivl_lpm_q output and the ivl_lpm_data inputs all have
981 * the width from the ivl_lpm_width() method. The Select input, from
982 * ivl_lpm_select, has the width ivl_lpm_selects().
984 * The ivl_lpm_data() method returns the inputs of the MUX device. The
985 * ivl_lpm_size() method returns the number of data inputs there
986 * are. All the data inputs have the same width, the width of the
987 * ivl_lpm_q output. The type of the device is devined from the
988 * inputs and the Q. All the types must be exactly the same.
990 * - D-FlipFlop (IVL_LPM_FF)
991 * This data is an edge sensitive register. The ivl_lpm_q output and
992 * single ivl_lpm_data input are the same with, ivl_lpm_width. This
993 * device carries a vector like other LPM devices.
995 * - Memory port (IVL_LPM_RAM) (deprecated in favor of IVL_LPM_ARRAY)
996 * These are structural ports into a memory device. They represent
997 * address/data ports of a memory device that the context can hook to
998 * for read or write. Read devices have an ivl_lpm_q output port that
999 * is the data being read.
1001 * The ivl_lpm_memory function returns the ivl_memory_t for the memory
1002 * that the port access. The ivl_lpm_width for the port then must
1003 * match the ivl_memory_width of the memory device.
1005 * Read or write, the ivl_lpm_select nexus is the address. The
1006 * ivl_lpm_selects function returns the vector width of the
1007 * address. The range of the address is always from 0 to the memory
1008 * size-1 -- the canonical form. It is up to the compiler to generate
1009 * offsets to correct for a range declaration.
1011 * Read ports use the ivl_lpm_q as the data output, and write ports
1012 * use the ivl_lpm_data(0) as the input. In either case the width of
1013 * the vector matches the width of the memory itself.
1015 * - Reduction operators (IVL_LPM_RE_*)
1016 * These devices have one input, a vector, and generate a single bit
1017 * result. The width from the ivl_lpm_width is the width of the input
1020 * - Repeat Node (IVL_LPM_REPEAT)
1021 * This node takes as input a single vector, and outputs a single
1022 * vector. The ivl_lpm_width if this node is the width of the *output*
1023 * vector. The ivl_lpm_size() returns the number of times the input is
1024 * repeated to get the desired width. The ivl core assures that the
1025 * input vector is exactly ivl_lpm_width() / ivl_lpm_size() bits.
1027 * - Sign Exend (IVL_LPM_SIGN_EXT)
1028 * This node takes a single input and generates a single output. The
1029 * input must be signed, and the output will be a vector sign extended
1030 * to the desired width. The ivl_lpm_width() value is the output
1031 * width, the input will be whatever it wants to be.
1033 * - Shifts (IVL_LPM_SHIFTL/SHIFTR)
1034 * This node takes two inputs, a vector and a shift distance. The
1035 * ivl_lpm_data(0) nexus is the vector input, and the ivl_lpm_data(1)
1036 * the shift distance. The vector input is the same width as the
1037 * output, but the distance has its own width.
1039 * The ivl_lpm_signed() flag means for IVL_LPM_SHIFTR that the right
1040 * shift is *signed*. For SHIFTL, then signed-ness is emaningless.
1042 * - System function call (IVL_LPM_SFUNC)
1043 * This device represents a netlist call to a system function. The
1044 * inputs to the device are passed to a system function, and the
1045 * result is sent via the output. The ivl_lpm_q function returns the
1048 * The ivl_lpm_size function returns the number of arguments, and the
1049 * ivl_lpm_data(net,N) returns the nexa for the argument.
1051 * The ivl_lpm_string(net) function returns the name of the system
1052 * function (i.e. "$display") that was found in the source code. The
1053 * compiler does little checking of that name.
1055 * - User Function Call (IVL_LPM_UFUNC)
1056 * This device is special as it represents a call to a user defined
1057 * function (behavioral code) within a netlist. The inputs to the
1058 * function are connected to the net, as is the output.
1060 * The function definition is associated with a scope, and the
1061 * ivl_lpm_define fuction returns the scope that is that definition.
1062 * See the ivl_scope_* fuctions for how to get at the actual
1065 * As with many LPM nodes, the ivl_lpm_q function returns the nexus
1066 * for the signal function return value. The width of this nexus must
1067 * exactly match the width of the device from ivl_lpm_width.
1069 * The ivl_lpm_data function retrives the nexa for all the input
1070 * ports. The ivl_lpm_size function returns the number of inputs for
1071 * the device, and the ivl_lpm_data() function index argument selects
1072 * the port to retrieve. Each port is sized independently.
1075 extern const char* ivl_lpm_name(ivl_lpm_t net
); /* (Obsolete) */
1076 extern const char* ivl_lpm_basename(ivl_lpm_t net
);
1077 extern ivl_scope_t
ivl_lpm_scope(ivl_lpm_t net
);
1078 extern int ivl_lpm_signed(ivl_lpm_t net
);
1079 extern ivl_lpm_type_t
ivl_lpm_type(ivl_lpm_t net
);
1080 extern unsigned ivl_lpm_width(ivl_lpm_t net
);
1083 extern ivl_nexus_t
ivl_lpm_async_clr(ivl_lpm_t net
);
1084 extern ivl_nexus_t
ivl_lpm_async_set(ivl_lpm_t net
);
1085 extern ivl_expr_t
ivl_lpm_aset_value(ivl_lpm_t net
);
1086 extern ivl_nexus_t
ivl_lpm_sync_clr(ivl_lpm_t net
);
1087 extern ivl_nexus_t
ivl_lpm_sync_set(ivl_lpm_t net
);
1088 extern ivl_expr_t
ivl_lpm_sset_value(ivl_lpm_t net
);
1090 extern ivl_signal_t
ivl_lpm_array(ivl_lpm_t net
);
1092 extern unsigned ivl_lpm_base(ivl_lpm_t net
);
1094 extern ivl_nexus_t
ivl_lpm_clk(ivl_lpm_t net
);
1096 extern ivl_scope_t
ivl_lpm_define(ivl_lpm_t net
);
1098 extern ivl_nexus_t
ivl_lpm_enable(ivl_lpm_t net
);
1099 /* IVL_LPM_ADD IVL_LPM_CONCAT IVL_LPM_FF IVL_LPM_PART IVL_LPM_MULT
1100 IVL_LPM_MUX IVL_LPM_SHIFTL IVL_LPM_SHIFTR IVL_LPM_SUB
1102 extern ivl_nexus_t
ivl_lpm_data(ivl_lpm_t net
, unsigned idx
);
1103 /* IVL_LPM_ADD IVL_LPM_MULT IVL_LPM_SUB */
1104 extern ivl_nexus_t
ivl_lpm_datab(ivl_lpm_t net
, unsigned idx
);
1105 /* IVL_LPM_ADD IVL_LPM_FF IVL_LPM_MULT IVL_LPM_PART
1106 IVL_LPM_SUB IVL_LPM_UFUNC */
1107 extern ivl_nexus_t
ivl_lpm_q(ivl_lpm_t net
, unsigned idx
);
1109 extern unsigned ivl_lpm_selects(ivl_lpm_t net
);
1111 extern ivl_nexus_t
ivl_lpm_select(ivl_lpm_t net
);
1112 /* IVL_LPM_CONCAT IVL_LPM_MUX IVL_LPM_REPEAT IVL_LPM_UFUNC */
1113 extern unsigned ivl_lpm_size(ivl_lpm_t net
);
1115 extern const char*ivl_lpm_string(ivl_lpm_t net
);
1118 * The l-values of assignments are concatenation of ivl_lval_t
1119 * objects. Each lvi_lval_t object is an assignment to a var or a
1120 * memory, through a bit select, part select or word select.
1122 * Var lvals are things like assignments to a part select or a bit
1123 * select. Assignment to the whole variable is a special case of a
1124 * part select, as is a bit select with a constant expression.
1127 * The width of a vector that this lval can receive. This accounts
1128 * for the local part selecting I might to in the lval object, as
1129 * well as the target object width.
1132 * If the l-value includes a bit select expression, this method
1133 * returns an ivl_expr_t that represents that
1134 * expression. Otherwise, it returns 0.
1136 * (Should this be combined with ivl_lval_idx? -Ed)
1138 * ivl_lval_mem (deprecated)
1139 * If the l-value is a memory, this method returns an
1140 * ivl_memory_t that represents that memory. Otherwise, it
1144 * If the l-value is a variable, this method returns the signal
1145 * object that is the target of the assign.
1148 * The part select of the signal is based here. This is the
1149 * canonical index of bit-0 of the part select. The return value is
1150 * an ivl_expr_t. If the return value is nil, then take the offset
1151 * as zero. Otherwise, evaluate the expression to get the offset.
1154 * If the l-value is a memory, this method returns an
1155 * ivl_expr_t that represents the index expression. Otherwise, it
1159 * The ivl_lval_width is not necessarily the same as the width of the
1160 * signal or memory word it represents. It is the width of the vector
1161 * it receives and assigns. This may be less then the width of the
1162 * signal (or even 1) if only a part of the l-value signal is to be
1165 * The ivl_lval_part_off is the canonical base of a part or
1168 * - Memory words (Replace this with Array words below)
1169 * If the l-value is a memory word, the ivl_lval_mem function returns
1170 * a non-nil value. The ivl_lval_idx function will return an
1171 * expression that calculates an address for the memory. The compiler
1172 * will assure that the ivl_lval_width will exactly match the
1173 * ivl_memory_width of the memory word.
1176 * If the l-value is an array, then ivl_lval_idx function will return
1177 * an expression that calculates the address of the array word. If
1178 * the referenced signal has more than one word, this expression must
1179 * be present. If the signal has exactly one word (it is not an array)
1180 * then the ivl_lval_idx exression must *not* be present.
1182 * For array words, the ivl_lval_width is the width of the word.
1185 extern unsigned ivl_lval_width(ivl_lval_t net
);
1186 extern ivl_expr_t
ivl_lval_mux(ivl_lval_t net
); // XXXX Obsolete?
1187 extern ivl_expr_t
ivl_lval_idx(ivl_lval_t net
);
1188 extern ivl_expr_t
ivl_lval_part_off(ivl_lval_t net
);
1189 extern ivl_signal_t
ivl_lval_sig(ivl_lval_t net
);
1193 * connections of signals and nodes is handled by single-bit
1194 * nexus. These functions manage the ivl_nexus_t object. They also
1195 * manage the ivl_nexus_ptr_t objects that are closely related to the
1199 * Each nexus is given a name, typically derived from the signals
1200 * connected to it, but completely made up if need be. The name of
1201 * every nexus is unique.
1204 * This function returns the number of pointers that are held by
1205 * the nexus. It should always return at least 1. The pointer
1206 * proper is accessed by index.
1209 * Return a nexus pointer given the nexus and an index.
1211 * ivl_nexus_set_private
1212 * ivl_nexus_get_private
1213 * The target module often needs to associate data with a nexus for
1214 * later use when the nexus is encountered associated with a
1215 * device. These methods allow the code generator to store to or
1216 * retrieve from a nexus a void* of private data. This pointer is
1217 * guaranteed to be 0 before the target module is invoked.
1219 * Once an ivl_nexus_ptr_t is selected by the ivl_nexus_ptr method,
1220 * the properties of the pointer can be accessed by the following
1224 * This returns the pin number of the device where this nexus
1225 * points. It is the bit within the signal or logic device that is
1226 * connected to the nexus.
1228 * If the target is an LPM device, then this value is zero, and it
1229 * is up to the application to find the pin that refers to this
1230 * nexus. The problem is that LPM devices do not have a pinout per
1231 * se, the pins all have specific names.
1234 * If this is a pointer to a magic constant device, then this
1235 * returns the net_const object.
1237 * ivl_nexus_ptr_drive0
1238 * ivl_nexus_ptr_drive1
1239 * These are the 0 and 1 strength values for the devices. For most
1240 * devices, these values are fixed by the description in the
1241 * original source, with the default as IVL_DR_STRONG. For pins
1242 * that are input only, drive0 and drive1 are both IVL_DR_HiZ.
1244 * The strength of strength-aware devices (such as nmos devices)
1245 * does not really matter, as long at the output is not
1246 * IVL_DR_HiZ. Testing for HiZ drivers is how code generators
1250 * If the target object is an ivl_net_logic_t, this method returns
1251 * the object. Otherwise, this method returns 0.
1254 * If the target object is an ivl_lpm_t, this method returns the
1255 * object. Otherwise, this method returns 0.
1258 * If the target object is an ivl_signal_t, this method returns the
1259 * object. If the target is not a signal, this method returns 0.
1262 * All the device pins that connect to a nexus have the same
1263 * type. That means, for example, that vector pins have the same
1264 * width. The compiler will insure this is so.
1267 extern const char* ivl_nexus_name(ivl_nexus_t net
);
1268 extern unsigned ivl_nexus_ptrs(ivl_nexus_t net
);
1269 extern ivl_nexus_ptr_t
ivl_nexus_ptr(ivl_nexus_t net
, unsigned idx
);
1271 extern void ivl_nexus_set_private(ivl_nexus_t net
, void*data
);
1272 extern void* ivl_nexus_get_private(ivl_nexus_t net
);
1275 extern ivl_drive_t
ivl_nexus_ptr_drive0(ivl_nexus_ptr_t net
);
1276 extern ivl_drive_t
ivl_nexus_ptr_drive1(ivl_nexus_ptr_t net
);
1277 extern unsigned ivl_nexus_ptr_pin(ivl_nexus_ptr_t net
);
1278 extern ivl_net_const_t
ivl_nexus_ptr_con(ivl_nexus_ptr_t net
);
1279 extern ivl_net_logic_t
ivl_nexus_ptr_log(ivl_nexus_ptr_t net
);
1280 extern ivl_lpm_t
ivl_nexus_ptr_lpm(ivl_nexus_ptr_t net
);
1281 extern ivl_signal_t
ivl_nexus_ptr_sig(ivl_nexus_ptr_t net
);
1284 * Parameters are named constants associated with a scope. The user
1285 * may set in the Verilog source the value of parameters, and that
1286 * leads to ivl_parameter_t objects contained in the ivl_scope_t
1289 * Parameters are essentially named constants. These constant values
1290 * can be accessed by looking at the scope (using ivl_scope_param) or
1291 * they can be discovered when they are used, via the
1292 * ivl_expr_parameter function. The fact that a constant has a name
1293 * (i.e. is a parameter) does not otherwise impose on the value or
1294 * interpretation of the constant expression so far as ivl_target is
1295 * concerned. The target may need this information, or may choose to
1296 * completely ignore it.
1298 * ivl_parameter_basename
1299 * return the name of the parameter.
1301 * ivl_parameter_scope
1302 * Return the scope of the parameter. The parameter name is only
1303 * unique within its scope.
1305 * ivl_parameter_expr
1306 * Return the value of the parameter. This should be a simple
1307 * constant expression, an IVL_EX_STRING or IVL_EX_NUMBER.
1309 extern const char* ivl_parameter_basename(ivl_parameter_t net
);
1310 extern ivl_scope_t
ivl_parameter_scope(ivl_parameter_t net
);
1311 extern ivl_expr_t
ivl_parameter_expr(ivl_parameter_t net
);
1315 * Scopes of various sort have these properties. Use these methods to
1316 * access them. Scopes come to exist in the elaborated design
1317 * generally when a module is instantiated, though they also come from
1318 * named blocks, tasks and functions.
1320 * - module instances (IVL_SCT_MODULE)
1321 * A module instance scope may contain events, logic gates, lpm
1322 * nodes, signals, and possibly children. The children are further
1323 * instances, or function/task scopes. Module instances do *not*
1324 * contain a definition.
1326 * - function scopes (IVL_SCT_FUNCTION)
1327 * These scopes represent functions. A function may not be a root,
1328 * so it is contained within a module instance scope. A function is
1329 * required to have a definition (in the form of a statement) and a
1330 * signal (IVL_SIG_REG) that is its return value.
1332 * A single function scope is created each time the module with the
1333 * definition is instantiated.
1336 * - task scopes (IVL_SCT_TASK)
1339 * ivl_scope_attr_cnt
1340 * ivl_scope_attr_val
1341 * A scope may have attributes attached to it. These functions
1342 * allow the target to access the attributes values.
1344 * ivl_scope_children
1345 * A scope may in turn contain other scopes. This method iterates
1346 * through all the child scopes of a given scope. If the function
1347 * returns any value other than 0, the iteration stops and the
1348 * method returns that value. Otherwise, iteration continues until
1349 * the children run out.
1351 * If the scope has no children, this method will return 0 and
1352 * otherwise do nothing.
1355 * Task definition scopes carry a task definition, in the form of
1356 * a statement. This method accesses that definition. The
1357 * ivl_scope_def function must return a statement for scopes that
1358 * are type FUNCTION or TASK, and must return nil otherwise.
1362 * Scopes have 0 or more event objects in them.
1370 * Scopes have 0 or more logic devices in them. A logic device is
1371 * represented by ivl_logic_t.
1375 * Scopes have 0 or more LPM devices in them. These functions access
1379 * ivl_scope_basename
1380 * Every scope has a hierarchical name. This name is also a prefix
1381 * of all the names of objects contained within the scope. The
1382 * ivl_scope_basename is the name of the scope without the included
1387 * A scope has zero or more named parameters. These parameters have
1388 * a name and an expression value.
1391 * If this is a non-root scope, then the parent is the scope that
1392 * contains this scope. Otherwise, the parent is nil.
1396 * Scopes that are functions or tasks have ports defined by
1397 * signals. These methods access the ports by name.
1399 * If this scope represents a function, then the ports list
1400 * includes the return value, as port 0. The remaining ports are
1401 * the input ports in order.
1405 * Scopes have 0 or more signals in them. These signals are
1406 * anything that can become and ivl_signal_t, include synthetic
1407 * signals generated by the compiler.
1409 * ivl_scope_time_units
1410 * Scopes have their own intrinsic time units, typically from the
1411 * timescale compiler directive. This method returns the units as a
1412 * signed power of 10 value.
1416 * Scopes have a type and a type name. For example, if a scope is
1417 * an instance of module foo, its type is IVL_SCT_MODULE and its
1418 * type name is "foo". This is different from the instance name
1419 * returned by ivl_scope_name above.
1422 extern unsigned ivl_scope_attr_cnt(ivl_scope_t net
);
1423 extern ivl_attribute_t
ivl_scope_attr_val(ivl_scope_t net
, unsigned idx
);
1425 extern int ivl_scope_children(ivl_scope_t net
,
1426 ivl_scope_f func
, void*cd
);
1428 extern ivl_statement_t
ivl_scope_def(ivl_scope_t net
);
1430 extern unsigned ivl_scope_events(ivl_scope_t net
);
1431 extern ivl_event_t
ivl_scope_event(ivl_scope_t net
, unsigned idx
);
1432 extern unsigned ivl_scope_logs(ivl_scope_t net
);
1433 extern ivl_net_logic_t
ivl_scope_log(ivl_scope_t net
, unsigned idx
);
1434 extern unsigned ivl_scope_lpms(ivl_scope_t net
);
1435 extern ivl_lpm_t
ivl_scope_lpm(ivl_scope_t
, unsigned idx
);
1436 extern const char* ivl_scope_name(ivl_scope_t net
);
1437 extern const char* ivl_scope_basename(ivl_scope_t net
);
1438 extern unsigned ivl_scope_params(ivl_scope_t net
);
1439 extern ivl_parameter_t
ivl_scope_param(ivl_scope_t net
, unsigned idx
);
1440 extern ivl_scope_t
ivl_scope_parent(ivl_scope_t net
);
1441 extern unsigned ivl_scope_ports(ivl_scope_t net
);
1442 extern ivl_signal_t
ivl_scope_port(ivl_scope_t net
, unsigned idx
);
1443 extern unsigned ivl_scope_sigs(ivl_scope_t net
);
1444 extern ivl_signal_t
ivl_scope_sig(ivl_scope_t net
, unsigned idx
);
1445 extern ivl_scope_type_t
ivl_scope_type(ivl_scope_t net
);
1446 extern const char* ivl_scope_tname(ivl_scope_t net
);
1447 extern int ivl_scope_time_units(ivl_scope_t net
);
1451 * Signals are named things in the Verilog source, like wires and
1452 * regs, and also named things that are created as temporaries during
1453 * certain elaboration or optimization steps. A signal may also be a
1454 * port of a module or task.
1456 * Signals have a name (obviously) and types. A signal may also be
1457 * signed or unsigned.
1460 * This is the nexus of the signal. This is used for managing
1461 * connections to the rest of the net. There is exactly one pin for
1462 * each word of a signal. Each word may in turn be a vector. The
1463 * word address is the zero-based index for the word. It is up to
1464 * the context to translate different bases to the canonical address.
1466 * ivl_signal_array_base
1467 * ivl_signal_array_count
1468 * The signal may be arrayed. If so, the array_count is >1. Each
1469 * word of the array has its own nexus. The array_base is the
1470 * address is the Verilg source for the canonical zero word. This
1471 * may be negative, positive or zero.
1473 * Note that arraying of the signal into words is distinct from the
1474 * vectors. The width of a signal is the width of a WORD.
1476 * ivl_signal_dimensions
1477 * The signal may be an array (of vectors) in which case this
1478 * function returns >0, the number of dimensions of the array.
1483 * These functions return the left and right indices, respectively,
1484 * of the signal. If the signal is a scalar, both return 0. However,
1485 * it doesn't mean that the signal is a scalar if both return 0, one
1486 * can have a vector with 0 as both indices.
1489 * If the signal is a port to a module, this function returns the
1490 * port direction. If the signal is not a port, it returns
1494 * A signal, which is a vector, may be signed. In Verilog 2000, any
1495 * net or variable may be signed. This function returns true if the
1499 * A signal that was generated by the compiler as a place holder is
1503 * Return the type of the signal, i.e., reg, wire, tri0, etc.
1505 * ivl_signal_data_type
1506 * Return the data type of the signal, i.e. logic, real, bool,
1507 * etc. All the signals connected to a nexus should have the same
1512 * This function returns the delay path object for the signal. The
1513 * delay path has this signal as the output, the source is attached
1514 * to the delay path itself.
1516 * ivl_signal_name (DEPRECATED)
1517 * This function returns the fully scoped hierarchical name for the
1518 * signal. The name refers to the entire vector that is the signal.
1520 * NOTE: This function is deprecated. The hierarchical name is too
1521 * vague a construct when escaped names can have . characters in
1522 * them. Do no use this function in new code, it will disappear.
1524 * ivl_signal_basename
1525 * This function returns the name of the signal, without the scope
1526 * information. This is the tail of the signal name. Since Verilog
1527 * has an escape syntax, this name can contain any ASCII
1528 * characters, except NULL or white space. The leading \ and
1529 * trailing ' ' of escaped names in Verilog source are not part of
1530 * the name, so not included here.
1533 * Icarus Verilog supports attaching attributes to signals, with
1534 * the attribute value (a string) associated with a key. This
1535 * function returns the attribute value for the given key. If the
1536 * key does not exist, the function returns 0.
1539 extern ivl_nexus_t
ivl_signal_nex(ivl_signal_t net
, unsigned word
);
1540 extern int ivl_signal_array_base(ivl_signal_t net
);
1541 extern unsigned ivl_signal_array_count(ivl_signal_t net
);
1542 extern unsigned ivl_signal_dimensions(ivl_signal_t net
);
1543 extern int ivl_signal_msb(ivl_signal_t net
);
1544 extern int ivl_signal_lsb(ivl_signal_t net
);
1545 extern unsigned ivl_signal_width(ivl_signal_t net
);
1546 extern ivl_signal_port_t
ivl_signal_port(ivl_signal_t net
);
1547 extern int ivl_signal_signed(ivl_signal_t net
);
1548 extern int ivl_signal_integer(ivl_signal_t net
);
1549 extern int ivl_signal_local(ivl_signal_t net
);
1550 extern unsigned ivl_signal_npath(ivl_signal_t net
);
1551 extern ivl_delaypath_t
ivl_signal_path(ivl_signal_t net
, unsigned idx
);
1552 extern ivl_signal_type_t
ivl_signal_type(ivl_signal_t net
);
1553 extern ivl_variable_type_t
ivl_signal_data_type(ivl_signal_t net
);
1554 extern const char* ivl_signal_name(ivl_signal_t net
);
1555 extern const char* ivl_signal_basename(ivl_signal_t net
);
1556 extern const char* ivl_signal_attr(ivl_signal_t net
, const char*key
);
1558 extern unsigned ivl_signal_attr_cnt(ivl_signal_t net
);
1559 extern ivl_attribute_t
ivl_signal_attr_val(ivl_signal_t net
, unsigned idx
);
1561 /* ivl_nexus_t ivl_signal_pin(ivl_signal_t net, unsigned idx); */
1562 /* unsigned ivl_signal_pins(ivl_signal_t net); */
1565 * These functions get information about a process. A process is
1566 * an initial or always block within the original Verilog source, that
1567 * is translated into a type and a single statement. (The statement
1568 * may be a compound statement.)
1570 * The ivl_process_type function gets the type of the process,
1571 * an "initial" or "always" statement.
1573 * A process is placed in a scope. The statement within the process
1574 * operates within the scope of the process unless there are calls
1575 * outside the scope.
1577 * The ivl_process_stmt function gets the statement that forms the
1578 * process. See the statement related functions for how to manipulate
1581 * Processes can have attributes attached to them. the attr_cnt and
1582 * attr_val methods return those attributes.
1584 extern ivl_process_type_t
ivl_process_type(ivl_process_t net
);
1586 extern ivl_scope_t
ivl_process_scope(ivl_process_t net
);
1588 extern ivl_statement_t
ivl_process_stmt(ivl_process_t net
);
1590 extern unsigned ivl_process_attr_cnt(ivl_process_t net
);
1591 extern ivl_attribute_t
ivl_process_attr_val(ivl_process_t net
, unsigned idx
);
1594 * These functions manage statements of various type. This includes
1595 * all the different kinds of statements (as enumerated in
1596 * ivl_statement_type_t) that might occur in behavioral code.
1598 * The ivl_statement_type() function returns the type code for the
1599 * statement. This is the major type, and implies which of the later
1600 * functions are applicable to the statement.
1602 extern ivl_statement_type_t
ivl_statement_type(ivl_statement_t net
);
1605 * The following functions retrieve specific single values from the
1606 * statement. These values are the bits of data and parameters that
1607 * make up the statement. Many of these functions apply to more than
1608 * one type of statement, so the comment in front of them tells which
1609 * statement types can be passed to the function.
1613 * ivl_stmt_block_scope
1614 * If the block is named, then there is a scope associated with
1615 * this. The code generator may need to know this in order to
1616 * handle disable statements.
1620 * Statements that have event arguments (TRIGGER and WAIT) make
1621 * those event objects available through these methods.
1625 * Return the number of l-values for an assignment statement, or
1626 * the specific l-value. If there is more than 1 l-value, then the
1627 * l-values are presumed to be vector values concatenated together
1628 * from msb (idx==0) to lsb.
1631 * Return the rval expression of the assignment. This is the value
1632 * that is to be calculated and assigned to the l-value in all the
1633 * assignment statements.
1636 * Some statements contain a single, subordinate statement. An
1637 * example is the IVL_ST_WAIT, which contains the statement to be
1638 * executed after the wait completes. This method retrieves that
1643 * - Assignments: IVL_ST_ASSIGN, IVL_ST_ASSIGN_NB, IVL_CASSIGN, IVL_ST_FORCE
1645 * The assignments support ivl_stmt_rval to get the r-value expression
1646 * that is to be assign to the l-value, and ivl_stmt_lval[s] to get
1647 * the l-value that receives the value. The compiler has already made
1648 * sure that the types (l-value and r-value) are compatible.
1650 * If the l-value is a vector, then the compiler also makes sure the
1651 * expression width of the r-values matches. It handles padding or
1652 * operator sizing as needed to get the width exactly right.
1654 * The blocking and non-blocking assignments may also have an internal
1655 * delay. These are of the form "lval = #<delay> rval;" and <delay> is
1656 * the internal delay expression. (It is internal because it is inside
1657 * the statement.) The ivl_stmt_delay_expr function returns the
1658 * expression for the delay, or nil if there is no delay expression.
1661 * This reflects a procedural continuous assignment to an l-value. The
1662 * l-value is the same as any other assignment (use ivl_stmt_lval).
1664 * The value to be assigned is an ivl_expr_t retrieved by the
1665 * ivl_stmt_rval function. The run time is expected to calculate the
1666 * value of the expression at the assignment, then continuous assign
1667 * that constant value. If the expression is non-constant, the code
1668 * generator is supposed to know what to do about that, too.
1670 * - IVL_ST_DELAY, IVL_ST_DELAYX
1671 * These statement types are delay statements. They are a way to
1672 * attach a delay to a statement. The ivl_stmt_sub_stmt() function
1673 * gets the statement to be executed after the delay. If this is
1674 * IVL_ST_DELAY, then the ivl_stmt_delay_val function gets the
1675 * constant delay. If this is IVL_ST_DELAYX, then the
1676 * ivl_stmt_delay_expr gets the expression of the delay. In this case,
1677 * the expression is not necessarily constant.
1679 * Whether constant or calculated, the resulting delay is in units of
1680 * simulation ticks. The compiler has already taken care of converting
1681 * the delay to the time scale/precision of the scope.
1684 * This is very much like IVL_ST_CASSIGN, but adds that l-values can
1685 * include nets (tri, wire, etc). Memory words are restricted from
1686 * force l-values, and also non-constant bit or part selects. The
1687 * compiler will assure these constraints are met.
1690 * This represents the "-> name" statement that sends a trigger to a
1691 * named event. The ivl_stmt_nevent function should always return 1,
1692 * and the ivl_stmt_events(net,0) function returns the target event,
1693 * as an ivl_event_t. The only behavior of this statement is to send a
1694 * "trigger" to the target event.
1697 * This is the edge sensitive wait (for event) statement. The
1698 * statement contains an array of events that are to be tested, and a
1699 * single statement that is to be executed when any of the array of
1702 * the ivl_stmt_events function accesses the array of events to wait
1703 * for, and the ivl_stmt_sub_stmt function gets the sub-statement,
1704 * which may be null, that is to be executed when an event
1705 * triggers. The statement waits even if the sub-statement is nul.
1708 /* IVL_ST_BLOCK, IVL_ST_FORK */
1709 extern unsigned ivl_stmt_block_count(ivl_statement_t net
);
1710 /* IVL_ST_BLOCK, IVL_ST_FORK */
1711 extern ivl_scope_t
ivl_stmt_block_scope(ivl_statement_t net
);
1712 /* IVL_ST_BLOCK, IVL_ST_FORK */
1713 extern ivl_statement_t
ivl_stmt_block_stmt(ivl_statement_t net
, unsigned i
);
1714 /* IVL_ST_UTASK IVL_ST_DISABLE */
1715 extern ivl_scope_t
ivl_stmt_call(ivl_statement_t net
);
1716 /* IVL_ST_CASE,IVL_ST_CASER,IVL_ST_CASEX,IVL_ST_CASEZ */
1717 extern unsigned ivl_stmt_case_count(ivl_statement_t net
);
1718 /* IVL_ST_CASE,IVL_ST_CASER,IVL_ST_CASEX,IVL_ST_CASEZ */
1719 extern ivl_expr_t
ivl_stmt_case_expr(ivl_statement_t net
, unsigned i
);
1720 /* IVL_ST_CASE,IVL_ST_CASER,IVL_ST_CASEX,IVL_ST_CASEZ */
1721 extern ivl_statement_t
ivl_stmt_case_stmt(ivl_statement_t net
, unsigned i
);
1722 /* IVL_ST_CONDIT IVL_ST_CASE IVL_ST_REPEAT IVL_ST_WHILE */
1723 extern ivl_expr_t
ivl_stmt_cond_expr(ivl_statement_t net
);
1725 extern ivl_statement_t
ivl_stmt_cond_false(ivl_statement_t net
);
1727 extern ivl_statement_t
ivl_stmt_cond_true(ivl_statement_t net
);
1728 /* IVL_ST_ASSIGN IVL_ST_ASSIGN_NB IVL_ST_DELAYX */
1729 extern ivl_expr_t
ivl_stmt_delay_expr(ivl_statement_t net
);
1731 extern uint64_t ivl_stmt_delay_val(ivl_statement_t net
);
1732 /* IVL_ST_WAIT IVL_ST_TRIGGER */
1733 extern unsigned ivl_stmt_nevent(ivl_statement_t net
);
1734 extern ivl_event_t
ivl_stmt_events(ivl_statement_t net
, unsigned idx
);
1735 /* IVL_ST_ASSIGN IVL_ST_ASSIGN_NB IVL_ST_CASSIGN IVL_ST_DEASSIGN
1736 IVL_ST_FORCE IVL_ST_RELEASE */
1737 extern ivl_lval_t
ivl_stmt_lval(ivl_statement_t net
, unsigned idx
);
1738 /* IVL_ST_ASSIGN IVL_ST_ASSIGN_NB IVL_ST_CASSIGN IVL_ST_DEASSIGN
1739 IVL_ST_FORCE IVL_ST_RELEASE */
1740 extern unsigned ivl_stmt_lvals(ivl_statement_t net
);
1741 /* IVL_ST_ASSIGN IVL_ST_ASSIGN_NB IVL_ST_CASSIGN */
1742 extern unsigned ivl_stmt_lwidth(ivl_statement_t net
);
1744 extern const char* ivl_stmt_name(ivl_statement_t net
);
1746 extern ivl_expr_t
ivl_stmt_parm(ivl_statement_t net
, unsigned idx
);
1748 extern unsigned ivl_stmt_parm_count(ivl_statement_t net
);
1749 /* IVL_ST_ASSIGN IVL_ST_ASSIGN_NB IVL_ST_CASSIGN IVL_ST_FORCE */
1750 extern ivl_expr_t
ivl_stmt_rval(ivl_statement_t net
);
1751 /* IVL_ST_DELAY, IVL_ST_DELAYX, IVL_ST_FOREVER, IVL_ST_REPEAT
1752 IVL_ST_WAIT, IVL_ST_WHILE */
1753 extern ivl_statement_t
ivl_stmt_sub_stmt(ivl_statement_t net
);
1756 #if defined(__MINGW32__) || defined (__CYGWIN32__)
1757 # define DLLEXPORT __declspec(dllexport)
1762 extern DLLEXPORT
int target_design(ivl_design_t des
);
1767 The "target_design" function is called once after the whole design
1768 is processed and available to the target. The target doesn't return
1769 from this function until it is finished with the design.
1771 The return value of this function should normally be zero. If the
1772 code generator detects errors, however, then the code generator
1773 returns a positive number to indicate the approximate number of
1774 errors detected (before it gave up.) Return values <0 are reserved
1775 for system and infrastructure errors.
1777 This function is implemented in the loaded target, and not in the
1778 ivl core. This function is how the target module is invoked. */
1780 typedef int (*target_design_f
)(ivl_design_t des
);
1786 * $Log: ivl_target.h,v $
1787 * Revision 1.182 2007/04/02 01:12:34 steve
1788 * Seperate arrayness from word count
1790 * Revision 1.181 2007/03/22 16:08:16 steve
1791 * Spelling fixes from Larry
1793 * Revision 1.180 2007/03/02 06:13:22 steve
1794 * Add support for edge sensitive spec paths.
1796 * Revision 1.179 2007/03/01 06:19:38 steve
1797 * Add support for conditional specify delay paths.
1799 * Revision 1.178 2007/02/26 19:49:49 steve
1800 * Spelling fixes (larry doolittle)
1802 * Revision 1.177 2007/02/25 23:08:24 steve
1803 * Process Verilog escape sequences much earlier.
1805 * Revision 1.176 2007/02/02 04:33:00 steve
1806 * Use inttypes.h instead of stdint.h for portability.
1808 * Revision 1.175 2007/01/29 01:52:51 steve
1809 * Clarify the use of ivl_scope_def for not-functions.
1811 * Revision 1.174 2007/01/17 05:00:12 steve
1812 * Dead code for memories in scopes.
1814 * Revision 1.173 2007/01/17 04:39:18 steve
1815 * Remove dead code related to memories.
1817 * Revision 1.172 2007/01/16 05:44:15 steve
1818 * Major rework of array handling. Memories are replaced with the
1819 * more general concept of arrays. The NetMemory and NetEMemory
1820 * classes are removed from the ivl core program, and the IVL_LPM_RAM
1821 * lpm type is removed from the ivl_target API.
1823 * Revision 1.171 2006/09/23 04:57:19 steve
1824 * Basic support for specify timing.
1826 * Revision 1.170 2006/08/08 05:11:37 steve
1827 * Handle 64bit delay constants.
1829 * Revision 1.169 2006/07/30 02:51:35 steve
1830 * Fix/implement signed right shift.
1832 * Revision 1.168 2006/06/18 04:15:50 steve
1833 * Add support for system functions in continuous assignments.
1835 * Revision 1.167 2006/04/16 00:15:43 steve
1836 * Fix part selects in l-values.
1838 * Revision 1.166 2006/04/10 00:37:42 steve
1839 * Add support for generate loops w/ wires and gates.
1841 * Revision 1.165 2006/02/02 02:43:58 steve
1842 * Allow part selects of memory words in l-values.
1844 * Revision 1.164 2006/01/02 05:33:19 steve
1845 * Node delays can be more general expressions in structural contexts.
1847 * Revision 1.163 2005/12/22 15:44:29 steve
1848 * Document binary expression use.
1850 * Revision 1.162 2005/11/20 15:58:25 steve
1851 * Document the IVL_ST_DELAY statements.