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) 1997
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
 
31
/* sco/cv_fns.c */
32
 
33
/**********************************************************************
34
$Author: release $
35
$Date: 1998/01/17 15:55:51 $
36
$Revision: 1.1.1.1 $
37
$Log: cv_fns.c,v $
38
 * Revision 1.1.1.1  1998/01/17  15:55:51  release
39
 * First version to be checked into rolling release.
40
 *
41
 * Revision 1.8  1997/04/04  15:15:14  pwe
42
 * attempt revert sco no diagnose registers
43
 *
44
 * Revision 1.7  1997/04/02  10:33:30  pwe
45
 * diagnose pl_tests
46
 *
47
 * Revision 1.6  1997/03/24  12:43:38  pwe
48
 * outn int->long
49
 *
50
 * Revision 1.5  1995/11/30  10:19:51  pwe
51
 * diag struct struct
52
 *
53
 * Revision 1.4  1995/10/30  16:59:16  pwe
54
 * sco diag line numbers must be >= 1
55
 *
56
 * Revision 1.3  1995/03/20  09:23:47  pwe
57
 * move codeview into sco directory
58
 *
59
 * Revision 1.2  1995/01/30  12:57:04  pwe
60
 * Ownership -> PWE, tidy banners
61
 *
62
 * Revision 1.1  1994/07/13  08:32:20  jmf
63
 * Initial revision
64
 *
65
**********************************************************************/
66
 
67
#include "config.h"
68
#include "common_types.h"
69
#include "basicread.h"
70
#include "out.h"
71
#include "machine.h"
72
#include "cv_types.h"
73
#include "cv_outtype.h"
74
#include "expmacs.h"
75
#include "tags.h"
76
#include "diag_fns.h"
77
#include "diagglob.h"
78
#include "mark_scope.h"
79
 
80
 
81
/* VARIABLES */
82
/* All variables initialised */
83
 
84
static int crt_proc_start;
85
static int last_line_no;
86
static char * main_filename;	/* init by diagnose_prelude */
87
static int filename_space = 0;	/* init by diagnose_prelude */
88
static long filename_pos;
89
static int filename_gate = 0;	/* init by diagnose_prelude */
90
 
91
/* PROCEDURES */
92
 
93
static int check_filename
94
    PROTO_N ( (sm) )
95
    PROTO_T ( sourcemark sm )
96
{
97
  if (main_filename)
98
    {
99
      if (!strcmp(main_filename, sm.file->file.ints.chars))
100
        return 1;
101
      return 0;
102
    }
103
  else
104
    {
105
      main_filename = sm.file->file.ints.chars;
106
      return 1;
107
    };
108
}
109
 
110
void out_diagnose_prelude
111
    PROTO_Z ()
112
{
113
  main_filename = (char*)0;
114
  filename_space = 0;
115
  filename_gate = 0;
116
  return;
117
}
118
 
119
void out_diagnose_postlude
120
    PROTO_Z ()
121
{
122
  return;
123
}
124
 
125
 
126
#ifdef NEWDIAGS
127
 
128
void code_diag_info
129
    PROTO_N ( (d, proc_no, mcode, args) )
130
    PROTO_T ( diag_info * d X int proc_no X void (*mcode)(void *) X void * args )
131
{
132
  if (d == nildiag) {
133
    (*mcode)(args);
134
    return;
135
  }
136
  switch (d->key) {
137
    case DIAG_INFO_SCOPE: {
138
	fprintf(fpout, " .def .bb; .val .; .scl 100;  .line %d; .endef\n",
139
           last_line_no);
140
	code_diag_info (d->more, proc_no, mcode, args);
141
	fprintf(fpout, " .def .eb; .val .; .scl 100; .line %d; .endef\n",
142
             last_line_no);
143
	return;
144
    }
145
    case DIAG_INFO_SOURCE: {
146
	int l = (int)d -> data.source.beg.line_no.nat_val.small_nat -
147
                       crt_proc_start + 1;
148
	if (check_filename(d -> data.source.beg) && l != last_line_no) {
149
	  last_line_no = l;
150
	  if (l > 0)
151
	    fprintf(fpout, " .ln %d\n", l);
152
	}
153
	code_diag_info (d->more, proc_no, mcode, args);
154
	return;
155
    }
156
    case DIAG_INFO_ID: {
157
	exp acc = d -> data.id_scope.access;
158
	ot ty;
159
	int p, param_dec;
160
	if (name(acc) != hold_tag && name(acc) != hold2_tag)
161
	  failer("not hold_tag");
162
	acc = son(acc);
163
	if (name(acc) == cont_tag && name(son(acc)) == name_tag && isvar(son(son(acc))))
164
	  acc = son(acc);
165
	if ( name(acc) == name_tag && !isdiscarded(acc) && !isglob(son(acc)) ) {
166
	  p = (no(acc) + no(son(acc))) / 8;
167
	  param_dec = isparam(son(acc));
168
	  fprintf(fpout, " .def %s; .val ", d -> data.id_scope.nme.ints.chars);
169
	  if (param_dec)
170
	    fprintf(fpout, "%d", p+8);
171
	  else
172
	    fprintf(fpout, "%d-.Ldisp%d", p, proc_no);
173
	  fprintf(fpout, "; .scl %d; ", (param_dec) ? 9 : 1);
174
	  ty = out_type(d -> data.id_scope.typ, 0);
175
	  fprintf(fpout, ".type 0%o; .endef\n", ty.type + (ty.modifier<<4));
176
	}
177
	code_diag_info (d->more, proc_no, mcode, args);
178
    }
179
  };
180
  return;
181
}
182
 
183
#else
184
 
185
void output_diag
186
    PROTO_N ( (d, proc_no, e) )
187
    PROTO_T ( diag_info * d X int proc_no X exp e )
188
{
189
  if (d -> key == DIAG_INFO_SOURCE)
190
   {
191
     int l = (int)d -> data.source.beg.line_no.nat_val.small_nat -
192
                       crt_proc_start + 1;
193
     if (!check_filename(d -> data.source.beg))
194
       return;
195
 
196
     if (l == last_line_no)
197
       return;
198
     last_line_no = l;
199
     if (l > 0)
200
       fprintf(fpout, " .ln %d\n", l);
201
     return;
202
   };
203
  if (d -> key == DIAG_INFO_ID)
204
   {
205
     ot ty;
206
     exp acc = d -> data.id_scope.access;
207
     int p = (no(acc) + no(son(acc))) / 8;
208
     int param_dec = isparam(son(acc));
209
 
210
     mark_scope(e);
211
 
212
     if (props(e) & 0x80)
213
      {
214
       fprintf(fpout, " .def .bb; .val .; .scl 100;  .line %d; .endef\n",
215
           last_line_no);
216
      };
217
 
218
     fprintf(fpout, " .def %s; .val ", d -> data.id_scope.nme.ints.chars);
219
     if (param_dec)
220
       fprintf(fpout, "%d", p+8);
221
     else
222
       fprintf(fpout, "%d-.Ldisp%d", p, proc_no);
223
     fprintf(fpout, "; .scl %d; ", (param_dec) ? 9 : 1);
224
     ty = out_type(d -> data.id_scope.typ, 0);
225
     fprintf(fpout, ".type 0%o; .endef\n", ty.type + (ty.modifier<<4));
226
 
227
     return;
228
   };
229
 
230
  return;
231
}
232
#endif
233
 
234
void output_end_scope
235
    PROTO_N ( (d, e) )
236
    PROTO_T ( diag_info * d X exp e )
237
{
238
  if (d -> key == DIAG_INFO_ID && props(e) & 0x80)
239
    fprintf(fpout, " .def .eb; .val .; .scl 100; .line %d; .endef\n",
240
             last_line_no);
241
  return;
242
}
243
 
244
void diag_val_begin
245
    PROTO_N ( (d, global, cname, pname) )
246
    PROTO_T ( diag_global * d X int global X int cname X char * pname )
247
{
248
  ot typ;
249
 
250
  outs(" .def ");
251
  outs(d -> data.id.nme.ints.chars);
252
  outs("; .val ");
253
  if (cname == -1) {
254
    outs (pname);
255
  }
256
  else {
257
    outs(local_prefix);
258
    outn ((long)cname);
259
  };
260
  outs("; .scl ");
261
  outn((long)(global ? 2 : 3));
262
  outs("; ");
263
  typ = out_type(d -> data.id.new_type, 0);
264
  fprintf(fpout, ".type 0%o; .endef\n", typ.type + (typ.modifier << 4));
265
  return;
266
}
267
 
268
void diag_val_end
269
    PROTO_N ( (d) )
270
    PROTO_T ( diag_global * d )
271
{
272
  UNUSED(d);
273
  return;
274
}
275
 
276
void diag_proc_begin
277
    PROTO_N ( (d, global, cname, pname) )
278
    PROTO_T ( diag_global * d X int global X int cname X char * pname )
279
{
280
  ot typ;
281
  UNUSED(cname);
282
 
283
  if (!d)
284
    return;
285
 
286
  check_filename(d -> data.id.whence);
287
 
288
  outs(" .def ");
289
  outs(d -> data.id.nme.ints.chars);
290
  outs("; .val ");
291
  outs(pname);
292
  outs("; .scl ");
293
  outn((long)(global ? 2 : 3));
294
  outs("; ");
295
  typ = out_type(d -> data.id.new_type->data.proc.result_type, 0);
296
  fprintf(fpout, ".type 0%o; .endef\n",
297
           typ.type + (typ.modifier << 6) + 32);
298
 
299
  crt_proc_start = d -> data.id.whence.line_no.nat_val.small_nat;
300
  last_line_no = 1;
301
  fprintf(fpout, " .def .bf; .val .; .scl 101; .line %d; .endef\n",
302
            crt_proc_start);
303
  fprintf(fpout, " .ln 1\n");
304
  return;
305
}
306
 
307
void diag_proc_end
308
    PROTO_N ( (d) )
309
    PROTO_T ( diag_global * d )
310
{
311
  if (!d)
312
    return;
313
  fprintf(fpout, " .def .ef; .val .; .scl 101; .line %d; .endef\n",
314
            last_line_no + 1);
315
  fprintf(fpout, " .def %s; .val .; .scl -1; .endef\n",
316
            d -> data.id.nme.ints.chars);
317
  return;
318
}
319
 
320
 
321
void OUTPUT_GLOBALS_TAB
322
    PROTO_Z ()
323
{
324
  diag_descriptor *di = unit_diagvar_tab.array;
325
  int n = unit_diagvar_tab.lastused;
326
  int i;
327
  ot typ;
328
 
329
  for (i=0; i<n; i++)
330
   {
331
     if ( di[i].key == DIAG_TYPEDEF_KEY )
332
      {
333
	fprintf (fpout, " .def %s; .scl 13; ", di[i].data.typ.nme.ints.chars);
334
	typ = out_type (di[i].data.typ.new_type, 0);
335
	fprintf(fpout, ".type 0%o; .endef\n", typ.type + (typ.modifier << 4));
336
      };
337
   };
338
  return;
339
}
340
 
341
void OUTPUT_DIAG_TAGS
342
    PROTO_Z ()
343
{
344
  diag_tagdef ** di = unit_ind_diagtags;
345
  int n = unit_no_of_diagtags;
346
  int i;
347
 
348
  if (!filename_space)
349
   {
350
     filename_pos = ftell(fpout);
351
     outs ("                                                                                                                      ");
352
     outnl ();
353
     filename_space = 1;
354
   };
355
 
356
  for (i=0; i<n; ++i)
357
   {
358
     diag_type d = di[i]->d_type;
359
     switch (d -> key)
360
      {
361
        case DIAG_TYPE_STRUCT:
362
        case DIAG_TYPE_UNION:
363
        case DIAG_TYPE_ENUM:
364
            out_tagged(d);
365
            break;
366
        default: break;
367
      };
368
   };
369
  return;
370
}
371
 
372
void INSPECT_FILENAME
373
    PROTO_N ( (fn) )
374
    PROTO_T ( filename fn )
375
{
376
  long here;
377
  char * nm = fn -> file.ints.chars;
378
  char * f;
379
  int len = (int)strlen(fn -> file.ints.chars);
380
 
381
  if (filename_gate || len < 4 || len > 120 || nm[len-1] == 'h' ||
382
           nm[len-2] != '.')
383
    return;
384
 
385
  f = &nm[len-2];
386
 
387
  while (f != nm && f[-1] != '/')
388
    --f;
389
 
390
  filename_gate = 1;
391
 
392
  if (!filename_space)
393
    fprintf(fpout, " .file \"%s\"\n", f);
394
  else
395
   {
396
      here = ftell(fpout);
397
      fseek (fpout, filename_pos, 0);
398
      fprintf(fpout, " .file \"%s\"\n", f);
399
      fseek(fpout, here, 0);
400
   };
401
  return;
402
}
403