blob: 74f8ba1c33424864bb708e678542049f626a496f [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_LLVM_COMPILER_H_
18#define ART_SRC_COMPILER_LLVM_LLVM_COMPILER_H_
19
20#include "constants.h"
21#include "dex_file.h"
22#include "macros.h"
23
24#include <UniquePtr.h>
25
26#include <string>
27
28namespace art {
29 class ClassLoader;
30 class CompiledMethod;
31 class Compiler;
32 class Mutex;
33}
34
35
36namespace llvm {
37 class Function;
38 class LLVMContext;
39 class Module;
40 class PointerType;
41 class StructType;
42 class Type;
43}
44
45
46namespace art {
47namespace compiler_llvm {
48
49class IRBuilder;
50
51class CompilerLLVM {
52 public:
53 CompilerLLVM(Compiler* compiler, InstructionSet insn_set);
54
55 ~CompilerLLVM();
56
57 void MaterializeLLVMModule();
58
59 void WriteBitcodeToFile(std::string const &filename);
60
61 Compiler* GetCompiler() const {
62 return compiler_;
63 }
64
65 InstructionSet GetInstructionSet() const {
66 return insn_set_;
67 }
68
69 llvm::Module* GetModule() const {
70 return module_;
71 }
72
73 llvm::LLVMContext* GetLLVMContext() const {
74 return context_.get();
75 }
76
77 IRBuilder* GetIRBuilder() const {
78 return irb_.get();
79 }
80
81 CompiledMethod* CompileDexMethod(DexFile::CodeItem const* code_item,
82 uint32_t access_flags,
83 uint32_t method_idx,
84 ClassLoader const* class_loader,
85 DexFile const& dex_file);
86
87 private:
88 Compiler* compiler_;
89
90 Mutex compiler_lock_;
91
92 InstructionSet insn_set_;
93
94 UniquePtr<llvm::LLVMContext> context_;
95
96 UniquePtr<IRBuilder> irb_;
97
98 llvm::Module* module_;
99
100 DISALLOW_COPY_AND_ASSIGN(CompilerLLVM);
101};
102
103
104} // namespace compiler_llvm
105} // namespace art
106
107#endif // ART_SRC_COMPILER_LLVM_LLVM_COMPILER_H_