Subversion Repositories tendra.SVN

Rev

Rev 2 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2 Rev 7
Line -... Line 1...
-
 
1
/*
-
 
2
 * Copyright (c) 2002-2006 The TenDRA Project <http://www.tendra.org/>.
-
 
3
 * All rights reserved.
-
 
4
 *
-
 
5
 * Redistribution and use in source and binary forms, with or without
-
 
6
 * modification, are permitted provided that the following conditions are met:
-
 
7
 *
-
 
8
 * 1. Redistributions of source code must retain the above copyright notice,
-
 
9
 *    this list of conditions and the following disclaimer.
-
 
10
 * 2. Redistributions in binary form must reproduce the above copyright notice,
-
 
11
 *    this list of conditions and the following disclaimer in the documentation
-
 
12
 *    and/or other materials provided with the distribution.
-
 
13
 * 3. Neither the name of The TenDRA Project nor the names of its contributors
-
 
14
 *    may be used to endorse or promote products derived from this software
-
 
15
 *    without specific, prior written permission.
-
 
16
 *
-
 
17
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS
-
 
18
 * IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
-
 
19
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-
 
20
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
-
 
21
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
-
 
22
 * EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
-
 
23
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
-
 
24
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-
 
25
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
-
 
26
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
-
 
27
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
 
28
 *
-
 
29
 * $Id$
-
 
30
 */
1
/*
31
/*
2
    		 Crown Copyright (c) 1996
32
    		 Crown Copyright (c) 1996
3
 
33
 
4
    This TenDRA(r) Computer Program is subject to Copyright
34
    This TenDRA(r) Computer Program is subject to Copyright
5
    owned by the United Kingdom Secretary of State for Defence
35
    owned by the United Kingdom Secretary of State for Defence
Line 48... Line 78...
48
 
78
 
49
 * Revision 1.1.1.1  1996/09/20  10:57:01  john
79
 * Revision 1.1.1.1  1996/09/20  10:57:01  john
50
 *
80
 *
51
 * Revision 1.2  1996/07/05  14:33:46  john
81
 * Revision 1.2  1996/07/05  14:33:46  john
52
 * Fix to diagnostics
82
 * Fix to diagnostics
53
 *
83
 *
54
 * Revision 1.1  95/03/08  16:46:19  ra
84
 * Revision 1.1  95/03/08  16:46:19  ra
55
 * Added missing files.
85
 * Added missing files.
56
 *
86
 *
57
 * Revision 1.1  93/02/22  17:17:20  17:17:20  ra (Robert Andrews)
87
 * Revision 1.1  93/02/22  17:17:20  17:17:20  ra (Robert Andrews)
58
 * Initial revision
88
 * Initial revision
Line 81... Line 111...
81
 
111
 
82
/*
112
/*
83
    DIAGNOSTICS INITIALIZATION ROUTINE
113
    DIAGNOSTICS INITIALIZATION ROUTINE
84
*/
114
*/
85
 
115
 
86
void diag_prologue
116
void
87
    PROTO_Z ()
117
diag_prologue(void)
88
{
118
{
89
    init_diag () ;
119
	init_diag();
90
    return ;
120
	return;
91
}
121
}
92
 
122
 
93
 
123
 
94
/*
124
/*
95
    DIAGNOSTICS TERMINATION ROUTINE
125
    DIAGNOSTICS TERMINATION ROUTINE
96
*/
126
*/
97
 
127
 
98
void diag_epilogue
128
void
99
    PROTO_Z ()
129
diag_epilogue(void)
100
{
130
{
101
    while ( dnt_end () ) /* empty */ ;
131
	while (dnt_end()) {
-
 
132
		; /* empty */
-
 
133
	}
102
    if ( diag_format == DIAG_STAB ) {
134
	if (diag_format == DIAG_STAB) {
103
	mach_op *op = make_extern_data ( "Letext", 0 ) ;
135
		mach_op *op = make_extern_data("Letext", 0);
104
	area ( ptext ) ;
136
		area(ptext);
105
	make_stabs ( "\"\"", 100, 0, op ) ;
137
		make_stabs("\"\"", 100, 0, op);
106
	make_external_label ( "Letext" ) ;
138
		make_external_label("Letext");
107
    }
139
	}
108
    output_all () ;
140
	output_all();
109
    copy_diag () ;
141
	copy_diag();
110
    return ;
142
	return;
111
}
143
}
112
 
144
 
113
 
145
 
114
/*
146
/*
115
    OUTPUT A DIAGNOSTICS SOURCE MARK
147
    OUTPUT A DIAGNOSTICS SOURCE MARK
116
*/
148
*/
117
 
149
 
118
static void diag_mark
150
static void
119
    PROTO_N ( ( sm ) )
-
 
120
    PROTO_T ( sourcemark *sm )
151
diag_mark(sourcemark *sm)
121
{
152
{
122
    char *nm = sm->file->file.ints.chars ;
153
	char *nm = sm->file->file.ints.chars;
123
    long ln = sm->line_no.nat_val.small_nat ;
154
	long ln = sm->line_no.nat_val.small_nat;
124
    diag_source ( nm, ln, 1 ) ;
155
	diag_source(nm, ln, 1);
125
    return ;
156
	return;
126
}
157
}
127
 
158
 
128
 
159
 
129
/*
160
/*
130
    DIAGNOSTICS FOR A LOCAL VARIABLE
161
    DIAGNOSTICS FOR A LOCAL VARIABLE
131
*/
162
*/
132
 
163
 
133
static void diag_variable
164
static void
134
    PROTO_N ( ( di, e ) )
-
 
135
    PROTO_T ( diag_info *di X exp e )
165
diag_variable(diag_info *di, exp e)
136
{
166
{
137
    exp s = di->data.id_scope.access ;
167
	exp s = di->data.id_scope.access;
138
    diag_type t = di->data.id_scope.typ ;
168
	diag_type t = di->data.id_scope.typ;
139
    char *nm = di->data.id_scope.nme.ints.chars ;
169
	char *nm = di->data.id_scope.nme.ints.chars;
140
    long p = ( no ( s ) + no ( son ( s ) ) ) / 8 ;
170
	long p = (no(s) + no(son(s))) / 8;
141
    if ( !isparam ( son ( s ) ) ) {
171
	if (!isparam(son(s))) {
142
	diag_local_variable ( t, nm, p ) ;
172
		diag_local_variable(t, nm, p);
143
    }
173
	}
144
    return ;
174
	return;
145
}
175
}
146
 
176
 
147
 
177
 
148
/*
178
/*
149
    START OF A DIAGNOSTICS ITEM
179
    START OF A DIAGNOSTICS ITEM
150
*/
180
*/
151
 
181
 
152
void diag_start
182
void
153
    PROTO_N ( ( di, e ) )
-
 
154
    PROTO_T ( diag_info *di X exp e )
183
diag_start(diag_info *di, exp e)
155
{
184
{
156
    switch ( di->key ) {
185
	switch (di->key) {
157
 
-
 
158
	case DIAG_INFO_SOURCE : {
186
	case DIAG_INFO_SOURCE: {
159
	    sourcemark *sm = &( di->data.source.beg ) ;
187
		sourcemark *sm = &(di->data.source.beg);
160
	    diag_mark ( sm ) ;
188
		diag_mark(sm);
161
	    break ;
-
 
162
	}
-
 
163
 
-
 
164
	case DIAG_INFO_ID : {
-
 
165
	    mark_scope ( e ) ;
-
 
166
	    if ( props ( e ) & 0x80 ) dnt_begin () ;
-
 
167
	    if ( diag_format != DIAG_XDB_NEW ) diag_variable ( di, e ) ;
-
 
168
	    break ;
189
		break;
169
	}
190
	}
-
 
191
	case DIAG_INFO_ID:
-
 
192
		mark_scope(e);
-
 
193
		if (props(e) & 0x80) {
-
 
194
			dnt_begin();
170
 
195
		}
-
 
196
		if (diag_format != DIAG_XDB_NEW) {
-
 
197
			diag_variable(di, e);
-
 
198
		}
-
 
199
		break;
171
	default : {
200
	default:
172
	    break ;
201
		break;
173
	}
202
	}
174
    }
-
 
175
    return ;
203
	return;
176
}
204
}
177
 
205
 
178
 
206
 
179
/*
207
/*
180
    END OF A DIAGNOSTICS ITEM
208
    END OF A DIAGNOSTICS ITEM
181
*/
209
*/
182
 
210
 
183
void diag_end
211
void
184
    PROTO_N ( ( di, e ) )
-
 
185
    PROTO_T ( diag_info *di X exp e )
212
diag_end(diag_info *di, exp e)
186
{
-
 
187
    if ( di->key == DIAG_INFO_ID ) {
-
 
188
	if ( diag_format == DIAG_XDB_NEW ) diag_variable ( di, e ) ;
-
 
189
	if ( props ( e ) & 0x80 ) dnt_end () ;
-
 
190
    }
-
 
191
    return ;
-
 
192
}
-
 
193
 
-
 
194
 
-
 
195
/*
-
 
196
    DIAGNOSTICS FOR THE START OF A PROCEDURE
-
 
197
*/
-
 
198
 
-
 
199
void xdb_diag_proc_begin
-
 
200
    PROTO_N ( ( di, p, pname, cname, is_ext ) )
-
 
201
    PROTO_T ( diag_global *di X exp p X char *pname X long cname X int is_ext )
-
 
202
{
-
 
203
    char *nm = di->data.id.nme.ints.chars ;
-
 
204
    diag_type t = di->data.id.new_type ;
-
 
205
    sourcemark *sm = &( di->data.id.whence ) ;
-
 
206
    diag_proc_main ( t, p, nm, !is_local ( pname ), pname ) ;
-
 
207
    diag_mark ( sm ) ;
-
 
208
    return ;
-
 
209
}
-
 
210
 
-
 
211
 
-
 
212
/*
-
 
213
    DIAGNOSTICS FOR THE RETURN STATEMENT OF A PROCEDURE
-
 
214
*/
-
 
215
 
-
 
216
void xdb_diag_proc_return
-
 
217
    PROTO_Z ()
-
 
218
{
213
{
-
 
214
	if (di->key == DIAG_INFO_ID) {
219
    if ( diag_format == DIAG_XDB_NEW ) slt_exit () ;
215
		if (diag_format == DIAG_XDB_NEW) {
-
 
216
			diag_variable(di, e);
-
 
217
		}
-
 
218
		if (props(e) & 0x80) {
-
 
219
			dnt_end();
-
 
220
		}
-
 
221
	}
220
    return ;
222
	return;
221
}
223
}
222
 
224
 
223
 
225
 
224
/*
226
/*
225
    DIAGNOSTICS FOR THE END OF A PROCEDURE
227
    DIAGNOSTICS FOR THE START OF A PROCEDURE
226
*/
228
*/
227
 
229
 
-
 
230
void
-
 
231
xdb_diag_proc_begin(diag_global *di, exp p, char *pname, long cname,
-
 
232
		    int is_ext)
-
 
233
{
-
 
234
	char *nm = di->data.id.nme.ints.chars;
-
 
235
	diag_type t = di->data.id.new_type;
-
 
236
	sourcemark *sm = & (di->data.id.whence);
-
 
237
	diag_proc_main(t, p, nm, !is_local(pname), pname);
-
 
238
	diag_mark(sm);
-
 
239
	return;
-
 
240
}
-
 
241
 
-
 
242
 
-
 
243
/*
-
 
244
    DIAGNOSTICS FOR THE RETURN STATEMENT OF A PROCEDURE
-
 
245
*/
-
 
246
 
-
 
247
void
228
void xdb_diag_proc_end
248
xdb_diag_proc_return(void)
-
 
249
{
-
 
250
	if (diag_format == DIAG_XDB_NEW) {
-
 
251
		slt_exit();
-
 
252
	}
-
 
253
	return;
-
 
254
}
-
 
255
 
-
 
256
 
-
 
257
/*
229
    PROTO_N ( ( di ) )
258
    DIAGNOSTICS FOR THE END OF A PROCEDURE
-
 
259
*/
-
 
260
 
-
 
261
void
230
    PROTO_T ( diag_global *di )
262
xdb_diag_proc_end(diag_global *di)
231
{
263
{
232
    area ( ptext ) ;
264
	area(ptext);
233
    if ( diag_format == DIAG_XDB_NEW ) {
265
	if (diag_format == DIAG_XDB_NEW) {
234
	mach_op *op1 = make_lab_data ( crt_diag_proc_lab, 0 ) ;
266
		mach_op *op1 = make_lab_data(crt_diag_proc_lab, 0);
235
	mach_op *op2 = make_extern_data ( ".-1", 0 ) ;
267
		mach_op *op2 = make_extern_data(".-1", 0);
236
	make_instr ( m_as_assign, op1, op2, 0 ) ;
268
		make_instr(m_as_assign, op1, op2, 0);
237
    } else if ( diag_format == DIAG_XDB_OLD ) {
269
	} else if (diag_format == DIAG_XDB_OLD) {
238
	make_label ( crt_diag_proc_lab ) ;
270
		make_label(crt_diag_proc_lab);
239
    }
271
	}
240
    dnt_end () ;
272
	dnt_end();
241
    area ( plast ) ;
273
	area(plast);
242
    return ;
274
	return;
243
}
275
}
244
 
276
 
245
 
277
 
246
/*
278
/*
247
    DIAGNOSTICS FOR THE START OF A VALUE
279
    DIAGNOSTICS FOR THE START OF A VALUE
248
*/
280
*/
249
 
281
 
250
void xdb_diag_val_begin
282
void
251
    PROTO_N ( ( di, pname, cname, is_ext ) )
-
 
252
    PROTO_T ( diag_global *di X char *pname X long cname X int is_ext )
283
xdb_diag_val_begin(diag_global *di, char *pname, long cname, int is_ext)
253
{
284
{
254
    char *nm = di->data.id.nme.ints.chars ;
285
	char *nm = di->data.id.nme.ints.chars;
255
    diag_type t = di->data.id.new_type ;
286
	diag_type t = di->data.id.new_type;
256
    diag_globl_variable ( t, nm, !is_local ( pname ), pname, 1 ) ;
287
	diag_globl_variable(t, nm, !is_local(pname), pname, 1);
257
    return ;
288
	return;
258
}
289
}
259
 
290
 
260
 
291
 
261
/*
292
/*
262
    OUTPUT GLOBAL TABLE
293
    OUTPUT GLOBAL TABLE
263
*/
294
*/
264
 
295
 
-
 
296
void
265
void OUTPUT_GLOBALS_TAB
297
OUTPUT_GLOBALS_TAB(void)
266
    PROTO_Z ()
-
 
267
{
298
{
268
    diag_descriptor *di = unit_diagvar_tab.array ;
299
	diag_descriptor *di = unit_diagvar_tab.array;
269
    unsigned long i, n = unit_diagvar_tab.lastused ;
300
	unsigned long i, n = unit_diagvar_tab.lastused;
270
    for ( i = 0 ; i < n ; i++ ) {
301
	for (i = 0; i < n; i++) {
271
	if ( di [i].key == DIAG_TYPEDEF_KEY ) {
302
		if (di[i].key == DIAG_TYPEDEF_KEY) {
272
	    diag_type d = di [i].data.typ.new_type ;
303
			diag_type d = di[i].data.typ.new_type;
273
	    char *nm = di [i].data.typ.nme.ints.chars ;
304
			char *nm = di[i].data.typ.nme.ints.chars;
274
	    diag_type_defn ( nm, d ) ;
305
			diag_type_defn(nm, d);
-
 
306
		}
275
	}
307
	}
276
    }
-
 
277
    return ;
308
	return;
278
}
309
}
279
 
310
 
280
 
311
 
281
/*
312
/*
282
    OUTPUT ALL DIAGNOSTIC TAGS
313
    OUTPUT ALL DIAGNOSTIC TAGS
283
*/
314
*/
284
 
315
 
-
 
316
void
285
void OUTPUT_DIAG_TAGS
317
OUTPUT_DIAG_TAGS(void)
286
    PROTO_Z ()
-
 
287
{
318
{
288
    return ;
319
	return;
289
}
320
}
290
 
321
 
291
 
322
 
292
/*
323
/*
293
    INSPECT FILENAME
324
    INSPECT FILENAME
294
*/
325
*/
295
 
326
 
296
void INSPECT_FILENAME
327
void
297
    PROTO_N ( ( fn ) )
-
 
298
    PROTO_T ( filename fn )
328
INSPECT_FILENAME(filename fn)
299
{
329
{
300
    char *nm = fn->file.ints.chars ;
330
	char *nm = fn->file.ints.chars;
301
    diag_source ( nm, 1, 0 ) ;
331
	diag_source(nm, 1, 0);
302
    return ;
332
	return;
303
}
333
}
304
 
334
 
305
 
335
 
306
/*
336
/*
307
    COMPARE TWO DECLARATIONS
337
    COMPARE TWO DECLARATIONS
308
*/
338
*/
309
 
339
 
310
static bool cmp_dec
340
static bool
311
    PROTO_N ( ( x, y ) )
-
 
312
    PROTO_T ( dec *x X dec *y )
341
cmp_dec(dec *x, dec *y)
313
{
342
{
314
    int c ;
343
	int c;
315
    long lx, ly ;
344
	long lx, ly;
316
    char *fx, *fy ;
345
	char *fx, *fy;
317
    sourcemark *sx, *sy ;
346
	sourcemark *sx, *sy;
318
    diag_global *dx = x->dec_u.dec_val.diag_info ;
347
	diag_global *dx = x->dec_u.dec_val.diag_info;
319
    diag_global *dy = y->dec_u.dec_val.diag_info ;
348
	diag_global *dy = y->dec_u.dec_val.diag_info;
320
    if ( dy == null || dy->key != DIAG_ID_KEY ) return ( 0 ) ;
349
	if (dy == null || dy->key != DIAG_ID_KEY) {
-
 
350
		return (0);
-
 
351
	}
321
    if ( dx == null || dx->key != DIAG_ID_KEY ) return ( 1 ) ;
352
	if (dx == null || dx->key != DIAG_ID_KEY) {
-
 
353
		return (1);
-
 
354
	}
322
    sx = &( dx->data.id.whence ) ;
355
	sx = & (dx->data.id.whence);
323
    fx = sx->file->file.ints.chars ;
356
	fx = sx->file->file.ints.chars;
324
    lx = sx->line_no.nat_val.small_nat ;
357
	lx = sx->line_no.nat_val.small_nat;
325
    sy = &( dy->data.id.whence ) ;
358
	sy = & (dy->data.id.whence);
326
    fy = sy->file->file.ints.chars ;
359
	fy = sy->file->file.ints.chars;
327
    ly = sy->line_no.nat_val.small_nat ;
360
	ly = sy->line_no.nat_val.small_nat;
328
    c = strcmp ( (char*)sx, (char*)sy ) ;
361
	c = strcmp((char *)sx, (char *)sy);
-
 
362
	if (c < 0) {
329
    if ( c < 0 ) return ( 0 ) ;
363
		return (0);
-
 
364
	}
-
 
365
	if (c > 0) {
330
    if ( c > 0 ) return ( 1 ) ;
366
		return (1);
-
 
367
	}
331
    return ( lx > ly ? 1 : 0 ) ;
368
	return (lx > ly ? 1 : 0);
332
}
369
}
333
 
370
 
334
 
371
 
335
/*
372
/*
336
    SORT DECLARATION INTO ORDER
373
    SORT DECLARATION INTO ORDER
337
*/
374
*/
338
 
375
 
339
dec *sort_decs
376
dec *
340
    PROTO_N ( ( p ) )
-
 
341
    PROTO_T ( dec *p )
377
sort_decs(dec *p)
342
{
378
{
343
    dec *res = null ;
379
	dec *res = null;
344
    dec *x = p, *y ;
380
	dec *x = p, *y;
345
    while ( x != null ) {
381
	while (x != null) {
346
	dec *nextx = x->def_next ;
382
		dec *nextx = x->def_next;
347
	dec *before = null ;
383
		dec *before = null;
348
	for ( y = res ; y != null ; y = y->def_next ) {
384
		for (y = res; y != null; y = y->def_next) {
349
	    if ( !cmp_dec ( x, y ) ) break ;
385
			if (!cmp_dec(x, y)) {
-
 
386
				break;
-
 
387
			}
350
	    before = y ;
388
			before = y;
351
	}
389
		}
352
	if ( before == null ) {
390
		if (before == null) {
353
	    x->def_next = res ;
391
			x->def_next = res;
354
	    res = x ;
392
			res = x;
355
	} else {
393
		} else {
356
	    x->def_next = before->def_next ;
394
			x->def_next = before->def_next;
357
	    before->def_next = x ;
395
			before->def_next = x;
-
 
396
		}
-
 
397
		x = nextx;
358
	}
398
	}
359
	x = nextx ;
-
 
360
    }
-
 
361
    return ( res ) ;
399
	return (res);
362
}
400
}