4 * Copyright (c) 2000-2008 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
23 # include "ivl_target.h"
24 # include "StringHeap.h"
28 #if defined(__MINGW32__)
30 typedef void *ivl_dll_t
;
31 #elif defined(HAVE_DLFCN_H)
33 typedef void* ivl_dll_t
;
34 #elif defined(HAVE_DL_H)
36 typedef shl_t ivl_dll_t
;
38 # error No DLL stub support for this target.
48 ivl_process_t threads_
;
50 ivl_net_const_t
*consts
;
57 * The DLL target type loads a named object file to handle the process
58 * of scanning the netlist. When it is time to start the design, I
59 * locate and link in the desired DLL, then start calling methods. The
60 * DLL will call me back to get information out of the netlist in
63 struct dll_target
: public target_t
, public expr_scan_t
{
65 bool start_design(const Design
*);
66 int end_design(const Design
*);
68 bool bufz(const NetBUFZ
*);
69 void event(const NetEvent
*);
70 void logic(const NetLogic
*);
71 bool tran(const NetTran
*);
72 bool ureduce(const NetUReduce
*);
73 void net_case_cmp(const NetCaseCmp
*);
74 void udp(const NetUDP
*);
75 void lpm_abs(const NetAbs
*);
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 void lpm_pow(const NetPow
*);
86 bool concat(const NetConcat
*);
87 bool part_select(const NetPartSelect
*);
88 bool replicate(const NetReplicate
*);
89 void net_assign(const NetAssign_
*);
90 bool net_sysfunction(const NetSysFunc
*);
91 bool net_function(const NetUserFunc
*);
92 bool net_const(const NetConst
*);
93 bool net_literal(const NetLiteral
*);
94 void net_probe(const NetEvProbe
*);
95 bool sign_extend(const NetSignExtend
*);
97 bool process(const NetProcTop
*);
98 void scope(const NetScope
*);
99 void signal(const NetNet
*);
100 bool signal_paths(const NetNet
*);
105 target_design_f target_
;
108 /* These methods and members are used for forming the
109 statements of a thread. */
110 struct ivl_statement_s
*stmt_cur_
;
111 void proc_assign(const NetAssign
*);
112 void proc_assign_nb(const NetAssignNB
*);
113 bool proc_block(const NetBlock
*);
114 void proc_case(const NetCase
*);
115 bool proc_cassign(const NetCAssign
*);
116 bool proc_condit(const NetCondit
*);
117 bool proc_deassign(const NetDeassign
*);
118 bool proc_delay(const NetPDelay
*);
119 bool proc_disable(const NetDisable
*);
120 bool proc_force(const NetForce
*);
121 void proc_forever(const NetForever
*);
122 bool proc_release(const NetRelease
*);
123 void proc_repeat(const NetRepeat
*);
124 void proc_stask(const NetSTask
*);
125 bool proc_trigger(const NetEvTrig
*);
126 void proc_utask(const NetUTask
*);
127 bool proc_wait(const NetEvWait
*);
128 void proc_while(const NetWhile
*);
130 bool func_def(const NetScope
*);
131 void task_def(const NetScope
*);
133 struct ivl_expr_s
*expr_
;
134 void expr_binary(const NetEBinary
*);
135 void expr_concat(const NetEConcat
*);
136 void expr_const(const NetEConst
*);
137 void expr_creal(const NetECReal
*);
138 void expr_param(const NetEConstParam
*);
139 void expr_event(const NetEEvent
*);
140 void expr_scope(const NetEScope
*);
141 void expr_select(const NetESelect
*);
142 void expr_sfunc(const NetESFunc
*);
143 void expr_ternary(const NetETernary
*);
144 void expr_ufunc(const NetEUFunc
*);
145 void expr_unary(const NetEUnary
*);
146 void expr_signal(const NetESignal
*);
148 ivl_scope_t
lookup_scope_(const NetScope
*scope
);
150 ivl_attribute_s
* fill_in_attributes(const Attrib
*net
);
151 void switch_attributes(struct ivl_switch_s
*obj
, const NetNode
*net
);
152 void logic_attributes(struct ivl_net_logic_s
*obj
, const NetNode
*net
);
157 static ivl_scope_t
find_scope(ivl_design_s
&des
, const NetScope
*cur
);
158 static ivl_signal_t
find_signal(ivl_design_s
&des
, const NetNet
*net
);
159 static ivl_parameter_t
scope_find_param(ivl_scope_t scope
,
162 void add_root(ivl_design_s
&des_
, const NetScope
*s
);
164 void make_assign_lvals_(const NetAssignBase
*net
);
165 void sub_off_from_expr_(long);
166 void mul_expr_by_const_(long);
168 void make_logic_delays_(struct ivl_net_logic_s
*obj
, const NetObj
*net
);
169 void make_lpm_delays_(struct ivl_lpm_s
*obj
, const NetObj
*net
);
170 void make_const_delays_(struct ivl_net_const_s
*obj
, const NetObj
*net
);
171 void make_scope_parameters(ivl_scope_t scope
, const NetScope
*net
);
172 void make_scope_param_expr(ivl_parameter_t cur_par
, NetExpr
*etmp
);
174 static ivl_expr_t
expr_from_value_(const verinum
&that
);
178 * These are various private declarations used by the t-dll target.
181 struct ivl_delaypath_s
{
194 unsigned nany
, nneg
, npos
;
199 * The ivl_expr_t is an opaque reference to one of these
200 * structures. This structure holds all the information we need about
201 * an expression node, including its type, the expression width, and
202 * type specific properties.
205 ivl_expr_type_t type_
;
206 ivl_variable_type_t value_
;
211 unsigned signed_
: 1;
228 ivl_parameter_t parameter
;
252 ivl_parameter_t parameter
;
278 ivl_parameter_t parameter
;
290 * LPM devices are handled by this suite of types. The ivl_lpm_s
291 * structure holds the core, including a type code, the object name
292 * and scope. The other properties of the device are held in the type
293 * specific member of the union.
302 // Value returned by ivl_lpm_width;
307 struct ivl_lpm_ff_s
{
322 ivl_expr_t aset_value
;
323 ivl_expr_t sset_value
;
326 struct ivl_lpm_mux_s
{
333 struct ivl_lpm_shift_s
{
335 unsigned signed_flag
:1;
339 struct ivl_lpm_arith_s
{
340 unsigned signed_flag
:1;
344 struct ivl_lpm_array_s
{
350 struct ivl_concat_s
{
357 unsigned signed_flag
:1;
361 // IVL_LPM_RE_* and IVL_LPM_SIGN_EXT use this.
362 struct ivl_lpm_reduce_s
{
366 struct ivl_lpm_repeat_s
{
371 struct ivl_lpm_sfunc_s
{
372 const char* fun_name
;
377 struct ivl_lpm_ufunc_s
{
386 * This object represents l-values to assignments. The l-value can be
387 * a register bit or part select, or a memory word select with a part
391 enum ivl_lval_type_t
{
394 /* IVL_LVAL_MEM = 2, / Deprecated in favor of LVAL_ARR? */
395 IVL_LVAL_NET
= 3, /* Only force can have NET l-values */
411 * This object represents a literal constant, possibly signed, in a
412 * structural context.
414 struct ivl_net_const_s
{
415 ivl_variable_type_t type
;
417 unsigned signed_
: 1;
421 char bit_
[sizeof(char*)];
431 * Logic gates (just about everything that has a single output) are
432 * represented structurally by instances of this object.
434 struct ivl_net_logic_s
{
445 struct ivl_attribute_s
*attr
;
451 struct ivl_switch_s
{
452 ivl_switch_type_t type
;
457 struct ivl_attribute_s
*attr
;
471 int sequ
; /* boolean */
474 typedef const char*ccharp_t
;
475 ccharp_t
*table
; // zero terminated array of pointers
479 * The ivl_nexus_t is a single-bit link of some number of pins of
480 * devices. the __nexus_ptr structure is a helper that actually does
483 * The type_ member specifies which of the object pointers in the
486 * The drive01 members gives the strength of the drive that the device
487 * is applying to the nexus, with 0 HiZ and 3 supply. If the pin is an
488 * input to the device, then the drives are both HiZ.
490 struct ivl_nexus_ptr_s
{
496 ivl_signal_t sig
; /* type 0 */
497 ivl_net_logic_t log
; /* type 1 */
498 ivl_net_const_t con
; /* type 2 */
499 ivl_lpm_t lpm
; /* type 3 */
500 ivl_switch_t swi
; /* type 4 */
503 # define __NEXUS_PTR_SIG 0
504 # define __NEXUS_PTR_LOG 1
505 # define __NEXUS_PTR_CON 2
506 # define __NEXUS_PTR_LPM 3
507 # define __NEXUS_PTR_SWI 4
510 * NOTE: ONLY allocate ivl_nexus_s objects with the included "new" operator.
514 struct ivl_nexus_ptr_s
*ptrs_
;
519 void* operator new (size_t s
);
520 void operator delete(void*obj
, size_t s
); // Not implemented
524 * This is the implementation of a parameter. Each scope has a list of
527 struct ivl_parameter_s
{
528 perm_string basename
;
535 * All we know about a process it its type (initial or always) and the
536 * single statement that is it. A process also has a scope, although
537 * that generally only matters for VPI calls.
539 struct ivl_process_s
{
540 ivl_process_type_t type_
;
542 ivl_statement_t stmt_
;
544 struct ivl_attribute_s
*attr
;
551 * Scopes are kept in a tree. Each scope points to its first child,
552 * and also to any siblings. Thus a parent can scan all its children
553 * by following its child pointer then following sibling pointers from
557 ivl_scope_t child_
, sibling_
, parent
;
562 perm_string def_file
;
565 ivl_scope_type_t type_
;
571 ivl_net_logic_t
*log_
;
580 ivl_parameter_t param_
;
582 /* Scopes that are tasks/functions have a definition. */
588 std::vector
<ivl_switch_t
>switches
;
590 signed int time_precision
:8;
591 signed int time_units
:8;
593 struct ivl_attribute_s
*attr
;
598 * A signal is a thing like a wire, a reg, or whatever. It has a type,
599 * and if it is a port is also has a direction. Signals are collected
600 * into scopes (which also point back to me) and have pins that
601 * connect to the rest of the netlist.
603 struct ivl_signal_s
{
604 ivl_signal_type_t type_
;
605 ivl_signal_port_t port_
;
606 ivl_variable_type_t data_type
;
611 unsigned signed_
: 1;
615 /* For now, support only 0 or 1 array dimensions. */
616 unsigned array_dimensions_
: 1;
618 /* These encode the run-time index for the least significant
619 bit, and the distance to the second bit. */
626 unsigned array_words
;
633 ivl_delaypath_s
*path
;
636 struct ivl_attribute_s
*attr
;
641 * The ivl_statement_t represents any statement. The type of statement
642 * is defined by the ivl_statement_type_t enumeration. Given the type,
643 * certain information about the statement may be available.
645 struct ivl_statement_s
{
646 enum ivl_statement_type_e type_
;
651 struct { /* IVL_ST_ASSIGN IVL_ST_ASSIGN_NB
652 IVL_ST_CASSIGN, IVL_ST_DEASSIGN */
654 struct ivl_lval_s
*lval_
;
659 struct { /* IVL_ST_BLOCK, IVL_ST_FORK */
660 struct ivl_statement_s
*stmt_
;
665 struct { /* IVL_ST_CASE, IVL_ST_CASEX, IVL_ST_CASEZ */
669 struct ivl_statement_s
*case_st
;
672 struct { /* IVL_ST_CONDIT */
673 /* This is the condition expression */
675 /* This is two statements, the true and false. */
676 struct ivl_statement_s
*stmt_
;
679 struct { /* IVL_ST_DELAY */
681 ivl_statement_t stmt_
;
684 struct { /* IVL_ST_DELAYX */
685 ivl_expr_t expr
; /* XXXX */
686 ivl_statement_t stmt_
;
689 struct { /* IVL_ST_DISABLE */
693 struct { /* IVL_ST_FOREVER */
694 ivl_statement_t stmt_
;
697 struct { /* IVL_ST_STASK */
703 struct { /* IVL_ST_UTASK */
707 struct { /* IVL_ST_TRIGGER IVL_ST_WAIT */
713 ivl_statement_t stmt_
;
716 struct { /* IVL_ST_WHILE IVL_ST_REPEAT */
718 ivl_statement_t stmt_
;
724 * The FILE_NAME function is a shorthand for attaching file/line
725 * information to the statement object.
727 static inline void FILE_NAME(ivl_statement_t stmt
, const LineInfo
*info
)
729 stmt
->file
= info
->get_file();
730 stmt
->lineno
= info
->get_lineno();
733 static inline void FILE_NAME(ivl_expr_t expr
, const LineInfo
*info
)
735 expr
->file
= info
->get_file();
736 expr
->lineno
= info
->get_lineno();
739 static inline void FILE_NAME(ivl_lpm_t lpm
, const LineInfo
*info
)
741 lpm
->file
= info
->get_file();
742 lpm
->lineno
= info
->get_lineno();
745 static inline void FILE_NAME(ivl_scope_t scope
, const NetScope
*info
)
747 scope
->file
= info
->get_file();
748 scope
->def_file
= info
->get_def_file();
749 scope
->lineno
= info
->get_lineno();
750 scope
->def_lineno
= info
->get_def_lineno();
753 static inline void FILE_NAME(ivl_switch_t net
, const LineInfo
*info
)
755 net
->file
= info
->get_file();
756 net
->lineno
= info
->get_lineno();