* src/vm/jit/emit-common.c: Moved to .cpp.
[cacao.git] / src / vm / jit / emit-common.hpp
1 /* src/vm/jit/emit-common.hpp - common code emitter functions
2
3    Copyright (C) 2006, 2007 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., 51 Franklin Street, Fifth Floor, Boston, MA
23    02110-1301, USA.
24
25 */
26
27
28 #ifndef _EMIT_COMMON_H
29 #define _EMIT_COMMON_H
30
31 #include "config.h"
32 #include "vm/types.h"
33
34 #include "arch.h"
35
36 #include "vm/jit/codegen-common.h"
37 #include "vm/jit/jit.hpp"
38
39
40 /* branch labels **************************************************************/
41
42 #define BRANCH_LABEL_1    1
43 #define BRANCH_LABEL_2    2
44 #define BRANCH_LABEL_3    3
45 #define BRANCH_LABEL_4    4
46 #define BRANCH_LABEL_5    5
47 #define BRANCH_LABEL_6    6
48
49
50 /* constant range macros ******************************************************/
51
52 #if SIZEOF_VOID_P == 8
53
54 # define IS_IMM8(c) \
55     (((s8) (c) >= -128) && ((s8) (c) <= 127))
56
57 # define IS_IMM32(c) \
58     (((s8) (c) >= (-2147483647-1)) && ((s8) (c) <= 2147483647))
59
60 #else
61
62 # define IS_IMM8(c) \
63     (((s4) (c) >= -128) && ((s4) (c) <= 127))
64
65 # define IS_IMM16(c) \
66     (((s4) (c) >= -32768) && ((s4) (c) <= 32767))
67
68 #endif
69
70
71 /* code generation functions **************************************************/
72
73 #ifdef __cplusplus
74 extern "C" {
75 #endif
76
77 s4 emit_load(jitdata *jd, instruction *iptr, varinfo *src, s4 tempreg);
78 s4 emit_load_s1(jitdata *jd, instruction *iptr, s4 tempreg);
79 s4 emit_load_s2(jitdata *jd, instruction *iptr, s4 tempreg);
80 s4 emit_load_s3(jitdata *jd, instruction *iptr, s4 tempreg);
81
82 #if SIZEOF_VOID_P == 4
83 s4 emit_load_low(jitdata *jd, instruction *iptr, varinfo *src, s4 tempreg);
84 s4 emit_load_s1_low(jitdata *jd, instruction *iptr, s4 tempreg);
85 s4 emit_load_s2_low(jitdata *jd, instruction *iptr, s4 tempreg);
86 s4 emit_load_s3_low(jitdata *jd, instruction *iptr, s4 tempreg);
87
88 s4 emit_load_high(jitdata *jd, instruction *iptr, varinfo *src, s4 tempreg);
89 s4 emit_load_s1_high(jitdata *jd, instruction *iptr, s4 tempreg);
90 s4 emit_load_s2_high(jitdata *jd, instruction *iptr, s4 tempreg);
91 s4 emit_load_s3_high(jitdata *jd, instruction *iptr, s4 tempreg);
92 #endif
93
94 void emit_store(jitdata *jd, instruction *iptr, varinfo *dst, s4 d);
95 void emit_store_dst(jitdata *jd, instruction *iptr, s4 d);
96
97 #if SIZEOF_VOID_P == 4
98 void emit_store_low(jitdata *jd, instruction *iptr, varinfo *dst, s4 d);
99 void emit_store_high(jitdata *jd, instruction *iptr, varinfo *dst, s4 d);
100 #endif
101
102 void emit_copy(jitdata *jd, instruction *iptr);
103
104 void emit_iconst(codegendata *cd, s4 d, s4 value);
105 void emit_lconst(codegendata *cd, s4 d, s8 value);
106
107 /* branch-emitting functions */
108 void emit_bccz(codegendata *cd, basicblock *target, s4 condition, s4 reg, u4 options);
109 void emit_bcc(codegendata *cd, basicblock *target, s4 condition, u4 options);
110
111 /* wrapper for unconditional branches */
112 void emit_br(codegendata *cd, basicblock *target);
113
114 /* wrappers for branches on one integer register */
115
116 #if SUPPORT_BRANCH_CONDITIONAL_ONE_INTEGER_REGISTER
117 void emit_beqz(codegendata *cd, basicblock *target, s4 reg);
118 void emit_bnez(codegendata *cd, basicblock *target, s4 reg);
119 void emit_bltz(codegendata *cd, basicblock *target, s4 reg);
120 void emit_bgez(codegendata *cd, basicblock *target, s4 reg);
121 void emit_bgtz(codegendata *cd, basicblock *target, s4 reg);
122 void emit_blez(codegendata *cd, basicblock *target, s4 reg);
123 #endif
124
125 /* wrappers for branches on two integer registers */
126
127 #if SUPPORT_BRANCH_CONDITIONAL_TWO_INTEGER_REGISTERS
128 void emit_beq(codegendata *cd, basicblock *target, s4 s1, s4 s2);
129 void emit_bne(codegendata *cd, basicblock *target, s4 s1, s4 s2);
130 #endif
131
132 /* wrappers for branches on condition codes */
133
134 #if SUPPORT_BRANCH_CONDITIONAL_CONDITION_REGISTER
135 void emit_beq(codegendata *cd, basicblock *target);
136 void emit_bne(codegendata *cd, basicblock *target);
137 void emit_blt(codegendata *cd, basicblock *target);
138 void emit_bge(codegendata *cd, basicblock *target);
139 void emit_bgt(codegendata *cd, basicblock *target);
140 void emit_ble(codegendata *cd, basicblock *target);
141 #endif
142
143 #if SUPPORT_BRANCH_CONDITIONAL_UNSIGNED_CONDITIONS
144 void emit_bult(codegendata *cd, basicblock *target);
145 void emit_bule(codegendata *cd, basicblock *target);
146 void emit_buge(codegendata *cd, basicblock *target);
147 void emit_bugt(codegendata *cd, basicblock *target);
148 #endif
149
150 #if defined(__POWERPC__) || defined(__POWERPC64__)
151 void emit_bnan(codegendata *cd, basicblock *target);
152 #endif
153
154 /* label-branches */
155 void emit_label_bccz(codegendata *cd, s4 label, s4 condition, s4 reg, u4 options);
156 void emit_label(codegendata *cd, s4 label);
157 void emit_label_bcc(codegendata *cd, s4 label, s4 condition, u4 options);
158
159 void emit_label_br(codegendata *cd, s4 label);
160
161 #if SUPPORT_BRANCH_CONDITIONAL_ONE_INTEGER_REGISTER
162 void emit_label_beqz(codegendata *cd, s4 label, s4 reg);
163 #endif
164
165 #if SUPPORT_BRANCH_CONDITIONAL_CONDITION_REGISTER
166 void emit_label_beq(codegendata *cd, s4 label);
167 void emit_label_bne(codegendata *cd, s4 label);
168 void emit_label_blt(codegendata *cd, s4 label);
169 void emit_label_bge(codegendata *cd, s4 label);
170 void emit_label_bgt(codegendata *cd, s4 label);
171 void emit_label_ble(codegendata *cd, s4 label);
172 #endif
173
174 /* machine dependent branch-emitting function */
175 void emit_branch(codegendata *cd, s4 disp, s4 condition, s4 reg, u4 options);
176
177 void emit_arithmetic_check(codegendata *cd, instruction *iptr, s4 reg);
178 void emit_arrayindexoutofbounds_check(codegendata *cd, instruction *iptr, s4 s1, s4 s2);
179 void emit_arraystore_check(codegendata *cd, instruction *iptr);
180 void emit_classcast_check(codegendata *cd, instruction *iptr, s4 condition, s4 reg, s4 s1);
181 void emit_nullpointer_check(codegendata *cd, instruction *iptr, s4 reg);
182 void emit_exception_check(codegendata *cd, instruction *iptr);
183
184 void emit_trap_compiler(codegendata *cd);
185 void emit_trap_countdown(codegendata *cd, s4 *counter);
186 uint32_t emit_trap(codegendata *cd);
187
188 void emit_patcher_traps(jitdata *jd);
189
190 void emit_verbosecall_enter(jitdata *jd);
191 void emit_verbosecall_exit(jitdata *jd);
192
193 #ifdef __cplusplus
194 }
195 #endif
196
197 #endif /* _EMIT_COMMON_H */
198
199
200 /*
201  * These are local overrides for various environment variables in Emacs.
202  * Please do not remove this and leave it at the end of the file, where
203  * Emacs will automagically detect them.
204  * ---------------------------------------------------------------------
205  * Local variables:
206  * mode: c
207  * indent-tabs-mode: t
208  * c-basic-offset: 4
209  * tab-width: 4
210  * End:
211  * vim:noexpandtab:sw=4:ts=4:
212  */