34557be37b86cca6828bb6130f0f928bb44f3e82
[cacao.git] / src / vm / jit / ir / icmd.hpp
1 /* src/vm/jit/ir/icmd.hpp - Intermediate Commands
2
3    Copyright (C) 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 _ICMD_HPP
27 #define _ICMD_HPP
28
29 #include "config.h"
30
31 #include <stdint.h>
32
33 #include "vm/jit/ir/bytecode.h"
34
35
36 // JavaVM operation codes (sorted).
37 enum {
38         ICMD_NOP               = BC_nop,
39
40         ICMD_ACONST            = BC_aconst_null,
41
42         ICMD_CHECKNULL         = 2,
43
44         ICMD_ICONST            = BC_iconst_0,
45
46         /* 3 */
47         /* 4 */
48
49         ICMD_IDIVPOW2          = 5,
50         ICMD_LDIVPOW2          = 6,
51
52         /* 7 */
53         /* 8 */
54
55         ICMD_LCONST            = BC_lconst_0,
56
57         ICMD_LCMPCONST         = 10,
58
59         ICMD_FCONST            = BC_fconst_0,
60
61         /* 12 */
62         /* 13 */
63
64         ICMD_DCONST            = BC_dconst_0,
65
66         ICMD_COPY              = 15,
67         ICMD_MOVE              = 16,
68
69         /* 17 */
70         /* 18 */
71         /* 19 */
72         /* 20 */
73
74         /* Order of LOAD instructions must be equal to order of TYPE_*
75            defines. */
76
77         ICMD_ILOAD            = BC_iload,
78         ICMD_LLOAD            = BC_lload,
79         ICMD_FLOAD            = BC_fload,
80         ICMD_DLOAD            = BC_dload,
81         ICMD_ALOAD            = BC_aload,
82
83         ICMD_IADDCONST        = 26,
84         ICMD_ISUBCONST        = 27,
85         ICMD_IMULCONST        = 28,
86         ICMD_IANDCONST        = 29,
87         ICMD_IORCONST         = 30,
88         ICMD_IXORCONST        = 31,
89
90         ICMD_ISHLCONST        = 32,
91         ICMD_ISHRCONST        = 33,
92         ICMD_IUSHRCONST       = 34,
93
94         ICMD_IREMPOW2         = 35,
95
96         ICMD_LADDCONST        = 36,
97         ICMD_LSUBCONST        = 37,
98         ICMD_LMULCONST        = 38,
99         ICMD_LANDCONST        = 39,
100         ICMD_LORCONST         = 40,
101         ICMD_LXORCONST        = 41,
102
103         ICMD_LSHLCONST        = 42,
104         ICMD_LSHRCONST        = 43,
105         ICMD_LUSHRCONST       = 44,
106
107         ICMD_LREMPOW2         = 45,
108
109         ICMD_IALOAD           = BC_iaload,
110         ICMD_LALOAD           = BC_laload,
111         ICMD_FALOAD           = BC_faload,
112         ICMD_DALOAD           = BC_daload,
113         ICMD_AALOAD           = BC_aaload,
114         ICMD_BALOAD           = BC_baload,
115         ICMD_CALOAD           = BC_caload,
116         ICMD_SALOAD           = BC_saload,
117
118         /* Order of STORE instructions must be equal to order of TYPE_*
119            defines. */
120
121         ICMD_ISTORE           = BC_istore,
122         ICMD_LSTORE           = BC_lstore,
123         ICMD_FSTORE           = BC_fstore,
124         ICMD_DSTORE           = BC_dstore,
125         ICMD_ASTORE           = BC_astore,
126
127         ICMD_IF_LEQ           = 59,
128         ICMD_IF_LNE           = 60,
129         ICMD_IF_LLT           = 61,
130         ICMD_IF_LGE           = 62,
131         ICMD_IF_LGT           = 63,
132         ICMD_IF_LLE           = 64,
133
134         ICMD_IF_LCMPEQ        = 65,
135         ICMD_IF_LCMPNE        = 66,
136         ICMD_IF_LCMPLT        = 67,
137         ICMD_IF_LCMPGE        = 68,
138         ICMD_IF_LCMPGT        = 69,
139         ICMD_IF_LCMPLE        = 70,
140
141         /* 71 */
142         /* 72 */
143         /* 73 */
144         /* 74 */
145         /* 75 */
146         /* 76 */
147         /* 77 */
148         /* 78 */
149
150         ICMD_IASTORE          = BC_iastore,
151         ICMD_LASTORE          = BC_lastore,
152         ICMD_FASTORE          = BC_fastore,
153         ICMD_DASTORE          = BC_dastore,
154         ICMD_AASTORE          = BC_aastore,
155         ICMD_BASTORE          = BC_bastore,
156         ICMD_CASTORE          = BC_castore,
157         ICMD_SASTORE          = BC_sastore,
158
159         ICMD_POP              = BC_pop,
160         ICMD_POP2             = BC_pop2,
161         ICMD_DUP              = BC_dup,
162         ICMD_DUP_X1           = BC_dup_x1,
163         ICMD_DUP_X2           = BC_dup_x2,
164         ICMD_DUP2             = BC_dup2,
165         ICMD_DUP2_X1          = BC_dup2_x1,
166         ICMD_DUP2_X2          = BC_dup2_x2,
167         ICMD_SWAP             = BC_swap,
168
169         ICMD_IADD             = BC_iadd,
170         ICMD_LADD             = BC_ladd,
171         ICMD_FADD             = BC_fadd,
172         ICMD_DADD             = BC_dadd,
173
174         ICMD_ISUB             = BC_isub,
175         ICMD_LSUB             = BC_lsub,
176         ICMD_FSUB             = BC_fsub,
177         ICMD_DSUB             = BC_dsub,
178
179         ICMD_IMUL             = BC_imul,
180         ICMD_LMUL             = BC_lmul,
181         ICMD_FMUL             = BC_fmul,
182         ICMD_DMUL             = BC_dmul,
183
184         ICMD_IDIV             = BC_idiv,
185         ICMD_LDIV             = BC_ldiv,
186         ICMD_FDIV             = BC_fdiv,
187         ICMD_DDIV             = BC_ddiv,
188
189         ICMD_IREM             = BC_irem,
190         ICMD_LREM             = BC_lrem,
191         ICMD_FREM             = BC_frem,
192         ICMD_DREM             = BC_drem,
193
194         ICMD_INEG             = BC_ineg,
195         ICMD_LNEG             = BC_lneg,
196         ICMD_FNEG             = BC_fneg,
197         ICMD_DNEG             = BC_dneg,
198
199         ICMD_ISHL             = BC_ishl,
200         ICMD_LSHL             = BC_lshl,
201         ICMD_ISHR             = BC_ishr,
202         ICMD_LSHR             = BC_lshr,
203         ICMD_IUSHR            = BC_iushr,
204         ICMD_LUSHR            = BC_lushr,
205
206         ICMD_IAND             = BC_iand,
207         ICMD_LAND             = BC_land,
208         ICMD_IOR              = BC_ior,
209         ICMD_LOR              = BC_lor,
210         ICMD_IXOR             = BC_ixor,
211         ICMD_LXOR             = BC_lxor,
212
213         ICMD_IINC             = BC_iinc,
214
215         ICMD_I2L              = BC_i2l,
216         ICMD_I2F              = BC_i2f,
217         ICMD_I2D              = BC_i2d,
218         ICMD_L2I              = BC_l2i,
219         ICMD_L2F              = BC_l2f,
220         ICMD_L2D              = BC_l2d,
221         ICMD_F2I              = BC_f2i,
222         ICMD_F2L              = BC_f2l,
223         ICMD_F2D              = BC_f2d,
224         ICMD_D2I              = BC_d2i,
225         ICMD_D2L              = BC_d2l,
226         ICMD_D2F              = BC_d2f,
227
228         ICMD_INT2BYTE         = BC_int2byte,
229         ICMD_INT2CHAR         = BC_int2char,
230         ICMD_INT2SHORT        = BC_int2short,
231
232         ICMD_LCMP             = BC_lcmp,
233         ICMD_FCMPL            = BC_fcmpl,
234         ICMD_FCMPG            = BC_fcmpg,
235         ICMD_DCMPL            = BC_dcmpl,
236         ICMD_DCMPG            = BC_dcmpg,
237
238         ICMD_IFEQ             = BC_ifeq,
239         ICMD_IFNE             = BC_ifne,
240         ICMD_IFLT             = BC_iflt,
241         ICMD_IFGE             = BC_ifge,
242         ICMD_IFGT             = BC_ifgt,
243         ICMD_IFLE             = BC_ifle,
244
245         ICMD_IF_ICMPEQ        = BC_if_icmpeq,
246         ICMD_IF_ICMPNE        = BC_if_icmpne,
247         ICMD_IF_ICMPLT        = BC_if_icmplt,
248         ICMD_IF_ICMPGE        = BC_if_icmpge,
249         ICMD_IF_ICMPGT        = BC_if_icmpgt,
250         ICMD_IF_ICMPLE        = BC_if_icmple,
251         ICMD_IF_ACMPEQ        = BC_if_acmpeq,
252         ICMD_IF_ACMPNE        = BC_if_acmpne,
253
254         ICMD_GOTO             = BC_goto,
255         ICMD_JSR              = BC_jsr,
256         ICMD_RET              = BC_ret,
257
258         ICMD_TABLESWITCH      = BC_tableswitch,
259         ICMD_LOOKUPSWITCH     = BC_lookupswitch,
260
261         ICMD_IRETURN          = BC_ireturn,
262         ICMD_LRETURN          = BC_lreturn,
263         ICMD_FRETURN          = BC_freturn,
264         ICMD_DRETURN          = BC_dreturn,
265         ICMD_ARETURN          = BC_areturn,
266         ICMD_RETURN           = BC_return,
267
268         ICMD_GETSTATIC        = BC_getstatic,
269         ICMD_PUTSTATIC        = BC_putstatic,
270         ICMD_GETFIELD         = BC_getfield,
271         ICMD_PUTFIELD         = BC_putfield,
272
273         ICMD_INVOKEVIRTUAL    = BC_invokevirtual,
274         ICMD_INVOKESPECIAL    = BC_invokespecial,
275         ICMD_INVOKESTATIC     = BC_invokestatic,
276         ICMD_INVOKEINTERFACE  = BC_invokeinterface,
277
278         /* 186 */
279
280         ICMD_NEW              = BC_new,
281         ICMD_NEWARRAY         = BC_newarray,
282         ICMD_ANEWARRAY        = BC_anewarray,
283
284         ICMD_ARRAYLENGTH      = BC_arraylength,
285
286         ICMD_ATHROW           = BC_athrow,
287
288         ICMD_CHECKCAST        = BC_checkcast,
289         ICMD_INSTANCEOF       = BC_instanceof,
290
291         ICMD_MONITORENTER     = BC_monitorenter,
292         ICMD_MONITOREXIT      = BC_monitorexit,
293
294         /* 196 */
295
296         ICMD_MULTIANEWARRAY   = BC_multianewarray,
297
298         ICMD_IFNULL           = BC_ifnull,
299         ICMD_IFNONNULL        = BC_ifnonnull,
300
301         /* 200 */
302         /* 201 */
303         /* 202 */
304
305         ICMD_IASTORECONST     = 204,
306         ICMD_LASTORECONST     = 205,
307         ICMD_FASTORECONST     = 206,
308         ICMD_DASTORECONST     = 207,
309         ICMD_AASTORECONST     = 208,
310         ICMD_BASTORECONST     = 209,
311         ICMD_CASTORECONST     = 210,
312         ICMD_SASTORECONST     = 211,
313
314         ICMD_PUTSTATICCONST   = 212,
315         ICMD_PUTFIELDCONST    = 213,
316
317         ICMD_IMULPOW2         = 214,
318         ICMD_LMULPOW2         = 215,
319
320         ICMD_GETEXCEPTION     = 249,
321         ICMD_PHI              = 250,
322
323         ICMD_INLINE_START     = 251,        /* instruction before inlined method  */
324         ICMD_INLINE_END       = 252,        /* instruction after inlined method   */
325         ICMD_INLINE_BODY      = 253,        /* start of inlined body              */
326
327         ICMD_BUILTIN          = 255         /* internal opcode                    */
328 };
329
330
331 /* data-flow constants for the ICMD table ************************************/
332
333 #define DF_0_TO_0      0
334 #define DF_1_TO_0      1
335 #define DF_2_TO_0      2
336 #define DF_3_TO_0      3
337
338 #define DF_DST_BASE    4      /* from this value on, iptr->dst is a variable */
339
340 #define DF_0_TO_1      (DF_DST_BASE + 0)
341 #define DF_1_TO_1      (DF_DST_BASE + 1)
342 #define DF_2_TO_1      (DF_DST_BASE + 2)
343 #define DF_3_TO_1      (DF_DST_BASE + 3)
344 #define DF_N_TO_1      (DF_DST_BASE + 4)
345
346 #define DF_INVOKE      (DF_DST_BASE + 5)
347 #define DF_BUILTIN     (DF_DST_BASE + 6)
348
349 #define DF_COPY        (DF_DST_BASE + 7)
350 #define DF_MOVE        (DF_DST_BASE + 8)
351
352 #define DF_DUP         -1
353 #define DF_DUP_X1      -1
354 #define DF_DUP_X2      -1
355 #define DF_DUP2        -1
356 #define DF_DUP2_X1     -1
357 #define DF_DUP2_X2     -1
358 #define DF_SWAP        -1
359
360 /* special data-flow recognized by verify/generate.pl: */
361 #define DF_LOAD        DF_COPY
362 #define DF_STORE       DF_MOVE
363 #define DF_IINC        DF_1_TO_1
364 #define DF_POP         DF_1_TO_0
365 #define DF_POP2        DF_2_TO_0
366
367
368 // Control-flow constants for the ICMD table.
369 #define CF_NORMAL      0
370 #define CF_IF          1
371
372 #define CF_END_BASE    2  /* from here on, they mark the end of a superblock */
373
374 #define CF_END         (CF_END_BASE + 0)
375 #define CF_GOTO        (CF_END_BASE + 1)
376 #define CF_TABLE       (CF_END_BASE + 2)
377 #define CF_LOOKUP      (CF_END_BASE + 3)
378 #define CF_JSR         (CF_END_BASE + 4)
379 #define CF_RET         (CF_END_BASE + 5)
380
381
382 // Flag constants for the ICMD table.
383 #define ICMDTABLE_PEI    0x0001               /* ICMD may throw an exception */
384 #define ICMDTABLE_CALLS  0x0002     /* needs registers to be saved, may call */
385
386
387 // ICMD table entry.
388 typedef struct icmdtable_entry_t icmdtable_entry_t;
389
390 struct icmdtable_entry_t {
391 #if !defined(NDEBUG)
392         const char* name;                           /* name, without ICMD_ prefix */
393 #endif
394         int32_t dataflow;                            /* a DF_ constant, see above */
395         int32_t controlflow;                         /* a CF_ constant, see above */
396         int32_t flags;                       /* a combination of ICMDTABLE_ flags */
397 };
398
399
400 // The ICMD table.
401 extern icmdtable_entry_t icmd_table[256];
402
403 #endif // _ICMD_HPP
404
405
406 /*
407  * These are local overrides for various environment variables in Emacs.
408  * Please do not remove this and leave it at the end of the file, where
409  * Emacs will automagically detect them.
410  * ---------------------------------------------------------------------
411  * Local variables:
412  * mode: c++
413  * indent-tabs-mode: t
414  * c-basic-offset: 4
415  * tab-width: 4
416  * End:
417  * vim:noexpandtab:sw=4:ts=4:
418  */