* SUCK_BE_*: We can't use optimized version on MIPS because of alignment.
[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 3876 2005-12-05 19:03:54Z 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/loader.h"
44
45
46 /* macros to read LE and BE types from a buffer ********************************
47
48    BE macros are for class file loading.
49    LE macros are for ZIP file loading.
50
51 *******************************************************************************/
52
53 #if WORDS_BIGENDIAN == 0
54
55 /* we can optimize the LE access on little endian machines */
56
57 #define SUCK_LE_U1(p)    *((u1 *) (p))
58 #define SUCK_LE_U2(p)    *((u2 *) (p))
59 #define SUCK_LE_U4(p)    *((u4 *) (p))
60
61 #if U8_AVAILABLE == 1
62 #define SUCK_LE_U8(p)    *((u8 *) (p))
63 #endif
64
65 #define SUCK_BE_U1(p) \
66       ((u1) (p)[0])
67
68 #define SUCK_BE_U2(p) \
69     ((((u2) (p)[0]) << 8) + \
70       ((u2) (p)[1]))
71
72 #define SUCK_BE_U4(p) \
73     ((((u4) (p)[0]) << 24) + \
74      (((u4) (p)[1]) << 16) + \
75      (((u4) (p)[2]) << 8) + \
76       ((u4) (p)[3]))
77
78 #if U8_AVAILABLE == 1
79 #define SUCK_BE_U8(p) \
80     ((((u8) (p)[0]) << 56) + \
81      (((u8) (p)[1]) << 48) + \
82      (((u8) (p)[2]) << 40) + \
83      (((u8) (p)[3]) << 32) + \
84      (((u8) (p)[4]) << 24) + \
85      (((u8) (p)[5]) << 16) + \
86      (((u8) (p)[6]) << 8) + \
87       ((u8) (p)[7]))
88 #endif
89
90 #else /* WORDS_BIGENDIAN == 0 */
91
92 #define SUCK_LE_U1(p) \
93       ((u1) (p)[0])
94
95 #define SUCK_LE_U2(p) \
96     ((((u2) (p)[1]) << 8) + \
97       ((u2) (p)[0]))
98
99 #define SUCK_LE_U4(p) \
100     ((((u4) (p)[3]) << 24) + \
101      (((u4) (p)[2]) << 16) + \
102      (((u4) (p)[1]) << 8) + \
103       ((u4) (p)[0]))
104
105 #if U8_AVAILABLE == 1
106 #define SUCK_LE_U8(p) \
107     ((((u8) (p)[7]) << 56) + \
108      (((u8) (p)[6]) << 48) + \
109      (((u8) (p)[5]) << 40) + \
110      (((u8) (p)[4]) << 32) + \
111      (((u8) (p)[3]) << 24) + \
112      (((u8) (p)[2]) << 16) + \
113      (((u8) (p)[1]) << 8) + \
114       ((u8) (p)[0]))
115 #endif
116
117 /* we can optimize the BE access on big endian machines */
118
119 #if defined(__MIPS__)
120
121 /* MIPS needs aligned access */
122
123 #define SUCK_BE_U1(p) \
124       ((u1) (p)[0])
125
126 #define SUCK_BE_U2(p) \
127     ((((u2) (p)[0]) << 8) + \
128       ((u2) (p)[1]))
129
130 #define SUCK_BE_U4(p) \
131     ((((u4) (p)[0]) << 24) + \
132      (((u4) (p)[1]) << 16) + \
133      (((u4) (p)[2]) << 8) + \
134       ((u4) (p)[3]))
135
136 #if U8_AVAILABLE == 1
137 #define SUCK_BE_U8(p) \
138     ((((u8) (p)[0]) << 56) + \
139      (((u8) (p)[1]) << 48) + \
140      (((u8) (p)[2]) << 40) + \
141      (((u8) (p)[3]) << 32) + \
142      (((u8) (p)[4]) << 24) + \
143      (((u8) (p)[5]) << 16) + \
144      (((u8) (p)[6]) << 8) + \
145       ((u8) (p)[7]))
146 #endif
147
148 #else /* defined(__MIPS__) */
149
150 #define SUCK_BE_U1(p)    *((u1 *) (p))
151 #define SUCK_BE_U2(p)    *((u2 *) (p))
152 #define SUCK_BE_U4(p)    *((u4 *) (p))
153
154 #if U8_AVAILABLE == 1
155 #define SUCK_BE_U8(p)    *((u8 *) (p))
156 #endif
157
158 #endif /* defined(__MIPS__) */
159
160 #endif /* WORDS_BIGENDIAN == 0 */
161
162
163 /* signed suck defines ********************************************************/
164
165 #define suck_s1(a)    (s1) suck_u1((a))
166 #define suck_s2(a)    (s2) suck_u2((a))
167 #define suck_s4(a)    (s4) suck_u4((a))
168 #define suck_s8(a)    (s8) suck_u8((a))
169
170
171 /* function prototypes ********************************************************/
172
173 bool suck_init(char *classpath);
174
175 bool suck_check_classbuffer_size(classbuffer *cb, s4 len);
176
177 u1 suck_u1(classbuffer *cb);
178 u2 suck_u2(classbuffer *cb);
179 u4 suck_u4(classbuffer *cb);
180 u8 suck_u8(classbuffer *cb);
181
182 float suck_float(classbuffer *cb);
183 double suck_double(classbuffer *cb);
184
185 void suck_nbytes(u1 *buffer, classbuffer *cb, s4 len);
186 void suck_skip_nbytes(classbuffer *cb, s4 len);
187
188 classbuffer *suck_start(classinfo *c);
189
190 void suck_stop(classbuffer *cb);
191
192 #endif /* _SUCK_H */
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  */