Subversion Repositories tendra.SVN

Rev

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

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