1 /* 2 * Copyright 2010-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 BCC_SCRIPTCOMPILED_H 18 #define BCC_SCRIPTCOMPILED_H 19 20 #include "Compiler.h" 21 #include "Script.h" 22 23 #include <bcc/bcc.h> 24 25 #include <list> 26 #include <map> 27 #include <string> 28 #include <utility> 29 #include <vector> 30 31 namespace llvm { 32 class Module; 33 } 34 35 namespace bcc { 36 struct CompilerOption; 37 38 class ScriptCompiled { 39 friend class Compiler; 40 friend class CodeEmitter; 41 42 private: 43 typedef std::list<std::pair<std::string, std::string> > PragmaList; 44 typedef std::list<void*> ExportVarList; 45 typedef std::list<void*> ExportFuncList; 46 typedef std::list<void*> ExportForEachList; 47 typedef std::map<std::string, FuncInfo *> FuncInfoMap; 48 typedef std::list<uint32_t> ObjectSlotList; 49 50 private: 51 Script *mpOwner; 52 53 Compiler mCompiler; 54 55 ExportVarList mExportVars; 56 57 std::vector<std::string> mExportVarsName; 58 std::vector<std::string> mExportFuncsName; 59 std::vector<std::string> mExportForEachName; 60 61 ExportFuncList mExportFuncs; 62 ExportForEachList mExportForEach; 63 PragmaList mPragmas; 64 ObjectSlotList mObjectSlots; 65 66 FuncInfoMap mEmittedFunctions; 67 68 public: ScriptCompiled(Script * owner)69 ScriptCompiled(Script *owner) 70 : mpOwner(owner), mCompiler(this) 71 { 72 } 73 74 ~ScriptCompiled(); 75 readModule(llvm::Module * module)76 int readModule(llvm::Module *module) { 77 return mCompiler.readModule(module); 78 } 79 linkModule(llvm::Module * module)80 int linkModule(llvm::Module *module) { 81 return mCompiler.linkModule(module); 82 } 83 compile(const CompilerOption & option)84 int compile(const CompilerOption &option) { 85 return mCompiler.compile(option); 86 } 87 getCompilerErrorMessage()88 char const *getCompilerErrorMessage() { 89 return mCompiler.getErrorMessage(); 90 } 91 92 void *lookup(const char *name); 93 getExportVarCount()94 size_t getExportVarCount() const { 95 return mExportVars.size(); 96 } 97 getExportFuncCount()98 size_t getExportFuncCount() const { 99 return mExportFuncs.size(); 100 } 101 getExportForEachCount()102 size_t getExportForEachCount() const { 103 return mExportForEach.size(); 104 } 105 getPragmaCount()106 size_t getPragmaCount() const { 107 return mPragmas.size(); 108 } 109 getFuncCount()110 size_t getFuncCount() const { 111 return mEmittedFunctions.size(); 112 } 113 getObjectSlotCount()114 size_t getObjectSlotCount() const { 115 return mObjectSlots.size(); 116 } 117 118 void getExportVarList(size_t varListSize, void **varList); 119 120 void getExportFuncList(size_t funcListSize, void **funcList); 121 122 void getExportForEachList(size_t forEachListSize, void **forEachList); 123 124 void getExportVarNameList(std::vector<std::string> &varList); 125 126 void getExportFuncNameList(std::vector<std::string> &funcList); 127 128 void getExportForEachNameList(std::vector<std::string> &forEachList); 129 130 void getPragmaList(size_t pragmaListSize, 131 char const **keyList, 132 char const **valueList); 133 134 void getFuncInfoList(size_t funcInfoListSize, 135 FuncInfo *funcInfoList); 136 137 void getObjectSlotList(size_t objectSlotListSize, 138 uint32_t *objectSlotList); 139 getUserDefinedExternalSymbols()140 std::vector<char const *> const & getUserDefinedExternalSymbols() const { 141 return mpOwner->getUserDefinedExternalSymbols(); 142 } 143 getELF()144 const char *getELF() const { 145 return &*mCompiler.getELF().begin(); 146 } 147 getELFSize()148 size_t getELFSize() const { 149 return mCompiler.getELF().size(); 150 } 151 registerSymbolCallback(BCCSymbolLookupFn pFn,void * pContext)152 void registerSymbolCallback(BCCSymbolLookupFn pFn, void *pContext) { 153 mCompiler.registerSymbolCallback(pFn, pContext); 154 } 155 }; 156 157 } // namespace bcc 158 159 #endif // BCC_SCRIPTCOMPILED_H 160