| /* |
| * Copyright 2010, The Android Open Source Project |
| * |
| * Licensed under the Apache License, Version 2.0 (the "License"); |
| * you may not use this file except in compliance with the License. |
| * You may obtain a copy of the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, software |
| * distributed under the License is distributed on an "AS IS" BASIS, |
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| * See the License for the specific language governing permissions and |
| * limitations under the License. |
| */ |
| |
| #ifndef BCC_SOURCEINFO_H |
| #define BCC_SOURCEINFO_H |
| |
| #include "Config.h" |
| |
| #include <llvm/Module.h> |
| |
| #include <stddef.h> |
| |
| namespace bcc { |
| namespace SourceKind { |
| enum SourceType { |
| File, |
| Buffer, |
| Module, |
| }; |
| } |
| |
| class SourceInfo { |
| private: |
| SourceKind::SourceType type; |
| |
| // Note: module should not be a part of union. Since, we are going to |
| // use module to store the pointer to parsed bitcode. |
| llvm::Module *module; |
| |
| union { |
| struct { |
| char const *resName; |
| char const *bitcode; |
| size_t bitcodeSize; |
| } buffer; |
| |
| struct { |
| char const *path; |
| } file; |
| }; |
| |
| unsigned long flags; |
| |
| unsigned char sha1[20]; |
| |
| private: |
| SourceInfo() : module(NULL) { } |
| |
| public: |
| static SourceInfo *createFromBuffer(char const *resName, |
| char const *bitcode, |
| size_t bitcodeSize, |
| unsigned long flags); |
| |
| static SourceInfo *createFromFile(char const *path, |
| unsigned long flags); |
| |
| static SourceInfo *createFromModule(llvm::Module *module, |
| unsigned long flags); |
| |
| inline llvm::Module *getModule() const { |
| return module; |
| } |
| |
| // Share with the given context if it's provided. |
| int prepareModule(llvm::LLVMContext &context); |
| |
| template <typename T> void introDependency(T &checker); |
| |
| ~SourceInfo(); |
| }; |
| |
| |
| } // namespace bcc |
| |
| #endif // BCC_SOURCEINFO_H |