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
/*									*/
33
/*		gen_tokens.c	Version 2.0				*/
34
/*									*/
35
/*  This program produces some of the target dependency tokens		*/
36
/*  in 'PL TDF' or 'tnc' format for the target system it is		*/
37
/*  compiled and run on.						*/
38
/*									*/
39
/*  Results are not guaranteed - they should be checked.		*/
40
/*									*/
41
/*  Each token value may be pre-set by externally defining a macro	*/
42
/*  with the appropriate local name and value.				*/
43
/*									*/
44
/*  Output format is PL TDF by default, 'tnc' if the macro TNC_SRC	*/
45
/*  is defined.								*/
46
/*									*/
47
/************************************************************************/
48
 
49
 
50
#include <stdio.h>
51
#include <stddef.h>
52
#include <limits.h>
53
#include "ossg.h"
54
/* Defined in '../../../../utilities/shared' */
55
 
56
 
57
static void out_nat
58
    PROTO_N ((name,value))
59
    PROTO_T (char* name X int value)
60
{
61
#ifdef TNC_SRC
62
	(void)printf("( make_tokdef .~%s nat %d )\n\n", name, value);
63
#else	/* PL TDF source */
64
	(void)printf("Tokdef .~%s = [] NAT %d;\n\n", name, value);
65
#endif
66
	return;
67
}
68
 
69
 
70
static void out_bool
71
    PROTO_N ((name,value))
72
    PROTO_T (char* name X int value)
73
{
74
	char *str = ( value ? "true" : "false" );
75
#ifdef TNC_SRC
76
	(void)printf("( make_tokdef .~%s bool %s )\n\n", name, str);
77
#else	/* PL TDF source */
78
	(void)printf("Tokdef .~%s = [] BOOL %s;\n\n", name, str);
79
#endif
80
	return;
81
}
82
 
83
 
84
static int calc_width
85
    PROTO_N ((s_max))
86
    PROTO_T (unsigned long s_max)
87
{
88
	int i;
89
	for (i=1;;i++) {
90
		if ((((unsigned long)1)<<i) > s_max) return i+1;
91
	}
92
	/* UNREACHED */
93
}
94
 
95
#define width(c)	calc_width((unsigned long)(c))
96
 
97
 
98
int main
99
    PROTO_Z ()
100
{
101
	int c_width, s_width, i_width, l_width, sz_width;
102
	int p_width, al_width, str_ch_width;
103
	int c_sgn, bf_sgn, bdiv, l_end;
104
 
105
#ifdef char_width
106
	c_width = char_width;
107
#else
108
	c_width = width(SCHAR_MAX);
109
#endif
110
	out_nat("char_width", c_width);
111
 
112
#ifdef short_width
113
	s_width = short_width;
114
#else
115
	s_width = width(SHRT_MAX);
116
#endif
117
	out_nat("short_width", s_width);
118
 
119
#ifdef int_width
120
	i_width = int_width;
121
#else
122
	i_width = width(INT_MAX);
123
#endif
124
	out_nat("int_width", i_width);
125
 
126
#ifdef long_width
127
	l_width = long_width;
128
#else
129
	l_width = width(LONG_MAX);
130
#endif
131
	out_nat("long_width", l_width);
132
 
133
#ifdef size_t_width
134
	sz_width = size_t_width;
135
#else
136
	sz_width = sizeof(size_t) * c_width;
137
#endif
138
	out_nat("size_t_width", sz_width);
139
 
140
#ifdef ptr_width
141
	p_width = ptr_width;
142
#else
143
	p_width = sizeof(char*) * c_width;
144
#endif
145
	out_nat("ptr_width", p_width);
146
 
147
#ifdef min_struct_rep
148
	al_width = min_struct_rep;
149
	str_ch_width = min_struct_rep;
150
#else
151
	{
152
		struct t { char c; struct { char c; } s; };
153
		struct c { char c; };
154
		al_width = offsetof(struct t,s) * c_width;
155
		str_ch_width = sizeof(struct c) * c_width;
156
	}
157
#endif
158
	if (al_width == str_ch_width)
159
		out_nat("min_struct_rep", al_width);
160
 
161
#ifdef char_is_signed
162
	c_sgn = char_is_signed;
163
#else
164
	c_sgn = (CHAR_MIN<0) ? 1 : 0;
165
#endif
166
	out_nat("char_is_signed", c_sgn);
167
 
168
#ifdef bitfield_is_signed
169
	bf_sgn = bitfield_is_signed;
170
#else
171
	{
172
		struct { int ibits : 2; } s;
173
		s.ibits = -1;
174
		bf_sgn = (s.ibits<0) ? 1 : 0;
175
	}
176
#endif
177
	out_nat("bitfield_is_signed", bf_sgn);
178
 
179
#ifdef best_div
180
	bdiv = best_div;
181
#else
182
	bdiv = (4%(-6)>0)+1;
183
#endif
184
	out_nat("best_div", bdiv);
185
 
186
#ifdef little_endian
187
	l_end = little_endian;
188
#else
189
	{
190
		unsigned u ;
191
		u = ('a' << 24) | ('b' << 16) | ('c' << 8) | ('d' << 0) ;
192
		l_end = -1;
193
		if (sizeof(u)==4 && *(char *)&u == 'd') l_end = 1;
194
		if (sizeof(u)==4 && *(char *)&u == 'a') l_end = 0;
195
	}
196
#endif
197
	if (l_end >= 0 && l_end <= 1)
198
		out_bool("little_endian", l_end);
199
 
200
	return 0;
201
}