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.

175 lines
5.1 KiB

  1. /***** ltl2ba : trans.c *****/
  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 "ltl2ba.h"
  32. extern int tl_verbose, tl_terse, tl_errs;
  33. extern FILE *tl_out;
  34. int Stack_mx=0, Max_Red=0, Total=0;
  35. static char dumpbuf[2048];
  36. #ifdef NXT
  37. int
  38. only_nxt(Node *n)
  39. {
  40. switch (n->ntyp) {
  41. case NEXT:
  42. return 1;
  43. case OR:
  44. case AND:
  45. return only_nxt(n->rgt) && only_nxt(n->lft);
  46. default:
  47. return 0;
  48. }
  49. }
  50. #endif
  51. int
  52. dump_cond(Node *pp, Node *r, int first)
  53. { Node *q;
  54. int frst = first;
  55. if (!pp) return frst;
  56. q = dupnode(pp);
  57. q = rewrite(q);
  58. if (q->ntyp == PREDICATE
  59. || q->ntyp == NOT
  60. #ifndef NXT
  61. || q->ntyp == OR
  62. #endif
  63. || q->ntyp == FALSE)
  64. { if (!frst) fprintf(tl_out, " && ");
  65. dump(q);
  66. frst = 0;
  67. #ifdef NXT
  68. } else if (q->ntyp == OR)
  69. { if (!frst) fprintf(tl_out, " && ");
  70. fprintf(tl_out, "((");
  71. frst = dump_cond(q->lft, r, 1);
  72. if (!frst)
  73. fprintf(tl_out, ") || (");
  74. else
  75. { if (only_nxt(q->lft))
  76. { fprintf(tl_out, "1))");
  77. return 0;
  78. }
  79. }
  80. frst = dump_cond(q->rgt, r, 1);
  81. if (frst)
  82. { if (only_nxt(q->rgt))
  83. fprintf(tl_out, "1");
  84. else
  85. fprintf(tl_out, "0");
  86. frst = 0;
  87. }
  88. fprintf(tl_out, "))");
  89. #endif
  90. } else if (q->ntyp == V_OPER
  91. && !anywhere(AND, q->rgt, r))
  92. { frst = dump_cond(q->rgt, r, frst);
  93. } else if (q->ntyp == AND)
  94. {
  95. frst = dump_cond(q->lft, r, frst);
  96. frst = dump_cond(q->rgt, r, frst);
  97. }
  98. return frst;
  99. }
  100. static void
  101. sdump(Node *n)
  102. {
  103. switch (n->ntyp) {
  104. case PREDICATE: strcat(dumpbuf, n->sym->name);
  105. break;
  106. case U_OPER: strcat(dumpbuf, "U");
  107. goto common2;
  108. case V_OPER: strcat(dumpbuf, "V");
  109. goto common2;
  110. case OR: strcat(dumpbuf, "|");
  111. goto common2;
  112. case AND: strcat(dumpbuf, "&");
  113. common2: sdump(n->rgt);
  114. common1: sdump(n->lft);
  115. break;
  116. #ifdef NXT
  117. case NEXT: strcat(dumpbuf, "X");
  118. goto common1;
  119. #endif
  120. case NOT: strcat(dumpbuf, "!");
  121. goto common1;
  122. case TRUE: strcat(dumpbuf, "T");
  123. break;
  124. case FALSE: strcat(dumpbuf, "F");
  125. break;
  126. default: strcat(dumpbuf, "?");
  127. break;
  128. }
  129. }
  130. Symbol *
  131. DoDump(Node *n)
  132. {
  133. if (!n) return ZS;
  134. if (n->ntyp == PREDICATE)
  135. return n->sym;
  136. dumpbuf[0] = '\0';
  137. sdump(n);
  138. return tl_lookup(dumpbuf);
  139. }
  140. void trans(Node *p)
  141. {
  142. if (!p || tl_errs) return;
  143. if (tl_verbose || tl_terse) {
  144. fprintf(tl_out, "\t/* Normlzd: ");
  145. dump(p);
  146. fprintf(tl_out, " */\n");
  147. }
  148. if (tl_terse)
  149. return;
  150. mk_alternating(p);
  151. mk_generalized();
  152. mk_buchi();
  153. }