2 This file is part of the software library CADLIB written by Conrad Ziesler
3 Copyright 2003, Conrad Ziesler, all rights reserved.
5 *************************
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 /* netlist.h, headers for generic netlist wrappers
25 /* even though the different file formats (spice, magic extract, verilog)
26 have widely different requirements, the basic information is still
27 comparable, so we try to build a common interface to the subtype procedures
55 #define EXTRACT_MAGIC 0x55315662
56 #define SPICE_MAGIC 0x435acde0
59 typedef struct geninput_st
66 /* internal definition of netlist type */
67 typedef union netlist_input_un
71 struct spice_st
*spice
;
72 struct extract_st
*ext
;
75 typedef union dev_input_un
78 struct m_st
*spice_fet
;
79 struct c_st
*spice_cap
;
93 device is: object with k terminals (k small)
94 netlist is connection of devices
96 share common terminal pointer.
101 #define TERMPTR_BITS_DEVI 24
102 #define TERMPTR_BITS_TERMI 3
103 #define TERMPTR_BITS_DEVT 4
105 typedef struct termptr_st
107 unsigned devi
: TERMPTR_BITS_DEVI
;
109 unsigned termi
: TERMPTR_BITS_TERMI
;
110 unsigned devt
: TERMPTR_BITS_DEVT
;
113 #define TERMPTR_MAX_DEVI ((1<<TERMPTR_BITS_DEVI)-1)
114 #define TERMPTR_MAX_TERMI ((1<<TERMPTR_BITS_TERMI)-1)
115 #define TERMPTR_MAX_DEVT ((1<<TERMPTR_BITS_DEVT)-1)
116 #define netlist_termptr_isnull(t) (t.nonnull==0)
121 an entity_t describes and holds a list of devices
123 the flexible device structure is formatted as follows
126 termptr_t terms[e->qterms];
127 eqn_t vals[e->qvals];
133 typedef struct entity_st
136 int qterms
; /* q terms of in generic structure */
137 int qvals
; /* q values in generic structure */
138 int qcount
; /* counted number, low level */
139 int id
; /* uniq device id */
140 int qother
; /* bytes of other info in dev structure */
141 char sym
[8]; /* symbolic name */
144 #define ENTITY_INVALID { LIST_INITDATA, 0, 0, 0, -1,0, "INVALID" }
146 /* macros for accessing entities */
148 #define NETLIST_E(nl,t,i) ((void *)list_data(&((nl)->e[(t)].l),i))
149 #define NETLIST_E_DATA(nl,t,i) ((char *)NETLIST_E(nl,t,i))
150 #define NETLIST_ED(e,i) ((char *)(list_data(&(e->l),i)))
151 #define NETLIST_OFFSET_PARENT(e) (0)
152 #define NETLIST_PARENTS(nl,t,i) ((dev_input_t*) (NETLIST_E_DATA(nl,t,i)+NETLIST_OFFSET_PARENT(nl->e[t])))
153 #define NETLIST_PARENT(nl,t,i) (NETLIST_PARENTS((nl),(t),(i))[0])
155 #define NETLIST_OFFSET_TERMS(e) (sizeof(dev_input_t) + NETLIST_OFFSET_PARENT(e) )
156 #define NETLIST_TERMS(nl,t,i) ((termptr_t*)(NETLIST_E_DATA(nl,t,i)+NETLIST_OFFSET_TERMS(nl->e[t])))
157 #define NETLIST_TERM(nl,t,i,j) (NETLIST_TERMS(nl,t,i)[(j)])
158 #define NETLIST_E_TERMS(e,i) ((termptr_t*) (NETLIST_ED(e,i) + NETLIST_OFFSET_TERMS(*(e))))
159 #define NETLIST_E_TERM(e,i,j) (NETLIST_E_TERMS(e,i)[(j)])
161 #define NETLIST_OFFSET_VALS(e) (NETLIST_OFFSET_TERMS((e)) + ((e).qterms*sizeof(termptr_t)))
162 #define NETLIST_VALS(nl,t,i) ((eqn_t *) (NETLIST_E_DATA(nl,t,i)+NETLIST_OFFSET_VALS(nl->e[t])))
163 #define NETLIST_VAL(nl,t,i,j) (NETLIST_VALS(nl,t,(i))[(j)])
166 #define NETLIST_OFFSET_REST(e) ( NETLIST_OFFSET_VALS(e) + (sizeof(eqn_t)*((e).qvals)))
167 #define NETLIST_REST(nl,t,i) ((void *) (NETLIST_E_DATA(nl,t,i) + NETLIST_OFFSET_REST(nl->e[t]))
169 #define NETLIST_OFFSET_OTHER(e) ( NETLIST_OFFSET_REST(e) + (e).qother )
170 #define NETLIST_OTHER(nl,t,i) ((void *) (NETLIST_E_DATA(nl,t,i)+NETLIST_OFFSET_OTHER(nl->e[t])))
172 #define NETLIST_E_QTERMS(e) ((e)->qterms)
173 #define NETLIST_QTERMS(nl,t) ((nl)->e[t].qterms)
174 #define NETLIST_E_QVALS(e) ((e)->qvals)
175 #define NETLIST_QVALS(nl,t) ((nl)->e[t].qvals)
177 #define DEVT_NODE 0 /* all netlists have type 0 as a node */
178 #define DEVP(nl,t) list_data(&((nl)->e[(t).devt].l),(t).devi)
179 #define DEVT_NODE_TERMS 2
181 typedef struct devnode_st
184 termptr_t n
[DEVT_NODE_TERMS
];
188 typedef struct netlist_st
190 netlist_input_t input
; /* where the netlist came from */
191 void *eqn_mem
; /* where we store our equations */
192 int iscopy
; /* this is set if we shouldn't free/modify some structures */
193 names_t
*names
; /* key off of node indices */
195 int qe
; /* valid entities */
196 entity_t e
[TERMPTR_MAX_DEVT
];
203 typedef struct netlistfunc_st
210 int (*sum
)(struct netlistfunc_st
*nm
,int ia
, int ib
);
211 void (*tocompare
)(struct netlistfunc_st
*nm
, int index
, void *data
);
215 void (*accumulate
)(struct netlistfunc_st
*nm
, int devi
, int termi
, float *nodeprops
);
216 void (*distribute
)(struct netlistfunc_st
*nm
, int devi
, int termi
, float *nodeprops
);
219 void (*fixup
)(struct netlistfunc_st
*nm
, termptr_t t
);
223 typedef struct netlist_param_st
225 struct netlist_param_st
*next
;
231 typedef enum netprint_en
244 /******* netlist.c ********/
245 void netlist_init(netlist_t
*nl
);
246 int netlist_register_entity (netlist_t
*nl
, int id
, int qterms
, int qvals
, int qrest
, char *sym
, int othersize
);
247 int netlist_print_nodep(netlist_t
*n
, netprint_t grp
, void *filefp
, void *gn
, char *str
);
248 netlist_input_t
netlist_parse_input(scanner_t
*scan
, char *type
, netlist_param_t
*params
);
249 void netlist_release(netlist_t
*nl
);
250 void netlist_free(netlist_t
*nl
);
251 int netlist_newdev_fromnode(netlist_t
*nl
, int devt
, dev_input_t parent
, termptr_t n
[]);
252 void netlist_debug_input(void *dbg_fp
, netlist_input_t p
);
253 void netlist_debug(void *dbg_fp
, netlist_t
*nl
);
254 void netlist_debug_(void *dbg_fp
, netlist_t
*nl
, int eval
);
255 termptr_t
netlist_node(netlist_t
*nl
, char *str
, void *parent
);
256 termptr_t
netlist_termptr(int dev
, int term
, int type
);
257 int netlist_node_termptr(netlist_t
*nl
, termptr_t t
);
258 int netlist_findnode(netlist_t
*nl
, char *str
);
259 void netlist_merge(netlistfunc_t
*nm
);
260 void netlist_distribute(netlistfunc_t
*nm
);
261 void netlist_fixup(netlistfunc_t
*nm
);
262 void netlist_eval(netlist_t
*n
);
263 void netlist_eqn_begin(netlist_t
*nl
);
264 void netlist_eqn_end(netlist_t
*nl
);
266 netlist_t
*netlist_copyisher(netlist_t
*in
, int extrasize
, int extrasizes
[]);
267 void netlist_copyfree(netlist_t
*nl
);
270 /********* netlist_spice.c *********/
272 struct spice_st
*spice_new(scanner_t
*scan
);
273 void spice_release(struct spice_st
*sp
);
275 void spice_build(netlist_t
*nl
);
276 void spice_count(netlist_t
*nl
);
277 void spice_debug(void *dbg_fp
, struct spice_st
*sp
);