.h file of codegen.inc
[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 1339 2004-07-21 16:03:08Z twisti $
30
31 */
32
33
34 #ifndef _CODEGEN_INC_H
35 #define _CODEGEN_INC_H
36
37
38 #include "types.h"
39 #include "global.h"
40
41
42 #define MCODEINITSIZE (1<<15)       /* 32 Kbyte code area initialization size */
43 #define DSEGINITSIZE  (1<<12)       /*  4 Kbyte data area initialization size */
44
45 #if POINTERSIZE == 8
46 #define dseg_addaddress(m, value)      dseg_adds8((m), (s8) (value))
47 #else
48 #define dseg_addaddress(m, value)      dseg_adds4((m), (s4) (value))
49 #endif
50
51
52 typedef struct codegendata codegendata;
53 typedef struct branchref branchref;
54 typedef struct jumpref jumpref;
55 typedef struct dataref dataref;
56 typedef struct linenumberref linenumberref;
57 typedef struct threadcritnodetemp threadcritnodetemp;
58
59
60 /************************* critical sections  *********************************/
61
62 struct threadcritnodetemp {
63         threadcritnodetemp *next;
64         s4 mcodebegin;
65         s4 mcodeend;
66         s4 mcoderestart;
67 };
68
69
70 struct codegendata {
71         u1 *mcodebase;                  /* base pointer of code area              */
72         s4 *mcodeend;                   /* pointer to end of code area            */
73         s4  mcodesize;                  /* complete size of code area (bytes)     */
74
75         u1 *mcodeptr;                   /* code generation pointer                */
76
77         u1 *dsegtop;                    /* pointer to top (end) of data area      */
78         s4  dsegsize;                   /* complete size of data area (bytes)     */
79         s4  dseglen;                    /* used size of data area (bytes)         */
80                                     /* data area grows from top to bottom     */
81
82         jumpref   *jumpreferences;      /* list of jumptable target addresses     */
83         dataref   *datareferences;      /* list of data segment references        */
84         branchref *xboundrefs;          /* list of bound check branches           */
85         branchref *xcheckarefs;         /* list of array size check branches      */
86         branchref *xnullrefs;           /* list of null check branches            */
87         branchref *xcastrefs;           /* list of cast check branches            */
88         branchref *xdivrefs;            /* list of divide by zero branches        */
89         branchref *xexceptionrefs;      /* list of exception branches             */
90
91         linenumberref *linenumberreferences; /* list of line numbers and the      */
92                                         /* program counters of their first        */
93                                         /* instruction                            */
94         s4 linenumbertablesizepos;
95         s4 linenumbertablestartpos;
96         s4 linenumbertab;
97
98         threadcritnodetemp *threadcrit; /* List of critical code regions          */
99         threadcritnodetemp threadcritcurrent;
100         s4 threadcritcount;             /* Number of critical regions             */
101 };
102
103
104 /***************** forward references in branch instructions ******************/
105
106 struct branchref {
107         s4 branchpos;               /* patching position in code segment          */
108         s4 reg;                     /* used for ArrayIndexOutOfBounds index reg   */
109         branchref *next;            /* next element in branchref list             */
110 };
111
112
113 /******************** forward references in tables  ***************************/
114
115 struct jumpref {
116         s4 tablepos;                /* patching position in data segment          */
117         struct basicblock *target;  /* target basic block                         */
118         jumpref *next;              /* next element in jumpref list               */
119 };
120
121
122 struct dataref {
123         u1 *pos;                    /* patching position in generated code        */
124         dataref *next;              /* next element in dataref list               */
125 };
126
127
128 struct linenumberref {
129         s4 tablepos;                /* patching position in data segment          */
130         int targetmpc;              /* machine code program counter of first      */
131                                     /* instruction for given line                 */
132         u2 linenumber;              /* line number, used for inserting into the   */
133                                     /* table and for validty checking             */
134         linenumberref *next;        /* next element in linenumberref list         */
135 };
136
137
138 #if defined(__I386__) || defined(__X86_64__)
139 typedef struct _methodtree_element methodtree_element;
140
141 struct _methodtree_element {
142         void *startpc;
143         void *endpc;
144 };
145 #endif
146
147
148 /* function prototypes */
149
150 void codegen_init();
151 void codegen_setup(methodinfo *m);  /* allocates code and data area           */
152 void codegen(methodinfo *m);
153 void codegen_close(methodinfo *m);  /* releases temporary storage             */
154 void codegen_insertmethod(void *startpc, void *endpc);
155
156 void dseg_display(methodinfo *m);
157
158 void init_exceptions();
159
160 #endif /* _CODEGEN_INC_H */
161
162
163 /*
164  * These are local overrides for various environment variables in Emacs.
165  * Please do not remove this and leave it at the end of the file, where
166  * Emacs will automagically detect them.
167  * ---------------------------------------------------------------------
168  * Local variables:
169  * mode: c
170  * indent-tabs-mode: t
171  * c-basic-offset: 4
172  * tab-width: 4
173  * End:
174  */