reprosrc.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /***** spin: reprosrc.c *****/
  2. /* Copyright (c) 2002-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. #include <stdio.h>
  11. #include "spin.h"
  12. #ifdef PC
  13. #include "y_tab.h"
  14. #else
  15. #include "y.tab.h"
  16. #endif
  17. static int indent = 1;
  18. extern ProcList *rdy;
  19. void repro_seq(Sequence *);
  20. void
  21. doindent(void)
  22. { int i;
  23. for (i = 0; i < indent; i++)
  24. printf(" ");
  25. }
  26. void
  27. repro_sub(Element *e)
  28. {
  29. doindent();
  30. switch (e->n->ntyp) {
  31. case D_STEP:
  32. printf("d_step {\n");
  33. break;
  34. case ATOMIC:
  35. printf("atomic {\n");
  36. break;
  37. case NON_ATOMIC:
  38. printf(" {\n");
  39. break;
  40. }
  41. indent++;
  42. repro_seq(e->n->sl->this);
  43. indent--;
  44. doindent();
  45. printf(" };\n");
  46. }
  47. void
  48. repro_seq(Sequence *s)
  49. { Element *e;
  50. Symbol *v;
  51. SeqList *h;
  52. for (e = s->frst; e; e = e->nxt)
  53. {
  54. v = has_lab(e, 0);
  55. if (v) printf("%s:\n", v->name);
  56. if (e->n->ntyp == UNLESS)
  57. { printf("/* normal */ {\n");
  58. repro_seq(e->n->sl->this);
  59. doindent();
  60. printf("} unless {\n");
  61. repro_seq(e->n->sl->nxt->this);
  62. doindent();
  63. printf("}; /* end unless */\n");
  64. } else if (e->sub)
  65. {
  66. switch (e->n->ntyp) {
  67. case DO: doindent(); printf("do\n"); indent++; break;
  68. case IF: doindent(); printf("if\n"); indent++; break;
  69. }
  70. for (h = e->sub; h; h = h->nxt)
  71. { indent--; doindent(); indent++; printf("::\n");
  72. repro_seq(h->this);
  73. printf("\n");
  74. }
  75. switch (e->n->ntyp) {
  76. case DO: indent--; doindent(); printf("od;\n"); break;
  77. case IF: indent--; doindent(); printf("fi;\n"); break;
  78. }
  79. } else
  80. { if (e->n->ntyp == ATOMIC
  81. || e->n->ntyp == D_STEP
  82. || e->n->ntyp == NON_ATOMIC)
  83. repro_sub(e);
  84. else if (e->n->ntyp != '.'
  85. && e->n->ntyp != '@'
  86. && e->n->ntyp != BREAK)
  87. {
  88. doindent();
  89. if (e->n->ntyp == C_CODE)
  90. { printf("c_code ");
  91. plunk_inline(stdout, e->n->sym->name, 1);
  92. } else if (e->n->ntyp == 'c'
  93. && e->n->lft->ntyp == C_EXPR)
  94. { printf("c_expr { ");
  95. plunk_expr(stdout, e->n->lft->sym->name);
  96. printf("} ->\n");
  97. } else
  98. { comment(stdout, e->n, 0);
  99. printf(";\n");
  100. } }
  101. }
  102. if (e == s->last)
  103. break;
  104. }
  105. }
  106. void
  107. repro_proc(ProcList *p)
  108. {
  109. if (!p) return;
  110. if (p->nxt) repro_proc(p->nxt);
  111. if (p->det) printf("D"); /* deterministic */
  112. printf("proctype %s()", p->n->name);
  113. if (p->prov)
  114. { printf(" provided ");
  115. comment(stdout, p->prov, 0);
  116. }
  117. printf("\n{\n");
  118. repro_seq(p->s);
  119. printf("}\n");
  120. }
  121. void
  122. repro_src(void)
  123. {
  124. repro_proc(rdy);
  125. }