1 /* 2 * Copyright 2010, 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 BCC_SOURCEINFO_H 18 #define BCC_SOURCEINFO_H 19 20 #include "Config.h" 21 22 #include <llvm/ADT/OwningPtr.h> 23 #include <llvm/Module.h> 24 25 #include <stddef.h> 26 27 namespace bcc { 28 class ScriptCompiled; 29 30 namespace SourceKind { 31 enum SourceType { 32 File, 33 Buffer, 34 Module, 35 }; 36 } 37 38 class SourceInfo { 39 private: 40 SourceKind::SourceType type; 41 42 llvm::OwningPtr<llvm::Module> module; 43 // Note: module should not be a part of union. Since, we are going to 44 // use module to store the pointer to parsed bitcode. 45 46 union { 47 struct { 48 char const *resName; 49 char const *bitcode; 50 size_t bitcodeSize; 51 } buffer; 52 53 struct { 54 char const *path; 55 } file; 56 }; 57 58 unsigned long flags; 59 60 #if USE_CACHE 61 unsigned char sha1[20]; 62 #endif 63 64 private: 65 SourceInfo() { } 66 67 public: 68 static SourceInfo *createFromBuffer(char const *resName, 69 char const *bitcode, 70 size_t bitcodeSize, 71 unsigned long flags); 72 73 static SourceInfo *createFromFile(char const *path, 74 unsigned long flags); 75 76 static SourceInfo *createFromModule(llvm::Module *module, 77 unsigned long flags); 78 79 llvm::Module *takeModule() { 80 return module.take(); 81 } 82 83 llvm::Module *getModule() const { 84 return module.get(); 85 } 86 87 int prepareModule(ScriptCompiled *); 88 89 #if USE_CACHE 90 template <typename T> void introDependency(T &checker); 91 #endif 92 }; 93 94 95 } // namespace bcc 96 97 #endif // BCC_SOURCEINFO_H 98