Make-lang.in, [...]: Replace "GNU CC" with "GCC" in the copyright header.
[gcc.git] / gcc / java / javaop.h
1 /* Utility macros to handle Java(TM) byte codes.
2
3 Copyright (C) 1996, 1998, 1999, 2003 Free Software Foundation, Inc.
4
5 This file is part of GCC.
6
7 GCC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
11
12 GCC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA.
21
22 Java and all Java-based marks are trademarks or registered trademarks
23 of Sun Microsystems, Inc. in the United States and other countries.
24 The Free Software Foundation is independent of Sun Microsystems, Inc. */
25
26 /* Written by Per Bothner <bothner@cygnus.com>, February 1996. */
27
28 #ifndef GCC_JAVAOP_H
29 #define GCC_JAVAOP_H
30
31 typedef unsigned char uint8;
32 #ifndef int16
33 #define int16 short
34 #endif
35 typedef unsigned int16 uint16;
36
37 #ifndef int32
38 #define int32 long
39 #endif
40 typedef unsigned int32 uint32;
41
42 /* A signed 64-bit (or more) integral type, suiteable for Java's 'long'. */
43 #ifndef int64
44 #define int64 long long
45 #endif
46 /* An unsigned 64-bit (or more) integral type, same length as int64. */
47 #ifndef uint64
48 #define uint64 unsigned int64
49 #endif
50
51 typedef uint16 jchar;
52 #ifdef __STDC__
53 typedef signed char jbyte;
54 #else
55 typedef char jbyte;
56 #endif
57 typedef int16 jshort;
58 typedef int32 jint;
59 typedef int64 jlong;
60 typedef void* jref;
61
62 /* A 32-bit IEEE single-precision float. */
63 #ifndef jfloat
64 #define jfloat float
65 #endif
66
67 /* A 32-bit IEEE double-precision float. */
68 #ifndef jdouble
69 #define jdouble double
70 #endif
71
72 union Word {
73 jint i;
74 jfloat f;
75 void *p;
76 };
77
78 /* A jword is an unsigned integral type big enough for a 32-bit jint
79 or jfloat *or* a pointer. It is the type appropriate for stack
80 locations and local variables in a Java interpreter. */
81
82
83 #ifndef jword
84 #define jword uint32
85 #endif
86
87 #ifndef IMMEDIATE_u1
88 #define IMMEDIATE_u1 (PC++, CHECK_PC_IN_RANGE(PC), BCODE[PC-1])
89 #endif
90 #ifndef IMMEDIATE_s1
91 #define IMMEDIATE_s1 (PC++, CHECK_PC_IN_RANGE(PC), (signed char)BCODE[PC-1])
92 #endif
93 #ifndef IMMEDIATE_s2
94 #define IMMEDIATE_s2 (PC+=2, CHECK_PC_IN_RANGE(PC), \
95 (signed char) BCODE[PC-2] * 256 + BCODE[PC-1])
96 #endif
97 #ifndef IMMEDIATE_u2
98 #define IMMEDIATE_u2 (PC+=2, CHECK_PC_IN_RANGE(PC),\
99 (BCODE[PC-2] * 256 + BCODE[PC-1]))
100 #endif
101 #ifndef IMMEDIATE_s4
102 #define IMMEDIATE_s4 (PC+=4, CHECK_PC_IN_RANGE(PC), \
103 (WORD_TO_INT((BCODE[PC-4] << 24) | (BCODE[PC-3] << 16) \
104 | (BCODE[PC-2] << 8) | (BCODE[PC-1]))))
105 #endif
106
107 static inline jfloat
108 WORD_TO_FLOAT(jword w)
109 { union Word wu;
110 wu.i = w;
111 return wu.f;
112 }
113
114 /* Sign extend w. If the host on which this cross-compiler runs uses
115 a 64-bit type for jword the appropriate sign extension is
116 performed; if it's a 32-bit type the arithmetic does nothing but is
117 harmless. */
118 static inline jint
119 WORD_TO_INT(jword w)
120 {
121 jint n = w & 0xffffffff; /* Mask lower 32 bits. */
122 n ^= (jint)1 << 31;
123 n -= (jint)1 << 31; /* Sign extend lower 32 bits to upper. */
124 return n;
125 }
126
127 static inline jlong
128 WORDS_TO_LONG(jword hi, jword lo)
129 {
130 return ((jlong) hi << 32) | ((jlong)lo & (((jlong)1 << 32) -1));
131 }
132
133 union DWord {
134 jdouble d;
135 jlong l;
136 jword w[2];
137 };
138
139 static inline jdouble
140 WORDS_TO_DOUBLE(jword hi, jword lo)
141 { union DWord wu;
142 #if (1 == HOST_FLOAT_WORDS_BIG_ENDIAN)
143 wu.l = WORDS_TO_LONG(lo, hi);
144 #else
145 wu.l = WORDS_TO_LONG(hi, lo);
146 #endif
147 return wu.d;
148 }
149
150 /* If PREFIX_CHAR is the first character of the Utf8 encoding of a character,
151 return the number of bytes taken by the encoding.
152 Return -1 for a continuation character. */
153 #define UT8_CHAR_LENGTH(PREFIX_CHAR) \
154 ((unsigned char)(PREFIX_CHAR) < 128 ? 1 \
155 : ((PREFIX_CHAR) & 0x40) == 0 ? -1 \
156 : ((PREFIX_CHAR) & 0x20) == 0 ? 2 \
157 : ((PREFIX_CHAR) & 0x10) == 0 ? 3 \
158 : ((PREFIX_CHAR) & 0x08) == 0 ? 4 : 5)
159
160 #endif /* ! GCC_JAVAOP_H */