Subversion Repositories tendra.SVN

Rev

Rev 2 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 7u83 1
/*
7 7u83 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
 */
31
/*
2 7u83 32
    		 Crown Copyright (c) 1996
33
 
34
    This TenDRA(r) Computer Program is subject to Copyright
35
    owned by the United Kingdom Secretary of State for Defence
36
    acting through the Defence Evaluation and Research Agency
37
    (DERA).  It is made available to Recipients with a
38
    royalty-free licence for its use, reproduction, transfer
39
    to other parties and amendment for any purpose not excluding
40
    product development provided that any such use et cetera
41
    shall be deemed to be acceptance of the following conditions:-
42
 
43
        (1) Its Recipients shall ensure that this Notice is
44
        reproduced upon any copies or amended versions of it;
45
 
46
        (2) Any amended version of it shall be clearly marked to
47
        show both the nature of and the organisation responsible
48
        for the relevant amendment or amendments;
49
 
50
        (3) Its onward transfer from a recipient to another
51
        party shall be deemed to be that party's acceptance of
52
        these conditions;
53
 
54
        (4) DERA gives no warranty or assurance as to its
55
        quality or suitability for any purpose and DERA accepts
56
        no liability whatsoever in relation to any use to which
57
        it may be put.
58
*/
59
/*
60
			    VERSION INFORMATION
61
			    ===================
62
 
63
--------------------------------------------------------------------------
64
$Header: /u/g/release/CVSROOT/Source/src/installers/680x0/common/xdb_basics.c,v 1.1.1.1 1998/01/17 15:55:50 release Exp $
65
--------------------------------------------------------------------------
66
$Log: xdb_basics.c,v $
67
 * Revision 1.1.1.1  1998/01/17  15:55:50  release
68
 * First version to be checked into rolling release.
69
 *
70
Revision 1.1.1.1  1997/10/13 12:43:02  ma
71
First version.
72
 
73
Revision 1.2  1997/03/20 12:53:13  ma
74
Removed warning.
75
 
76
Revision 1.1.1.1  1997/03/14 07:50:22  ma
77
Imported from DRA
78
 
79
 * Revision 1.1.1.1  1996/09/20  10:57:01  john
80
 *
81
 * Revision 1.2  1996/07/05  14:33:46  john
82
 * Fix to diagnostics
83
 *
84
 * Revision 1.1  95/03/08  16:46:19  ra
85
 * Added missing files.
86
 *
87
 * Revision 1.1  93/02/22  17:17:20  17:17:20  ra (Robert Andrews)
88
 * Initial revision
89
 *
90
--------------------------------------------------------------------------
91
*/
92
 
93
 
94
#include "config.h"
95
#include "common_types.h"
96
#include "codex.h"
97
#include "diag_fns.h"
98
#include "diagglob.h"
99
#include "expmacs.h"
100
#include "instrs.h"
101
#include "mach.h"
102
#include "mach_ins.h"
103
#include "mach_op.h"
104
#include "mark_scope.h"
105
#include "output.h"
106
#include "xdb_types.h"
107
#include "xdb_basics.h"
108
#include "xdb_output.h"
109
#include "stab_types.h"
110
 
111
 
112
/*
113
    DIAGNOSTICS INITIALIZATION ROUTINE
114
*/
115
 
7 7u83 116
void
117
diag_prologue(void)
2 7u83 118
{
7 7u83 119
	init_diag();
120
	return;
2 7u83 121
}
122
 
123
 
124
/*
125
    DIAGNOSTICS TERMINATION ROUTINE
126
*/
127
 
7 7u83 128
void
129
diag_epilogue(void)
2 7u83 130
{
7 7u83 131
	while (dnt_end()) {
132
		; /* empty */
133
	}
134
	if (diag_format == DIAG_STAB) {
135
		mach_op *op = make_extern_data("Letext", 0);
136
		area(ptext);
137
		make_stabs("\"\"", 100, 0, op);
138
		make_external_label("Letext");
139
	}
140
	output_all();
141
	copy_diag();
142
	return;
2 7u83 143
}
144
 
145
 
146
/*
147
    OUTPUT A DIAGNOSTICS SOURCE MARK
148
*/
149
 
7 7u83 150
static void
151
diag_mark(sourcemark *sm)
2 7u83 152
{
7 7u83 153
	char *nm = sm->file->file.ints.chars;
154
	long ln = sm->line_no.nat_val.small_nat;
155
	diag_source(nm, ln, 1);
156
	return;
2 7u83 157
}
158
 
159
 
160
/*
161
    DIAGNOSTICS FOR A LOCAL VARIABLE
162
*/
163
 
7 7u83 164
static void
165
diag_variable(diag_info *di, exp e)
2 7u83 166
{
7 7u83 167
	exp s = di->data.id_scope.access;
168
	diag_type t = di->data.id_scope.typ;
169
	char *nm = di->data.id_scope.nme.ints.chars;
170
	long p = (no(s) + no(son(s))) / 8;
171
	if (!isparam(son(s))) {
172
		diag_local_variable(t, nm, p);
173
	}
174
	return;
2 7u83 175
}
176
 
177
 
178
/*
179
    START OF A DIAGNOSTICS ITEM
180
*/
181
 
7 7u83 182
void
183
diag_start(diag_info *di, exp e)
2 7u83 184
{
7 7u83 185
	switch (di->key) {
186
	case DIAG_INFO_SOURCE: {
187
		sourcemark *sm = &(di->data.source.beg);
188
		diag_mark(sm);
189
		break;
2 7u83 190
	}
7 7u83 191
	case DIAG_INFO_ID:
192
		mark_scope(e);
193
		if (props(e) & 0x80) {
194
			dnt_begin();
195
		}
196
		if (diag_format != DIAG_XDB_NEW) {
197
			diag_variable(di, e);
198
		}
199
		break;
200
	default:
201
		break;
2 7u83 202
	}
7 7u83 203
	return;
2 7u83 204
}
205
 
206
 
207
/*
208
    END OF A DIAGNOSTICS ITEM
209
*/
210
 
7 7u83 211
void
212
diag_end(diag_info *di, exp e)
2 7u83 213
{
7 7u83 214
	if (di->key == DIAG_INFO_ID) {
215
		if (diag_format == DIAG_XDB_NEW) {
216
			diag_variable(di, e);
217
		}
218
		if (props(e) & 0x80) {
219
			dnt_end();
220
		}
221
	}
222
	return;
2 7u83 223
}
224
 
225
 
226
/*
227
    DIAGNOSTICS FOR THE START OF A PROCEDURE
228
*/
229
 
7 7u83 230
void
231
xdb_diag_proc_begin(diag_global *di, exp p, char *pname, long cname,
232
		    int is_ext)
2 7u83 233
{
7 7u83 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;
2 7u83 240
}
241
 
242
 
243
/*
244
    DIAGNOSTICS FOR THE RETURN STATEMENT OF A PROCEDURE
245
*/
246
 
7 7u83 247
void
248
xdb_diag_proc_return(void)
2 7u83 249
{
7 7u83 250
	if (diag_format == DIAG_XDB_NEW) {
251
		slt_exit();
252
	}
253
	return;
2 7u83 254
}
255
 
256
 
257
/*
258
    DIAGNOSTICS FOR THE END OF A PROCEDURE
259
*/
260
 
7 7u83 261
void
262
xdb_diag_proc_end(diag_global *di)
2 7u83 263
{
7 7u83 264
	area(ptext);
265
	if (diag_format == DIAG_XDB_NEW) {
266
		mach_op *op1 = make_lab_data(crt_diag_proc_lab, 0);
267
		mach_op *op2 = make_extern_data(".-1", 0);
268
		make_instr(m_as_assign, op1, op2, 0);
269
	} else if (diag_format == DIAG_XDB_OLD) {
270
		make_label(crt_diag_proc_lab);
271
	}
272
	dnt_end();
273
	area(plast);
274
	return;
2 7u83 275
}
276
 
277
 
278
/*
279
    DIAGNOSTICS FOR THE START OF A VALUE
280
*/
281
 
7 7u83 282
void
283
xdb_diag_val_begin(diag_global *di, char *pname, long cname, int is_ext)
2 7u83 284
{
7 7u83 285
	char *nm = di->data.id.nme.ints.chars;
286
	diag_type t = di->data.id.new_type;
287
	diag_globl_variable(t, nm, !is_local(pname), pname, 1);
288
	return;
2 7u83 289
}
290
 
291
 
292
/*
293
    OUTPUT GLOBAL TABLE
294
*/
295
 
7 7u83 296
void
297
OUTPUT_GLOBALS_TAB(void)
2 7u83 298
{
7 7u83 299
	diag_descriptor *di = unit_diagvar_tab.array;
300
	unsigned long i, n = unit_diagvar_tab.lastused;
301
	for (i = 0; i < n; i++) {
302
		if (di[i].key == DIAG_TYPEDEF_KEY) {
303
			diag_type d = di[i].data.typ.new_type;
304
			char *nm = di[i].data.typ.nme.ints.chars;
305
			diag_type_defn(nm, d);
306
		}
2 7u83 307
	}
7 7u83 308
	return;
2 7u83 309
}
310
 
311
 
312
/*
313
    OUTPUT ALL DIAGNOSTIC TAGS
314
*/
315
 
7 7u83 316
void
317
OUTPUT_DIAG_TAGS(void)
2 7u83 318
{
7 7u83 319
	return;
2 7u83 320
}
321
 
322
 
323
/*
324
    INSPECT FILENAME
325
*/
326
 
7 7u83 327
void
328
INSPECT_FILENAME(filename fn)
2 7u83 329
{
7 7u83 330
	char *nm = fn->file.ints.chars;
331
	diag_source(nm, 1, 0);
332
	return;
2 7u83 333
}
334
 
335
 
336
/*
337
    COMPARE TWO DECLARATIONS
338
*/
339
 
7 7u83 340
static bool
341
cmp_dec(dec *x, dec *y)
2 7u83 342
{
7 7u83 343
	int c;
344
	long lx, ly;
345
	char *fx, *fy;
346
	sourcemark *sx, *sy;
347
	diag_global *dx = x->dec_u.dec_val.diag_info;
348
	diag_global *dy = y->dec_u.dec_val.diag_info;
349
	if (dy == null || dy->key != DIAG_ID_KEY) {
350
		return (0);
351
	}
352
	if (dx == null || dx->key != DIAG_ID_KEY) {
353
		return (1);
354
	}
355
	sx = & (dx->data.id.whence);
356
	fx = sx->file->file.ints.chars;
357
	lx = sx->line_no.nat_val.small_nat;
358
	sy = & (dy->data.id.whence);
359
	fy = sy->file->file.ints.chars;
360
	ly = sy->line_no.nat_val.small_nat;
361
	c = strcmp((char *)sx, (char *)sy);
362
	if (c < 0) {
363
		return (0);
364
	}
365
	if (c > 0) {
366
		return (1);
367
	}
368
	return (lx > ly ? 1 : 0);
2 7u83 369
}
370
 
371
 
372
/*
373
    SORT DECLARATION INTO ORDER
374
*/
375
 
7 7u83 376
dec *
377
sort_decs(dec *p)
2 7u83 378
{
7 7u83 379
	dec *res = null;
380
	dec *x = p, *y;
381
	while (x != null) {
382
		dec *nextx = x->def_next;
383
		dec *before = null;
384
		for (y = res; y != null; y = y->def_next) {
385
			if (!cmp_dec(x, y)) {
386
				break;
387
			}
388
			before = y;
389
		}
390
		if (before == null) {
391
			x->def_next = res;
392
			res = x;
393
		} else {
394
			x->def_next = before->def_next;
395
			before->def_next = x;
396
		}
397
		x = nextx;
2 7u83 398
	}
7 7u83 399
	return (res);
2 7u83 400
}