Zonr Chang | bf6498e | 2012-04-13 14:35:45 +0800 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 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_EXECUTION_ENGINE_RS_EXECUTABLE_H |
| 18 | #define BCC_EXECUTION_ENGINE_RS_EXECUTABLE_H |
| 19 | |
| 20 | #include <cstddef> |
| 21 | |
| 22 | #include "DebugHelper.h" |
| 23 | #include "ObjectLoader.h" |
| 24 | #include "RSInfo.h" |
| 25 | |
| 26 | #include <utils/Vector.h> |
| 27 | |
| 28 | namespace bcc { |
| 29 | |
| 30 | class FileBase; |
| 31 | class SymbolResolverProxy; |
| 32 | |
| 33 | /* |
| 34 | * RSExecutable holds the build results of a RSScript. |
| 35 | */ |
| 36 | class RSExecutable { |
| 37 | private: |
| 38 | RSInfo *mInfo; |
| 39 | bool mIsInfoDirty; |
| 40 | |
| 41 | FileBase *mObjFile; |
| 42 | |
| 43 | ObjectLoader *mLoader; |
| 44 | |
| 45 | // Memory address of rs export stuffs |
| 46 | android::Vector<void *> mExportVarAddrs; |
| 47 | android::Vector<void *> mExportFuncAddrs; |
| 48 | android::Vector<void *> mExportForeachFuncAddrs; |
| 49 | |
| 50 | // FIXME: These are designed for RenderScript HAL and is initialized in |
| 51 | // RSExecutable::Create(). Both of them come from RSInfo::getPragmas(). |
| 52 | // If possible, read the pragma key/value pairs directly from RSInfo. |
| 53 | android::Vector<const char *> mPragmaKeys; |
| 54 | android::Vector<const char *> mPragmaValues; |
| 55 | |
| 56 | RSExecutable(RSInfo &pInfo, FileBase &pObjFile, ObjectLoader &pLoader) |
| 57 | : mInfo(&pInfo), mIsInfoDirty(false), mObjFile(&pObjFile), mLoader(&pLoader) |
| 58 | { } |
| 59 | |
| 60 | public: |
| 61 | // This is a NULL-terminated string array which specifies "Special" functions |
| 62 | // in RenderScript (e.g., root().) |
| 63 | static const char *SpecialFunctionNames[]; |
| 64 | |
| 65 | // Return NULL on error. If the return object is non-NULL, it claims the |
| 66 | // ownership of pInfo and pObjFile. |
| 67 | static RSExecutable *Create(RSInfo &pInfo, |
| 68 | FileBase &pObjFile, |
| 69 | SymbolResolverProxy &pResolver); |
| 70 | |
| 71 | inline const RSInfo &getInfo() const |
| 72 | { return *mInfo; } |
| 73 | |
| 74 | // Interfaces to RSInfo |
| 75 | inline bool isThreadable() const |
| 76 | { return mInfo->isThreadable(); } |
| 77 | |
| 78 | inline void setThreadable(bool pThreadable = true) { |
| 79 | if (mInfo->isThreadable() != pThreadable) { |
| 80 | mInfo->setThreadable(pThreadable); |
| 81 | mIsInfoDirty = true; |
| 82 | } |
| 83 | return; |
| 84 | } |
| 85 | |
| 86 | // Interfaces to ObjectLoader |
| 87 | inline void *getSymbolAddress(const char *pName) const |
| 88 | { return mLoader->getSymbolAddress(pName); } |
| 89 | |
| 90 | bool syncInfo(bool pForce = false); |
| 91 | |
| 92 | inline const android::Vector<void *> &getExportVarAddrs() const |
| 93 | { return mExportVarAddrs; } |
| 94 | inline const android::Vector<void *> &getExportFuncAddrs() const |
| 95 | { return mExportFuncAddrs; } |
| 96 | inline const android::Vector<void *> &getExportForeachFuncAddrs() const |
| 97 | { return mExportForeachFuncAddrs; } |
| 98 | |
| 99 | inline const android::Vector<const char *> &getPragmaKeys() const |
| 100 | { return mPragmaKeys; } |
| 101 | inline const android::Vector<const char *> &getPragmaValues() const |
| 102 | { return mPragmaValues; } |
| 103 | |
| 104 | ~RSExecutable(); |
| 105 | }; |
| 106 | |
| 107 | } // end namespace bcc |
| 108 | |
| 109 | #endif // BCC_EXECUTION_ENGINE_RS_EXECUTABLE_H |