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