CACAO
MethodC2.hpp
Go to the documentation of this file.
1 /* src/vm/jit/compiler2/MethodC2.hpp - Method
2 
3  Copyright (C) 2013
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 #ifndef _JIT_COMPILER2_METHOD
26 #define _JIT_COMPILER2_METHOD
27 
28 #include <cstddef>
29 
32 
33 // forware declaration
34 struct methodinfo;
35 class Utf8String;
36 
37 namespace cacao {
38 class OStream;
39 }
40 
41 namespace cacao {
42 namespace jit {
43 namespace compiler2 {
44 
45 // forware declaration
46 class Instruction;
47 class BeginInst;
48 class MethodDescriptor;
49 
50 template <typename _NodeType>
51 struct edge {
52  _NodeType predecessor;
53  _NodeType successsor;
54  edge(_NodeType p, _NodeType s) : predecessor(p), successsor(s) {}
55 };
56 
57 template <typename _NodeType>
58 edge<_NodeType> make_edge (_NodeType x, _NodeType y) {
59  return ( edge<_NodeType>(x,y) );
60 }
61 
62 class Method {
63 public:
66  typedef InstructionListTy::iterator iterator;
67  typedef InstructionListTy::const_iterator const_iterator;
68  typedef BBListTy::iterator bb_iterator;
69  typedef BBListTy::const_iterator const_bb_iterator;
70 private:
71  /**
72  * This is were the instructions live.
73  */
81 public:
82  Method(methodinfo *m);
83  ~Method();
84 
85  const Utf8String& get_name_utf8() const { return method_name_utf8; }
86  const Utf8String& get_class_name_utf8() const { return class_name_utf8; }
87  const Utf8String& get_desc_utf8() const { return method_desc_utf8; }
88  /**
89  * Add instructions to a Method.
90  *
91  * Instructions added via this method will be deleted by ~Method.
92  * use remove_Instruction() to delete them manually.
93  */
95 
96  /**
97  * Remove an Instruction for a Method.
98  *
99  * The constructor will be called
100  */
102 
103  /**
104  * Replaces the instructions of the method, with the instructions in the
105  * given range [first, last).
106  *
107  * Instructions added via this method will be deleted by ~Method.
108  * use remove_Instruction() to delete them manually.
109  */
110  template <class InputIterator>
111  void replace_instruction_list(InputIterator first, InputIterator last) {
112  inst_list.assign(first, last);
113  }
114 
115  /**
116  * Add a BeginInst.
117  *
118  * The Instruction will be added using add_Instruction().
119  */
120  void add_bb(BeginInst *bi);
121 
122  /**
123  * Remove BeginInst.
124  *
125  * The Instruction will be removed using remove_Instruction().
126  */
127  void remove_bb(BeginInst *bi);
128 
129  void set_init_bb(BeginInst *bi) {
130  init_bb = bi;
131  }
132 
134  return init_bb;
135  }
136 
138  return inst_list.begin();
139  }
140 
141  const_iterator end() const {
142  return inst_list.end();
143  }
144 
145  size_t size() const {
146  return inst_list.size();
147  }
148 
150  return bb_list.begin();
151  }
152 
154  return bb_list.end();
155  }
156 
157  size_t bb_size() const {
158  return bb_list.size();
159  }
160 
161  /**
162  * Get the MethodDescriptor
163  */
165  return *method_desc;
166  }
167 
168  void clear_schedule() const;
169 
170  /**
171  * Get a BeginInst representing an edge
172  */
174 
175 };
176 
177 OStream& operator<<(OStream &OS, const Method &M);
178 
179 } // end namespace cacao
180 } // end namespace jit
181 } // end namespace compiler2
182 
183 #endif /* _JIT_COMPILER2_METHOD */
184 
185 
186 /*
187  * These are local overrides for various environment variables in Emacs.
188  * Please do not remove this and leave it at the end of the file, where
189  * Emacs will automagically detect them.
190  * ---------------------------------------------------------------------
191  * Local variables:
192  * mode: c++
193  * indent-tabs-mode: t
194  * c-basic-offset: 4
195  * tab-width: 4
196  * End:
197  * vim:noexpandtab:sw=4:ts=4:
198  */
const Utf8String & get_name_utf8() const
Definition: MethodC2.hpp:85
edge< _NodeType > make_edge(_NodeType x, _NodeType y)
Definition: MethodC2.hpp:58
alloc::list< Instruction * >::type InstructionListTy
Definition: MethodC2.hpp:64
BeginInst * get_edge_block(BeginInst *pred, BeginInst *succ)
Get a BeginInst representing an edge.
Definition: MethodC2.cpp:117
const MethodDescriptor & get_MethodDescriptor() const
Get the MethodDescriptor.
Definition: MethodC2.hpp:164
BBListTy::const_iterator const_bb_iterator
Definition: MethodC2.hpp:69
const_bb_iterator bb_end() const
Definition: MethodC2.hpp:153
This Instruction mark the start of a basic block.
void remove_Instruction(Instruction *I)
Remove an Instruction for a Method.
Definition: MethodC2.cpp:89
BBListTy::iterator bb_iterator
Definition: MethodC2.hpp:68
alloc::list< BeginInst * >::type BBListTy
Definition: MethodC2.hpp:65
void replace_instruction_list(InputIterator first, InputIterator last)
Replaces the instructions of the method, with the instructions in the given range [first...
Definition: MethodC2.hpp:111
InstructionListTy::iterator iterator
Definition: MethodC2.hpp:66
const Utf8String & get_desc_utf8() const
Definition: MethodC2.hpp:87
std::list< T, Allocator< T > > type
Definition: list.hpp:38
MethodDescriptor * method_desc
Definition: MethodC2.hpp:77
void remove_bb(BeginInst *bi)
Remove BeginInst.
Definition: MethodC2.cpp:102
Simple stream class for formatted output.
Definition: OStream.hpp:141
Instruction super class.
Definition: Instruction.hpp:73
OStream & operator<<(OStream &OS, const Conditional::CondID &cond)
Definition: Conditional.cpp:34
void add_Instruction(Instruction *I)
Add instructions to a Method.
Definition: MethodC2.cpp:82
void set_init_bb(BeginInst *bi)
Definition: MethodC2.hpp:129
InstructionListTy::const_iterator const_iterator
Definition: MethodC2.hpp:67
const_iterator end() const
Definition: MethodC2.hpp:141
OStream & OS
const Utf8String & get_class_name_utf8() const
Definition: MethodC2.hpp:86
#define I(value)
Definition: codegen.c:279
InstructionListTy inst_list
This is were the instructions live.
Definition: MethodC2.hpp:74
void add_bb(BeginInst *bi)
Add a BeginInst.
Definition: MethodC2.cpp:97
const Method & M
const_iterator begin() const
Definition: MethodC2.hpp:137
edge(_NodeType p, _NodeType s)
Definition: MethodC2.hpp:54
BeginInst * get_init_bb() const
Definition: MethodC2.hpp:133
const_bb_iterator bb_begin() const
Definition: MethodC2.hpp:149
MethodDescriptor TODO: more info.