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