Subversion Repositories tendra.SVN

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

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