Merge from subtype.
[cacao.git] / src / vm / suck.hpp
1 /* src/vm/suck.hpp - functions to read LE ordered types from a buffer
2
3    Copyright (C) 1996-2005, 2006, 2007, 2008
4    CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
5
6    This file is part of CACAO.
7
8    This program is free software; you can redistribute it and/or
9    modify it under the terms of the GNU General Public License as
10    published by the Free Software Foundation; either version 2, or (at
11    your option) any later version.
12
13    This program is distributed in the hope that it will be useful, but
14    WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16    General Public License for more details.
17
18    You should have received a copy of the GNU General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21    02110-1301, USA.
22
23 */
24
25
26 #ifndef _SUCK_HPP
27 #define _SUCK_HPP
28
29 #include "config.h"
30
31 #include "vm/types.h"
32
33 #include "threads/mutex.hpp"
34
35 #include "toolbox/hashtable.h"
36 #include "toolbox/list.hpp"
37
38 #include "vm/class.hpp"
39 #include "vm/global.h"
40 #include "vm/loader.hpp"
41
42
43 /* list_classpath_entry *******************************************************/
44
45 enum {
46         CLASSPATH_PATH,
47         CLASSPATH_ARCHIVE
48 };
49
50 typedef struct list_classpath_entry list_classpath_entry;
51
52 struct list_classpath_entry {
53 #if defined(ENABLE_THREADS)
54         Mutex             *mutex;               /* mutex locking on zip/jar files */
55 #endif
56         s4                 type;
57         char              *path;
58         s4                 pathlen;
59 #if defined(ENABLE_ZLIB)
60         hashtable         *htclasses;
61 #endif
62 };
63
64
65 /* macros to read LE and BE types from a buffer ********************************
66
67    BE macros are for Java class file loading.
68    LE macros are for ZIP file loading.
69
70 *******************************************************************************/
71
72 /* LE macros (for ZIP files ) *************************************************/
73
74 #if defined(__I386__) || defined(__X86_64__)
75
76 /* we can optimize the LE access on little endian machines without alignment */
77
78 #define SUCK_LE_U1(p)    *((u1 *) (p))
79 #define SUCK_LE_U2(p)    *((u2 *) (p))
80 #define SUCK_LE_U4(p)    *((u4 *) (p))
81 #define SUCK_LE_U8(p)    *((u8 *) (p))
82
83 #else /* defined(__I386__) || defined(__X86_64__) */
84
85 #define SUCK_LE_U1(p) \
86       ((u1) (p)[0])
87
88 #define SUCK_LE_U2(p) \
89     ((((u2) (p)[1]) << 8) + \
90       ((u2) (p)[0]))
91
92 #define SUCK_LE_U4(p) \
93     ((((u4) (p)[3]) << 24) + \
94      (((u4) (p)[2]) << 16) + \
95      (((u4) (p)[1]) << 8) + \
96       ((u4) (p)[0]))
97
98 #define SUCK_LE_U8(p) \
99     ((((u8) (p)[7]) << 56) + \
100      (((u8) (p)[6]) << 48) + \
101      (((u8) (p)[5]) << 40) + \
102      (((u8) (p)[4]) << 32) + \
103      (((u8) (p)[3]) << 24) + \
104      (((u8) (p)[2]) << 16) + \
105      (((u8) (p)[1]) << 8) + \
106       ((u8) (p)[0]))
107
108 #endif /* defined(__I386__) || defined(__X86_64__) */
109
110
111 /* BE macros (for Java class files ) ******************************************/
112
113 #define SUCK_BE_U1(p) \
114       ((u1) (p)[0])
115
116 #define SUCK_BE_U2(p) \
117     ((((u2) (p)[0]) << 8) + \
118       ((u2) (p)[1]))
119
120 #define SUCK_BE_U4(p) \
121     ((((u4) (p)[0]) << 24) + \
122      (((u4) (p)[1]) << 16) + \
123      (((u4) (p)[2]) << 8) + \
124       ((u4) (p)[3]))
125
126 #define SUCK_BE_U8(p) \
127     ((((u8) (p)[0]) << 56) + \
128      (((u8) (p)[1]) << 48) + \
129      (((u8) (p)[2]) << 40) + \
130      (((u8) (p)[3]) << 32) + \
131      (((u8) (p)[4]) << 24) + \
132      (((u8) (p)[5]) << 16) + \
133      (((u8) (p)[6]) << 8) + \
134       ((u8) (p)[7]))
135
136
137 #define SUCK_BE_S1(p)    (s1) SUCK_BE_U1(p)
138 #define SUCK_BE_S2(p)    (s2) SUCK_BE_U2(p)
139 #define SUCK_BE_S4(p)    (s4) SUCK_BE_U4(p)
140 #define SUCK_BE_S8(p)    (s8) SUCK_BE_U8(p)
141
142
143 /* signed suck defines ********************************************************/
144
145 #define suck_s1(a)    (s1) suck_u1((a))
146 #define suck_s2(a)    (s2) suck_u2((a))
147 #define suck_s4(a)    (s4) suck_u4((a))
148 #define suck_s8(a)    (s8) suck_u8((a))
149
150
151 /* export variables ***********************************************************/
152
153 #ifdef __cplusplus
154 extern List<list_classpath_entry*>* list_classpath_entries;
155 #else
156 extern List* list_classpath_entries;
157 #endif
158
159 /* function prototypes ********************************************************/
160
161 #ifdef __cplusplus
162 extern "C" {
163 #endif
164
165 bool suck_init(void);
166
167 void suck_add(char *classpath);
168 void suck_add_from_property(const char *key);
169
170 bool suck_check_classbuffer_size(classbuffer *cb, s4 len);
171
172 u1 suck_u1(classbuffer *cb);
173 u2 suck_u2(classbuffer *cb);
174 u4 suck_u4(classbuffer *cb);
175 u8 suck_u8(classbuffer *cb);
176
177 float suck_float(classbuffer *cb);
178 double suck_double(classbuffer *cb);
179
180 void suck_nbytes(u1 *buffer, classbuffer *cb, s4 len);
181 void suck_skip_nbytes(classbuffer *cb, s4 len);
182
183 classbuffer *suck_start(classinfo *c);
184
185 void suck_stop(classbuffer *cb);
186
187 #ifdef __cplusplus
188 }
189 #endif
190
191 #endif // _SUCK_HPP
192
193
194 /*
195  * These are local overrides for various environment variables in Emacs.
196  * Please do not remove this and leave it at the end of the file, where
197  * Emacs will automagically detect them.
198  * ---------------------------------------------------------------------
199  * Local variables:
200  * mode: c++
201  * indent-tabs-mode: t
202  * c-basic-offset: 4
203  * tab-width: 4
204  * End:
205  * vim:noexpandtab:sw=4:ts=4:
206  */