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
/**********************************************************************
32
$Author: pwe $
33
$Date: 1998/03/11 11:03:32 $
34
$Revision: 1.2 $
35
$Log: diag_fns.c,v $
36
 * Revision 1.2  1998/03/11  11:03:32  pwe
37
 * DWARF optimisation info
38
 *
39
 * Revision 1.1.1.1  1998/01/17  15:55:46  release
40
 * First version to be checked into rolling release.
41
 *
42
 * Revision 1.9  1998/01/11  18:45:03  pwe
43
 * consistent new/old diags
44
 *
45
 * Revision 1.8  1998/01/09  09:29:55  pwe
46
 * prep restructure
47
 *
48
 * Revision 1.7  1997/12/04  19:36:38  pwe
49
 * ANDF-DE V1.9
50
 *
51
 * Revision 1.6  1997/11/06  09:17:49  pwe
52
 * ANDF-DE V1.8
53
 *
54
 * Revision 1.5  1997/10/23  09:21:15  pwe
55
 * ANDF-DE V1.7 and extra diags
56
 *
57
 * Revision 1.4  1997/10/10  18:16:46  pwe
58
 * prep ANDF-DE revision
59
 *
60
 * Revision 1.3  1997/08/23  13:26:59  pwe
61
 * initial ANDF-DE
62
 *
63
 * Revision 1.2  1997/02/18  12:55:50  currie
64
 * NEW DIAG STRUCTURE
65
 *
66
 * Revision 1.1  1995/04/06  10:42:55  currie
67
 * Initial revision
68
 *
69
***********************************************************************/
70
 
71
 
72
 
73
 
74
#include "config.h"
75
#include "common_types.h"
76
#include "readglob.h"
77
#include "table_fns.h"
78
#include "basicread.h"
79
#include "sortmacs.h"
80
#include "shapemacs.h"
81
#include "expmacs.h"
82
#include "tags.h"
83
#include "main_reads.h"
84
#include "natmacs.h"
85
#include "install_fns.h"
86
#include "diag_fns.h"
87
#include "xalloc.h"
88
 
89
 
90
#ifdef NEWDIAGS
91
 
92
 
93
/* allocate space in this file */
94
#define EXTERN_DIAG
95
 
96
#include "diagglob.h"
97
#include "dg_globs.h"
98
#include "dg_aux.h"
99
#include "externs.h"
100
 
101
 
102
diag_descriptor f_dummy_diag_descriptor;
103
diag_tag f_dummy_diag_tag;
104
diag_tagdef f_dummy_diag_tagdef;
105
diag_type f_dummy_diag_type;
106
diag_tq f_dummy_diag_tq;
107
filename f_dummy_filename;
108
sourcemark f_dummy_sourcemark;
109
 
110
 
111
#define DEBUG(x) x
112
 
113
 
114
static dg_filename primary_file = (dg_filename)0;
115
 
116
static nat zero_nat;
117
 
118
 
119
static dg_tag
120
	dg_tag_void_star,
121
	dg_tag_signed_char, dg_tag_unsigned_char,
122
	dg_tag_short, dg_tag_unsigned_short,
123
	dg_tag_int, dg_tag_unsigned_int,
124
	dg_tag_long_long, dg_tag_unsigned_long_long,
125
	dg_tag_float, dg_tag_double, dg_tag_long_double,
126
	dg_tag_complex, dg_tag_double_complex, dg_tag_long_double_complex;
127
 
128
 
129
extern shape shcomplexsh;
130
extern shape complexsh;
131
extern shape complexdoublesh;
132
 
133
static dg_tag make_bastype
134
    PROTO_N ( (s) )
135
    PROTO_T ( char * s )
136
{
137
  dg_tag ans = (dgtag_struct *) xmalloc (sizeof(dgtag_struct));
138
  init_dgtag (ans);
139
  ans->outref.k = LAB_STR;
140
  ans->outref.u.s = s;
141
  return ans;
142
}
143
 
144
static int tags_initialised = 0;
145
 
146
static void init_basic_diag_tags
147
    PROTO_Z ()
148
{
149
  dg_tag_void_star		= make_bastype ("__D_void_star");
150
  dg_tag_signed_char		= make_bastype ("__D_signed_char");
151
  dg_tag_unsigned_char		= make_bastype ("__D_unsigned_char");
152
  dg_tag_short			= make_bastype ("__D_short");
153
  dg_tag_unsigned_short		= make_bastype ("__D_unsigned_short");
154
  dg_tag_int			= make_bastype ("__D_int");
155
  dg_tag_unsigned_int		= make_bastype ("__D_unsigned_int");
156
  dg_tag_long_long		= make_bastype ("__D_long_long");
157
  dg_tag_unsigned_long_long	= make_bastype ("__D_unsigned_long_long");
158
  dg_tag_float			= make_bastype ("__D_float");
159
  dg_tag_double			= make_bastype ("__D_double");
160
  dg_tag_long_double		= make_bastype ("__D_long_double");
161
  dg_tag_complex		= make_bastype ("__D_complex");
162
  dg_tag_double_complex		= make_bastype ("__D_double_complex");
163
  dg_tag_long_double_complex	= make_bastype ("__D_long double_complex");
164
  tags_initialised = 1;
165
}
166
 
167
static shape basic_tag_shape
168
    PROTO_N ( (t) )
169
    PROTO_T ( dg_tag t )
170
{
171
  if (t == dg_tag_void_star)
172
    return f_pointer (f_alignment (scharsh));
173
  if (t == dg_tag_signed_char)
174
    return scharsh;
175
  if (t == dg_tag_unsigned_char)
176
    return ucharsh;
177
  if (t == dg_tag_short)
178
    return swordsh;
179
  if (t == dg_tag_unsigned_short)
180
    return uwordsh;
181
  if (t == dg_tag_int)
182
    return slongsh;
183
  if (t == dg_tag_unsigned_int)
184
    return ulongsh;
185
  if (t == dg_tag_long_long)
186
    return s64sh;
187
  if (t == dg_tag_unsigned_long_long)
188
    return u64sh;
189
  if (t == dg_tag_float)
190
    return shrealsh;
191
  if (t == dg_tag_double)
192
    return realsh;
193
  if (t == dg_tag_long_double)
194
    return doublesh;
195
  if (t == dg_tag_complex)
196
    return shcomplexsh;
197
  if (t == dg_tag_double_complex)
198
    return complexsh;
199
  if (t == dg_tag_long_double_complex)
200
    return complexdoublesh;
201
  failer ("unexpected bitfield type");
202
  return slongsh;
203
}
204
 
205
 
206
 
207
 
208
 
209
/*----------------------- diagdef and diag_descriptor  lists ----------------*/
210
 
211
void start_make_diagdef_unit
212
    PROTO_N ( (toks, tags, als, diagtags) )
213
    PROTO_T ( int toks X int tags X int als X int diagtags )
214
{
215
  int i;
216
 
217
  if (!tags_initialised)
218
    init_basic_diag_tags ();
219
 
220
  unit_no_of_tokens = toks;
221
  unit_ind_tokens = (tok_define * *)xcalloc(unit_no_of_tokens,
222
                    sizeof(tok_define *));
223
  for (i = 0; i < unit_no_of_tokens; ++i)
224
    unit_ind_tokens[i] = (tok_define*)0;
225
 
226
  unit_no_of_tags = tags;
227
  unit_ind_tags = (dec * *)xcalloc(unit_no_of_tags,
228
                    sizeof(dec *));
229
  for (i = 0; i < unit_no_of_tags; ++i)
230
    unit_ind_tags[i] = (dec*)0;
231
 
232
  unit_no_of_als = als;
233
  unit_ind_als = (aldef * *)xcalloc(unit_no_of_als,
234
                    sizeof(aldef *));
235
  for (i = 0; i < unit_no_of_als; ++i)
236
    unit_ind_als[i] = (aldef*)0;
237
 
238
  unit_no_of_diagtags = diagtags;
239
  unit_ind_diagtags = (diag_tagdef * *)xcalloc(unit_no_of_diagtags,
240
                    sizeof(diag_tagdef *));
241
  for (i = 0; i < unit_no_of_diagtags; ++i)
242
    unit_ind_diagtags[i] = (diag_tagdef *)0;
243
 
244
  return;
245
}
246
 
247
void init_diag_unit
248
    PROTO_Z ()
249
{
250
  return;
251
}
252
 
253
diag_unit f_build_diag_unit
254
    PROTO_N ( (labels, descriptors) )
255
    PROTO_T ( tdfint labels X diag_descriptor_list descriptors )
256
{
257
  UNUSED(labels); UNUSED(descriptors);
258
  failer("f_build_diag_unit isn't really here");
259
  exit(EXIT_FAILURE);
260
}
261
 
262
diag_type_unit f_build_diagtype_unit
263
    PROTO_N ( (labels, descriptors) )
264
    PROTO_T ( tdfint labels X diag_tagdef_list descriptors )
265
{
266
  UNUSED(labels); UNUSED(descriptors);
267
  failer("f_build_diagtype_unit isn't really here");
268
  exit(EXIT_FAILURE);
269
}
270
 
271
 
272
void f_make_diagdef_unit
273
    PROTO_Z ()
274
{
275
  int i;
276
  int j = 0;
277
  int no_of_labels;
278
  int was_within_diags;
279
 
280
  for (i = 0; i < unit_no_of_tokens; ++i)
281
  {
282
    if (unit_ind_tokens[i] == (tok_define*)0)
283
      unit_ind_tokens[i] = &unit_toktab[j++];
284
  };
285
 
286
  j = 0;
287
  for (i = 0; i < unit_no_of_tags; ++i)
288
  {
289
    if (unit_ind_tags[i] == (dec*)0)
290
      unit_ind_tags[i] = &unit_tagtab[j++];
291
  };
292
 
293
  j = 0;
294
  for (i = 0; i < unit_no_of_als; ++i)
295
  {
296
    if (unit_ind_als[i] == (aldef*)0)
297
      unit_ind_als[i] = &unit_altab[j++];
298
  };
299
 
300
  j=0;
301
  for (i = 0; i < unit_no_of_diagtags; ++i)
302
  {
303
    if (unit_ind_diagtags[i] == (diag_tagdef *)0)
304
      unit_ind_diagtags[i] = &unit_diag_tagdeftab[j++];
305
  };
306
 
307
  was_within_diags = within_diags;
308
  within_diags = 1;
309
  {
310
    dg_compilation * comp_unit_ptr = &all_comp_units;
311
    dg_compilation ans;
312
    dg_name_list desc_list;
313
    while (* comp_unit_ptr)
314
      comp_unit_ptr = &(* comp_unit_ptr)->another;
315
    primary_file = (dg_filename)0;
316
    start_bytestream();
317
    no_of_labels = small_dtdfint();
318
    unit_no_of_labels = no_of_labels;
319
    unit_labtab = (exp*)xcalloc(unit_no_of_labels, sizeof(exp));
320
    desc_list = d_diag_descriptor_list();
321
    end_bytestream();
322
    if (!primary_file)
323
      primary_file = get_filename ((long)0, "", "", "no_source_file");
324
    (* comp_unit_ptr) = ans = (dg_compilation) xmalloc (sizeof (struct dg_comp_t));
325
    ans->prim_file = primary_file;
326
    ans->comp_deps = new_string_list (0);
327
    ans->date = 0;
328
    ans->language = 1;	/* assume ANSI C */
329
    ans->id_case = 0;	/* case sensitive */
330
    ans->producer = "TenDRA";
331
    ans->comp_dir = get_filename ((long)0, "", "unknown directory", "");
332
    ans->options = new_string_list (0);
333
    ans->dn_list = desc_list;
334
    ans->macros = new_dg_macro_list (0);
335
    ans->another = (dg_compilation)0;
336
  }
337
  within_diags = was_within_diags;
338
  return;
339
}
340
 
341
 
342
diag_descriptor f_diag_desc_id
343
    PROTO_N ( (n, whence, acc, new_type) )
344
    PROTO_T ( tdfstring n X sourcemark whence X exp acc X diag_type new_type )
345
{
346
  dg_idname nid;
347
  if (brog(son(acc))->dec_u.dec_val.extnamed)
348
    nid = f_dg_external_idname (n);
349
  else
350
    nid = f_dg_sourcestring_idname (n);
351
  if (new_type->key == DGT_PROC && !isvar(son(acc)))
352
    return f_dg_proc_name (
353
	nid,
354
	whence,
355
	new_type,
356
	yes_exp_option (diag_locate (acc)),
357
	no_dg_accessibility_option,
358
	no_dg_virtuality_option,
359
	f_false,
360
	no_dg_type_list_option,
361
	no_dg_tag_option);
362
  else
363
    return f_dg_object_name (
364
	nid,
365
	whence,
366
	new_type,
367
	yes_exp_option (diag_locate (acc)),
368
	no_dg_accessibility_option);
369
}
370
 
371
diag_descriptor f_diag_desc_struct
372
    PROTO_N ( (n, whence, new_type) )
373
    PROTO_T ( tdfstring n X sourcemark whence X diag_type new_type )
374
{
375
  UNUSED (n);
376
  UNUSED (whence);
377
  UNUSED (new_type);
378
  failer ("diag_desc_struct is obsolete");
379
  return f_dummy_diag_descriptor;
380
}
381
 
382
diag_descriptor f_diag_desc_typedef
383
    PROTO_N ( (n, whence, new_type) )
384
    PROTO_T ( tdfstring n X sourcemark whence X diag_type new_type )
385
{
386
  if (!new_type || (new_type->key == DGT_TAGGED &&
387
		    new_type->data.t_tag->key == DGK_NONE))
388
    return (dg_name)0;		/* no type definition for __va_list etc */
389
  return f_dg_type_name (
390
	f_dg_sourcestring_idname (n),
391
	whence,
392
	no_dg_accessibility_option,
393
	yes_dg_type_option (new_type),
394
	f_false,
395
	no_bool_option,
396
	no_dg_constraint_list_option);
397
}
398
 
399
void init_diag_descriptor
400
    PROTO_Z ()
401
{
402
  return;
403
}
404
 
405
diag_descriptor_list new_diag_descriptor_list
406
    PROTO_N ( (n) )
407
    PROTO_T ( int n )
408
{
409
  return new_dg_name_list (n);
410
}
411
 
412
diag_descriptor_list add_diag_descriptor_list
413
    PROTO_N ( (list, elem,index) )
414
    PROTO_T ( diag_descriptor_list list X diag_descriptor elem X int index )
415
{
416
  if (!elem)		/* no type definition for __va_list etc */
417
    return list;
418
  return add_dg_name_list (list, elem, index);
419
}
420
 
421
/*---------------------------- diag_tq--------------------------*/
422
 
423
diag_tq f_diag_tq_null = 0;
424
 
425
diag_tq f_add_diag_const
426
    PROTO_N ( (qual) )
427
    PROTO_T ( diag_tq qual )
428
{
429
  return (qual | (1 << DG_CONST_T));
430
}
431
 
432
diag_tq f_add_diag_volatile
433
    PROTO_N ( (qual) )
434
    PROTO_T ( diag_tq qual )
435
{
436
  return (qual | (1 << DG_VOL_T));
437
}
438
 
439
/*--------------------------diag_type -----------------------------*/
440
 
441
diag_type f_diag_type_null = (dg_type)0;
442
 
443
diag_type f_diag_type_apply_token
444
    PROTO_N ( (token_value, token_args) )
445
    PROTO_T ( token token_value X bitstream token_args )
446
{
447
   tokval v;
448
   v = apply_tok(token_value, token_args,  DIAG_TYPE_SORT, (tokval*)0);
449
   return v.tk_diag_type;
450
}
451
 
452
diag_type f_diag_array
453
    PROTO_N ( (element_type, stride, lower_bound, upper_bound, index_type) )
454
    PROTO_T ( diag_type element_type X exp stride X exp lower_bound X exp upper_bound X diag_type index_type )
455
{
456
  return f_dg_array_type (
457
	element_type,
458
	stride,
459
	no_bool_option,
460
	add_dg_dim_list (new_dg_dim_list (1),
461
		f_dg_bounds_dim (
462
			f_dg_static_bound (lower_bound),
463
			f_dg_static_bound (upper_bound),
464
			index_type),
465
		0));
466
}
467
 
468
diag_type f_diag_bitfield
469
    PROTO_N ( (typ, number_of_bits) )
470
    PROTO_T ( diag_type typ X nat number_of_bits )
471
{
472
  shape sha;
473
  if (typ->key == DGT_BASIC)
474
    sha = typ->data.t_bas.b_sh;
475
  else
476
  if (typ->key == DGT_ENUM)
477
    sha = typ->data.t_enum.sha;
478
  else
479
  if (typ->key == DGT_TAGGED && typ->data.t_tag->outref.k == LAB_STR)
480
    sha = basic_tag_shape (typ->data.t_tag);
481
  else {
482
    failer ("unexpected bitfield type");
483
    sha = slongsh;
484
  }
485
  return f_dg_bitfield_type (
486
	typ,
487
	f_bfvar_bits (((name(sha) & 1) ? 1 : 0), number_of_bits),
488
	sha);
489
}
490
 
491
 
492
diag_type f_diag_enum
493
    PROTO_N ( (base_type, enum_name, values) )
494
    PROTO_T ( diag_type base_type X tdfstring enum_name X enum_values_list values )
495
{
496
  UNUSED (base_type);
497
  return f_dg_enum_type (
498
	values,
499
	yes_dg_idname_option (f_dg_sourcestring_idname (enum_name)),
500
	no_dg_sourcepos_option,
501
	sh(son(values.array->value)),
502
	f_false);
503
}
504
 
505
 
506
diag_type f_diag_floating_variety
507
    PROTO_N ( (var) )
508
    PROTO_T ( floating_variety var )
509
{
510
  switch (var) {
511
    case shrealfv:
512
      return (f_dg_named_type (dg_tag_float));
513
    case realfv:
514
      return (f_dg_named_type (dg_tag_double));
515
    case doublefv:
516
      return (f_dg_named_type (dg_tag_long_double));
517
    case shcomplexfv:
518
      return (f_dg_named_type (dg_tag_complex));
519
    case complexfv:
520
      return (f_dg_named_type (dg_tag_double_complex));
521
    case complexdoublefv:
522
      return (f_dg_named_type (dg_tag_long_double_complex));
523
  }
524
  failer ("bad variety");
525
  return f_dummy_diag_type;
526
}
527
 
528
diag_type f_diag_loc
529
    PROTO_N ( (object, qualifier) )
530
    PROTO_T ( diag_type object X diag_tq qualifier )
531
{
532
  if (qualifier & (1 << DG_CONST_T))
533
    object = f_dg_qualified_type (DG_CONST_T, object);
534
  if (qualifier & (1 << DG_VOL_T))
535
    object = f_dg_qualified_type (DG_VOL_T, object);
536
  return object;
537
}
538
 
539
diag_type f_diag_proc
540
    PROTO_N ( (params, optional_args, result_type) )
541
    PROTO_T ( diag_type_list params X bool optional_args X diag_type result_type )
542
{
543
  int i;
544
  dg_param_list plist;
545
  dg_param thispar;
546
  procprops_option prps = no_procprops_option;
547
  if (params.len == 1 && !params.array[0])
548
    params.len = 0;
549
  plist = new_dg_param_list (params.len);
550
  for (i=0; i<params.len; i++) {
551
    if (!params.array[i])
552
      failer ("dummy parameter?");
553
    thispar = f_dg_object_param (
554
	no_dg_idname_option,
555
	no_dg_sourcepos_option,
556
	no_dg_param_mode_option,
557
	params.array[i],
558
	no_dg_default_option);
559
    plist = add_dg_param_list (plist, thispar, i);
560
  }
561
  if (optional_args)
562
    prps = yes_procprops_option (f_var_callers);
563
  return f_dg_proc_type (plist, result_type, no_bool_option,
564
	no_nat_option, no_nat_option, prps);
565
}
566
 
567
 
568
diag_type f_diag_ptr
569
    PROTO_N ( (object, qualifier) )
570
    PROTO_T ( diag_type object X diag_tq qualifier )
571
{
572
  dg_type ptr = (object ? f_dg_pointer_type (object, no_bool_option)
573
			: f_dg_named_type (dg_tag_void_star));
574
  return f_diag_loc (ptr, qualifier);
575
}
576
 
577
diag_type f_diag_struct
578
    PROTO_N ( (tdf_shape, n, fields) )
579
    PROTO_T ( shape tdf_shape X tdfstring n X diag_field_list fields )
580
{
581
  return f_dg_struct_type (
582
	fields,
583
	yes_shape_option (tdf_shape),
584
	yes_dg_idname_option (f_dg_sourcestring_idname (n)),
585
	no_dg_sourcepos_option,
586
	no_dg_varpart_option,
587
	f_false,
588
	f_false);
589
}
590
 
591
diag_type f_diag_union
592
    PROTO_N ( (tdf_shape, n, fields) )
593
    PROTO_T ( shape tdf_shape X tdfstring n X diag_field_list fields )
594
{
595
  return f_dg_struct_type (
596
	fields,
597
	yes_shape_option (tdf_shape),
598
	yes_dg_idname_option (f_dg_sourcestring_idname (n)),
599
	no_dg_sourcepos_option,
600
	no_dg_varpart_option,
601
	f_true,
602
	f_false);
603
}
604
 
605
diag_type f_diag_variety
606
    PROTO_N ( (var) )
607
    PROTO_T ( variety var )
608
{
609
  switch (name(var)) {
610
    case scharhd:
611
      return (f_dg_named_type (dg_tag_signed_char));
612
    case ucharhd:
613
      return (f_dg_named_type (dg_tag_unsigned_char));
614
    case swordhd:
615
      return (f_dg_named_type (dg_tag_short));
616
    case uwordhd:
617
      return (f_dg_named_type (dg_tag_unsigned_short));
618
    case slonghd:
619
      return (f_dg_named_type (dg_tag_int));
620
    case ulonghd:
621
      return (f_dg_named_type (dg_tag_unsigned_int));
622
    case s64hd:
623
      return (f_dg_named_type (dg_tag_long_long));
624
    case u64hd:
625
      return (f_dg_named_type (dg_tag_unsigned_long_long));
626
  }
627
  failer ("bad variety");
628
  return f_dummy_diag_type;
629
}
630
 
631
void init_diag_type
632
    PROTO_Z ()
633
{
634
  zero_nat.nat_val.small_nat = 0;
635
  zero_nat.issmall = 1;
636
  return;
637
}
638
 
639
/*-------------------------- DIAG TYPE HELPERS ---------------------*/
640
/*---------------------------enum_values ---------------------------*/
641
 
642
enum_values f_make_enum_values
643
    PROTO_N ( (value, n) )
644
    PROTO_T ( exp value X tdfstring n )
645
{
646
  return f_make_dg_enum (
647
	value,
648
	f_dg_sourcestring_idname (n),
649
	f_dg_null_sourcepos);
650
}
651
 
652
void init_enum_values
653
    PROTO_Z ()
654
{
655
  return;
656
}
657
 
658
enum_values_list new_enum_values_list
659
    PROTO_N ( (n) )
660
    PROTO_T ( int n )
661
{
662
  return new_dg_enum_list (n);
663
}
664
 
665
enum_values_list add_enum_values_list
666
    PROTO_N ( (list, elem, index) )
667
    PROTO_T ( enum_values_list list X enum_values elem X int index )
668
{
669
  return add_dg_enum_list (list, elem, index);
670
}
671
 
672
/*--------------------------struct fields-------------------------*/
673
diag_field f_make_diag_field
674
    PROTO_N ( (field_name, wh, field_type) )
675
    PROTO_T ( tdfstring field_name X exp wh X diag_type field_type )
676
{
677
  return f_dg_field_classmem (
678
	f_dg_sourcestring_idname (field_name),
679
	f_dg_null_sourcepos,
680
	wh,
681
	field_type,
682
	no_dg_accessibility_option,
683
	no_bool_option,
684
	no_dg_default_option);
685
}
686
 
687
void init_diag_field
688
    PROTO_Z ()
689
{
690
  return;
691
}
692
 
693
diag_field_list new_diag_field_list
694
    PROTO_N ( (n) )
695
    PROTO_T ( int n )
696
{
697
  return new_dg_classmem_list (n);
698
}
699
 
700
diag_field_list add_diag_field_list
701
    PROTO_N ( (list, elem, index) )
702
    PROTO_T ( diag_field_list list X diag_field elem X int index )
703
{
704
  return add_dg_classmem_list (list, elem, list.len - index - 1);
705
}
706
 
707
/*----------------------diag type list----------------------*/
708
diag_type_list new_diag_type_list
709
    PROTO_N ( (n) )
710
    PROTO_T ( int n )
711
{
712
  return new_dg_type_list (n);
713
}
714
 
715
diag_type_list add_diag_type_list
716
    PROTO_N ( (list, elem,index) )
717
    PROTO_T ( diag_type_list list X diag_type elem X int index )
718
{
719
  return add_dg_type_list (list, elem, index);
720
}
721
/*----------------------------END HELPERS------------------------------------*/
722
 
723
/*-------------------------- sourcemark ---------------------------------*/
724
 
725
sourcemark f_make_sourcemark
726
    PROTO_N ( (file, line_no, char_offset) )
727
    PROTO_T ( filename file X nat line_no X nat char_offset )
728
{
729
  return f_dg_mark_sourcepos (file, line_no, char_offset);
730
}
731
 
732
void init_sourcemark
733
    PROTO_Z ()
734
{
735
  return;
736
}
737
 
738
/*------------------------------filename ------------------------*/
739
 
740
filename f_make_filename
741
    PROTO_N ( (date, machine, file) )
742
    PROTO_T ( nat date X tdfstring machine X tdfstring file )
743
{
744
  filename f;
745
  tdfstring path;
746
  char * dot;
747
  path.size = 8;
748
  path.number = 0;
749
  path.ints.chars = "";
750
  f = f_make_dg_filename (date,  machine, path, file);
751
  if (!primary_file && (dot = strrchr (f->file_name, '.'), !dot || dot[1] != 'h'))
752
    primary_file = f;
753
  return f;
754
}
755
 
756
 
757
filename f_filename_apply_token
758
    PROTO_N ( (token_value, token_args) )
759
    PROTO_T ( token token_value X bitstream token_args )
760
{
761
   tokval v;
762
   v = apply_tok(token_value, token_args, DIAG_FILENAME, (tokval*)0);
763
   return v.tk_filename;
764
}
765
 
766
/*----------------------------- diag tag ------------------------------*/
767
 
768
 
769
void init_diag_tag
770
    PROTO_Z ()
771
{
772
  return;
773
}
774
 
775
diag_tag f_make_diag_tag
776
    PROTO_N ( (num) )
777
    PROTO_T ( tdfint num )
778
{
779
  int index = natint(num);
780
  if (index >= unit_no_of_diagtags)
781
    failer("make_dg_tag out of range");
782
  return unit_ind_diagtags[index];
783
}
784
 
785
 
786
/*---------------------------- diag_tagdef =diag_typeunit ------------------*/
787
 
788
static dg_name_list s_tags;
789
 
790
void init_diag_tagdef
791
    PROTO_Z ()
792
{
793
  return;
794
}
795
 
796
diag_tagdef f_make_diag_tagdef
797
    PROTO_N ( (t, dtype) )
798
    PROTO_T ( tdfint t X diag_type dtype )
799
{
800
  dg_tag tg = f_make_diag_tag (t);
801
  IGNORE f_dg_tag_type (tg, dtype);
802
  if ((dtype->key == DGT_STRUCT && dtype->data.t_struct.idnam.id_key == DG_ID_SRC
803
		&& dtype->data.t_struct.idnam.idd.nam[0])
804
	|| (dtype->key == DGT_ENUM && dtype->data.t_enum.tnam[0])) {
805
    dg_name * nm = &s_tags;
806
    while (*nm) nm = &((*nm)->next);
807
    (*nm) = f_dg_type_name (
808
	no_dg_idname_option,
809
	f_dg_null_sourcepos,
810
	no_dg_accessibility_option,
811
	yes_dg_type_option (dtype),
812
	f_false,
813
	no_bool_option,
814
	no_dg_constraint_list_option);
815
  }
816
  return f_dummy_diag_tagdef;
817
}
818
 
819
 
820
void init_capsule_diagtags
821
    PROTO_Z ()
822
{
823
  /* the space has been calloced in read_fns */
824
 
825
  int i;
826
  for (i = 0; i < capsule_no_of_diagtags; ++i)
827
  {
828
    init_dgtag (&capsule_diag_tagtab[i]);
829
  }
830
  return;
831
}
832
 
833
void start_make_diagtype_unit
834
    PROTO_N ( (toks, tags, als, diags) )
835
    PROTO_T ( int toks X int tags X int als X int diags )
836
{
837
  int i;
838
 
839
  if (!tags_initialised)
840
    init_basic_diag_tags ();
841
 
842
  unit_no_of_tokens = toks;
843
  unit_ind_tokens = (tok_define * *)xcalloc(unit_no_of_tokens,
844
                    sizeof(tok_define *));
845
  for (i = 0; i < unit_no_of_tokens; ++i)
846
    unit_ind_tokens[i] = (tok_define*)0;
847
 
848
  unit_no_of_tags = tags;
849
  unit_ind_tags = (dec * *)xcalloc(unit_no_of_tags,
850
                    sizeof(dec *));
851
  for (i = 0; i < unit_no_of_tags; ++i)
852
    unit_ind_tags[i] = (dec*)0;
853
 
854
  unit_no_of_als = als;
855
  unit_ind_als = (aldef * *)xcalloc(unit_no_of_als,
856
                    sizeof(aldef *));
857
  for (i = 0; i < unit_no_of_als; ++i)
858
    unit_ind_als[i] = (aldef*)0;
859
 
860
  unit_no_of_diagtags = diags;
861
  unit_ind_diagtags = (diag_tagdef * *)xcalloc(unit_no_of_diagtags,
862
                    sizeof(diag_tagdef *));
863
  for (i = 0; i < unit_no_of_diagtags; ++i)
864
    unit_ind_diagtags[i] = (diag_tagdef *)0;
865
  s_tags = (dg_name)0;
866
  return;
867
}
868
 
869
void init_unit_diagtags
870
    PROTO_N ( (n) )
871
    PROTO_T ( int n )
872
{
873
 
874
  int i;
875
 
876
  unit_diag_tagdeftab = (diag_tagdef *) xcalloc(unit_no_of_diagtags - n,
877
					sizeof(diag_tagdef));
878
 
879
  for (i = 0; i < unit_no_of_diagtags - n; ++i)
880
  {
881
    init_dgtag (&unit_diag_tagdeftab[i]);
882
  }
883
  return;
884
}
885
 
886
diag_type_unit f_make_diagtype_unit
887
    PROTO_Z ()
888
{
889
  int i;
890
  int j = 0;
891
  int no_of_labels;
892
  int was_within_diags;
893
 
894
  for (i = 0; i < unit_no_of_tokens; ++i)
895
  {
896
    if (unit_ind_tokens[i] == (tok_define*)0)
897
      unit_ind_tokens[i] = &unit_toktab[j++];
898
  };
899
 
900
  j = 0;
901
  for (i = 0; i < unit_no_of_tags; ++i)
902
  {
903
    if (unit_ind_tags[i] == (dec*)0)
904
      unit_ind_tags[i] = &unit_tagtab[j++];
905
  };
906
 
907
  j = 0;
908
  for (i = 0; i < unit_no_of_als; ++i)
909
  {
910
    if (unit_ind_als[i] == (aldef*)0)
911
      unit_ind_als[i] = &unit_altab[j++];
912
  };
913
 
914
  j=0;
915
  for (i = 0; i < unit_no_of_diagtags; ++i)
916
  {
917
    if (unit_ind_diagtags[i] == (diag_tagdef *)0)
918
      unit_ind_diagtags[i] = &unit_diag_tagdeftab[j++];
919
  };
920
 
921
  was_within_diags = within_diags;
922
  within_diags = 1;
923
  start_bytestream();
924
  no_of_labels = small_dtdfint();
925
  unit_no_of_labels = no_of_labels;
926
  unit_labtab = (exp*)xcalloc(unit_no_of_labels, sizeof(exp));
927
  IGNORE d_diag_tagdef_list();
928
  end_bytestream();
929
  if (s_tags) {
930
    dg_compilation * comp_unit_ptr = &all_comp_units;
931
    dg_compilation ans;
932
    while (* comp_unit_ptr)
933
      comp_unit_ptr = &(* comp_unit_ptr)->another;
934
    (* comp_unit_ptr) = ans = (dg_compilation) xmalloc (sizeof (struct dg_comp_t));
935
    ans->prim_file = get_filename ((long)0, "", "", "no_source_file");
936
    ans->comp_deps = new_string_list (0);
937
    ans->date = 0;
938
    ans->language = 1;	/* assume ANSI C */
939
    ans->id_case = 0;	/* case sensitive */
940
    ans->producer = "TenDRA";
941
    ans->comp_dir = get_filename ((long)0, "", "unknown directory", "");
942
    ans->options = new_string_list (0);
943
    ans->dn_list = s_tags;
944
    ans->macros = new_dg_macro_list (0);
945
    ans->another = (dg_compilation)0;
946
  }
947
  within_diags = was_within_diags;
948
  return 0;
949
}
950
 
951
diag_tagdef_list new_diag_tagdef_list
952
    PROTO_N ( (n) )
953
    PROTO_T ( int n )
954
{
955
  UNUSED(n);
956
  return 0;
957
}
958
 
959
diag_tagdef_list add_diag_tagdef_list
960
    PROTO_N ( (list, elem, index) )
961
    PROTO_T ( diag_tagdef_list list X diag_tagdef elem X int index )
962
{
963
  UNUSED(list); UNUSED(elem); UNUSED(index);
964
  return 0;
965
}
966
 
967
linkextern f_make_diagtagextern
968
    PROTO_N ( (internal,ext) )
969
    PROTO_T ( tdfint internal X external ext )
970
{
971
  dg_tag tg = &capsule_diag_tagtab[natint(internal)];
972
  tg->outref.k = NO_LAB;	/* old diag names are internal ! */
973
  tg->outref.u.s = external_to_string(ext);
974
  return 0;
975
}
976
 
977
diag_type f_use_diag_tag
978
    PROTO_N ( (t) )
979
    PROTO_T ( diag_tag t )
980
{
981
  return f_dg_named_type (t);
982
}
983
 
984
 
985
void f_make_diagtaglink
986
    PROTO_N ( (i, ext) )
987
    PROTO_T ( tdfint i X tdfint ext )
988
{
989
  unit_ind_diagtags[natint(i)] =
990
      &capsule_diag_tagtab[natint(ext)];
991
  return;
992
}
993
 
994
 
995
void init_diag_tq
996
    PROTO_Z ()
997
{
998
  return;
999
}
1000
 
1001
void init_filename
1002
    PROTO_Z ()
1003
{
1004
  return;
1005
}
1006
 
1007
void init_diag_type_unit
1008
    PROTO_Z ()
1009
{
1010
  return;
1011
}
1012
 
1013
void init_linkinfo_props
1014
    PROTO_Z ()
1015
{
1016
  return;
1017
}
1018
 
1019
 
1020
 
1021
#else
1022
	/* !NEWDIAGS */
1023
 
1024
#if issparc
1025
#include "sparcdiags.h"
1026
#endif
1027
 
1028
#if is68000
1029
#include "xdb_basics.h"
1030
#endif
1031
 
1032
#if ishppa
1033
#include "hppadiags.h"
1034
#endif
1035
 
1036
#if isAlpha
1037
#include "alphadiags.h"
1038
#endif
1039
 
1040
 
1041
/* allocate space in this file */
1042
#define EXTERN_DIAG
1043
 
1044
#include "diagglob.h"
1045
 
1046
#define DEBUG(x) x
1047
 
1048
/* VARIABLES */
1049
/* All variables initialised */
1050
 
1051
diag_tq f_diag_tq_null;	/* no need to initialise. Not really used. */
1052
 
1053
/* IDENTITIES */
1054
 
1055
struct diag_type_t f_diag_type_null_obj = { DIAG_TYPE_NULL };
1056
 
1057
diag_type f_diag_type_null = &f_diag_type_null_obj;
1058
 
1059
 
1060
/* PROCEDURES */
1061
 
1062
/*----------------------- diagdef and diag_descriptor  lists ----------------*/
1063
 
1064
void start_make_diagdef_unit
1065
    PROTO_N ( (toks, tags, als, diagtags) )
1066
    PROTO_T ( int toks X int tags X int als X int diagtags )
1067
{
1068
  int i;
1069
 
1070
  unit_no_of_tokens = toks;
1071
  unit_ind_tokens = (tok_define * *)xcalloc(unit_no_of_tokens,
1072
                    sizeof(tok_define *));
1073
  for (i = 0; i < unit_no_of_tokens; ++i)
1074
    unit_ind_tokens[i] = (tok_define*)0;
1075
 
1076
  unit_no_of_tags = tags;
1077
  unit_ind_tags = (dec * *)xcalloc(unit_no_of_tags,
1078
                    sizeof(dec *));
1079
  for (i = 0; i < unit_no_of_tags; ++i)
1080
    unit_ind_tags[i] = (dec*)0;
1081
 
1082
  unit_no_of_als = als;
1083
  unit_ind_als = (aldef * *)xcalloc(unit_no_of_als,
1084
                    sizeof(aldef *));
1085
  for (i = 0; i < unit_no_of_als; ++i)
1086
    unit_ind_als[i] = (aldef*)0;
1087
 
1088
  unit_no_of_diagtags = diagtags;
1089
  unit_ind_diagtags = (diag_tagdef * *)xcalloc(unit_no_of_diagtags,
1090
                    sizeof(diag_tagdef *));
1091
  for (i = 0; i < unit_no_of_diagtags; ++i)
1092
    unit_ind_diagtags[i] = (diag_tagdef *)0;
1093
 
1094
  return;
1095
}
1096
 
1097
void init_diag_unit
1098
    PROTO_Z ()
1099
{
1100
  return;
1101
}
1102
 
1103
diag_unit f_build_diag_unit
1104
    PROTO_N ( (labels, descriptors) )
1105
    PROTO_T ( tdfint labels X diag_descriptor_list descriptors )
1106
{
1107
  UNUSED(labels); UNUSED(descriptors);
1108
  failer("f_build_diag_unit isn't really here");
1109
  exit(EXIT_FAILURE);
1110
}
1111
 
1112
diag_type_unit f_build_diagtype_unit
1113
    PROTO_N ( (labels, descriptors) )
1114
    PROTO_T ( tdfint labels X diag_tagdef_list descriptors )
1115
{
1116
  UNUSED(labels); UNUSED(descriptors);
1117
  failer("f_build_diagtype_unit isn't really here");
1118
  exit(EXIT_FAILURE);
1119
}
1120
 
1121
 
1122
void f_make_diagdef_unit
1123
    PROTO_Z ()
1124
{
1125
  int i;
1126
  int j = 0;
1127
  int no_of_labels;
1128
 
1129
  for (i = 0; i < unit_no_of_tokens; ++i)
1130
  {
1131
    if (unit_ind_tokens[i] == (tok_define*)0)
1132
      unit_ind_tokens[i] = &unit_toktab[j++];
1133
  };
1134
 
1135
  j = 0;
1136
  for (i = 0; i < unit_no_of_tags; ++i)
1137
  {
1138
    if (unit_ind_tags[i] == (dec*)0)
1139
      unit_ind_tags[i] = &unit_tagtab[j++];
1140
  };
1141
 
1142
  j = 0;
1143
  for (i = 0; i < unit_no_of_als; ++i)
1144
  {
1145
    if (unit_ind_als[i] == (aldef*)0)
1146
      unit_ind_als[i] = &unit_altab[j++];
1147
  };
1148
 
1149
  j=0;
1150
  for (i = 0; i < unit_no_of_diagtags; ++i)
1151
  {
1152
    if (unit_ind_diagtags[i] == (diag_tagdef *)0)
1153
      unit_ind_diagtags[i] = &unit_diag_tagdeftab[j++];
1154
  };
1155
 
1156
  start_bytestream();
1157
  no_of_labels = small_dtdfint();
1158
  unit_no_of_labels = no_of_labels;
1159
  unit_labtab = (exp*)xcalloc(unit_no_of_labels, sizeof(exp));
1160
  unit_diagvar_tab = d_diag_descriptor_list();
1161
  end_bytestream();
1162
  OUTPUT_GLOBALS_TAB();
1163
  return;
1164
}
1165
 
1166
/*---------------------- diag_descriptor fns --------------------*/
1167
 
1168
				/* HACK attack */
1169
				/* since diag_descriptor are not a pointer
1170
				 type we cant set the diag_global field
1171
				 easily, so we CHEAT via a global */
1172
 
1173
static diag_descriptor * last_diag_desc;
1174
 
1175
diag_descriptor f_diag_desc_id
1176
    PROTO_N ( (n, whence, acc, new_type) )
1177
    PROTO_T ( tdfstring n X sourcemark whence X exp acc X diag_type new_type )
1178
{
1179
  diag_descriptor new;
1180
 
1181
  if (name(acc) != name_tag)
1182
    failer("No name in f_diag_desc_id");
1183
 
1184
  new.key	 	= DIAG_ID_KEY;
1185
  new.data.id.nme 	= n;
1186
  new.data.id.whence	= whence;
1187
  new.data.id.access	= acc;
1188
  new.data.id.new_type	= new_type;
1189
 
1190
  brog(son(acc))->dec_u.dec_val.diag_info =
1191
    NEW_DIAG_GLOBAL(last_diag_desc);
1192
 
1193
  return new;
1194
}
1195
 
1196
diag_descriptor f_diag_desc_struct
1197
    PROTO_N ( (n, whence, new_type) )
1198
    PROTO_T ( tdfstring n X sourcemark whence X diag_type new_type )
1199
{
1200
  diag_descriptor new;
1201
 
1202
  new.key	 	= DIAG_STRUCT_KEY;
1203
  new.data.struc.nme 	= n;
1204
  new.data.struc.whence	= whence;
1205
  new.data.struc.new_type	= new_type;
1206
 
1207
  return new;
1208
}
1209
 
1210
diag_descriptor f_diag_desc_typedef
1211
    PROTO_N ( (n, whence, new_type) )
1212
    PROTO_T ( tdfstring n X sourcemark whence X diag_type new_type )
1213
{
1214
  diag_descriptor new;
1215
 
1216
  new.key	 	= DIAG_TYPEDEF_KEY;
1217
  new.data.typ.nme 	= n;
1218
  new.data.typ.whence	= whence;
1219
  new.data.typ.new_type	= new_type;
1220
 
1221
  return new;
1222
}
1223
 
1224
void init_diag_descriptor
1225
    PROTO_Z ()
1226
{
1227
  return;
1228
}
1229
 
1230
diag_descriptor_list new_diag_descriptor_list
1231
    PROTO_N ( (n) )
1232
    PROTO_T ( int n )
1233
{
1234
  diag_descriptor_list new;
1235
 
1236
  new.len = n;
1237
  new.lastused = 0;
1238
  new.array = (diag_descriptor *) xcalloc(n,sizeof( diag_descriptor ));
1239
  last_diag_desc = new.array;
1240
  return new;
1241
}
1242
 
1243
diag_descriptor_list add_diag_descriptor_list
1244
    PROTO_N ( (list, elem,index) )
1245
    PROTO_T ( diag_descriptor_list list X diag_descriptor elem X int index )
1246
{
1247
  UNUSED(index);
1248
  last_diag_desc++;
1249
  list.array[list.lastused++] = elem;
1250
  return list;
1251
}
1252
 
1253
/*---------------------------- diag_tq--------------------------*/
1254
 
1255
 
1256
diag_tq f_add_diag_const
1257
    PROTO_N ( (qual) )
1258
    PROTO_T ( diag_tq qual )
1259
{
1260
  diag_tq new;
1261
  new = qual;
1262
  new.is_const = 1;
1263
  return new;
1264
}
1265
 
1266
diag_tq f_add_diag_volatile
1267
    PROTO_N ( (qual) )
1268
    PROTO_T ( diag_tq qual )
1269
{
1270
  diag_tq new;
1271
  new = qual;
1272
  new.is_volatile = 1;
1273
  return new;
1274
}
1275
 
1276
/*--------------------------diag_type -----------------------------*/
1277
 
1278
diag_type f_diag_type_apply_token
1279
    PROTO_N ( (token_value, token_args) )
1280
    PROTO_T ( token token_value X bitstream token_args )
1281
{
1282
   tokval v;
1283
   v = apply_tok(token_value, token_args,  DIAG_TYPE_SORT, (tokval*)0);
1284
   return v.tk_diag_type;
1285
}
1286
 
1287
#ifndef NULL
1288
#define NULL ((OUTPUT_REC)0)
1289
#endif
1290
 
1291
diag_type f_diag_array
1292
    PROTO_N ( (element_type, stride, lower_bound, upper_bound, index_type) )
1293
    PROTO_T ( diag_type element_type X exp stride X exp lower_bound X exp upper_bound X diag_type index_type )
1294
{
1295
  diag_type new = (diag_type) xcalloc(1,sizeof(struct diag_type_t));
1296
 
1297
  new->key	= DIAG_TYPE_ARRAY;
1298
  new->been_outed = 0;
1299
 
1300
  new->data.array.element_type	= element_type;
1301
  new->data.array.stride	= stride;
1302
  new->data.array.lower_b	= lower_bound;
1303
  new->data.array.upper_b	= upper_bound;
1304
  new->data.array.index_type	= index_type;
1305
 
1306
  return new;
1307
}
1308
 
1309
diag_type f_diag_bitfield
1310
    PROTO_N ( (type, number_of_bits) )
1311
    PROTO_T ( diag_type type X nat number_of_bits )
1312
{
1313
  diag_type new = (diag_type) xcalloc(1,sizeof(struct diag_type_t));
1314
 
1315
  new->key      = DIAG_TYPE_BITFIELD;
1316
  new->been_outed = 0;
1317
 
1318
  new->data.bitfield.result_type	= type;
1319
  new->data.bitfield.no_of_bits		= number_of_bits;
1320
 
1321
  return new;
1322
}
1323
 
1324
 
1325
diag_type f_diag_enum
1326
    PROTO_N ( (base_type, enum_name, values) )
1327
    PROTO_T ( diag_type base_type X tdfstring enum_name X enum_values_list values )
1328
{
1329
  diag_type new = (diag_type) xcalloc(1,sizeof(struct diag_type_t));
1330
 
1331
  new->key      = DIAG_TYPE_ENUM;
1332
  new->been_outed = 0;
1333
 
1334
  new->data.t_enum.base_type	= base_type;
1335
  new->data.t_enum.nme		= enum_name;
1336
  new->data.t_enum.values	= values;
1337
 
1338
  return new;
1339
}
1340
 
1341
 
1342
diag_type f_diag_floating_variety
1343
    PROTO_N ( (var) )
1344
    PROTO_T ( floating_variety var )
1345
{
1346
  diag_type new = (diag_type) xcalloc(1,sizeof(struct diag_type_t));
1347
 
1348
  new->key      = DIAG_TYPE_FLOAT;
1349
  new->been_outed = 0;
1350
 
1351
  new->data.f_var	= var;
1352
 
1353
  return new;
1354
}
1355
 
1356
diag_type f_diag_loc
1357
    PROTO_N ( (object, qualifier) )
1358
    PROTO_T ( diag_type object X diag_tq qualifier )
1359
{
1360
  diag_type new = (diag_type) xcalloc(1,sizeof(struct diag_type_t));
1361
 
1362
  new->key      = DIAG_TYPE_LOC;
1363
  new->been_outed = 0;
1364
 
1365
  new->data.loc.object		= object;
1366
  new->data.loc.qualifier	= qualifier;
1367
 
1368
  return new;
1369
}
1370
 
1371
diag_type f_diag_proc
1372
    PROTO_N ( (params, optional_args, result_type) )
1373
    PROTO_T ( diag_type_list params X bool optional_args X diag_type result_type )
1374
{
1375
  diag_type new = (diag_type) xcalloc(1,sizeof(struct diag_type_t));
1376
 
1377
  new->key      = DIAG_TYPE_PROC;
1378
  new->been_outed = 0;
1379
 
1380
  new->data.proc.params		= params;
1381
  new->data.proc.opt_args	= optional_args;
1382
  new->data.proc.result_type	= result_type;
1383
 
1384
  return new;
1385
}
1386
 
1387
 
1388
diag_type f_diag_ptr
1389
    PROTO_N ( (object, qualifier) )
1390
    PROTO_T ( diag_type object X diag_tq qualifier )
1391
{
1392
  diag_type new = (diag_type) xcalloc(1,sizeof(struct diag_type_t));
1393
 
1394
  new->key      = DIAG_TYPE_PTR;
1395
  new->been_outed = 0;
1396
 
1397
  new->data.ptr.object		= object;
1398
  new->data.ptr.qualifier	= qualifier;
1399
 
1400
  return new;
1401
}
1402
 
1403
diag_type f_diag_struct
1404
    PROTO_N ( (tdf_shape, n, fields) )
1405
    PROTO_T ( shape tdf_shape X tdfstring n X diag_field_list fields )
1406
{
1407
  diag_type new = (diag_type) xcalloc(1,sizeof(struct diag_type_t));
1408
 
1409
  new->key      = DIAG_TYPE_STRUCT;
1410
  new->been_outed = 0;
1411
 
1412
  new->data.t_struct.tdf_shape	= tdf_shape;
1413
  new->data.t_struct.nme	= n;
1414
  new->data.t_struct.fields	= fields;
1415
 
1416
  return new;
1417
}
1418
 
1419
diag_type f_diag_union
1420
    PROTO_N ( (tdf_shape, n, fields) )
1421
    PROTO_T ( shape tdf_shape X tdfstring n X diag_field_list fields )
1422
{
1423
  diag_type new = (diag_type) xcalloc(1,sizeof(struct diag_type_t));
1424
 
1425
  new->key      = DIAG_TYPE_UNION;
1426
  new->been_outed = 0;
1427
 
1428
  new->data.t_union.tdf_shape	= tdf_shape;
1429
  new->data.t_union.nme		= n;
1430
  new->data.t_union.fields	= fields;
1431
 
1432
  return new;
1433
}
1434
 
1435
diag_type f_diag_variety
1436
    PROTO_N ( (var) )
1437
    PROTO_T ( variety var )
1438
{
1439
  diag_type new = (diag_type) xcalloc(1,sizeof(struct diag_type_t));
1440
 
1441
  new->key      = DIAG_TYPE_VARIETY;
1442
  new->been_outed = 0;
1443
 
1444
  new->data.var	= var;
1445
 
1446
  return new;
1447
}
1448
 
1449
void init_diag_type
1450
    PROTO_Z ()
1451
{
1452
  return;
1453
}
1454
 
1455
/*-------------------------- DIAG TYPE HELPERS ---------------------*/
1456
/*---------------------------enum_values ---------------------------*/
1457
 
1458
enum_values f_make_enum_values
1459
    PROTO_N ( (value, n) )
1460
    PROTO_T ( exp value X tdfstring n )
1461
{
1462
  enum_values new = (enum_values) xcalloc(1,sizeof(struct enum_values_t));
1463
 
1464
  new->val	= value;
1465
  new->nme 	= n;
1466
 
1467
  return new;
1468
}
1469
 
1470
void init_enum_values
1471
    PROTO_Z ()
1472
{
1473
  return;
1474
}
1475
 
1476
enum_values_list new_enum_values_list
1477
    PROTO_N ( (n) )
1478
    PROTO_T ( int n )
1479
{
1480
  enum_values_list new = (enum_values_list)
1481
    xcalloc(1,sizeof(struct enum_values_list_t));
1482
 
1483
  new->len = n;
1484
  new->lastused = 0;
1485
  new->array = (enum_values *) xcalloc(n,sizeof( enum_values ));
1486
  return new;
1487
}
1488
 
1489
enum_values_list add_enum_values_list
1490
    PROTO_N ( (list, elem, index) )
1491
    PROTO_T ( enum_values_list list X enum_values elem X int index )
1492
{
1493
  UNUSED(index);
1494
  list->array[list->lastused++] = elem;
1495
  return list;
1496
}
1497
 
1498
/*--------------------------struct fields-------------------------*/
1499
diag_field f_make_diag_field
1500
    PROTO_N ( (field_name, wh, field_type) )
1501
    PROTO_T ( tdfstring field_name X exp wh X diag_type field_type )
1502
{
1503
  diag_field new = (diag_field) xcalloc(1,sizeof(struct diag_field_t));
1504
 
1505
  new->field_name	= field_name;
1506
  new->where		= wh;
1507
  new->field_type	= field_type;
1508
 
1509
  return new;
1510
 
1511
}
1512
 
1513
void init_diag_field
1514
    PROTO_Z ()
1515
{
1516
  return;
1517
}
1518
 
1519
diag_field_list new_diag_field_list
1520
    PROTO_N ( (n) )
1521
    PROTO_T ( int n )
1522
{
1523
  diag_field_list new = (diag_field_list)
1524
    xcalloc(1,sizeof(struct diag_field_list_t));
1525
 
1526
  new->len = n;
1527
  new->lastused = 0;
1528
  new->array = (diag_field*) xcalloc(n,sizeof( diag_field));
1529
  return new;
1530
}
1531
 
1532
diag_field_list add_diag_field_list
1533
    PROTO_N ( (list, elem, index) )
1534
    PROTO_T ( diag_field_list list X diag_field elem X int index )
1535
{
1536
  UNUSED(index);
1537
  list->array[list->lastused++] = elem;
1538
  return list;
1539
}
1540
 
1541
/*----------------------diag type list----------------------*/
1542
diag_type_list new_diag_type_list
1543
    PROTO_N ( (n) )
1544
    PROTO_T ( int n )
1545
{
1546
  diag_type_list new = (diag_type_list)
1547
    xcalloc(1,sizeof(struct diag_type_list_t));
1548
 
1549
  new->len = n;
1550
  new->lastused = 0;
1551
  new->array = (diag_type *) xcalloc(n,sizeof( diag_type ));
1552
  return new;
1553
}
1554
 
1555
diag_type_list add_diag_type_list
1556
    PROTO_N ( (list, elem,index) )
1557
    PROTO_T ( diag_type_list list X diag_type elem X int index )
1558
{
1559
  UNUSED(index);
1560
  list->array[list->lastused++] = elem;
1561
  return list;
1562
}
1563
/*----------------------------END HELPERS------------------------------------*/
1564
 
1565
/*-------------------------- sourcemark ---------------------------------*/
1566
 
1567
sourcemark f_make_sourcemark
1568
    PROTO_N ( (file, line_no, char_offset) )
1569
    PROTO_T ( filename file X nat line_no X nat char_offset )
1570
{
1571
  sourcemark new;
1572
  new.file	= file;
1573
  new.line_no	= line_no;
1574
  new.char_off	= char_offset;
1575
 
1576
  return new;
1577
}
1578
 
1579
void init_sourcemark
1580
    PROTO_Z ()
1581
{
1582
  return;
1583
}
1584
 
1585
/*------------------------------filename ------------------------*/
1586
 
1587
filename f_make_filename
1588
    PROTO_N ( (date, machine, file) )
1589
    PROTO_T ( nat date X tdfstring machine X tdfstring file )
1590
{
1591
  filename new;
1592
  new 	= (filename) xcalloc(1,sizeof(struct filename_t));
1593
  new->date 	= date;
1594
  new->machine	= machine;
1595
  new->file 	= file;
1596
 
1597
  INSPECT_FILENAME(new);
1598
  return new;
1599
}
1600
 
1601
 
1602
filename f_filename_apply_token
1603
    PROTO_N ( (token_value, token_args) )
1604
    PROTO_T ( token token_value X bitstream token_args )
1605
{
1606
   tokval v;
1607
   v = apply_tok(token_value, token_args, DIAG_FILENAME, (tokval*)0);
1608
   return v.tk_filename;
1609
}
1610
 
1611
/*----------------------------- diag tag ------------------------------*/
1612
 
1613
 
1614
void init_diag_tag
1615
    PROTO_Z ()
1616
{
1617
  return;
1618
}
1619
 
1620
diag_tag f_make_diag_tag
1621
    PROTO_N ( (num) )
1622
    PROTO_T ( tdfint num )
1623
{
1624
  return num;
1625
}
1626
 
1627
 
1628
/*---------------------------- diag_tagdef =diag_typeunit ------------------*/
1629
 
1630
void init_diag_tagdef
1631
    PROTO_Z ()
1632
{
1633
  return;
1634
}
1635
 
1636
diag_tagdef f_make_diag_tagdef
1637
    PROTO_N ( (t, dtype) )
1638
    PROTO_T ( tdfint t X diag_type dtype )
1639
{
1640
  diag_tagdef new;
1641
 
1642
  new.d_tag 	= t;
1643
  new.d_type	= dtype;
1644
 
1645
  return new;
1646
}
1647
 
1648
 
1649
void init_capsule_diagtags
1650
    PROTO_Z ()
1651
{
1652
  /* the space has been calloced in read_fns */
1653
 
1654
  int i;
1655
  for (i = 0; i < capsule_no_of_diagtags; ++i)
1656
  {
1657
    diag_tagdef * tp 	= &capsule_diag_tagtab[i];
1658
    tp->d_type = (diag_type) xcalloc(1,sizeof(struct diag_type_t));
1659
    tp->d_type->key = DIAG_TYPE_INITED;
1660
  }
1661
  return;
1662
}
1663
 
1664
void start_make_diagtype_unit
1665
    PROTO_N ( (toks, tags, als, diags) )
1666
    PROTO_T ( int toks X int tags X int als X int diags )
1667
{
1668
  int i;
1669
 
1670
  unit_no_of_tokens = toks;
1671
  unit_ind_tokens = (tok_define * *)xcalloc(unit_no_of_tokens,
1672
                    sizeof(tok_define *));
1673
  for (i = 0; i < unit_no_of_tokens; ++i)
1674
    unit_ind_tokens[i] = (tok_define*)0;
1675
 
1676
  unit_no_of_tags = tags;
1677
  unit_ind_tags = (dec * *)xcalloc(unit_no_of_tags,
1678
                    sizeof(dec *));
1679
  for (i = 0; i < unit_no_of_tags; ++i)
1680
    unit_ind_tags[i] = (dec*)0;
1681
 
1682
  unit_no_of_als = als;
1683
  unit_ind_als = (aldef * *)xcalloc(unit_no_of_als,
1684
                    sizeof(aldef *));
1685
  for (i = 0; i < unit_no_of_als; ++i)
1686
    unit_ind_als[i] = (aldef*)0;
1687
 
1688
  unit_no_of_diagtags = diags;
1689
  unit_ind_diagtags = (diag_tagdef * *)xcalloc(unit_no_of_diagtags,
1690
                    sizeof(diag_tagdef *));
1691
  for (i = 0; i < unit_no_of_diagtags; ++i)
1692
    unit_ind_diagtags[i] = (diag_tagdef *)0;
1693
  return;
1694
}
1695
 
1696
void init_unit_diagtags
1697
    PROTO_N ( (n) )
1698
    PROTO_T ( int n )
1699
{
1700
 
1701
  int i;
1702
 
1703
  unit_diag_tagdeftab = (diag_tagdef *) xcalloc(unit_no_of_diagtags - n,
1704
					sizeof(diag_tagdef));
1705
 
1706
  for (i = 0; i < unit_no_of_diagtags - n; ++i)
1707
  {
1708
    diag_tagdef * tp = &unit_diag_tagdeftab[i];
1709
    tp->d_type = (diag_type) xcalloc(1,sizeof(struct diag_type_t));
1710
    tp->d_type->key = DIAG_TYPE_INITED;
1711
  }
1712
  return;
1713
}
1714
 
1715
diag_type_unit f_make_diagtype_unit
1716
    PROTO_Z ()
1717
{
1718
  int i;
1719
  int j = 0;
1720
  int no_of_labels;
1721
 
1722
  for (i = 0; i < unit_no_of_tokens; ++i)
1723
  {
1724
    if (unit_ind_tokens[i] == (tok_define*)0)
1725
      unit_ind_tokens[i] = &unit_toktab[j++];
1726
  };
1727
 
1728
  j = 0;
1729
  for (i = 0; i < unit_no_of_tags; ++i)
1730
  {
1731
    if (unit_ind_tags[i] == (dec*)0)
1732
      unit_ind_tags[i] = &unit_tagtab[j++];
1733
  };
1734
 
1735
  j = 0;
1736
  for (i = 0; i < unit_no_of_als; ++i)
1737
  {
1738
    if (unit_ind_als[i] == (aldef*)0)
1739
      unit_ind_als[i] = &unit_altab[j++];
1740
  };
1741
 
1742
  j=0;
1743
  for (i = 0; i < unit_no_of_diagtags; ++i)
1744
  {
1745
    if (unit_ind_diagtags[i] == (diag_tagdef *)0)
1746
      unit_ind_diagtags[i] = &unit_diag_tagdeftab[j++];
1747
  };
1748
 
1749
  start_bytestream();
1750
  no_of_labels = small_dtdfint();
1751
  unit_no_of_labels = no_of_labels;
1752
  unit_labtab = (exp*)xcalloc(unit_no_of_labels, sizeof(exp));
1753
  IGNORE d_diag_tagdef_list();
1754
  end_bytestream();
1755
  OUTPUT_DIAG_TAGS();
1756
  return 0;
1757
}
1758
 
1759
diag_tagdef_list new_diag_tagdef_list
1760
    PROTO_N ( (n) )
1761
    PROTO_T ( int n )
1762
{
1763
  UNUSED(n);
1764
  return 0;
1765
}
1766
 
1767
diag_tagdef_list add_diag_tagdef_list
1768
    PROTO_N ( (list, elem, index) )
1769
    PROTO_T ( diag_tagdef_list list X diag_tagdef elem X int index )
1770
{
1771
  diag_tagdef * new = unit_ind_diagtags[natint(elem.d_tag)];
1772
  UNUSED(list); UNUSED(index);
1773
 
1774
  new->d_tag 	= elem.d_tag;
1775
  new->ext_name	= elem.ext_name;
1776
  IGNORE memcpy(new->d_type,elem.d_type,sizeof(struct diag_type_t));
1777
 
1778
  return 0;
1779
}
1780
 
1781
linkextern f_make_diagtagextern
1782
    PROTO_N ( (internal,ext) )
1783
    PROTO_T ( tdfint internal X external ext )
1784
{
1785
  diag_tagdef * dp = &capsule_diag_tagtab[natint(internal)];
1786
  char *nm = ext.ex.id.ints.chars;
1787
  char * id;
1788
  int idl = (int)strlen(nm);
1789
  int   j;
1790
 
1791
  /* copy it  in case we need to vandalize it sometime */
1792
 
1793
  id = (char *) xcalloc ( (idl + 1), sizeof (char));
1794
  id[idl] = 0;
1795
 
1796
  for (j = 0; j < idl; ++j)
1797
    id[j] = nm[j];
1798
 
1799
  dp->ext_name = id;
1800
 
1801
  return 1;
1802
}
1803
 
1804
diag_type f_use_diag_tag
1805
    PROTO_N ( (t) )
1806
    PROTO_T ( diag_tag t )
1807
{
1808
  return unit_ind_diagtags[natint(t)]->d_type;
1809
}
1810
 
1811
 
1812
void f_make_diagtaglink
1813
    PROTO_N ( (i, ext) )
1814
    PROTO_T ( tdfint i X tdfint ext )
1815
{
1816
  unit_ind_diagtags[natint(i)] =
1817
      &capsule_diag_tagtab[natint(ext)];
1818
  return;
1819
}
1820
 
1821
diag_descriptor f_dummy_diag_descriptor;
1822
diag_tag f_dummy_diag_tag;
1823
diag_tagdef f_dummy_diag_tagdef;
1824
diag_type f_dummy_diag_type;
1825
diag_tq f_dummy_diag_tq;
1826
filename f_dummy_filename;
1827
sourcemark f_dummy_sourcemark;
1828
 
1829
void init_diag_tq
1830
    PROTO_Z ()
1831
{
1832
  return;
1833
}
1834
 
1835
void init_filename
1836
    PROTO_Z ()
1837
{
1838
  return;
1839
}
1840
 
1841
void init_diag_type_unit
1842
    PROTO_Z ()
1843
{
1844
  return;
1845
}
1846
 
1847
void init_linkinfo_props
1848
    PROTO_Z ()
1849
{
1850
  return;
1851
}
1852
 
1853
 
1854
#endif