Logan | f7f0ac5 | 2011-01-07 03:53:43 +0800 | [diff] [blame] | 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_SCRIPTCACHED_H |
| 18 | #define BCC_SCRIPTCACHED_H |
| 19 | |
| 20 | #include <bcc/bcc.h> |
| 21 | #include <bcc/bcc_cache.h> |
| 22 | |
| 23 | #include <llvm/ADT/SmallVector.h> |
| 24 | |
| 25 | #include <map> |
| 26 | #include <string> |
| 27 | #include <utility> |
| 28 | #include <vector> |
| 29 | |
| 30 | #include <stddef.h> |
| 31 | |
| 32 | namespace llvm { |
| 33 | class Module; |
| 34 | } |
| 35 | |
| 36 | namespace bcc { |
| 37 | class Script; |
| 38 | |
| 39 | class ScriptCached { |
| 40 | friend class CacheReader; |
| 41 | |
| 42 | private: |
| 43 | enum { SMALL_VECTOR_QUICKN = 16 }; |
| 44 | |
| 45 | typedef llvm::SmallVector<std::pair<char const *, char const *>, |
| 46 | SMALL_VECTOR_QUICKN> PragmaList; |
| 47 | |
| 48 | typedef std::map<std::string, std::pair<void *, size_t> > FuncTable; |
| 49 | |
| 50 | private: |
| 51 | Script *mpOwner; |
| 52 | |
| 53 | OBCC_ExportVarList *mpExportVars; |
| 54 | OBCC_ExportFuncList *mpExportFuncs; |
| 55 | PragmaList mPragmas; |
| 56 | |
| 57 | FuncTable mFunctions; |
| 58 | |
| 59 | char *mContext; |
| 60 | |
| 61 | OBCC_StringPool *mpStringPoolRaw; |
| 62 | std::vector<char const *> mStringPool; |
| 63 | |
Logan | f3c83ce | 2011-01-07 06:36:33 +0800 | [diff] [blame] | 64 | bool mLibRSThreadable; |
| 65 | |
Logan | f7f0ac5 | 2011-01-07 03:53:43 +0800 | [diff] [blame] | 66 | public: |
| 67 | ScriptCached(Script *owner) |
| 68 | : mpOwner(owner), mpExportVars(NULL), mpExportFuncs(NULL), |
Logan | f3c83ce | 2011-01-07 06:36:33 +0800 | [diff] [blame] | 69 | mContext(NULL), mpStringPoolRaw(NULL), mLibRSThreadable(false) { |
Logan | f7f0ac5 | 2011-01-07 03:53:43 +0800 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | ~ScriptCached(); |
| 73 | |
| 74 | void *lookup(const char *name); |
| 75 | |
| 76 | void getExportVars(BCCsizei *actualVarCount, |
| 77 | BCCsizei maxVarCount, |
| 78 | BCCvoid **vars); |
| 79 | |
| 80 | void getExportFuncs(BCCsizei *actualFuncCount, |
| 81 | BCCsizei maxFuncCount, |
| 82 | BCCvoid **funcs); |
| 83 | |
| 84 | void getPragmas(BCCsizei *actualStringCount, |
| 85 | BCCsizei maxStringCount, |
| 86 | BCCchar **strings); |
| 87 | |
| 88 | void getFunctions(BCCsizei *actualFunctionCount, |
| 89 | BCCsizei maxFunctionCount, |
| 90 | BCCchar **functions); |
| 91 | |
| 92 | void getFunctionBinary(BCCchar *function, |
| 93 | BCCvoid **base, |
| 94 | BCCsizei *length); |
| 95 | |
Logan | a27a83f | 2011-01-07 10:25:48 +0800 | [diff] [blame^] | 96 | char *getContext() { |
| 97 | return mContext; |
| 98 | } |
| 99 | |
Logan | f3c83ce | 2011-01-07 06:36:33 +0800 | [diff] [blame] | 100 | // Dirty hack for libRS. |
| 101 | // TODO(all): This should be removed in the future. |
| 102 | bool isLibRSThreadable() const { |
| 103 | return mLibRSThreadable; |
| 104 | } |
| 105 | |
Logan | f7f0ac5 | 2011-01-07 03:53:43 +0800 | [diff] [blame] | 106 | #if 0 |
| 107 | void registerSymbolCallback(BCCSymbolLookupFn pFn, BCCvoid *pContext) { |
| 108 | mCompiler.registerSymbolCallback(pFn, pContext); |
| 109 | } |
| 110 | #endif |
| 111 | }; |
| 112 | |
| 113 | } // namespace bcc |
| 114 | |
| 115 | #endif // BCC_SCRIPTCACHED_H |