spin.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429
  1. /*
  2. * This file is part of the UCB release of Plan 9. It is subject to the license
  3. * terms in the LICENSE file found in the top-level directory of this
  4. * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  5. * part of the UCB release of Plan 9, including this file, may be copied,
  6. * modified, propagated, or distributed except according to the terms contained
  7. * in the LICENSE file.
  8. */
  9. /***** spin: spin.h *****/
  10. /* Copyright (c) 1989-2009 by Lucent Technologies, Bell Laboratories. */
  11. /* All Rights Reserved. This software is for educational purposes only. */
  12. /* No guarantee whatsoever is expressed or implied by the distribution of */
  13. /* this code. Permission is given to distribute this code provided that */
  14. /* this introductory message is not removed and no monies are exchanged. */
  15. /* Software written by Gerard J. Holzmann. For tool documentation see: */
  16. /* http://spinroot.com/ */
  17. /* Send all bug-reports and/or questions to: bugs@spinroot.com */
  18. #ifndef SEEN_SPIN_H
  19. #define SEEN_SPIN_H
  20. #include <stdio.h>
  21. #include <string.h>
  22. #include <ctype.h>
  23. enum { INIV, PUTV, LOGV }; /* for pangen[14].c */
  24. 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 */
  37. } Lextok;
  38. typedef struct Slicer {
  39. Lextok *n; /* global var, usable as slice criterion */
  40. short code; /* type of use: DEREF_USE or normal USE */
  41. short used; /* set when handled */
  42. struct Slicer *nxt; /* linked list */
  43. } Slicer;
  44. typedef struct Access {
  45. struct Symbol *who; /* proctype name of accessor */
  46. struct Symbol *what; /* proctype name of accessed */
  47. int cnt, typ; /* parameter nr and, e.g., 's' or 'r' */
  48. struct Access *lnk; /* linked list */
  49. } Access;
  50. typedef struct Symbol {
  51. char *name;
  52. int Nid; /* unique number for the name */
  53. unsigned short type; /* bit,short,.., chan,struct */
  54. unsigned char hidden; /* bit-flags:
  55. 1=hide, 2=show,
  56. 4=bit-equiv, 8=byte-equiv,
  57. 16=formal par, 32=inline par,
  58. 64=treat as if local; 128=read at least once
  59. */
  60. unsigned char colnr; /* for use with xspin during simulation */
  61. unsigned char isarray; /* set if decl specifies array bound */
  62. unsigned char *bscp; /* block scope */
  63. int nbits; /* optional width specifier */
  64. int nel; /* 1 if scalar, >1 if array */
  65. int setat; /* last depth value changed */
  66. int *val; /* runtime value(s), initl 0 */
  67. Lextok **Sval; /* values for structures */
  68. int xu; /* exclusive r or w by 1 pid */
  69. struct Symbol *xup[2]; /* xr or xs proctype */
  70. struct Access *access;/* e.g., senders and receives of chan */
  71. Lextok *ini; /* initial value, or chan-def */
  72. Lextok *Slst; /* template for structure if struct */
  73. struct Symbol *Snm; /* name of the defining struct */
  74. struct Symbol *owner; /* set for names of subfields in typedefs */
  75. struct Symbol *context; /* 0 if global, or procname */
  76. struct Symbol *next; /* linked list */
  77. } Symbol;
  78. typedef struct Ordered { /* links all names in Symbol table */
  79. struct Symbol *entry;
  80. struct Ordered *next;
  81. } Ordered;
  82. typedef struct Queue {
  83. short qid; /* runtime q index */
  84. int qlen; /* nr messages stored */
  85. int nslots, nflds; /* capacity, flds/slot */
  86. int setat; /* last depth value changed */
  87. int *fld_width; /* type of each field */
  88. int *contents; /* the values stored */
  89. int *stepnr; /* depth when each msg was sent */
  90. struct Queue *nxt; /* linked list */
  91. } Queue;
  92. typedef struct FSM_state { /* used in pangen5.c - dataflow */
  93. int from; /* state number */
  94. int seen; /* used for dfs */
  95. int in; /* nr of incoming edges */
  96. int cr; /* has reachable 1-relevant successor */
  97. int scratch;
  98. unsigned long *dom, *mod; /* to mark dominant nodes */
  99. struct FSM_trans *t; /* outgoing edges */
  100. struct FSM_trans *p; /* incoming edges, predecessors */
  101. struct FSM_state *nxt; /* linked list of all states */
  102. } FSM_state;
  103. typedef struct FSM_trans { /* used in pangen5.c - dataflow */
  104. int to;
  105. short relevant; /* when sliced */
  106. short round; /* ditto: iteration when marked */
  107. struct FSM_use *Val[2]; /* 0=reads, 1=writes */
  108. struct Element *step;
  109. struct FSM_trans *nxt;
  110. } FSM_trans;
  111. typedef struct FSM_use { /* used in pangen5.c - dataflow */
  112. Lextok *n;
  113. Symbol *var;
  114. int special;
  115. struct FSM_use *nxt;
  116. } FSM_use;
  117. typedef struct Element {
  118. Lextok *n; /* defines the type & contents */
  119. int Seqno; /* identifies this el within system */
  120. int seqno; /* identifies this el within a proc */
  121. int merge; /* set by -O if step can be merged */
  122. int merge_start;
  123. int merge_single;
  124. short merge_in; /* nr of incoming edges */
  125. short merge_mark; /* state was generated in merge sequence */
  126. unsigned int status; /* used by analyzer generator */
  127. struct FSM_use *dead; /* optional dead variable list */
  128. struct SeqList *sub; /* subsequences, for compounds */
  129. struct SeqList *esc; /* zero or more escape sequences */
  130. struct Element *Nxt; /* linked list - for global lookup */
  131. struct Element *nxt; /* linked list - program structure */
  132. } Element;
  133. typedef struct Sequence {
  134. Element *frst;
  135. Element *last; /* links onto continuations */
  136. Element *extent; /* last element in original */
  137. int maxel; /* 1+largest id in sequence */
  138. } Sequence;
  139. typedef struct SeqList {
  140. Sequence *this; /* one sequence */
  141. struct SeqList *nxt; /* linked list */
  142. } SeqList;
  143. typedef struct Label {
  144. Symbol *s;
  145. Symbol *c;
  146. Element *e;
  147. int uiid; /* non-zero if label appears in an inline */
  148. int visible; /* label referenced in claim (slice relevant) */
  149. struct Label *nxt;
  150. } Label;
  151. typedef struct Lbreak {
  152. Symbol *l;
  153. struct Lbreak *nxt;
  154. } Lbreak;
  155. typedef struct RunList {
  156. Symbol *n; /* name */
  157. int tn; /* ordinal of type */
  158. int pid; /* process id */
  159. int priority; /* for simulations only */
  160. enum btypes b; /* the type of process */
  161. Element *pc; /* current stmnt */
  162. Sequence *ps; /* used by analyzer generator */
  163. Lextok *prov; /* provided clause */
  164. Symbol *symtab; /* local variables */
  165. struct RunList *nxt; /* linked list */
  166. } RunList;
  167. typedef struct ProcList {
  168. Symbol *n; /* name */
  169. Lextok *p; /* parameters */
  170. Sequence *s; /* body */
  171. Lextok *prov; /* provided clause */
  172. enum btypes b; /* e.g., claim, trace, proc */
  173. short tn; /* ordinal number */
  174. unsigned char det; /* deterministic */
  175. unsigned char unsafe; /* contains global var inits */
  176. struct ProcList *nxt; /* linked list */
  177. } ProcList;
  178. typedef Lextok *Lexptr;
  179. #define YYSTYPE Lexptr
  180. #define ZN (Lextok *)0
  181. #define ZS (Symbol *)0
  182. #define ZE (Element *)0
  183. #define DONE 1 /* status bits of elements */
  184. #define ATOM 2 /* part of an atomic chain */
  185. #define L_ATOM 4 /* last element in a chain */
  186. #define I_GLOB 8 /* inherited global ref */
  187. #define DONE2 16 /* used in putcode and main*/
  188. #define D_ATOM 32 /* deterministic atomic */
  189. #define ENDSTATE 64 /* normal endstate */
  190. #define CHECK2 128 /* status bits for remote ref check */
  191. #define CHECK3 256 /* status bits for atomic jump check */
  192. #define Nhash 255 /* slots in symbol hash-table */
  193. #define XR 1 /* non-shared receive-only */
  194. #define XS 2 /* non-shared send-only */
  195. #define XX 4 /* overrides XR or XS tag */
  196. #define CODE_FRAG 2 /* auto-numbered code-fragment */
  197. #define CODE_DECL 4 /* auto-numbered c_decl */
  198. #define PREDEF 3 /* predefined name: _p, _last */
  199. #define UNSIGNED 5 /* val defines width in bits */
  200. #define BIT 1 /* also equal to width in bits */
  201. #define BYTE 8 /* ditto */
  202. #define SHORT 16 /* ditto */
  203. #define INT 32 /* ditto */
  204. #define CHAN 64 /* not */
  205. #define STRUCT 128 /* user defined structure name */
  206. #define SOMETHINGBIG 65536
  207. #define RATHERSMALL 512
  208. #define MAXSCOPESZ 1024
  209. #ifndef max
  210. #define max(a,b) (((a)<(b)) ? (b) : (a))
  211. #endif
  212. #ifdef PC
  213. #define MFLAGS "wb"
  214. #else
  215. #define MFLAGS "w"
  216. #endif
  217. /***** prototype definitions *****/
  218. Element *eval_sub(Element *);
  219. Element *get_lab(Lextok *, int);
  220. Element *huntele(Element *, int, int);
  221. Element *huntstart(Element *);
  222. Element *target(Element *);
  223. Lextok *do_unless(Lextok *, Lextok *);
  224. Lextok *expand(Lextok *, int);
  225. Lextok *getuname(Symbol *);
  226. Lextok *mk_explicit(Lextok *, int, int);
  227. Lextok *nn(Lextok *, int, Lextok *, Lextok *);
  228. Lextok *rem_lab(Symbol *, Lextok *, Symbol *);
  229. Lextok *rem_var(Symbol *, Lextok *, Symbol *, Lextok *);
  230. Lextok *tail_add(Lextok *, Lextok *);
  231. ProcList *ready(Symbol *, Lextok *, Sequence *, int, Lextok *, enum btypes);
  232. SeqList *seqlist(Sequence *, SeqList *);
  233. Sequence *close_seq(int);
  234. Symbol *break_dest(void);
  235. Symbol *findloc(Symbol *);
  236. Symbol *has_lab(Element *, int);
  237. Symbol *lookup(char *);
  238. Symbol *prep_inline(Symbol *, Lextok *);
  239. char *emalloc(size_t);
  240. long Rand(void);
  241. int any_oper(Lextok *, int);
  242. int any_undo(Lextok *);
  243. int c_add_sv(FILE *);
  244. int cast_val(int, int, int);
  245. int checkvar(Symbol *, int);
  246. int Cnt_flds(Lextok *);
  247. int cnt_mpars(Lextok *);
  248. int complete_rendez(void);
  249. int enable(Lextok *);
  250. int Enabled0(Element *);
  251. int eval(Lextok *);
  252. int find_lab(Symbol *, Symbol *, int);
  253. int find_maxel(Symbol *);
  254. int full_name(FILE *, Lextok *, Symbol *, int);
  255. int getlocal(Lextok *);
  256. int getval(Lextok *);
  257. int glob_inline(char *);
  258. int has_typ(Lextok *, int);
  259. int in_bound(Symbol *, int);
  260. int interprint(FILE *, Lextok *);
  261. int printm(FILE *, Lextok *);
  262. int is_inline(void);
  263. int ismtype(char *);
  264. int isproctype(char *);
  265. int isutype(char *);
  266. int Lval_struct(Lextok *, Symbol *, int, int);
  267. int main(int, char **);
  268. int pc_value(Lextok *);
  269. int pid_is_claim(int);
  270. int proper_enabler(Lextok *);
  271. int putcode(FILE *, Sequence *, Element *, int, int, int);
  272. int q_is_sync(Lextok *);
  273. int qlen(Lextok *);
  274. int qfull(Lextok *);
  275. int qmake(Symbol *);
  276. int qrecv(Lextok *, int);
  277. int qsend(Lextok *);
  278. int remotelab(Lextok *);
  279. int remotevar(Lextok *);
  280. int Rval_struct(Lextok *, Symbol *, int);
  281. int setlocal(Lextok *, int);
  282. int setval(Lextok *, int);
  283. int sputtype(char *, int);
  284. int Sym_typ(Lextok *);
  285. int tl_main(int, char *[]);
  286. int Width_set(int *, int, Lextok *);
  287. int yyparse(void);
  288. int yywrap(void);
  289. int yylex(void);
  290. void AST_track(Lextok *, int);
  291. void add_seq(Lextok *);
  292. void alldone(int);
  293. void announce(char *);
  294. void c_state(Symbol *, Symbol *, Symbol *);
  295. void c_add_def(FILE *);
  296. void c_add_loc(FILE *, char *);
  297. void c_add_locinit(FILE *, int, char *);
  298. void c_add_use(FILE *);
  299. void c_chandump(FILE *);
  300. void c_preview(void);
  301. void c_struct(FILE *, char *, Symbol *);
  302. void c_track(Symbol *, Symbol *, Symbol *);
  303. void c_var(FILE *, char *, Symbol *);
  304. void c_wrapper(FILE *);
  305. void chanaccess(void);
  306. void check_param_count(int, Lextok *);
  307. void checkrun(Symbol *, int);
  308. void comment(FILE *, Lextok *, int);
  309. void cross_dsteps(Lextok *, Lextok *);
  310. void disambiguate(void);
  311. void doq(Symbol *, int, RunList *);
  312. void dotag(FILE *, char *);
  313. void do_locinits(FILE *);
  314. void do_var(FILE *, int, char *, Symbol *, char *, char *, char *);
  315. void dump_struct(Symbol *, char *, RunList *);
  316. void dumpclaims(FILE *, int, char *);
  317. void dumpglobals(void);
  318. void dumplabels(void);
  319. void dumplocal(RunList *);
  320. void dumpsrc(int, int);
  321. void fatal(char *, char *);
  322. void fix_dest(Symbol *, Symbol *);
  323. void genaddproc(void);
  324. void genaddqueue(void);
  325. void gencodetable(FILE *);
  326. void genheader(void);
  327. void genother(void);
  328. void gensrc(void);
  329. void gensvmap(void);
  330. void genunio(void);
  331. void ini_struct(Symbol *);
  332. void loose_ends(void);
  333. void make_atomic(Sequence *, int);
  334. void match_trail(void);
  335. void no_side_effects(char *);
  336. void nochan_manip(Lextok *, Lextok *, int);
  337. void non_fatal(char *, char *);
  338. void ntimes(FILE *, int, int, char *c[]);
  339. void open_seq(int);
  340. void p_talk(Element *, int);
  341. void pickup_inline(Symbol *, Lextok *);
  342. void plunk_c_decls(FILE *);
  343. void plunk_c_fcts(FILE *);
  344. void plunk_expr(FILE *, char *);
  345. void plunk_inline(FILE *, char *, int, int);
  346. void prehint(Symbol *);
  347. void preruse(FILE *, Lextok *);
  348. void prune_opts(Lextok *);
  349. void pstext(int, char *);
  350. void pushbreak(void);
  351. void putname(FILE *, char *, Lextok *, int, char *);
  352. void putremote(FILE *, Lextok *, int);
  353. void putskip(int);
  354. void putsrc(Element *);
  355. void putstmnt(FILE *, Lextok *, int);
  356. void putunames(FILE *);
  357. void rem_Seq(void);
  358. void runnable(ProcList *, int, int);
  359. void sched(void);
  360. void setaccess(Symbol *, Symbol *, int, int);
  361. void set_lab(Symbol *, Element *);
  362. void setmtype(Lextok *);
  363. void setpname(Lextok *);
  364. void setptype(Lextok *, int, Lextok *);
  365. void setuname(Lextok *);
  366. void setutype(Lextok *, Symbol *, Lextok *);
  367. void setxus(Lextok *, int);
  368. void show_lab(void);
  369. void Srand(unsigned);
  370. void start_claim(int);
  371. void struct_name(Lextok *, Symbol *, int, char *);
  372. void symdump(void);
  373. void symvar(Symbol *);
  374. void sync_product(void);
  375. void trackchanuse(Lextok *, Lextok *, int);
  376. void trackvar(Lextok *, Lextok *);
  377. void trackrun(Lextok *);
  378. void trapwonly(Lextok * /* , char * */); /* spin.y and main.c */
  379. void typ2c(Symbol *);
  380. void typ_ck(int, int, char *);
  381. void undostmnt(Lextok *, int);
  382. void unrem_Seq(void);
  383. void unskip(int);
  384. void varcheck(Element *, Element *);
  385. void whoruns(int);
  386. void wrapup(int);
  387. void yyerror(char *, ...);
  388. #endif