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