blob: 8d9820a453f26d0669c8e8b7efd04c31d4585a2d [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:
Logan Chien83426162011-12-09 09:29:50 +080060 InstructionSet insn_set_;
61 Compiler* compiler_;
62 compiler_llvm::CompilerLLVM* compiler_llvm_;
Shih-wei Liaod1fec812012-02-13 09:51:10 -080063
Logan Chien83426162011-12-09 09:29:50 +080064 ClassLinker* class_linker_;
65 ClassLoader const* class_loader_;
Shih-wei Liaod1fec812012-02-13 09:51:10 -080066
Logan Chien83426162011-12-09 09:29:50 +080067 DexFile const* dex_file_;
68 DexCache* dex_cache_;
69 DexFile::CodeItem const* code_item_;
Shih-wei Liaod1fec812012-02-13 09:51:10 -080070
Logan Chien83426162011-12-09 09:29:50 +080071 Method* method_;
72 MethodHelper method_helper_;
Shih-wei Liaod1fec812012-02-13 09:51:10 -080073
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:
Logan Chien83426162011-12-09 09:29:50 +080083 MethodCompiler(InstructionSet insn_set,
84 Compiler* compiler,
85 ClassLinker* class_linker,
86 ClassLoader const* class_loader,
87 DexFile const* dex_file,
88 DexCache* dex_cache,
89 DexFile::CodeItem const* code_item,
Shih-wei Liaod1fec812012-02-13 09:51:10 -080090 uint32_t method_idx,
91 uint32_t access_flags);
92
93 ~MethodCompiler();
94
Logan Chien83426162011-12-09 09:29:50 +080095 CompiledMethod* Compile();
Shih-wei Liaod1fec812012-02-13 09:51:10 -080096
97 private:
98 void CreateFunction();
99
100 void EmitPrologue();
101 void EmitInstructions();
Logan Chien83426162011-12-09 09:29:50 +0800102 void EmitInstruction(uint32_t dex_pc, Instruction const* insn);
Shih-wei Liaod1fec812012-02-13 09:51:10 -0800103
104};
105
106
107} // namespace compiler_llvm
108} // namespace art
109
110#endif // ART_SRC_COMPILER_LLVM_METHOD_COMPILER_H_