debug.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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. #include <em_spec.h>
  13. #include "types.h"
  14. #include "def.h"
  15. #include "debug.h"
  16. #include "global.h"
  17. int linecount; /* # lines in this file */
  18. bool verbose_flag = FALSE; /* generate verbose output ? */
  19. /* VARARGS1 */
  20. error(s,a) char *s,*a; {
  21. fprintf(stderr,"error on line %u",linecount);
  22. if (filename != (char *) 0) {
  23. fprintf(stderr," file %s",filename);
  24. }
  25. fprintf(stderr,": ");
  26. fprintf(stderr,s,a);
  27. fprintf(stderr,"\n");
  28. abort();
  29. exit(-1);
  30. }
  31. #ifdef TRACE
  32. /* VARARGS1 */
  33. OUTTRACE(s,n)
  34. char *s;
  35. int n;
  36. {
  37. fprintf(stderr,"> ");
  38. fprintf(stderr,s,n);
  39. fprintf(stderr,"\n");
  40. }
  41. #endif
  42. #ifdef VERBOSE
  43. /* VARARGS1 */
  44. OUTVERBOSE(s,n1,n2)
  45. char *s;
  46. int n1,n2;
  47. {
  48. if (verbose_flag) {
  49. fprintf(stderr,"optimization: ");
  50. fprintf(stderr,s,n1,n2);
  51. fprintf(stderr,"\n");
  52. }
  53. }
  54. #endif
  55. #ifdef DEBUG
  56. badassertion(file,line) char *file; unsigned line; {
  57. fprintf(stderr,"assertion failed file %s, line %u\n",file,line);
  58. error("assertion");
  59. }
  60. /* Valid Address */
  61. VA(a) short *a; {
  62. if (a == (short *) 0) error("VA: 0 argument");
  63. if ( ((unsigned) a & 01) == 01) {
  64. /* MACHINE DEPENDENT TEST */
  65. error("VA: odd argument");
  66. }
  67. }
  68. /* Valid Instruction code */
  69. VI(i) short i; {
  70. if (i > ps_last) error("VI: illegal instr: %d", i);
  71. }
  72. /* Valid Line */
  73. VL(l) line_p l; {
  74. byte instr, optype;
  75. VA((short *) l);
  76. instr = l->l_instr;
  77. VI(instr);
  78. optype = TYPE(l);
  79. if (optype < OP_FIRST || optype > OP_LAST) {
  80. error("VL: illegal optype: %d", optype);
  81. }
  82. }
  83. /* Valid Data block */
  84. VD(d) dblock_p d; {
  85. byte pseudo;
  86. VA((short *) d);
  87. pseudo = d->d_pseudo;
  88. if (pseudo < D_FIRST || pseudo > D_LAST) {
  89. error("VD: illegal pseudo: %d",pseudo);
  90. }
  91. }
  92. /* Valid Object */
  93. VO(o) obj_p o; {
  94. offset off;
  95. VA((short *) o);
  96. off = o->o_off;
  97. if (off < 0 || off > 10000) {
  98. error("VO: unlikely offset: %d", off);
  99. }
  100. }
  101. /* Valid Proc */
  102. VP(p) proc_p p; {
  103. proc_id pid;
  104. int nrlabs;
  105. VA((short *) p);
  106. pid = p->p_id;
  107. if (pid <0 || pid > 1000) {
  108. error("VP: unlikely proc_id: %d", (int) pid);
  109. }
  110. nrlabs = p->p_nrlabels;
  111. if (nrlabs < 0 || nrlabs > 500) {
  112. error("VP: unlikely p_nrlabels: %d", nrlabs);
  113. }
  114. }
  115. #endif