Subversion Repositories tendra.SVN

Rev

Rev 2 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2 Rev 7
Line -... Line 1...
-
 
1
/*
-
 
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
 */
1
/*
31
/*
2
    		 Crown Copyright (c) 1997
32
    		 Crown Copyright (c) 1997
3
    
33
 
4
    This TenDRA(r) Computer Program is subject to Copyright
34
    This TenDRA(r) Computer Program is subject to Copyright
5
    owned by the United Kingdom Secretary of State for Defence
35
    owned by the United Kingdom Secretary of State for Defence
6
    acting through the Defence Evaluation and Research Agency
36
    acting through the Defence Evaluation and Research Agency
7
    (DERA).  It is made available to Recipients with a
37
    (DERA).  It is made available to Recipients with a
8
    royalty-free licence for its use, reproduction, transfer
38
    royalty-free licence for its use, reproduction, transfer
9
    to other parties and amendment for any purpose not excluding
39
    to other parties and amendment for any purpose not excluding
10
    product development provided that any such use et cetera
40
    product development provided that any such use et cetera
11
    shall be deemed to be acceptance of the following conditions:-
41
    shall be deemed to be acceptance of the following conditions:-
12
    
42
 
13
        (1) Its Recipients shall ensure that this Notice is
43
        (1) Its Recipients shall ensure that this Notice is
14
        reproduced upon any copies or amended versions of it;
44
        reproduced upon any copies or amended versions of it;
15
    
45
 
16
        (2) Any amended version of it shall be clearly marked to
46
        (2) Any amended version of it shall be clearly marked to
17
        show both the nature of and the organisation responsible
47
        show both the nature of and the organisation responsible
18
        for the relevant amendment or amendments;
48
        for the relevant amendment or amendments;
19
    
49
 
20
        (3) Its onward transfer from a recipient to another
50
        (3) Its onward transfer from a recipient to another
21
        party shall be deemed to be that party's acceptance of
51
        party shall be deemed to be that party's acceptance of
22
        these conditions;
52
        these conditions;
23
    
53
 
24
        (4) DERA gives no warranty or assurance as to its
54
        (4) DERA gives no warranty or assurance as to its
25
        quality or suitability for any purpose and DERA accepts
55
        quality or suitability for any purpose and DERA accepts
26
        no liability whatsoever in relation to any use to which
56
        no liability whatsoever in relation to any use to which
27
        it may be put.
57
        it may be put.
28
*/
58
*/
Line 44... Line 74...
44
/*  Output format is PL TDF by default, 'tnc' if the macro TNC_SRC	*/
74
/*  Output format is PL TDF by default, 'tnc' if the macro TNC_SRC	*/
45
/*  is defined.								*/
75
/*  is defined.								*/
46
/*									*/
76
/*									*/
47
/************************************************************************/
77
/************************************************************************/
48
 
78
 
49
 
79
 
50
#include <stdio.h>
80
#include <stdio.h>
51
#include <stddef.h>
81
#include <stddef.h>
52
#include <limits.h>
82
#include <limits.h>
53
#include "ossg.h"
-
 
54
/* Defined in '../../../../utilities/shared' */
83
/* Defined in '../../../../utilities/shared' */
55
 
84
 
56
 
85
 
57
static void out_nat
86
static void
58
    PROTO_N ((name,value))
-
 
59
    PROTO_T (char* name X int value)
87
out_nat(char *name, int value)
60
{
88
{
61
#ifdef TNC_SRC
89
#ifdef TNC_SRC
62
	(void)printf("( make_tokdef .~%s nat %d )\n\n", name, value);
90
	(void)printf("( make_tokdef .~%s nat %d )\n\n", name, value);
63
#else	/* PL TDF source */
91
#else	/* PL TDF source */
64
	(void)printf("Tokdef .~%s = [] NAT %d;\n\n", name, value);
92
	(void)printf("Tokdef .~%s = [] NAT %d;\n\n", name, value);
65
#endif
93
#endif
66
	return;
94
	return;
67
}
95
}
68
 
96
 
69
 
97
 
70
static void out_bool
98
static void
71
    PROTO_N ((name,value))
-
 
72
    PROTO_T (char* name X int value)
99
out_bool(char *name, int value)
73
{
100
{
74
	char *str = ( value ? "true" : "false" );
101
	char *str = (value ? "true" : "false");
75
#ifdef TNC_SRC
102
#ifdef TNC_SRC
76
	(void)printf("( make_tokdef .~%s bool %s )\n\n", name, str);
103
	(void)printf("( make_tokdef .~%s bool %s )\n\n", name, str);
77
#else	/* PL TDF source */
104
#else	/* PL TDF source */
78
	(void)printf("Tokdef .~%s = [] BOOL %s;\n\n", name, str);
105
	(void)printf("Tokdef .~%s = [] BOOL %s;\n\n", name, str);
79
#endif
106
#endif
80
	return;
107
	return;
81
}
108
}
82
 
109
 
83
 
110
 
84
static int calc_width
111
static int
85
    PROTO_N ((s_max))
-
 
86
    PROTO_T (unsigned long s_max)
112
calc_width(unsigned long s_max)
87
{
113
{
88
	int i;
114
	int i;
89
	for (i=1;;i++) {
115
	for (i=1;;i++) {
90
		if ((((unsigned long)1)<<i) > s_max) return i+1;
116
		if ((((unsigned long)1) <<i) > s_max) return i+1;
91
	}
117
	}
92
	/* UNREACHED */
118
	/* UNREACHED */
93
}
119
}
94
 
120
 
95
#define width(c)	calc_width((unsigned long)(c))
121
#define width(c)	calc_width((unsigned long)(c))
96
 
122
 
97
 
123
 
98
int main
124
int
99
    PROTO_Z ()
125
main(void)
100
{
126
{
101
	int c_width, s_width, i_width, l_width, sz_width;
127
	int c_width, s_width, i_width, l_width, sz_width;
102
	int p_width, al_width, str_ch_width;
128
	int p_width, al_width, str_ch_width;
103
	int c_sgn, bf_sgn, bdiv, l_end;
129
	int c_sgn, bf_sgn, bdiv, l_end;
104
 
130
 
Line 131... Line 157...
131
	out_nat("long_width", l_width);
157
	out_nat("long_width", l_width);
132
 
158
 
133
#ifdef size_t_width
159
#ifdef size_t_width
134
	sz_width = size_t_width;
160
	sz_width = size_t_width;
135
#else
161
#else
136
	sz_width = sizeof(size_t) * c_width;
162
	sz_width = sizeof(size_t)* c_width;
137
#endif
163
#endif
138
	out_nat("size_t_width", sz_width);
164
	out_nat("size_t_width", sz_width);
139
 
165
 
140
#ifdef ptr_width
166
#ifdef ptr_width
141
	p_width = ptr_width;
167
	p_width = ptr_width;
142
#else
168
#else
143
	p_width = sizeof(char*) * c_width;
169
	p_width = sizeof(char*)* c_width;
144
#endif
170
#endif
145
	out_nat("ptr_width", p_width);
171
	out_nat("ptr_width", p_width);
146
 
172
 
147
#ifdef min_struct_rep
173
#ifdef min_struct_rep
148
	al_width = min_struct_rep;
174
	al_width = min_struct_rep;
149
	str_ch_width = min_struct_rep;
175
	str_ch_width = min_struct_rep;
150
#else
176
#else
151
	{
177
	{
152
		struct t { char c; struct { char c; } s; };
178
		struct t { char c; struct { char c; } s; };
153
		struct c { char c; };
179
		struct c { char c; };
154
		al_width = offsetof(struct t,s) * c_width;
180
		al_width = offsetof(struct t,s)* c_width;
155
		str_ch_width = sizeof(struct c) * c_width;
181
		str_ch_width = sizeof(struct c)* c_width;
156
	}
182
	}
157
#endif
183
#endif
158
	if (al_width == str_ch_width)
184
	if (al_width == str_ch_width) {
159
		out_nat("min_struct_rep", al_width);
185
		out_nat("min_struct_rep", al_width);
-
 
186
	}
160
 
187
 
161
#ifdef char_is_signed
188
#ifdef char_is_signed
162
	c_sgn = char_is_signed;
189
	c_sgn = char_is_signed;
163
#else
190
#else
164
	c_sgn = (CHAR_MIN<0) ? 1 : 0;
191
	c_sgn = (CHAR_MIN<0)? 1 : 0;
165
#endif
192
#endif
166
	out_nat("char_is_signed", c_sgn);
193
	out_nat("char_is_signed", c_sgn);
167
 
194
 
168
#ifdef bitfield_is_signed
195
#ifdef bitfield_is_signed
169
	bf_sgn = bitfield_is_signed;
196
	bf_sgn = bitfield_is_signed;
170
#else
197
#else
171
	{
198
	{
172
		struct { int ibits : 2; } s;
199
		struct { int ibits : 2; } s;
173
		s.ibits = -1;
200
		s.ibits = -1;
174
		bf_sgn = (s.ibits<0) ? 1 : 0;
201
		bf_sgn = (s.ibits<0)? 1 : 0;
175
	}
202
	}
176
#endif
203
#endif
177
	out_nat("bitfield_is_signed", bf_sgn);
204
	out_nat("bitfield_is_signed", bf_sgn);
178
 
205
 
179
#ifdef best_div
206
#ifdef best_div
180
	bdiv = best_div;
207
	bdiv = best_div;
181
#else
208
#else
182
	bdiv = (4%(-6)>0)+1;
209
	bdiv = (4%(-6) >0) +1;
183
#endif
210
#endif
184
	out_nat("best_div", bdiv);
211
	out_nat("best_div", bdiv);
185
 
212
 
186
#ifdef little_endian
213
#ifdef little_endian
187
	l_end = little_endian;
214
	l_end = little_endian;
188
#else
215
#else
189
	{
216
	{
190
		unsigned u ;
217
		unsigned u;
191
		u = ('a' << 24) | ('b' << 16) | ('c' << 8) | ('d' << 0) ;
218
		u = ('a' << 24) | ('b' << 16) | ('c' << 8) | ('d' << 0);
192
		l_end = -1;
219
		l_end = -1;
193
		if (sizeof(u)==4 && *(char *)&u == 'd') l_end = 1;
220
		if (sizeof(u) ==4 && *(char *) &u == 'd')l_end = 1;
194
		if (sizeof(u)==4 && *(char *)&u == 'a') l_end = 0;
221
		if (sizeof(u) ==4 && *(char *) &u == 'a')l_end = 0;
195
	}
222
	}
196
#endif
223
#endif
197
	if (l_end >= 0 && l_end <= 1)
224
	if (l_end >= 0 && l_end <= 1) {
198
		out_bool("little_endian", l_end);
225
		out_bool("little_endian", l_end);
-
 
226
	}
199
 
227
 
200
	return 0;
228
	return 0;
201
}
229
}