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