c89 fix.
[cacao.git] / src / vm / jit / codegen.inc.h
1 /* jit/codegen.inc.h - code generation header
2
3    Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
4    R. Grafl, A. Krall, C. Kruegel, C. Oates, R. Obermaisser,
5    M. Probst, S. Ring, E. Steiner, C. Thalinger, D. Thuernbeck,
6    P. Tomsich, J. Wenninger
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    $Id: codegen.inc.h 1494 2004-11-12 13:34:26Z twisti $
30
31 */
32
33
34 #ifndef _CODEGEN_INC_H
35 #define _CODEGEN_INC_H
36
37 /* We typedef these structures before #includes to resolve circular           */
38 /* dependencies.                                                              */
39
40 typedef struct codegendata codegendata;
41 typedef struct branchref branchref;
42 typedef struct jumpref jumpref;
43 typedef struct dataref dataref;
44 typedef struct linenumberref linenumberref;
45 typedef struct threadcritnodetemp threadcritnodetemp;
46
47
48 #include "types.h"
49 #include "global.h"
50 #include "jit/inline.h"
51 #include "jit/reg.h"
52
53
54 #define MCODEINITSIZE (1<<15)       /* 32 Kbyte code area initialization size */
55 #define DSEGINITSIZE  (1<<12)       /*  4 Kbyte data area initialization size */
56
57 #if POINTERSIZE == 8
58 #define dseg_addaddress(cd,value)    dseg_adds8((cd), (s8) (value))
59 #else
60 #define dseg_addaddress(cd,value)    dseg_adds4((cd), (s4) (value))
61 #endif
62
63
64 /************************* critical sections  *********************************/
65
66 struct threadcritnodetemp {
67         threadcritnodetemp *next;
68         s4 mcodebegin;
69         s4 mcodeend;
70         s4 mcoderestart;
71 };
72
73
74 struct codegendata {
75         u1 *mcodebase;                  /* base pointer of code area              */
76         s4 *mcodeend;                   /* pointer to end of code area            */
77         s4  mcodesize;                  /* complete size of code area (bytes)     */
78
79         u1 *mcodeptr;                   /* code generation pointer                */
80
81         u1 *dsegtop;                    /* pointer to top (end) of data area      */
82         s4  dsegsize;                   /* complete size of data area (bytes)     */
83         s4  dseglen;                    /* used size of data area (bytes)         */
84                                     /* data area grows from top to bottom     */
85
86         jumpref   *jumpreferences;      /* list of jumptable target addresses     */
87         dataref   *datareferences;      /* list of data segment references        */
88         branchref *xboundrefs;          /* list of bound check branches           */
89         branchref *xcheckarefs;         /* list of array size check branches      */
90         branchref *xnullrefs;           /* list of null check branches            */
91         branchref *xcastrefs;           /* list of cast check branches            */
92         branchref *xdivrefs;            /* list of divide by zero branches        */
93         branchref *xexceptionrefs;      /* list of exception branches             */
94
95         linenumberref *linenumberreferences; /* list of line numbers and the      */
96                                         /* program counters of their first        */
97                                         /* instruction                            */
98         s4 linenumbertablesizepos;
99         s4 linenumbertablestartpos;
100         s4 linenumbertab;
101
102         methodinfo *method;
103         s4  exceptiontablelength;/* exceptiontable length                  */
104         exceptiontable *exceptiontable; /* the exceptiontable                     */
105
106         threadcritnodetemp *threadcrit; /* List of critical code regions          */
107         threadcritnodetemp threadcritcurrent;
108         s4 threadcritcount;             /* Number of critical regions             */
109         int maxstack;
110         int maxlocals;
111 };
112
113
114 /***************** forward references in branch instructions ******************/
115
116 struct branchref {
117         s4 branchpos;               /* patching position in code segment          */
118         s4 reg;                     /* used for ArrayIndexOutOfBounds index reg   */
119         branchref *next;            /* next element in branchref list             */
120 };
121
122
123 /******************** forward references in tables  ***************************/
124
125 struct jumpref {
126         s4 tablepos;                /* patching position in data segment          */
127         struct basicblock *target;  /* target basic block                         */
128         jumpref *next;              /* next element in jumpref list               */
129 };
130
131
132 struct dataref {
133         u1 *pos;                    /* patching position in generated code        */
134         dataref *next;              /* next element in dataref list               */
135 };
136
137
138 struct linenumberref {
139         s4 tablepos;                /* patching position in data segment          */
140         int targetmpc;              /* machine code program counter of first      */
141                                     /* instruction for given line                 */
142         u2 linenumber;              /* line number, used for inserting into the   */
143                                     /* table and for validty checking             */
144         linenumberref *next;        /* next element in linenumberref list         */
145 };
146
147
148 #if defined(__I386__) || defined(__X86_64__)
149 typedef struct _methodtree_element methodtree_element;
150
151 struct _methodtree_element {
152         functionptr startpc;
153         functionptr endpc;
154 };
155 #endif
156
157
158 /* function prototypes */
159
160 void codegen_init();
161 void codegen_setup(methodinfo *m, codegendata *cd, t_inlining_globals *e);
162 void codegen(methodinfo *m, codegendata *cd, registerdata *rd);
163 void codegen_free(methodinfo *m, codegendata *cd);
164 void codegen_close();
165 void codegen_insertmethod(functionptr startpc, functionptr endpc);
166
167 #if defined(__I386__) || defined(__X86_64__)
168 void codegen_addreference(codegendata *cd, struct basicblock *target, void *branchptr);
169 #endif
170
171 void dseg_display(methodinfo *m, codegendata *cd);
172
173 void init_exceptions();
174
175 #endif /* _CODEGEN_INC_H */
176
177
178 /*
179  * These are local overrides for various environment variables in Emacs.
180  * Please do not remove this and leave it at the end of the file, where
181  * Emacs will automagically detect them.
182  * ---------------------------------------------------------------------
183  * Local variables:
184  * mode: c
185  * indent-tabs-mode: t
186  * c-basic-offset: 4
187  * tab-width: 4
188  * End:
189  */