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
{
189 unsigned nany
, nneg
, npos
;
194 * The ivl_expr_t is an opaque reference to one of these
195 * structures. This structure holds all the information we need about
196 * an expression node, including its type, the expression width, and
197 * type specific properties.
200 ivl_expr_type_t type_
;
201 ivl_variable_type_t value_
;
204 unsigned signed_
: 1;
221 ivl_parameter_t parameter
;
245 ivl_parameter_t parameter
;
271 ivl_parameter_t parameter
;
283 * LPM devices are handled by this suite of types. The ivl_lpm_s
284 * structure holds the core, including a type code, the object name
285 * and scope. The other properties of the device are held in the type
286 * specific member of the union.
293 // Value returned by ivl_lpm_width;
297 struct ivl_lpm_ff_s
{
312 ivl_expr_t aset_value
;
313 ivl_expr_t sset_value
;
316 struct ivl_lpm_mux_s
{
323 struct ivl_lpm_shift_s
{
325 unsigned signed_flag
:1;
329 struct ivl_lpm_arith_s
{
330 unsigned signed_flag
:1;
334 struct ivl_lpm_array_s
{
340 struct ivl_concat_s
{
347 unsigned signed_flag
:1;
351 // IVL_LPM_RE_* and IVL_LPM_SIGN_EXT use this.
352 struct ivl_lpm_reduce_s
{
356 struct ivl_lpm_repeat_s
{
361 struct ivl_lpm_sfunc_s
{
362 const char* fun_name
;
367 struct ivl_lpm_ufunc_s
{
376 * This object represents l-values to assignments. The l-value can be
377 * a register bit or part select, or a memory word select with a part
381 enum ivl_lval_type_t
{
384 /* IVL_LVAL_MEM = 2, / Deprecated in favor of LVAL_ARR? */
385 IVL_LVAL_NET
= 3, /* Only force can have NET l-values */
401 * This object represents a literal constant, possibly signed, in a
402 * structural context.
404 struct ivl_net_const_s
{
405 ivl_variable_type_t type
;
407 unsigned signed_
: 1;
411 char bit_
[sizeof(char*)];
419 * Logic gates (just about everything that has a single output) are
420 * represented structurally by instances of this object.
422 struct ivl_net_logic_s
{
433 struct ivl_attribute_s
*attr
;
446 int sequ
; /* boolen */
449 typedef const char*ccharp_t
;
450 ccharp_t
*table
; // zero terminated array of pointers
454 * The ivl_nexus_t is a single-bit link of some number of pins of
455 * devices. the __nexus_ptr structure is a helper that actually does
458 * The type_ member specifies which of the object pointers in the
461 * The drive01 members gives the strength of the drive that the device
462 * is applying to the nexus, with 0 HiZ and 3 supply. If the pin is an
463 * input to the device, then the drives are both HiZ.
465 struct ivl_nexus_ptr_s
{
471 ivl_signal_t sig
; /* type 0 */
472 ivl_net_logic_t log
; /* type 1 */
473 ivl_net_const_t con
; /* type 2 */
474 ivl_lpm_t lpm
; /* type 3 */
477 # define __NEXUS_PTR_SIG 0
478 # define __NEXUS_PTR_LOG 1
479 # define __NEXUS_PTR_CON 2
480 # define __NEXUS_PTR_LPM 3
483 * NOTE: ONLY allocat ivl_nexus_s objects with the included "new" operator.
487 struct ivl_nexus_ptr_s
*ptrs_
;
492 void* operator new (size_t s
);
493 void operator delete(void*obj
, size_t s
); // Not implemented
497 * This is the implementation of a parameter. Each scope has a list of
500 struct ivl_parameter_s
{
501 perm_string basename
;
506 * All we know about a process it its type (initial or always) and the
507 * single statement that is it. A process also has a scope, although
508 * that generally only matters for VPI calls.
510 struct ivl_process_s
{
511 ivl_process_type_t type_
;
513 ivl_statement_t stmt_
;
515 struct ivl_attribute_s
*attr
;
522 * Scopes are kept in a tree. Each scope points to its first child,
523 * and also to any siblings. Thus a parent can scan all its children
524 * by following its child pointer then following sibling pointers from
528 ivl_scope_t child_
, sibling_
, parent
;
532 ivl_scope_type_t type_
;
538 ivl_net_logic_t
*log_
;
547 ivl_parameter_t param_
;
549 /* Scopes that are tasks/functions have a definition. */
555 signed int time_precision
:8;
556 signed int time_units
:8;
558 struct ivl_attribute_s
*attr
;
563 * A signal is a thing like a wire, a reg, or whatever. It has a type,
564 * and if it is a port is also has a direction. Signals are collected
565 * into scopes (which also point back to me) and have pins that
566 * connect to the rest of the netlist.
568 struct ivl_signal_s
{
569 ivl_signal_type_t type_
;
570 ivl_signal_port_t port_
;
571 ivl_variable_type_t data_type
;
574 unsigned signed_
: 1;
578 /* For now, support only 0 or 1 array dimensions. */
579 unsigned array_dimensions_
: 1;
581 /* These encode the run-time index for the least significant
582 bit, and the distance to the second bit. */
589 unsigned array_words
;
596 ivl_delaypath_s
*path
;
599 struct ivl_attribute_s
*attr
;
604 * The ivl_statement_t represents any statement. The type of statement
605 * is defined by the ivl_statement_type_t enumeration. Given the type,
606 * certain information about the statement may be available.
608 struct ivl_statement_s
{
609 enum ivl_statement_type_e type_
;
611 struct { /* IVL_ST_ASSIGN IVL_ST_ASSIGN_NB
612 IVL_ST_CASSIGN, IVL_ST_DEASSIGN */
614 struct ivl_lval_s
*lval_
;
619 struct { /* IVL_ST_BLOCK, IVL_ST_FORK */
620 struct ivl_statement_s
*stmt_
;
625 struct { /* IVL_ST_CASE, IVL_ST_CASEX, IVL_ST_CASEZ */
629 struct ivl_statement_s
*case_st
;
632 struct { /* IVL_ST_CONDIT */
633 /* This is the condition expression */
635 /* This is two statements, the true and false. */
636 struct ivl_statement_s
*stmt_
;
639 struct { /* IVL_ST_DELAY */
641 ivl_statement_t stmt_
;
644 struct { /* IVL_ST_DELAYX */
645 ivl_expr_t expr
; /* XXXX */
646 ivl_statement_t stmt_
;
649 struct { /* IVL_ST_DISABLE */
653 struct { /* IVL_ST_FOREVER */
654 ivl_statement_t stmt_
;
657 struct { /* IVL_ST_STASK */
663 struct { /* IVL_ST_UTASK */
667 struct { /* IVL_ST_TRIGGER IVL_ST_WAIT */
673 ivl_statement_t stmt_
;
676 struct { /* IVL_ST_WHILE IVL_ST_REPEAT */
678 ivl_statement_t stmt_
;