Stephen Hines | 4a68b1c | 2012-05-03 12:28:14 -0700 | [diff] [blame^] | 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 <list> |
| 21 | #include <map> |
| 22 | #include <string> |
| 23 | #include <utility> |
| 24 | #include <vector> |
| 25 | |
| 26 | #include <bcc/bcc.h> |
| 27 | |
| 28 | #include "Compiler.h" |
| 29 | #include "RSScript.h" |
| 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 | RSScript *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: |
| 69 | ScriptCompiled(RSScript *owner) |
| 70 | : mpOwner(owner), mCompiler(this) |
| 71 | { |
| 72 | } |
| 73 | |
| 74 | ~ScriptCompiled(); |
| 75 | |
| 76 | int readModule(llvm::Module &pModule) { |
| 77 | return mCompiler.readModule(pModule); |
| 78 | } |
| 79 | |
| 80 | int compile(const CompilerOption &option) { |
| 81 | return mCompiler.compile(option); |
| 82 | } |
| 83 | |
| 84 | char const *getCompilerErrorMessage() { |
| 85 | return mCompiler.getErrorMessage(); |
| 86 | } |
| 87 | |
| 88 | void *lookup(const char *name); |
| 89 | |
| 90 | size_t getExportVarCount() const { |
| 91 | return mExportVars.size(); |
| 92 | } |
| 93 | |
| 94 | size_t getExportFuncCount() const { |
| 95 | return mExportFuncs.size(); |
| 96 | } |
| 97 | |
| 98 | size_t getExportForEachCount() const { |
| 99 | return mExportForEach.size(); |
| 100 | } |
| 101 | |
| 102 | size_t getPragmaCount() const { |
| 103 | return mPragmas.size(); |
| 104 | } |
| 105 | |
| 106 | size_t getFuncCount() const { |
| 107 | return mEmittedFunctions.size(); |
| 108 | } |
| 109 | |
| 110 | size_t getObjectSlotCount() const { |
| 111 | return mObjectSlots.size(); |
| 112 | } |
| 113 | |
| 114 | void getExportVarList(size_t varListSize, void **varList); |
| 115 | |
| 116 | void getExportFuncList(size_t funcListSize, void **funcList); |
| 117 | |
| 118 | void getExportForEachList(size_t forEachListSize, void **forEachList); |
| 119 | |
| 120 | void getExportVarNameList(std::vector<std::string> &varList); |
| 121 | |
| 122 | void getExportFuncNameList(std::vector<std::string> &funcList); |
| 123 | |
| 124 | void getExportForEachNameList(std::vector<std::string> &forEachList); |
| 125 | |
| 126 | void getPragmaList(size_t pragmaListSize, |
| 127 | char const **keyList, |
| 128 | char const **valueList); |
| 129 | |
| 130 | void getFuncInfoList(size_t funcInfoListSize, |
| 131 | FuncInfo *funcInfoList); |
| 132 | |
| 133 | void getObjectSlotList(size_t objectSlotListSize, |
| 134 | uint32_t *objectSlotList); |
| 135 | |
| 136 | std::vector<char const *> const & getUserDefinedExternalSymbols() const { |
| 137 | return mpOwner->getUserDefinedExternalSymbols(); |
| 138 | } |
| 139 | |
| 140 | const char *getELF() const { |
| 141 | return &*mCompiler.getELF().begin(); |
| 142 | } |
| 143 | |
| 144 | size_t getELFSize() const { |
| 145 | return mCompiler.getELF().size(); |
| 146 | } |
| 147 | |
| 148 | void registerSymbolCallback(BCCSymbolLookupFn pFn, void *pContext) { |
| 149 | mCompiler.registerSymbolCallback(pFn, pContext); |
| 150 | } |
| 151 | }; |
| 152 | |
| 153 | } // namespace bcc |
| 154 | |
| 155 | #endif // BCC_SCRIPTCOMPILED_H |