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: t-dll.h,v 1.143 2007/06/02 03:42:13 steve Exp $"
26 # include "ivl_target.h"
27 # include "StringHeap.h"
30 #if defined(__MINGW32__)
32 typedef void *ivl_dll_t
;
33 #elif defined(HAVE_DLFCN_H)
35 typedef void* ivl_dll_t
;
36 #elif defined(HAVE_DL_H)
38 typedef shl_t ivl_dll_t
;
40 # error No DLL stub support for this target.
50 ivl_process_t threads_
;
52 ivl_net_const_t
*consts
;
59 * The DLL target type loads a named object file to handle the process
60 * of scanning the netlist. When it is time to start the design, I
61 * locate and link in the desired DLL, then start calling methods. The
62 * DLL will call me back to get information out of the netlist in
65 struct dll_target
: public target_t
, public expr_scan_t
{
67 bool start_design(const Design
*);
68 int end_design(const Design
*);
70 bool bufz(const NetBUFZ
*);
71 void event(const NetEvent
*);
72 void logic(const NetLogic
*);
73 bool ureduce(const NetUReduce
*);
74 void net_case_cmp(const NetCaseCmp
*);
75 void udp(const NetUDP
*);
76 void lpm_add_sub(const NetAddSub
*);
77 bool lpm_array_dq(const NetArrayDq
*);
78 void lpm_clshift(const NetCLShift
*);
79 void lpm_compare(const NetCompare
*);
80 void lpm_divide(const NetDivide
*);
81 void lpm_ff(const NetFF
*);
82 void lpm_modulo(const NetModulo
*);
83 void lpm_mult(const NetMult
*);
84 void lpm_mux(const NetMux
*);
85 bool concat(const NetConcat
*);
86 bool part_select(const NetPartSelect
*);
87 bool replicate(const NetReplicate
*);
88 void net_assign(const NetAssign_
*);
89 bool net_sysfunction(const NetSysFunc
*);
90 bool net_function(const NetUserFunc
*);
91 bool net_const(const NetConst
*);
92 bool net_literal(const NetLiteral
*);
93 void net_probe(const NetEvProbe
*);
94 bool sign_extend(const NetSignExtend
*);
96 bool process(const NetProcTop
*);
97 void scope(const NetScope
*);
98 void signal(const NetNet
*);
99 bool signal_paths(const NetNet
*);
104 target_design_f target_
;
107 /* These methods and members are used for forming the
108 statements of a thread. */
109 struct ivl_statement_s
*stmt_cur_
;
110 void proc_assign(const NetAssign
*);
111 void proc_assign_nb(const NetAssignNB
*);
112 bool proc_block(const NetBlock
*);
113 void proc_case(const NetCase
*);
114 bool proc_cassign(const NetCAssign
*);
115 bool proc_condit(const NetCondit
*);
116 bool proc_deassign(const NetDeassign
*);
117 bool proc_delay(const NetPDelay
*);
118 bool proc_disable(const NetDisable
*);
119 bool proc_force(const NetForce
*);
120 void proc_forever(const NetForever
*);
121 bool proc_release(const NetRelease
*);
122 void proc_repeat(const NetRepeat
*);
123 void proc_stask(const NetSTask
*);
124 bool proc_trigger(const NetEvTrig
*);
125 void proc_utask(const NetUTask
*);
126 bool proc_wait(const NetEvWait
*);
127 void proc_while(const NetWhile
*);
129 bool func_def(const NetScope
*);
130 void task_def(const NetScope
*);
132 struct ivl_expr_s
*expr_
;
133 void expr_binary(const NetEBinary
*);
134 void expr_concat(const NetEConcat
*);
135 void expr_const(const NetEConst
*);
136 void expr_creal(const NetECReal
*);
137 void expr_param(const NetEConstParam
*);
138 void expr_event(const NetEEvent
*);
139 void expr_scope(const NetEScope
*);
140 void expr_select(const NetESelect
*);
141 void expr_sfunc(const NetESFunc
*);
142 void expr_ternary(const NetETernary
*);
143 void expr_ufunc(const NetEUFunc
*);
144 void expr_unary(const NetEUnary
*);
145 void expr_signal(const NetESignal
*);
147 ivl_scope_t
lookup_scope_(const NetScope
*scope
);
149 ivl_attribute_s
* fill_in_attributes(const Attrib
*net
);
150 void logic_attributes(struct ivl_net_logic_s
*obj
, const NetNode
*net
);
155 static ivl_scope_t
find_scope(ivl_design_s
&des
, const NetScope
*cur
);
156 static ivl_signal_t
find_signal(ivl_design_s
&des
, const NetNet
*net
);
157 static ivl_parameter_t
scope_find_param(ivl_scope_t scope
,
160 void add_root(ivl_design_s
&des_
, const NetScope
*s
);
162 void make_assign_lvals_(const NetAssignBase
*net
);
163 void sub_off_from_expr_(long);
164 void mul_expr_by_const_(long);
166 void make_logic_delays_(struct ivl_net_logic_s
*obj
, const NetObj
*net
);
167 void make_scope_parameters(ivl_scope_t scope
, const NetScope
*net
);
168 void make_scope_param_expr(ivl_parameter_t cur_par
, NetExpr
*etmp
);
170 static ivl_expr_t
expr_from_value_(const verinum
&that
);
174 * These are various private declarations used by the t-dll target.
177 struct ivl_delaypath_s
{
188 unsigned nany
, nneg
, npos
;
193 * The ivl_expr_t is an opaque reference to one of these
194 * structures. This structure holds all the information we need about
195 * an expression node, including its type, the expression width, and
196 * type specific properties.
199 ivl_expr_type_t type_
;
200 ivl_variable_type_t value_
;
203 unsigned signed_
: 1;
220 ivl_parameter_t parameter
;
244 ivl_parameter_t parameter
;
270 ivl_parameter_t parameter
;
282 * LPM devices are handled by this suite of types. The ivl_lpm_s
283 * structure holds the core, including a type code, the object name
284 * and scope. The other properties of the device are held in the type
285 * specific member of the union.
292 // Value returned by ivl_lpm_width;
296 struct ivl_lpm_ff_s
{
311 ivl_expr_t aset_value
;
312 ivl_expr_t sset_value
;
315 struct ivl_lpm_mux_s
{
322 struct ivl_lpm_shift_s
{
324 unsigned signed_flag
:1;
328 struct ivl_lpm_arith_s
{
329 unsigned signed_flag
:1;
333 struct ivl_lpm_array_s
{
339 struct ivl_concat_s
{
346 unsigned signed_flag
:1;
350 // IVL_LPM_RE_* and IVL_LPM_SIGN_EXT use this.
351 struct ivl_lpm_reduce_s
{
355 struct ivl_lpm_repeat_s
{
360 struct ivl_lpm_sfunc_s
{
361 const char* fun_name
;
366 struct ivl_lpm_ufunc_s
{
375 * This object represents l-values to assignments. The l-value can be
376 * a register bit or part select, or a memory word select with a part
380 enum ivl_lval_type_t
{
383 /* IVL_LVAL_MEM = 2, / Deprecated in favor of LVAL_ARR? */
384 IVL_LVAL_NET
= 3, /* Only force can have NET l-values */
400 * This object represents a literal constant, possibly signed, in a
401 * structural context.
403 struct ivl_net_const_s
{
404 ivl_variable_type_t type
;
406 unsigned signed_
: 1;
410 char bit_
[sizeof(char*)];
418 * Logic gates (just about everything that has a single output) are
419 * represented structurally by instances of this object.
421 struct ivl_net_logic_s
{
432 struct ivl_attribute_s
*attr
;
445 int sequ
; /* boolen */
448 typedef const char*ccharp_t
;
449 ccharp_t
*table
; // zero terminated array of pointers
453 * The ivl_nexus_t is a single-bit link of some number of pins of
454 * devices. the __nexus_ptr structure is a helper that actually does
457 * The type_ member specifies which of the object pointers in the
460 * The drive01 members gives the strength of the drive that the device
461 * is applying to the nexus, with 0 HiZ and 3 supply. If the pin is an
462 * input to the device, then the drives are both HiZ.
464 struct ivl_nexus_ptr_s
{
470 ivl_signal_t sig
; /* type 0 */
471 ivl_net_logic_t log
; /* type 1 */
472 ivl_net_const_t con
; /* type 2 */
473 ivl_lpm_t lpm
; /* type 3 */
476 # define __NEXUS_PTR_SIG 0
477 # define __NEXUS_PTR_LOG 1
478 # define __NEXUS_PTR_CON 2
479 # define __NEXUS_PTR_LPM 3
482 * NOTE: ONLY allocat ivl_nexus_s objects with the included "new" operator.
486 struct ivl_nexus_ptr_s
*ptrs_
;
491 void* operator new (size_t s
);
492 void operator delete(void*obj
, size_t s
); // Not implemented
496 * This is the implementation of a parameter. Each scope has a list of
499 struct ivl_parameter_s
{
500 perm_string basename
;
505 * All we know about a process it its type (initial or always) and the
506 * single statement that is it. A process also has a scope, although
507 * that generally only matters for VPI calls.
509 struct ivl_process_s
{
510 ivl_process_type_t type_
;
512 ivl_statement_t stmt_
;
514 struct ivl_attribute_s
*attr
;
521 * Scopes are kept in a tree. Each scope points to its first child,
522 * and also to any siblings. Thus a parent can scan all its children
523 * by following its child pointer then following sibling pointers from
527 ivl_scope_t child_
, sibling_
, parent
;
531 ivl_scope_type_t type_
;
537 ivl_net_logic_t
*log_
;
546 ivl_parameter_t param_
;
548 /* Scopes that are tasks/functions have a definition. */
554 signed int time_precision
:8;
555 signed int time_units
:8;
557 struct ivl_attribute_s
*attr
;
562 * A signal is a thing like a wire, a reg, or whatever. It has a type,
563 * and if it is a port is also has a direction. Signals are collected
564 * into scopes (which also point back to me) and have pins that
565 * connect to the rest of the netlist.
567 struct ivl_signal_s
{
568 ivl_signal_type_t type_
;
569 ivl_signal_port_t port_
;
570 ivl_variable_type_t data_type
;
573 unsigned signed_
: 1;
577 /* For now, support only 0 or 1 array dimensions. */
578 unsigned array_dimensions_
: 1;
580 /* These encode the run-time index for the least significant
581 bit, and the distance to the second bit. */
588 unsigned array_words
;
595 ivl_delaypath_s
*path
;
598 struct ivl_attribute_s
*attr
;
603 * The ivl_statement_t represents any statement. The type of statement
604 * is defined by the ivl_statement_type_t enumeration. Given the type,
605 * certain information about the statement may be available.
607 struct ivl_statement_s
{
608 enum ivl_statement_type_e type_
;
610 struct { /* IVL_ST_ASSIGN IVL_ST_ASSIGN_NB
611 IVL_ST_CASSIGN, IVL_ST_DEASSIGN */
613 struct ivl_lval_s
*lval_
;
618 struct { /* IVL_ST_BLOCK, IVL_ST_FORK */
619 struct ivl_statement_s
*stmt_
;
624 struct { /* IVL_ST_CASE, IVL_ST_CASEX, IVL_ST_CASEZ */
628 struct ivl_statement_s
*case_st
;
631 struct { /* IVL_ST_CONDIT */
632 /* This is the condition expression */
634 /* This is two statements, the true and false. */
635 struct ivl_statement_s
*stmt_
;
638 struct { /* IVL_ST_DELAY */
640 ivl_statement_t stmt_
;
643 struct { /* IVL_ST_DELAYX */
644 ivl_expr_t expr
; /* XXXX */
645 ivl_statement_t stmt_
;
648 struct { /* IVL_ST_DISABLE */
652 struct { /* IVL_ST_FOREVER */
653 ivl_statement_t stmt_
;
656 struct { /* IVL_ST_STASK */
662 struct { /* IVL_ST_UTASK */
666 struct { /* IVL_ST_TRIGGER IVL_ST_WAIT */
672 ivl_statement_t stmt_
;
675 struct { /* IVL_ST_WHILE IVL_ST_REPEAT */
677 ivl_statement_t stmt_
;