Merged.
[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.hpp"
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 private:
92         std::vector<Linenumber> _linenumbers;
93
94         // Comparator class.
95         class comparator : public std::binary_function<Linenumber, void*, bool> {
96         public:
97                 bool operator() (const Linenumber& ln, const void* pc) const
98                 {
99                         return (pc >= ln.get_pc());
100                 }
101         };
102
103 public:
104         LinenumberTable(jitdata* jd);
105         ~LinenumberTable();
106
107         int32_t find(methodinfo **pm, void* pc);
108 };
109
110 #else
111
112 typedef struct LinenumberTable LinenumberTable;
113
114 #endif
115
116 #include "vm/jit/codegen-common.hpp"
117
118 #ifdef __cplusplus
119 extern "C" {
120 #endif
121
122 void    linenumbertable_list_entry_add(codegendata *cd, int32_t linenumber);
123 void    linenumbertable_list_entry_add_inline_start(codegendata *cd, instruction *iptr);
124 void    linenumbertable_list_entry_add_inline_end(codegendata *cd, instruction *iptr);
125
126 #ifdef __cplusplus
127 } // extern "C"
128 #endif
129
130 #endif // _LINENUMBERTABLE_HPP
131
132
133 /*
134  * These are local overrides for various environment variables in Emacs.
135  * Please do not remove this and leave it at the end of the file, where
136  * Emacs will automagically detect them.
137  * ---------------------------------------------------------------------
138  * Local variables:
139  * mode: c++
140  * indent-tabs-mode: t
141  * c-basic-offset: 4
142  * tab-width: 4
143  * End:
144  * vim:noexpandtab:sw=4:ts=4:
145  */