spin.h 12 KB

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