extended type system to use symbolic references
[cacao.git] / src / vm / jit / codegen.inc.h
1 /* src/vm/jit/codegen.inc.h - code generation header
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: codegen.inc.h 2181 2005-04-01 16:53:33Z edwin $
32
33 */
34
35
36 #ifndef _CODEGEN_INC_H
37 #define _CODEGEN_INC_H
38
39 /* We typedef these structures before #includes to resolve circular           */
40 /* dependencies.                                                              */
41
42 typedef struct codegendata codegendata;
43 typedef struct branchref branchref;
44 typedef struct jumpref jumpref;
45 typedef struct dataref dataref;
46 typedef struct clinitref clinitref;
47 typedef struct linenumberref linenumberref;
48 typedef struct threadcritnodetemp threadcritnodetemp;
49
50
51 #include "types.h"
52 #include "vm/global.h"
53 #include "vm/references.h"
54 #include "vm/method.h"
55 #include "vm/jit/jit.h"
56 #include "vm/jit/reg.h"
57 #include "vm/jit/inline/inline.h"
58
59
60 #define MCODEINITSIZE (1<<15)       /* 32 Kbyte code area initialization size */
61 #define DSEGINITSIZE  (1<<12)       /*  4 Kbyte data area initialization size */
62
63 #if POINTERSIZE == 8
64 #define dseg_addaddress(cd,value)    dseg_adds8((cd), (s8) (value))
65 #else
66 #define dseg_addaddress(cd,value)    dseg_adds4((cd), (s4) (value))
67 #endif
68
69
70 /************************* critical sections  *********************************/
71
72 struct threadcritnodetemp {
73         threadcritnodetemp *next;
74         s4                  mcodebegin;
75         s4                  mcodeend;
76         s4                  mcoderestart;
77 };
78
79
80 struct codegendata {
81         u1             *mcodebase;      /* base pointer of code area              */
82         s4             *mcodeend;       /* pointer to end of code area            */
83         s4              mcodesize;      /* complete size of code area (bytes)     */
84
85 #if defined(__I386__) || defined(__X86_64__)
86         u1             *mcodeptr;       /* code generation pointer                */
87 #endif
88
89         u1             *dsegtop;        /* pointer to top (end) of data area      */
90         s4              dsegsize;       /* complete size of data area (bytes)     */
91         s4              dseglen;        /* used size of data area (bytes)         */
92                                     /* data area grows from top to bottom     */
93
94         jumpref        *jumpreferences; /* list of jumptable target addresses     */
95         dataref        *datareferences; /* list of data segment references        */
96         branchref      *xboundrefs;     /* list of bound check branches           */
97         branchref      *xcheckarefs;    /* list of array size check branches      */
98         branchref      *xnullrefs;      /* list of null check branches            */
99         branchref      *xcastrefs;      /* list of cast check branches            */
100         branchref      *xdivrefs;       /* list of divide by zero branches        */
101         branchref      *xexceptionrefs; /* list of exception branches             */
102         clinitref      *clinitrefs;
103
104         linenumberref  *linenumberreferences; /* list of line numbers and the     */
105                                         /* program counters of their first        */
106                                         /* instruction                            */
107         s4              linenumbertablesizepos;
108         s4              linenumbertablestartpos;
109         s4              linenumbertab;
110
111         methodinfo     *method;
112         s4              exceptiontablelength; /* exceptiontable length            */
113         exceptiontable *exceptiontable; /* the exceptiontable                     */
114
115         threadcritnodetemp *threadcrit; /* List of critical code regions          */
116         threadcritnodetemp threadcritcurrent;
117         s4                 threadcritcount; /* Number of critical regions         */
118
119         s4              maxstack;
120         s4              maxlocals;
121 };
122
123
124 /***************** forward references in branch instructions ******************/
125
126 struct branchref {
127         s4         branchpos;       /* patching position in code segment          */
128         s4         reg;             /* used for ArrayIndexOutOfBounds index reg   */
129         branchref *next;            /* next element in branchref list             */
130 };
131
132
133 /******************** forward references in tables  ***************************/
134
135 struct jumpref {
136         s4          tablepos;       /* patching position in data segment          */
137         basicblock *target;         /* target basic block                         */
138         jumpref    *next;           /* next element in jumpref list               */
139 };
140
141
142 struct dataref {
143         u1      *pos;               /* patching position in generated code        */
144         dataref *next;              /* next element in dataref list               */
145 };
146
147
148 struct clinitref {
149         s4         branchpos;
150         classinfo *class;
151         clinitref *next;
152 };
153
154
155 struct linenumberref {
156         s4             tablepos;    /* patching position in data segment          */
157         s4             targetmpc;   /* machine code program counter of first      */
158                                     /* instruction for given line                 */
159         u2             linenumber;  /* line number, used for inserting into the   */
160                                     /* table and for validty checking             */
161         linenumberref *next;        /* next element in linenumberref list         */
162 };
163
164
165 #if defined(__I386__) || defined(__X86_64__)
166 typedef struct _methodtree_element methodtree_element;
167
168 struct _methodtree_element {
169         functionptr startpc;
170         functionptr endpc;
171 };
172 #endif
173
174
175 /* function prototypes ********************************************************/
176
177 void codegen_init();
178 void codegen_setup(methodinfo *m, codegendata *cd, t_inlining_globals *e);
179 void codegen(methodinfo *m, codegendata *cd, registerdata *rd);
180 void codegen_free(methodinfo *m, codegendata *cd);
181 void codegen_close();
182 void codegen_insertmethod(functionptr startpc, functionptr endpc);
183
184 #if defined(__I386__) || defined(__X86_64__)
185 functionptr codegen_findmethod(functionptr pc);
186 #elif defined(__ALPHA__)
187 void *codegen_findmethod(void *returnAdress);
188 #endif
189
190 #if defined(__I386__) || defined(__X86_64__)
191 void codegen_addreference(codegendata *cd, struct basicblock *target, void *branchptr);
192 #endif
193
194
195 void dseg_display(methodinfo *m, codegendata *cd);
196
197 void init_exceptions();
198
199
200 u1 *createcompilerstub(methodinfo *m);
201 u1 *createnativestub(functionptr f, methodinfo *m);
202
203 void removecompilerstub(u1 *stub);
204 void removenativestub(u1 *stub);
205
206 #endif /* _CODEGEN_INC_H */
207
208
209 /*
210  * These are local overrides for various environment variables in Emacs.
211  * Please do not remove this and leave it at the end of the file, where
212  * Emacs will automagically detect them.
213  * ---------------------------------------------------------------------
214  * Local variables:
215  * mode: c
216  * indent-tabs-mode: t
217  * c-basic-offset: 4
218  * tab-width: 4
219  * End:
220  */