1 /****************************************************************************
3 * GNAT COMPILER COMPONENTS *
7 * C Implementation File *
10 * Copyright (C) 1992-2001 Free Software Foundation, Inc. *
12 * GNAT is free software; you can redistribute it and/or modify it under *
13 * terms of the GNU General Public License as published by the Free Soft- *
14 * ware Foundation; either version 2, or (at your option) any later ver- *
15 * sion. GNAT is distributed in the hope that it will be useful, but WITH- *
16 * OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY *
17 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License *
18 * for more details. You should have received a copy of the GNU General *
19 * Public License distributed with GNAT; see file COPYING. If not, write *
20 * to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, *
21 * MA 02111-1307, USA. *
23 * GNAT was originally developed by the GNAT team at New York University. *
24 * Extensive contributions were provided by Ada Core Technologies Inc. *
26 ****************************************************************************/
28 /* This file corresponds to the Ada package body Uintp. It was created
29 manually from the files uintp.ads and uintp.adb. */
33 #include "coretypes.h"
46 /* Universal integers are represented by the Uint type which is an index into
47 the Uints_Ptr table containing Uint_Entry values. A Uint_Entry contains an
48 index and length for getting the "digits" of the universal integer from the
51 For efficiency, this method is used only for integer values larger than the
52 constant Uint_Bias. If a Uint is less than this constant, then it contains
53 the integer value itself. The origin of the Uints_Ptr table is adjusted so
54 that a Uint value of Uint_Bias indexes the first element. */
56 /* Similarly to UI_To_Int, but return a GCC INTEGER_CST. Overflow is tested
57 by the constant-folding used to build the node. TYPE is the GCC type of the
61 UI_To_gnu (Input
, type
)
67 if (Input
<= Uint_Direct_Last
)
68 gnu_ret
= convert (type
, build_int_2 (Input
- Uint_Direct_Bias
,
69 Input
< Uint_Direct_Bias
? -1 : 0));
72 Int Idx
= Uints_Ptr
[Input
].Loc
;
73 Pos Length
= Uints_Ptr
[Input
].Length
;
74 Int First
= Udigits_Ptr
[Idx
];
75 /* Do computations in integer type or TYPE whichever is wider, then
76 convert later. This avoid overflow if type is short integer. */
78 = (TYPE_PRECISION (type
) >= TYPE_PRECISION (integer_type_node
)
79 ? type
: integer_type_node
);
80 tree gnu_base
= convert (comp_type
, build_int_2 (Base
, 0));
85 gnu_ret
= convert (comp_type
, build_int_2 (First
, First
< 0 ? -1 : 0));
87 for (Idx
++, Length
--; Length
; Idx
++, Length
--)
88 gnu_ret
= fold (build (MINUS_EXPR
, comp_type
,
89 fold (build (MULT_EXPR
, comp_type
,
92 build_int_2 (Udigits_Ptr
[Idx
], 0))));
94 for (Idx
++, Length
--; Length
; Idx
++, Length
--)
95 gnu_ret
= fold (build (PLUS_EXPR
, comp_type
,
96 fold (build (MULT_EXPR
, comp_type
,
99 build_int_2 (Udigits_Ptr
[Idx
], 0))));
102 gnu_ret
= convert (type
, gnu_ret
);
104 /* We don't need any NOP_EXPR or NON_LVALUE_EXPR on GNU_RET. */
105 while ((TREE_CODE (gnu_ret
) == NOP_EXPR
106 || TREE_CODE (gnu_ret
) == NON_LVALUE_EXPR
)
107 && TREE_TYPE (TREE_OPERAND (gnu_ret
, 0)) == TREE_TYPE (gnu_ret
))
108 gnu_ret
= TREE_OPERAND (gnu_ret
, 0);