OSDN Git Service

Initial revision
[pf3gnuchains/gcc-fork.git] / gcc / java / javaop.h
1 /* Utility macros to handle Java(TM) byte codes.
2
3    Copyright (C) 1996  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 JAVAOP_H
27 #define JAVAOP_H
28
29 typedef char            int8;
30 typedef unsigned char   uint8;
31 #ifndef int16
32 #define int16 short
33 #endif
34 typedef unsigned int16  uint16;
35
36 #ifndef int32
37 #define int32 long
38 #endif
39 typedef unsigned int32  uint32;
40
41 /* A signed 64-bit (or more) integral type, suiteable for Java's 'long'. */
42 #ifndef int64
43 #define int64 long long
44 #endif
45 /* An unsigned 64-bit (or more) integral type, same length as int64. */
46 #ifndef uint64
47 #define uint64 unsigned int64
48 #endif
49
50 typedef uint16                  jchar;
51 typedef int8                    jbyte;
52 typedef int16                   jshort;
53 typedef int32                   jint;
54 typedef int64                   jlong;
55 typedef void*                   jref;
56
57 /* A 32-bit IEEE single-precision float. */
58 #ifndef jfloat 
59 #define jfloat float
60 #endif
61
62 /* A 32-bit IEEE double-precision float. */
63 #ifndef jdouble
64 #define jdouble double
65 #endif
66
67 union Word {
68   jint i;
69   jfloat f;
70   void *p;
71 };
72
73 /* A jword is an unsigned integral type big enough for a 32-bit jint
74    or jfloat *or* a pointer.  It is the type appropriate for stack
75    locations and local variables in a Java interpreter. */
76
77
78 #ifndef jword
79 #define jword uint32
80 #endif
81
82 #if !defined(inline) && !defined(__GC__) && !defined(__cplusplus)
83 #define inline static
84 #endif
85
86 #ifndef IMMEDIATE_u1
87 #define IMMEDIATE_u1 (PC++, CHECK_PC_IN_RANGE(PC), BCODE[PC-1])
88 #endif
89 #ifndef IMMEDIATE_s1
90 #define IMMEDIATE_s1 (PC++, CHECK_PC_IN_RANGE(PC), (signed char)BCODE[PC-1])
91 #endif
92 #ifndef IMMEDIATE_s2
93 #define IMMEDIATE_s2 (PC+=2, CHECK_PC_IN_RANGE(PC), \
94   (signed char) BCODE[PC-2] * 256 + BCODE[PC-1])
95 #endif
96 #ifndef IMMEDIATE_u2
97 #define IMMEDIATE_u2 (PC+=2, CHECK_PC_IN_RANGE(PC),\
98   (BCODE[PC-2] * 256 + BCODE[PC-1]))
99 #endif
100 #ifndef IMMEDIATE_s4
101 #define IMMEDIATE_s4 (PC+=4, CHECK_PC_IN_RANGE(PC), \
102   ((jint)((BCODE[PC-4] << 24) | (BCODE[PC-3] << 16) \
103          | (BCODE[PC-2] << 8) | (BCODE[PC-1]))))
104 #endif
105
106 inline jfloat
107 WORD_TO_FLOAT(jword w)
108 { union Word wu;
109   wu.i = w;
110   return wu.f;
111
112
113 inline jlong
114 WORDS_TO_LONG(jword hi, jword lo)
115 {
116   return ((jlong) hi << 32) | ((jlong)lo & (((jlong)1 << 32) -1));
117 }
118
119 union DWord {
120   jdouble d;
121   jlong l;
122   jword w[2];
123 };
124
125 inline jdouble
126 WORDS_TO_DOUBLE(jword hi, jword lo)
127 { union DWord wu;
128   wu.l = WORDS_TO_LONG(hi, lo);
129   return wu.d;
130
131
132 /* If PREFIX_CHAR is the first character of the Utf8 encoding of a character,
133    return the number of bytes taken by the encoding.
134    Return -1 for a continuation character.  */
135 #define UT8_CHAR_LENGTH(PREFIX_CHAR) \
136   ((unsigned char)(PREFIX_CHAR) < 128 ? 1 \
137    : ((PREFIX_CHAR) & 0x40) == 0 ? -1 \
138    : ((PREFIX_CHAR) & 0x20) == 0 ? 2 \
139    : ((PREFIX_CHAR) & 0x10) == 0 ? 3 \
140    : ((PREFIX_CHAR) & 0x08) == 0 ? 4 : 5)
141
142 #endif /* !JAVAOP_H */