2 |
7u83 |
1 |
/*
|
6 |
7u83 |
2 |
* Copyright (c) 2002-2005 The TenDRA Project <http://www.tendra.org/>.
|
|
|
3 |
* All rights reserved.
|
|
|
4 |
*
|
|
|
5 |
* Redistribution and use in source and binary forms, with or without
|
|
|
6 |
* modification, are permitted provided that the following conditions are met:
|
|
|
7 |
*
|
|
|
8 |
* 1. Redistributions of source code must retain the above copyright notice,
|
|
|
9 |
* this list of conditions and the following disclaimer.
|
|
|
10 |
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
|
11 |
* this list of conditions and the following disclaimer in the documentation
|
|
|
12 |
* and/or other materials provided with the distribution.
|
|
|
13 |
* 3. Neither the name of The TenDRA Project nor the names of its contributors
|
|
|
14 |
* may be used to endorse or promote products derived from this software
|
|
|
15 |
* without specific, prior written permission.
|
|
|
16 |
*
|
|
|
17 |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS
|
|
|
18 |
* IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
|
|
19 |
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
|
20 |
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
|
|
|
21 |
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
|
|
22 |
* EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
|
23 |
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
|
|
24 |
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
|
|
25 |
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
|
|
26 |
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
|
|
27 |
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
28 |
*
|
|
|
29 |
* $Id$
|
|
|
30 |
*/
|
|
|
31 |
/*
|
2 |
7u83 |
32 |
Crown Copyright (c) 1997
|
6 |
7u83 |
33 |
|
2 |
7u83 |
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:-
|
6 |
7u83 |
42 |
|
2 |
7u83 |
43 |
(1) Its Recipients shall ensure that this Notice is
|
|
|
44 |
reproduced upon any copies or amended versions of it;
|
6 |
7u83 |
45 |
|
2 |
7u83 |
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;
|
6 |
7u83 |
49 |
|
2 |
7u83 |
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;
|
6 |
7u83 |
53 |
|
2 |
7u83 |
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 |
#ifndef CONSTANT_INCLUDED
|
|
|
62 |
#define CONSTANT_INCLUDED
|
|
|
63 |
|
|
|
64 |
|
|
|
65 |
/*
|
|
|
66 |
CONSTANT EVALUATION MACROS
|
|
|
67 |
|
|
|
68 |
All the calculation routines are based on lists of unsigned int's
|
6 |
7u83 |
69 |
holding values in the range [0, 0xffff]. The type unsigned long is
|
|
|
70 |
guaranteed to contain at least the range [0, 0xffffffff]. All
|
2 |
7u83 |
71 |
calculations are performed in this double precision type to allow for
|
|
|
72 |
overflows. The macros LO_HALF, HI_HALF, EXTEND_VALUE and COMBINE_VALUES
|
|
|
73 |
are used for converting to and from the extended type.
|
|
|
74 |
*/
|
|
|
75 |
|
|
|
76 |
#define NAT_DIGITS 16
|
6 |
7u83 |
77 |
#define NAT_MASK ((unsigned)0xffff)
|
2 |
7u83 |
78 |
|
6 |
7u83 |
79 |
#define LO_HALF(A) ((unsigned)((A) & NAT_MASK))
|
|
|
80 |
#define HI_HALF(A) (LO_HALF((A) >> NAT_DIGITS))
|
2 |
7u83 |
81 |
|
6 |
7u83 |
82 |
#define EXTEND_VALUE(A) ((unsigned long)(A))
|
|
|
83 |
#define COMBINE_VALUES(A, B) (EXTEND_VALUE(A) +\
|
|
|
84 |
(EXTEND_VALUE(B) << NAT_DIGITS))
|
|
|
85 |
#define EXTENDED_MAX COMBINE_VALUES(NAT_MASK, NAT_MASK)
|
2 |
7u83 |
86 |
|
|
|
87 |
|
|
|
88 |
/*
|
|
|
89 |
CONSTANT EVALUATION DECLARATIONS
|
|
|
90 |
|
|
|
91 |
The routines in this module are concerned with constructing and
|
|
|
92 |
performing calculations with integer constant expressions.
|
|
|
93 |
*/
|
|
|
94 |
|
6 |
7u83 |
95 |
extern void init_constant(void);
|
|
|
96 |
extern void init_float(FLOAT_TYPE);
|
|
|
97 |
extern FLOAT get_float(TYPE, int);
|
2 |
7u83 |
98 |
|
6 |
7u83 |
99 |
extern NAT make_nat_literal(NAT, unsigned, unsigned);
|
|
|
100 |
extern NAT make_large_nat(LIST(unsigned));
|
|
|
101 |
extern NAT make_nat_value(unsigned long);
|
|
|
102 |
extern NAT make_small_nat(int);
|
|
|
103 |
extern unsigned long get_nat_value(NAT);
|
|
|
104 |
extern NAT negate_nat(NAT);
|
|
|
105 |
extern NAT binary_nat_op(unsigned, NAT, NAT);
|
|
|
106 |
extern int compare_nat(NAT, NAT);
|
|
|
107 |
extern int eq_nat(NAT, NAT);
|
2 |
7u83 |
108 |
|
6 |
7u83 |
109 |
extern int check_nat_range(TYPE, NAT);
|
|
|
110 |
extern int check_type_size(TYPE, NAT);
|
|
|
111 |
extern NAT max_type_value(TYPE, int);
|
|
|
112 |
extern void check_bounds(int, TYPE, EXP);
|
|
|
113 |
extern unsigned eval_const_cond(EXP);
|
|
|
114 |
extern unsigned no_bits(unsigned);
|
|
|
115 |
extern int divides_nat(EXP, EXP);
|
|
|
116 |
extern int is_zero_nat(NAT);
|
|
|
117 |
extern int is_negative_nat(NAT);
|
|
|
118 |
extern int is_error_nat(NAT);
|
|
|
119 |
extern int is_calc_nat(NAT);
|
|
|
120 |
extern int is_zero_exp(EXP);
|
|
|
121 |
extern int is_literal(EXP);
|
2 |
7u83 |
122 |
|
|
|
123 |
|
|
|
124 |
/*
|
|
|
125 |
CONSTANT EVALUATION ROUTINES
|
|
|
126 |
|
|
|
127 |
These routines are concerned with the evaluation of integer constant
|
|
|
128 |
expressions. They are so designed that the int_lit expressions are
|
|
|
129 |
precisely the constant-expressions from the grammar.
|
|
|
130 |
*/
|
|
|
131 |
|
6 |
7u83 |
132 |
extern EXP make_test_nat(EXP);
|
|
|
133 |
extern EXP make_unary_nat(unsigned, EXP);
|
|
|
134 |
extern EXP make_binary_nat(unsigned, EXP, EXP);
|
|
|
135 |
extern EXP make_compare_nat(NTEST, EXP, EXP);
|
|
|
136 |
extern EXP make_cond_nat(EXP, EXP, EXP);
|
|
|
137 |
extern EXP make_cast_nat(TYPE, EXP, ERROR *, unsigned);
|
|
|
138 |
extern EXP make_int_exp(TYPE, unsigned, NAT);
|
|
|
139 |
extern NAT make_nat_exp(EXP, ERROR *);
|
|
|
140 |
extern EXP calc_nat_value(NAT, TYPE);
|
2 |
7u83 |
141 |
|
|
|
142 |
#define SMALL_NAT_SIZE 257
|
|
|
143 |
#define SMALL_NAT_ALLOC 17
|
|
|
144 |
#define SMALL_FLT_SIZE 2
|
|
|
145 |
|
6 |
7u83 |
146 |
extern NAT small_neg_nat[SMALL_NAT_SIZE];
|
|
|
147 |
extern NAT small_nat[SMALL_NAT_SIZE];
|
|
|
148 |
extern string small_number[SMALL_FLT_SIZE];
|
2 |
7u83 |
149 |
|
|
|
150 |
|
|
|
151 |
#endif
|