Shih-wei Liao | 4ce024b | 2012-04-25 03:40:50 -0700 | [diff] [blame] | 1 | /* |
Stephen Hines | 2f6a493 | 2012-05-03 12:27:13 -0700 | [diff] [blame^] | 2 | * Copyright 2010, The Android Open Source Project |
Shih-wei Liao | 4ce024b | 2012-04-25 03:40:50 -0700 | [diff] [blame] | 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 | |
Stephen Hines | 2f6a493 | 2012-05-03 12:27:13 -0700 | [diff] [blame^] | 17 | #ifndef BCC_EXECUTION_ENGINE_SOURCE_H |
| 18 | #define BCC_EXECUTION_ENGINE_SOURCE_H |
Shih-wei Liao | 4ce024b | 2012-04-25 03:40:50 -0700 | [diff] [blame] | 19 | |
| 20 | #include <string> |
| 21 | |
| 22 | namespace llvm { |
| 23 | class Module; |
| 24 | } |
| 25 | |
| 26 | namespace bcc { |
| 27 | |
| 28 | class BCCContext; |
| 29 | |
| 30 | class Source { |
| 31 | private: |
| 32 | BCCContext &mContext; |
| 33 | llvm::Module *mModule; |
| 34 | |
| 35 | // If true, destructor won't destroy the mModule. |
| 36 | bool mNoDelete; |
| 37 | |
| 38 | private: |
| 39 | Source(BCCContext &pContext, llvm::Module &pModule, bool pNoDelete = false); |
| 40 | |
| 41 | public: |
| 42 | static Source *CreateFromBuffer(BCCContext &pContext, |
| 43 | const char *pName, |
| 44 | const char *pBitcode, |
| 45 | size_t pBitcodeSize); |
| 46 | |
| 47 | static Source *CreateFromFile(BCCContext &pContext, |
| 48 | const std::string &pPath); |
| 49 | |
| 50 | // Create a Source object from an existing module. If pNoDelete |
| 51 | // is true, destructor won't call delete on the given module. |
| 52 | static Source *CreateFromModule(BCCContext &pContext, |
| 53 | llvm::Module &pModule, |
| 54 | bool pNoDelete = false); |
| 55 | |
| 56 | static Source *CreateEmpty(BCCContext &pContext, const std::string &pName); |
| 57 | |
| 58 | // Merge the current source with pSource. If pPreserveSource is false, pSource |
| 59 | // will be destroyed after successfully merged. Return false on error. |
| 60 | bool merge(Source &pSource, bool pPreserveSource = false); |
| 61 | |
| 62 | inline BCCContext &getContext() |
| 63 | { return mContext; } |
| 64 | inline const BCCContext &getContext() const |
| 65 | { return mContext; } |
| 66 | |
| 67 | inline llvm::Module &getModule() |
| 68 | { return *mModule; } |
| 69 | inline const llvm::Module &getModule() const |
| 70 | { return *mModule; } |
| 71 | |
| 72 | // Get the "identifier" of the bitcode. This will return the value of pName |
| 73 | // when it's created using CreateFromBuffer and pPath if CreateFromFile(). |
| 74 | const std::string &getIdentifier() const; |
| 75 | |
| 76 | ~Source(); |
| 77 | }; |
| 78 | |
| 79 | } // namespace bcc |
| 80 | |
Stephen Hines | 2f6a493 | 2012-05-03 12:27:13 -0700 | [diff] [blame^] | 81 | #endif // BCC_EXECUTION_ENGINE_SOURCE_H |