* Updated to jitcache-arm-x86 branch d4f6023b26c5+d1b5b1c106ac
[cacao.git] / src / vm / jit / linenumbertable.hpp
1 /* src/vm/jit/linenumbertable.hpp - linenumber table
2
3    Copyright (C) 2007, 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 _LINENUMBERTABLE_HPP
27 #define _LINENUMBERTABLE_HPP
28
29 #include "config.h"
30
31 #include <stdint.h>
32
33 #ifdef __cplusplus
34 #include <functional>
35 #include <vector>
36 #endif
37
38 #include "toolbox/list.hpp"
39
40 #include "vm/method.h"
41
42 #include "vm/jit/jit.hpp"
43 #include "vm/jit/code.hpp"
44
45 #include "vm/jit/ir/instruction.hpp"
46
47
48 #ifdef __cplusplus
49
50 /**
51  * Represents a Java line number.
52  */
53 class Linenumber {
54 private:
55         // TODO Add constants.
56         /* -1......start of inlined body              */
57         /* -2......end of inlined body                */
58         /* <= -3...special entry with methodinfo *    */
59         /* (see doc/inlining_stacktrace.txt)          */
60
61         int32_t _linenumber;
62         void*   _pc;
63
64 public:
65         Linenumber(int32_t linenumber, void* pc) : _linenumber(linenumber), _pc(pc) {}
66
67         inline int32_t get_linenumber() const { return _linenumber; }
68         inline void*   get_pc        () const { return _pc; }
69
70         void resolve(const codeinfo* code);
71 };
72
73
74 /**
75  * Unary function to resolve Linenumber objects.
76  */
77 class LinenumberResolver : public std::binary_function<Linenumber, codeinfo*, void> {
78 public:
79         // Unary resolve function.
80         void operator() (Linenumber& ln, const codeinfo* code) const
81         {
82                 ln.resolve(code);
83         }
84 };
85
86
87 /**
88  * Linenumber table of a Java method.
89  */
90 class LinenumberTable {
91 public:
92         std::vector<Linenumber> _linenumbers;
93 private:
94
95         // Comparator class.
96         class comparator : public std::binary_function<Linenumber, void*, bool> {
97         public:
98                 bool operator() (const Linenumber& ln, const void* pc) const
99                 {
100                         return (pc >= ln.get_pc());
101                 }
102         };
103
104 public:
105         LinenumberTable(jitdata* jd);
106         LinenumberTable() { }
107         ~LinenumberTable();
108
109         int32_t find(methodinfo **pm, void* pc);
110 };
111
112 #else
113
114 typedef struct LinenumberTable LinenumberTable;
115
116 #endif
117
118 #include "vm/jit/codegen-common.hpp"
119
120 #ifdef __cplusplus
121 extern "C" {
122 #endif
123
124 void    linenumbertable_list_entry_add(codegendata *cd, int32_t linenumber);
125 void    linenumbertable_list_entry_add_inline_start(codegendata *cd, instruction *iptr);
126 void    linenumbertable_list_entry_add_inline_end(codegendata *cd, instruction *iptr);
127
128 #ifdef __cplusplus
129 } // extern "C"
130 #endif
131
132 #endif // _LINENUMBERTABLE_HPP
133
134
135 /*
136  * These are local overrides for various environment variables in Emacs.
137  * Please do not remove this and leave it at the end of the file, where
138  * Emacs will automagically detect them.
139  * ---------------------------------------------------------------------
140  * Local variables:
141  * mode: c++
142  * indent-tabs-mode: t
143  * c-basic-offset: 4
144  * tab-width: 4
145  * End:
146  * vim:noexpandtab:sw=4:ts=4:
147  */