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; |
Logan Chien | f04364f | 2012-02-10 12:01:39 +0800 | [diff] [blame^] | 30 | class CompiledInvokeStub; |
Shih-wei Liao | d1fec81 | 2012-02-13 09:51:10 -0800 | [diff] [blame] | 31 | class CompiledMethod; |
| 32 | class Compiler; |
Shih-wei Liao | d1fec81 | 2012-02-13 09:51:10 -0800 | [diff] [blame] | 33 | } |
| 34 | |
| 35 | |
| 36 | namespace llvm { |
| 37 | class Function; |
| 38 | class LLVMContext; |
| 39 | class Module; |
| 40 | class PointerType; |
| 41 | class StructType; |
| 42 | class Type; |
| 43 | } |
| 44 | |
| 45 | |
| 46 | namespace art { |
| 47 | namespace compiler_llvm { |
| 48 | |
| 49 | class IRBuilder; |
| 50 | |
| 51 | class 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 | |
Logan Chien | f04364f | 2012-02-10 12:01:39 +0800 | [diff] [blame^] | 87 | CompiledInvokeStub* CreateInvokeStub(bool is_static, char const *shorty); |
| 88 | |
Shih-wei Liao | d1fec81 | 2012-02-13 09:51:10 -0800 | [diff] [blame] | 89 | private: |
| 90 | Compiler* compiler_; |
| 91 | |
| 92 | Mutex compiler_lock_; |
| 93 | |
| 94 | InstructionSet insn_set_; |
| 95 | |
| 96 | UniquePtr<llvm::LLVMContext> context_; |
| 97 | |
| 98 | UniquePtr<IRBuilder> irb_; |
| 99 | |
| 100 | llvm::Module* module_; |
| 101 | |
| 102 | DISALLOW_COPY_AND_ASSIGN(CompilerLLVM); |
| 103 | }; |
| 104 | |
| 105 | |
| 106 | } // namespace compiler_llvm |
| 107 | } // namespace art |
| 108 | |
| 109 | #endif // ART_SRC_COMPILER_LLVM_LLVM_COMPILER_H_ |