You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

248 lines
6.7 KiB

  1. /***** ltl2ba : ltl2ba.h *****/
  2. /* Written by Denis Oddoux, LIAFA, France */
  3. /* Copyright (c) 2001 Denis Oddoux */
  4. /* Modified by Paul Gastin, LSV, France */
  5. /* Copyright (c) 2007 Paul Gastin */
  6. /* */
  7. /* This program is free software; you can redistribute it and/or modify */
  8. /* it under the terms of the GNU General Public License as published by */
  9. /* the Free Software Foundation; either version 2 of the License, or */
  10. /* (at your option) any later version. */
  11. /* */
  12. /* This program is distributed in the hope that it will be useful, */
  13. /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
  14. /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
  15. /* GNU General Public License for more details. */
  16. /* */
  17. /* You should have received a copy of the GNU General Public License */
  18. /* along with this program; if not, write to the Free Software */
  19. /* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA*/
  20. /* */
  21. /* Based on the translation algorithm by Gastin and Oddoux, */
  22. /* presented at the 13th International Conference on Computer Aided */
  23. /* Verification, CAV 2001, Paris, France. */
  24. /* Proceedings - LNCS 2102, pp. 53-65 */
  25. /* */
  26. /* Send bug-reports and/or questions to Paul Gastin */
  27. /* http://www.lsv.ens-cachan.fr/~gastin */
  28. /* */
  29. /* Some of the code in this file was taken from the Spin software */
  30. /* Written by Gerard J. Holzmann, Bell Laboratories, U.S.A. */
  31. #include <stdio.h>
  32. #include <string.h>
  33. #include <stdlib.h>
  34. #include <sys/time.h>
  35. #include <sys/resource.h>
  36. typedef struct Symbol {
  37. char *name;
  38. struct Symbol *next; /* linked list, symbol table */
  39. } Symbol;
  40. typedef struct Node {
  41. short ntyp; /* node type */
  42. struct Symbol *sym;
  43. struct Node *lft; /* tree */
  44. struct Node *rgt; /* tree */
  45. struct Node *nxt; /* if linked list */
  46. } Node;
  47. typedef struct Graph {
  48. Symbol *name;
  49. Symbol *incoming;
  50. Symbol *outgoing;
  51. Symbol *oldstring;
  52. Symbol *nxtstring;
  53. Node *New;
  54. Node *Old;
  55. Node *Other;
  56. Node *Next;
  57. unsigned char isred[64], isgrn[64];
  58. unsigned char redcnt, grncnt;
  59. unsigned char reachable;
  60. struct Graph *nxt;
  61. } Graph;
  62. typedef struct Mapping {
  63. char *from;
  64. Graph *to;
  65. struct Mapping *nxt;
  66. } Mapping;
  67. typedef struct ATrans {
  68. int *to;
  69. int *pos;
  70. int *neg;
  71. struct ATrans *nxt;
  72. } ATrans;
  73. typedef struct AProd {
  74. int astate;
  75. struct ATrans *prod;
  76. struct ATrans *trans;
  77. struct AProd *nxt;
  78. struct AProd *prv;
  79. } AProd;
  80. typedef struct GTrans {
  81. int *pos;
  82. int *neg;
  83. struct GState *to;
  84. int *final;
  85. struct GTrans *nxt;
  86. } GTrans;
  87. typedef struct GState {
  88. int id;
  89. int incoming;
  90. int *nodes_set;
  91. struct GTrans *trans;
  92. struct GState *nxt;
  93. struct GState *prv;
  94. } GState;
  95. typedef struct BTrans {
  96. struct BState *to;
  97. int *pos;
  98. int *neg;
  99. struct BTrans *nxt;
  100. } BTrans;
  101. typedef struct BState {
  102. struct GState *gstate;
  103. int id;
  104. int incoming;
  105. int final;
  106. struct BTrans *trans;
  107. struct BState *nxt;
  108. struct BState *prv;
  109. } BState;
  110. typedef struct GScc {
  111. struct GState *gstate;
  112. int rank;
  113. int theta;
  114. struct GScc *nxt;
  115. } GScc;
  116. typedef struct BScc {
  117. struct BState *bstate;
  118. int rank;
  119. int theta;
  120. struct BScc *nxt;
  121. } BScc;
  122. enum {
  123. ALWAYS=257,
  124. AND, /* 258 */
  125. EQUIV, /* 259 */
  126. EVENTUALLY, /* 260 */
  127. FALSE, /* 261 */
  128. IMPLIES, /* 262 */
  129. NOT, /* 263 */
  130. OR, /* 264 */
  131. PREDICATE, /* 265 */
  132. TRUE, /* 266 */
  133. U_OPER, /* 267 */
  134. V_OPER /* 268 */
  135. #ifdef NXT
  136. , NEXT /* 269 */
  137. #endif
  138. };
  139. Node *Canonical(Node *);
  140. Node *canonical(Node *);
  141. Node *cached(Node *);
  142. Node *dupnode(Node *);
  143. Node *getnode(Node *);
  144. Node *in_cache(Node *);
  145. Node *push_negation(Node *);
  146. Node *right_linked(Node *);
  147. Node *tl_nn(int, Node *, Node *);
  148. Symbol *tl_lookup(char *);
  149. Symbol *getsym(Symbol *);
  150. Symbol *DoDump(Node *);
  151. char *emalloc(int);
  152. int anywhere(int, Node *, Node *);
  153. int dump_cond(Node *, Node *, int);
  154. int isequal(Node *, Node *);
  155. int tl_Getchar(void);
  156. void *tl_emalloc(int);
  157. ATrans *emalloc_atrans();
  158. void free_atrans(ATrans *, int);
  159. void free_all_atrans();
  160. GTrans *emalloc_gtrans();
  161. void free_gtrans(GTrans *, GTrans *, int);
  162. BTrans *emalloc_btrans();
  163. void free_btrans(BTrans *, BTrans *, int);
  164. void a_stats(void);
  165. void addtrans(Graph *, char *, Node *, char *);
  166. void cache_stats(void);
  167. void dump(Node *);
  168. void exit(int);
  169. void Fatal(char *, char *);
  170. void fatal(char *, char *);
  171. void fsm_print(void);
  172. void releasenode(int, Node *);
  173. void tfree(void *);
  174. void tl_explain(int);
  175. void tl_UnGetchar(void);
  176. void tl_parse(void);
  177. void tl_yyerror(char *);
  178. void trans(Node *);
  179. void mk_alternating(Node *);
  180. void mk_generalized();
  181. void mk_buchi();
  182. ATrans *dup_trans(ATrans *);
  183. ATrans *merge_trans(ATrans *, ATrans *);
  184. void do_merge_trans(ATrans **, ATrans *, ATrans *);
  185. int *new_set(int);
  186. int *clear_set(int *, int);
  187. int *make_set(int , int);
  188. void copy_set(int *, int *, int);
  189. int *dup_set(int *, int);
  190. void merge_sets(int *, int *, int);
  191. void do_merge_sets(int *, int *, int *, int);
  192. int *intersect_sets(int *, int *, int);
  193. void add_set(int *, int);
  194. void rem_set(int *, int);
  195. void spin_print_set(int *, int*);
  196. void print_set(int *, int);
  197. int empty_set(int *, int);
  198. int empty_intersect_sets(int *, int *, int);
  199. int same_sets(int *, int *, int);
  200. int included_set(int *, int *, int);
  201. int in_set(int *, int);
  202. int *list_set(int *, int);
  203. int timeval_subtract (struct timeval *, struct timeval *, struct timeval *);
  204. #define ZN (Node *)0
  205. #define ZS (Symbol *)0
  206. #define Nhash 255
  207. #define True tl_nn(TRUE, ZN, ZN)
  208. #define False tl_nn(FALSE, ZN, ZN)
  209. #define Not(a) push_negation(tl_nn(NOT, a, ZN))
  210. #define rewrite(n) canonical(right_linked(n))
  211. typedef Node *Nodeptr;
  212. #define YYSTYPE Nodeptr
  213. #define Debug(x) { if (0) printf(x); }
  214. #define Debug2(x,y) { if (tl_verbose) printf(x,y); }
  215. #define Dump(x) { if (0) dump(x); }
  216. #define Explain(x) { if (tl_verbose) tl_explain(x); }
  217. #define Assert(x, y) { if (!(x)) { tl_explain(y); \
  218. Fatal(": assertion failed\n",(char *)0); } }
  219. #define min(x,y) ((x<y)?x:y)