blob: 2d9f91c771c5fccd1c33c50ec3c2c363494cdef5 [file] [log] [blame]
Shih-wei Liaod1fec812012-02-13 09:51:10 -08001/*
2 * Copyright (C) 2012 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef ART_SRC_COMPILER_LLVM_METHOD_COMPILER_H_
18#define ART_SRC_COMPILER_LLVM_METHOD_COMPILER_H_
19
20#include "constants.h"
21#include "dex_file.h"
22#include "dex_instruction.h"
23#include "object_utils.h"
24
25#include <llvm/Support/IRBuilder.h>
26
27#include <vector>
28
29#include <stdint.h>
30
31
32namespace art {
33 class ClassLinker;
34 class ClassLoader;
35 class CompiledMethod;
36 class Compiler;
37 class DexCache;
38}
39
40
41namespace llvm {
42 class AllocaInst;
43 class BasicBlock;
44 class Function;
45 class FunctionType;
46 class LLVMContext;
47 class Module;
48 class Type;
49}
50
51
52namespace art {
53namespace compiler_llvm {
54
55class CompilerLLVM;
56class IRBuilder;
57
58class MethodCompiler {
59 private:
60 art::InstructionSet insn_set_;
61 art::Compiler const* compiler_;
62 art::compiler_llvm::CompilerLLVM* compiler_llvm_;
63
64 art::ClassLinker* class_linker_;
65 art::ClassLoader const* class_loader_;
66
67 art::DexFile const* dex_file_;
68 art::DexCache* dex_cache_;
69 art::DexFile::CodeItem const* code_item_;
70
71 art::Method* method_;
72 art::MethodHelper method_helper_;
73
74 uint32_t method_idx_;
75 uint32_t access_flags_;
76
77 llvm::Module* module_;
78 llvm::LLVMContext* context_;
79 IRBuilder& irb_;
80 llvm::Function* func_;
81
82 public:
83 MethodCompiler(art::InstructionSet insn_set,
84 art::Compiler const* compiler,
85 art::ClassLinker* class_linker,
86 art::ClassLoader const* class_loader,
87 art::DexFile const* dex_file,
88 art::DexCache* dex_cache,
89 art::DexFile::CodeItem const* code_item,
90 uint32_t method_idx,
91 uint32_t access_flags);
92
93 ~MethodCompiler();
94
95 art::CompiledMethod* Compile();
96
97 private:
98 void CreateFunction();
99
100 void EmitPrologue();
101 void EmitInstructions();
102 void EmitInstruction(uint32_t addr, art::Instruction const* insn);
103 void EmitEpilogue();
104
105};
106
107
108} // namespace compiler_llvm
109} // namespace art
110
111#endif // ART_SRC_COMPILER_LLVM_METHOD_COMPILER_H_