1 /***** spin: spin.h *****/
4 * This file is part of the public release of Spin. It is subject to the
5 * terms in the LICENSE file that is included in this source directory.
6 * Tool documentation is available at http://spinroot.com
15 #if !defined(WIN32) && !defined(WIN64)
18 #if !defined(PC) && !defined(_PLAN9)
22 enum { INIV, PUTV, LOGV }; /* used in pangen1.c */
23 enum btypes { NONE, N_CLAIM, I_PROC, A_PROC, P_PROC, E_TRACE, N_TRACE };
25 typedef struct Lextok {
26 unsigned short ntyp; /* node type */
27 short ismtyp; /* CONST derived from MTYP */
28 int val; /* value attribute */
29 int ln; /* line number */
30 int indstep; /* part of d_step sequence */
31 int uiid; /* inline id, if non-zero */
32 struct Symbol *fn; /* file name */
33 struct Symbol *sym; /* symbol reference */
34 struct Sequence *sq; /* sequence */
35 struct SeqList *sl; /* sequence list */
36 struct Lextok *lft, *rgt; /* children in parse tree */
39 typedef struct Slicer {
40 Lextok *n; /* global var, usable as slice criterion */
41 short code; /* type of use: DEREF_USE or normal USE */
42 short used; /* set when handled */
43 struct Slicer *nxt; /* linked list */
46 typedef struct Access {
47 struct Symbol *who; /* proctype name of accessor */
48 struct Symbol *what; /* proctype name of accessed */
49 int cnt, typ; /* parameter nr and, e.g., 's' or 'r' */
50 struct Access *lnk; /* linked list */
53 typedef struct Symbol {
55 int Nid; /* unique number for the name */
56 unsigned short type; /* bit,short,.., chan,struct */
57 unsigned char hidden; /* bit-flags:
59 4=bit-equiv, 8=byte-equiv,
60 16=formal par, 32=inline par,
61 64=treat as if local; 128=read at least once
63 unsigned char colnr; /* for use with xspin during simulation */
64 unsigned char isarray; /* set if decl specifies array bound */
65 unsigned char *bscp; /* block scope */
66 int sc; /* scope seq no -- set only for proctypes */
67 int nbits; /* optional width specifier */
68 int nel; /* 1 if scalar, >1 if array */
69 int setat; /* last depth value changed */
70 int *val; /* runtime value(s), initl 0 */
71 Lextok **Sval; /* values for structures */
73 int xu; /* exclusive r or w by 1 pid */
74 struct Symbol *xup[2]; /* xr or xs proctype */
75 struct Access *access;/* e.g., senders and receives of chan */
76 Lextok *ini; /* initial value, or chan-def */
77 Lextok *Slst; /* template for structure if struct */
78 struct Symbol *Snm; /* name of the defining struct */
79 struct Symbol *owner; /* set for names of subfields in typedefs */
80 struct Symbol *context; /* 0 if global, or procname */
81 struct Symbol *next; /* linked list */
84 typedef struct Ordered { /* links all names in Symbol table */
89 typedef struct Queue {
90 short qid; /* runtime q index */
91 int qlen; /* nr messages stored */
92 int nslots, nflds; /* capacity, flds/slot */
93 int setat; /* last depth value changed */
94 int *fld_width; /* type of each field */
95 int *contents; /* the values stored */
96 int *stepnr; /* depth when each msg was sent */
97 struct Queue *nxt; /* linked list */
100 typedef struct FSM_state { /* used in pangen5.c - dataflow */
101 int from; /* state number */
102 int seen; /* used for dfs */
103 int in; /* nr of incoming edges */
104 int cr; /* has reachable 1-relevant successor */
106 unsigned long *dom, *mod; /* to mark dominant nodes */
107 struct FSM_trans *t; /* outgoing edges */
108 struct FSM_trans *p; /* incoming edges, predecessors */
109 struct FSM_state *nxt; /* linked list of all states */
112 typedef struct FSM_trans { /* used in pangen5.c - dataflow */
114 short relevant; /* when sliced */
115 short round; /* ditto: iteration when marked */
116 struct FSM_use *Val[2]; /* 0=reads, 1=writes */
117 struct Element *step;
118 struct FSM_trans *nxt;
121 typedef struct FSM_use { /* used in pangen5.c - dataflow */
128 typedef struct Element {
129 Lextok *n; /* defines the type & contents */
130 int Seqno; /* identifies this el within system */
131 int seqno; /* identifies this el within a proc */
132 int merge; /* set by -O if step can be merged */
135 short merge_in; /* nr of incoming edges */
136 short merge_mark; /* state was generated in merge sequence */
137 unsigned int status; /* used by analyzer generator */
138 struct FSM_use *dead; /* optional dead variable list */
139 struct SeqList *sub; /* subsequences, for compounds */
140 struct SeqList *esc; /* zero or more escape sequences */
141 struct Element *Nxt; /* linked list - for global lookup */
142 struct Element *nxt; /* linked list - program structure */
145 typedef struct Sequence {
147 Element *last; /* links onto continuations */
148 Element *extent; /* last element in original */
149 int minel; /* minimum Seqno, set and used only in guided.c */
150 int maxel; /* 1+largest id in sequence */
153 typedef struct SeqList {
154 Sequence *this; /* one sequence */
155 struct SeqList *nxt; /* linked list */
158 typedef struct Label {
162 int uiid; /* non-zero if label appears in an inline */
163 int visible; /* label referenced in claim (slice relevant) */
167 typedef struct Lbreak {
172 typedef struct L_List {
177 typedef struct RunList {
178 Symbol *n; /* name */
179 int tn; /* ordinal of type */
180 int pid; /* process id */
181 int priority; /* for simulations only */
182 enum btypes b; /* the type of process */
183 Element *pc; /* current stmnt */
184 Sequence *ps; /* used by analyzer generator */
185 Lextok *prov; /* provided clause */
186 Symbol *symtab; /* local variables */
187 struct RunList *nxt; /* linked list */
190 typedef struct ProcList {
191 Symbol *n; /* name */
192 Lextok *p; /* parameters */
193 Sequence *s; /* body */
194 Lextok *prov; /* provided clause */
195 enum btypes b; /* e.g., claim, trace, proc */
196 short tn; /* ordinal number */
197 unsigned char det; /* deterministic */
198 unsigned char unsafe; /* contains global var inits */
199 unsigned char priority; /* process priority, if any */
200 struct ProcList *nxt; /* linked list */
208 typedef Lextok *Lexptr;
210 #define YYSTYPE Lexptr
212 #define ZN (Lextok *)0
213 #define ZS (Symbol *)0
214 #define ZE (Element *)0
216 #define DONE 1 /* status bits of elements */
217 #define ATOM 2 /* part of an atomic chain */
218 #define L_ATOM 4 /* last element in a chain */
219 #define I_GLOB 8 /* inherited global ref */
220 #define DONE2 16 /* used in putcode and main*/
221 #define D_ATOM 32 /* deterministic atomic */
222 #define ENDSTATE 64 /* normal endstate */
223 #define CHECK2 128 /* status bits for remote ref check */
224 #define CHECK3 256 /* status bits for atomic jump check */
226 #define Nhash 255 /* slots in symbol hash-table */
228 #define XR 1 /* non-shared receive-only */
229 #define XS 2 /* non-shared send-only */
230 #define XX 4 /* overrides XR or XS tag */
232 #define CODE_FRAG 2 /* auto-numbered code-fragment */
233 #define CODE_DECL 4 /* auto-numbered c_decl */
234 #define PREDEF 3 /* predefined name: _p, _last */
236 #define UNSIGNED 5 /* val defines width in bits */
237 #define BIT 1 /* also equal to width in bits */
238 #define BYTE 8 /* ditto */
239 #define SHORT 16 /* ditto */
240 #define INT 32 /* ditto */
241 #define CHAN 64 /* not */
242 #define STRUCT 128 /* user defined structure name */
244 #define SOMETHINGBIG 65536
245 #define RATHERSMALL 512
246 #define MAXSCOPESZ 1024
249 #define max(a,b) (((a)<(b)) ? (b) : (a))
258 /***** prototype definitions *****/
259 Element *eval_sub(Element *);
260 Element *get_lab(Lextok *, int);
261 Element *huntele(Element *, unsigned int, int);
262 Element *huntstart(Element *);
263 Element *mk_skip(void);
264 Element *target(Element *);
266 Lextok *do_unless(Lextok *, Lextok *);
267 Lextok *expand(Lextok *, int);
268 Lextok *getuname(Symbol *);
269 Lextok *mk_explicit(Lextok *, int, int);
270 Lextok *nn(Lextok *, int, Lextok *, Lextok *);
271 Lextok *rem_lab(Symbol *, Lextok *, Symbol *);
272 Lextok *rem_var(Symbol *, Lextok *, Symbol *, Lextok *);
273 Lextok *tail_add(Lextok *, Lextok *);
274 Lextok *return_statement(Lextok *);
276 ProcList *ready(Symbol *, Lextok *, Sequence *, int, Lextok *, enum btypes);
278 SeqList *seqlist(Sequence *, SeqList *);
279 Sequence *close_seq(int);
281 Symbol *break_dest(void);
282 Symbol *findloc(Symbol *);
283 Symbol *has_lab(Element *, int);
284 Symbol *lookup(char *);
285 Symbol *prep_inline(Symbol *, Lextok *);
287 char *put_inline(FILE *, char *);
288 char *emalloc(size_t);
291 int any_oper(Lextok *, int);
292 int any_undo(Lextok *);
293 int c_add_sv(FILE *);
294 int cast_val(int, int, int);
295 int checkvar(Symbol *, int);
296 int check_track(Lextok *);
297 int Cnt_flds(Lextok *);
298 int cnt_mpars(Lextok *);
299 int complete_rendez(void);
300 int enable(Lextok *);
301 int Enabled0(Element *);
303 int find_lab(Symbol *, Symbol *, int);
304 int find_maxel(Symbol *);
305 int full_name(FILE *, Lextok *, Symbol *, int);
306 int getlocal(Lextok *);
307 int getval(Lextok *);
308 int glob_inline(char *);
309 int has_typ(Lextok *, int);
310 int in_bound(Symbol *, int);
311 int interprint(FILE *, Lextok *);
312 int printm(FILE *, Lextok *);
315 int isproctype(char *);
317 int Lval_struct(Lextok *, Symbol *, int, int);
318 int main(int, char **);
319 int pc_value(Lextok *);
320 int pid_is_claim(int);
321 int proper_enabler(Lextok *);
322 int putcode(FILE *, Sequence *, Element *, int, int, int);
323 int q_is_sync(Lextok *);
327 int qrecv(Lextok *, int);
329 int remotelab(Lextok *);
330 int remotevar(Lextok *);
331 int Rval_struct(Lextok *, Symbol *, int);
332 int setlocal(Lextok *, int);
333 int setval(Lextok *, int);
334 int sputtype(char *, int);
335 int Sym_typ(Lextok *);
336 int tl_main(int, char *[]);
337 int Width_set(int *, int, Lextok *);
341 void AST_track(Lextok *, int);
342 void add_seq(Lextok *);
344 void announce(char *);
345 void c_state(Symbol *, Symbol *, Symbol *);
346 void c_add_def(FILE *);
347 void c_add_loc(FILE *, char *);
348 void c_add_locinit(FILE *, int, char *);
349 void c_chandump(FILE *);
350 void c_preview(void);
351 void c_struct(FILE *, char *, Symbol *);
352 void c_track(Symbol *, Symbol *, Symbol *);
353 void c_var(FILE *, char *, Symbol *);
354 void c_wrapper(FILE *);
355 void chanaccess(void);
356 void check_param_count(int, Lextok *);
357 void checkrun(Symbol *, int);
358 void comment(FILE *, Lextok *, int);
359 void cross_dsteps(Lextok *, Lextok *);
360 void disambiguate(void);
361 void doq(Symbol *, int, RunList *);
362 void dotag(FILE *, char *);
363 void do_locinits(FILE *);
364 void do_var(FILE *, int, char *, Symbol *, char *, char *, char *);
365 void dump_struct(Symbol *, char *, RunList *);
366 void dumpclaims(FILE *, int, char *);
367 void dumpglobals(void);
368 void dumplabels(void);
369 void dumplocal(RunList *);
370 void dumpsrc(int, int);
371 void fatal(char *, char *);
372 void fix_dest(Symbol *, Symbol *);
373 void genaddproc(void);
374 void genaddqueue(void);
375 void gencodetable(FILE *);
376 void genheader(void);
381 void ini_struct(Symbol *);
382 void loose_ends(void);
383 void make_atomic(Sequence *, int);
384 void mark_last(void);
385 void match_trail(void);
386 void no_side_effects(char *);
387 void nochan_manip(Lextok *, Lextok *, int);
388 void non_fatal(char *, char *);
389 void ntimes(FILE *, int, int, const char *c[]);
391 void p_talk(Element *, int);
392 void pickup_inline(Symbol *, Lextok *, Lextok *);
393 void plunk_c_decls(FILE *);
394 void plunk_c_fcts(FILE *);
395 void plunk_expr(FILE *, char *);
396 void plunk_inline(FILE *, char *, int, int);
397 void prehint(Symbol *);
398 void preruse(FILE *, Lextok *);
399 void pretty_print(void);
400 void prune_opts(Lextok *);
401 void pstext(int, char *);
402 void pushbreak(void);
403 void putname(FILE *, char *, Lextok *, int, char *);
404 void putremote(FILE *, Lextok *, int);
406 void putsrc(Element *);
407 void putstmnt(FILE *, Lextok *, int);
408 void putunames(FILE *);
410 void runnable(ProcList *, int, int);
412 void setaccess(Symbol *, Symbol *, int, int);
413 void set_lab(Symbol *, Element *);
414 void setmtype(Lextok *);
415 void setpname(Lextok *);
416 void setptype(Lextok *, int, Lextok *);
417 void setuname(Lextok *);
418 void setutype(Lextok *, Symbol *, Lextok *);
419 void setxus(Lextok *, int);
420 void Srand(unsigned);
421 void start_claim(int);
422 void struct_name(Lextok *, Symbol *, int, char *);
424 void symvar(Symbol *);
425 void sync_product(void);
426 void trackchanuse(Lextok *, Lextok *, int);
427 void trackvar(Lextok *, Lextok *);
428 void trackrun(Lextok *);
429 void trapwonly(Lextok * /* , char * */); /* spin.y and main.c */
430 void typ2c(Symbol *);
431 void typ_ck(int, int, char *);
432 void undostmnt(Lextok *, int);
433 void unrem_Seq(void);
437 void yyerror(char *, ...);
439 extern int unlink(const char *);
441 #define TMP_FILE1 "._s_p_i_n_"
442 #define TMP_FILE2 "._n_i_p_s_"