reprosrc.c 2.9 KB

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