Corrected a long-standing error in which ending text with a literal
[xcircuit.git] / spiceparser / netlist_spice.h
bloba988b23a7827302fcbcf860c2925207103dbf427
1 /********************
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
20 ******************/
21 /* spice.h, header for spice parsing routines
22 Conrad Ziesler
25 /* note: alot of this is imported from legacy/adb
26 so it has some historic baggage still
29 #ifndef __NETLIST_SPICE_H__
30 #define __NETLIST_SPICE_H__
32 #ifndef __EQN_H__
33 #include "eqn.h"
34 #endif
36 #ifndef __HASH_H__
37 #include "hash.h"
38 #endif
40 #ifndef __SCANNER_H__
41 #include "scanner.h"
42 #endif
45 /*******************************************************/
46 /********* SPICE HASH TABLE CLIENTS ********************/
48 #define PAYLOAD_null 0
49 #define PAYLOAD_card_val 1
50 #define PAYLOAD_parent 2
51 #define PAYLOAD_gnptr 3
52 #define PAYLOAD_subckt 4
53 #define PAYLOAD_node 5
56 /* HACK **/
57 #ifndef __NETLIST_H__
58 #define TERMPTR_BITS_DEVI 24
59 #define TERMPTR_BITS_TERMI 3
60 #define TERMPTR_BITS_DEVT 4
62 typedef struct termptr_st
64 unsigned devi: TERMPTR_BITS_DEVI;
65 unsigned nonnull: 1;
66 unsigned termi: TERMPTR_BITS_TERMI;
67 unsigned devt: TERMPTR_BITS_DEVT;
68 }termptr_t;
69 #endif
71 union paydata_u
73 void *p;
74 char *s;
75 struct subckt_st *subckt;
76 termptr_t t;
79 typedef struct hashload_st
81 int flag;
82 union paydata_u data;
83 }hashload_t;
85 typedef struct nodeclient_st
87 hashload_t payload;
88 unsigned char str[4]; /* alloc in place */
89 }nodeclient_t;
91 typedef struct nodeclient_st *node_t;
93 #define FORALL_HASH(h,i,p) hash_forall(h,i,p)
96 typedef struct paramload_st
98 eqn_t eqn;
99 struct callparam_st *patch_call;
100 int global_i;
101 }paramload_t;
104 typedef struct paramclient_st
106 paramload_t payload;
107 char str[4];
108 }paramclient_t;
110 typedef struct paramlookup_st
112 struct stack_st *sp;
113 struct netlist_st *nl;
114 }paramlookup_t;
117 typedef struct callparam_st
119 eqn_t eqn;
120 char str[4];
121 }callparam_t;
124 /*****************************************/
125 /****** SPICE NETLIST READING *******/
127 /***** scanner stuff *****/
131 typedef enum keyword_et
133 Kother, Kinclude, Ksubckt, Kends, Kend, Kendm, Kmodel, Kparam, Kglobal, Kmult, Kscale, Knull
134 }keyword_t;
136 #define SPICE_TOKENS { \
137 { Kinclude, ".include" }, \
138 { Ksubckt, ".subckt" }, \
139 { Kends, ".ends" }, \
140 { Kendm, ".endm" }, \
141 { Kmodel, ".model" }, \
142 { Kparam, ".param" }, \
143 { Kglobal, ".global" }, \
144 { Kmult, ".mult" }, \
145 { Kscale, ".scale" }, \
146 { Knull, NULL } \
149 extern tokenmap_t spice_tokens[];
152 /****** pass 2 ************/
154 struct subckt_st;
156 typedef struct x_st
158 int nn;
159 struct subckt_st *xp;
160 node_t *nodes;
161 callparam_t **locals;
162 int nl;
163 deck_t *deck;
164 card_t *rest;
165 }x_t;
167 #define INDEX_GATE 1
168 #define INDEX_DRAIN 0
169 #define INDEX_SOURCE 2
170 #define INDEX_BULK 3
172 typedef struct m_st
174 node_t nodes[4];
175 eqn_t l,w,as,ad,ps,pd;
176 deck_t *deck;
177 card_t *rest;
178 uchar type;
179 }m_t;
181 typedef struct c_st
183 node_t nodes[2];
184 eqn_t c;
185 deck_t *deck;
186 card_t *rest;
187 }c_t;
189 typedef struct r_st
191 node_t nodes[2];
192 eqn_t r;
193 deck_t *deck;
194 card_t *rest;
195 }r_t;
197 typedef struct l_st
199 node_t nodes[2];
200 eqn_t l;
201 deck_t *deck;
202 card_t *rest;
203 }l_t;
205 typedef struct v_st
207 node_t nodes[2];
208 eqn_t v;
209 deck_t *deck;
210 card_t *rest;
211 }v_t;
213 typedef struct i_st
215 node_t nodes[2];
216 eqn_t i;
217 deck_t *deck;
218 card_t *rest;
219 }i_t;
221 #define SUBCKT_MAGIC 0x43236513
223 typedef struct subckt_st
225 int subckt_magic;
226 struct subckt_st *parent; /* who are we descended from */
227 hash_t *nodes; /* table of nodes */
228 hash_t *params; /* table of parameters (those defined elsewhere) */
229 hash_t *lparams; /* table of local parameters (those on the .subckt line) */
230 hash_t *cktdir; /* table of locally defined subckts */
231 hash_t *global; /* table of locally defined globals */
232 uchar *name; /* our name */
233 int ndefn;
234 int nm;
235 int nc;
236 int nr;
237 int nl;
238 int nx;
239 int nv;
240 int ni;
241 node_t *defn; /* ptrs into table of [nodes] for definitions */
242 m_t *m; /* array of mosfets */
243 c_t *c; /* array of capacitors */
244 r_t *r; /* array of resistors */
245 l_t *l; /* array of inductors */
246 x_t *x; /* array of subcircuit calls */
247 v_t *v; /* array of voltage sources */
248 i_t *i; /* array of current sources */
249 int flag;
250 float scale,mult;
251 }subckt_t;
254 typedef struct stack_st
256 int level;
257 struct stack_st *parent;
258 subckt_t *ckt;
259 x_t *call;
260 struct stack_st *top;
261 struct netlist_st *nl;
262 scanner_t *scan;
263 }stack_t;
265 typedef struct spice_st
267 int spice_magic;
268 scanner_t *scan;
269 deck_t *deck;
270 subckt_t *ckt;
271 void *eqn_mem;
272 }spice_t;
276 #define minimum(a,b) (((a)<(b))?(a):(b))
279 subckt_t *spice_find_subckt(subckt_t *parent, char *name);
280 spice_t *spice_new(scanner_t *scan);
281 void spice_release(spice_t *sp);
282 void spice_debug(void * dbg_fp, spice_t *sp);
283 list_t spice_list_subckt(subckt_t *parent);
288 #endif /* __NETLIST_SPICE_H__*/