debug.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. /* $Id$ */
  2. /*
  3. * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
  4. * See the copyright notice in the ACK home directory, in the file "Copyright".
  5. */
  6. /* S H A R E D F I L E
  7. *
  8. * D E B U G . C
  9. */
  10. #include <stdlib.h>
  11. #include <stdio.h>
  12. #ifdef __STDC__
  13. #include <stdarg.h>
  14. #endif
  15. #include <em_spec.h>
  16. #include "types.h"
  17. #include "def.h"
  18. #include "debug.h"
  19. #include "global.h"
  20. int linecount; /* # lines in this file */
  21. bool verbose_flag = FALSE; /* generate verbose output ? */
  22. #ifdef __STDC__
  23. /* VARARGS1 */
  24. void error(char *s, ...)
  25. {
  26. va_list ap;
  27. fprintf(stderr,"error on line %u",linecount);
  28. if (filename != (char *) 0) {
  29. fprintf(stderr," file %s",filename);
  30. }
  31. fprintf(stderr,": ");
  32. va_start(ap, s);
  33. vfprintf(stderr,s, ap);
  34. va_end(ap);
  35. fprintf(stderr,"\n");
  36. abort();
  37. exit(-1);
  38. }
  39. #ifdef TRACE
  40. /* VARARGS1 */
  41. void OUTTRACE(char *s, ...)
  42. {
  43. va_list ap;
  44. fprintf(stderr,"> ");
  45. va_start(ap, s);
  46. vfprintf(stderr,s, ap);
  47. va_end(ap);
  48. fprintf(stderr,"\n");
  49. }
  50. #endif
  51. #ifdef VERBOSE
  52. /* VARARGS1 */
  53. void OUTVERBOSE(char *s, ...)
  54. {
  55. if (verbose_flag) {
  56. va_list ap;
  57. fprintf(stderr,"optimization: ");
  58. va_start(ap, s);
  59. vfprintf(stderr,s, ap);
  60. va_end(ap);
  61. fprintf(stderr,"\n");
  62. }
  63. }
  64. #endif
  65. #else /* __STDC__ */
  66. /* VARARGS1 */
  67. void error(char *s, char *a)
  68. {
  69. fprintf(stderr,"error on line %u",linecount);
  70. if (filename != (char *) 0) {
  71. fprintf(stderr," file %s",filename);
  72. }
  73. fprintf(stderr,": ");
  74. fprintf(stderr,s,a);
  75. fprintf(stderr,"\n");
  76. abort();
  77. exit(-1);
  78. }
  79. #ifdef TRACE
  80. /* VARARGS1 */
  81. void OUTTRACE(char *s, int n)
  82. {
  83. fprintf(stderr,"> ");
  84. fprintf(stderr,s,n);
  85. fprintf(stderr,"\n");
  86. }
  87. #endif
  88. #ifdef VERBOSE
  89. /* VARARGS1 */
  90. void OUTVERBOSE(char *s, int n1, int n2)
  91. {
  92. if (verbose_flag) {
  93. fprintf(stderr,"optimization: ");
  94. fprintf(stderr,s,n1,n2);
  95. fprintf(stderr,"\n");
  96. }
  97. }
  98. #endif
  99. #endif /* __STDC__ */
  100. #ifdef DEBUG
  101. void badassertion(char *file, unsigned int line)
  102. {
  103. fprintf(stderr,"assertion failed file %s, line %u\n",file,line);
  104. error("assertion");
  105. }
  106. /* Valid Address */
  107. void VA(short *a)
  108. {
  109. if (a == (short *) 0) error("VA: 0 argument");
  110. if ( ((unsigned) a & 01) == 01) {
  111. /* MACHINE DEPENDENT TEST */
  112. error("VA: odd argument");
  113. }
  114. }
  115. /* Valid Instruction code */
  116. void VI(short i)
  117. {
  118. if (i > ps_last) error("VI: illegal instr: %d", i);
  119. }
  120. /* Valid Line */
  121. void VL(line_p l)
  122. {
  123. byte instr, optype;
  124. VA((short *) l);
  125. instr = l->l_instr;
  126. VI(instr);
  127. optype = TYPE(l);
  128. if (optype < OP_FIRST || optype > OP_LAST) {
  129. error("VL: illegal optype: %d", optype);
  130. }
  131. }
  132. /* Valid Data block */
  133. void VD(dblock_p d)
  134. {
  135. byte pseudo;
  136. VA((short *) d);
  137. pseudo = d->d_pseudo;
  138. if (pseudo < D_FIRST || pseudo > D_LAST) {
  139. error("VD: illegal pseudo: %d",pseudo);
  140. }
  141. }
  142. /* Valid Object */
  143. void VO(obj_p o)
  144. {
  145. offset off;
  146. VA((short *) o);
  147. off = o->o_off;
  148. if (off < 0 || off > 10000) {
  149. error("VO: unlikely offset: %d", off);
  150. }
  151. }
  152. /* Valid Proc */
  153. void VP(proc_p p)
  154. {
  155. proc_id pid;
  156. int nrlabs;
  157. VA((short *) p);
  158. pid = p->p_id;
  159. if (pid <0 || pid > 1000) {
  160. error("VP: unlikely proc_id: %d", (int) pid);
  161. }
  162. nrlabs = p->p_nrlabels;
  163. if (nrlabs < 0 || nrlabs > 500) {
  164. error("VP: unlikely p_nrlabels: %d", nrlabs);
  165. }
  166. }
  167. #endif