* list_classpath_entry: Renamed classes to htclasses.
[cacao.git] / src / vm / suck.h
1 /* src/vm/suck.h - functions to read LE ordered types from a buffer
2
3    Copyright (C) 1996-2005 R. Grafl, A. Krall, C. Kruegel, C. Oates,
4    R. Obermaisser, M. Platter, M. Probst, S. Ring, E. Steiner,
5    C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich, J. Wenninger,
6    Institut f. Computersprachen - TU Wien
7
8    This file is part of CACAO.
9
10    This program is free software; you can redistribute it and/or
11    modify it under the terms of the GNU General Public License as
12    published by the Free Software Foundation; either version 2, or (at
13    your option) any later version.
14
15    This program is distributed in the hope that it will be useful, but
16    WITHOUT ANY WARRANTY; without even the implied warranty of
17    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18    General Public License for more details.
19
20    You should have received a copy of the GNU General Public License
21    along with this program; if not, write to the Free Software
22    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
23    02111-1307, USA.
24
25    Contact: cacao@complang.tuwien.ac.at
26
27    Authors: Christian Thalinger
28
29    Changes:
30
31    $Id: suck.h 3959 2005-12-20 23:25:07Z twisti $
32
33 */
34
35
36 #ifndef _SUCK_H
37 #define _SUCK_H
38
39 #include "config.h"
40 #include "vm/types.h"
41
42 #include "vm/class.h"
43 #include "vm/hashtable.h"
44 #include "vm/loader.h"
45
46
47 /* list_classpath_entry *******************************************************/
48
49 enum {
50         CLASSPATH_PATH,
51         CLASSPATH_ARCHIVE
52 };
53
54 typedef struct list_classpath_entry list_classpath_entry;
55
56 struct list_classpath_entry {
57 #if defined(USE_THREADS)
58         /* Required for monitor locking on zip/jar files. */
59         java_objectheader  header;
60 #endif                            
61         s4                 type;
62         char              *path;
63         s4                 pathlen;
64 #if defined(ENABLE_ZLIB)
65         hashtable         *htclasses;
66 #endif
67         listnode           linkage;
68 };
69
70
71 /* macros to read LE and BE types from a buffer ********************************
72
73    BE macros are for class file loading.
74    LE macros are for ZIP file loading.
75
76 *******************************************************************************/
77
78 #if WORDS_BIGENDIAN == 0
79
80 /* we can optimize the LE access on little endian machines */
81
82 #define SUCK_LE_U1(p)    *((u1 *) (p))
83 #define SUCK_LE_U2(p)    *((u2 *) (p))
84 #define SUCK_LE_U4(p)    *((u4 *) (p))
85
86 #if U8_AVAILABLE == 1
87 #define SUCK_LE_U8(p)    *((u8 *) (p))
88 #endif
89
90 #define SUCK_BE_U1(p) \
91       ((u1) (p)[0])
92
93 #define SUCK_BE_U2(p) \
94     ((((u2) (p)[0]) << 8) + \
95       ((u2) (p)[1]))
96
97 #define SUCK_BE_U4(p) \
98     ((((u4) (p)[0]) << 24) + \
99      (((u4) (p)[1]) << 16) + \
100      (((u4) (p)[2]) << 8) + \
101       ((u4) (p)[3]))
102
103 #if U8_AVAILABLE == 1
104 #define SUCK_BE_U8(p) \
105     ((((u8) (p)[0]) << 56) + \
106      (((u8) (p)[1]) << 48) + \
107      (((u8) (p)[2]) << 40) + \
108      (((u8) (p)[3]) << 32) + \
109      (((u8) (p)[4]) << 24) + \
110      (((u8) (p)[5]) << 16) + \
111      (((u8) (p)[6]) << 8) + \
112       ((u8) (p)[7]))
113 #endif
114
115 #else /* WORDS_BIGENDIAN == 0 */
116
117 #define SUCK_LE_U1(p) \
118       ((u1) (p)[0])
119
120 #define SUCK_LE_U2(p) \
121     ((((u2) (p)[1]) << 8) + \
122       ((u2) (p)[0]))
123
124 #define SUCK_LE_U4(p) \
125     ((((u4) (p)[3]) << 24) + \
126      (((u4) (p)[2]) << 16) + \
127      (((u4) (p)[1]) << 8) + \
128       ((u4) (p)[0]))
129
130 #if U8_AVAILABLE == 1
131 #define SUCK_LE_U8(p) \
132     ((((u8) (p)[7]) << 56) + \
133      (((u8) (p)[6]) << 48) + \
134      (((u8) (p)[5]) << 40) + \
135      (((u8) (p)[4]) << 32) + \
136      (((u8) (p)[3]) << 24) + \
137      (((u8) (p)[2]) << 16) + \
138      (((u8) (p)[1]) << 8) + \
139       ((u8) (p)[0]))
140 #endif
141
142 /* we can optimize the BE access on big endian machines */
143
144 #if defined(__MIPS__)
145
146 /* MIPS needs aligned access */
147
148 #define SUCK_BE_U1(p) \
149       ((u1) (p)[0])
150
151 #define SUCK_BE_U2(p) \
152     ((((u2) (p)[0]) << 8) + \
153       ((u2) (p)[1]))
154
155 #define SUCK_BE_U4(p) \
156     ((((u4) (p)[0]) << 24) + \
157      (((u4) (p)[1]) << 16) + \
158      (((u4) (p)[2]) << 8) + \
159       ((u4) (p)[3]))
160
161 #if U8_AVAILABLE == 1
162 #define SUCK_BE_U8(p) \
163     ((((u8) (p)[0]) << 56) + \
164      (((u8) (p)[1]) << 48) + \
165      (((u8) (p)[2]) << 40) + \
166      (((u8) (p)[3]) << 32) + \
167      (((u8) (p)[4]) << 24) + \
168      (((u8) (p)[5]) << 16) + \
169      (((u8) (p)[6]) << 8) + \
170       ((u8) (p)[7]))
171 #endif
172
173 #else /* defined(__MIPS__) */
174
175 #define SUCK_BE_U1(p)    *((u1 *) (p))
176 #define SUCK_BE_U2(p)    *((u2 *) (p))
177 #define SUCK_BE_U4(p)    *((u4 *) (p))
178
179 #if U8_AVAILABLE == 1
180 #define SUCK_BE_U8(p)    *((u8 *) (p))
181 #endif
182
183 #endif /* defined(__MIPS__) */
184
185 #endif /* WORDS_BIGENDIAN == 0 */
186
187
188 /* signed suck defines ********************************************************/
189
190 #define suck_s1(a)    (s1) suck_u1((a))
191 #define suck_s2(a)    (s2) suck_u2((a))
192 #define suck_s4(a)    (s4) suck_u4((a))
193 #define suck_s8(a)    (s8) suck_u8((a))
194
195
196 /* export variables ***********************************************************/
197
198 extern list *list_classpath_entries;
199
200
201 /* function prototypes ********************************************************/
202
203 bool suck_init(void);
204
205 void suck_add(char *classpath);
206
207 bool suck_check_classbuffer_size(classbuffer *cb, s4 len);
208
209 u1 suck_u1(classbuffer *cb);
210 u2 suck_u2(classbuffer *cb);
211 u4 suck_u4(classbuffer *cb);
212 u8 suck_u8(classbuffer *cb);
213
214 float suck_float(classbuffer *cb);
215 double suck_double(classbuffer *cb);
216
217 void suck_nbytes(u1 *buffer, classbuffer *cb, s4 len);
218 void suck_skip_nbytes(classbuffer *cb, s4 len);
219
220 classbuffer *suck_start(classinfo *c);
221
222 void suck_stop(classbuffer *cb);
223
224 #endif /* _SUCK_H */
225
226 /*
227  * These are local overrides for various environment variables in Emacs.
228  * Please do not remove this and leave it at the end of the file, where
229  * Emacs will automagically detect them.
230  * ---------------------------------------------------------------------
231  * Local variables:
232  * mode: c
233  * indent-tabs-mode: t
234  * c-basic-offset: 4
235  * tab-width: 4
236  * End:
237  */