spin.h 12 KB

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