Logan | cf3e521 | 2010-12-29 01:44:55 +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_SCRIPTCOMPILED_H |
| 18 | #define BCC_SCRIPTCOMPILED_H |
| 19 | |
| 20 | #include "Compiler.h" |
| 21 | |
| 22 | #include <bcc/bcc.h> |
| 23 | |
| 24 | namespace llvm { |
| 25 | class Module; |
| 26 | } |
| 27 | |
| 28 | namespace bcc { |
| 29 | class Script; |
| 30 | |
| 31 | class ScriptCompiled { |
Logan | 2a6dc82 | 2011-01-06 04:05:20 +0800 | [diff] [blame^] | 32 | friend class Compiler; |
| 33 | |
| 34 | private: |
| 35 | typedef std::list< std::pair<std::string, std::string> > PragmaList; |
| 36 | typedef std::list<void*> ExportVarList; |
| 37 | typedef std::list<void*> ExportFuncList; |
| 38 | |
Logan | cf3e521 | 2010-12-29 01:44:55 +0800 | [diff] [blame] | 39 | private: |
| 40 | Script *mpOwner; |
| 41 | |
| 42 | Compiler mCompiler; |
| 43 | |
Logan | 2a6dc82 | 2011-01-06 04:05:20 +0800 | [diff] [blame^] | 44 | PragmaList mPragmas; |
| 45 | ExportVarList mExportVars; |
| 46 | ExportFuncList mExportFuncs; |
| 47 | |
Logan | cf3e521 | 2010-12-29 01:44:55 +0800 | [diff] [blame] | 48 | public: |
Logan | 2a6dc82 | 2011-01-06 04:05:20 +0800 | [diff] [blame^] | 49 | ScriptCompiled(Script *owner) : mpOwner(owner), mCompiler(this) { |
Logan | cf3e521 | 2010-12-29 01:44:55 +0800 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | int readBC(const char *bitcode, |
| 53 | size_t bitcodeSize, |
| 54 | long bitcodeFileModTime, |
| 55 | long bitcodeFileCRC32, |
| 56 | const BCCchar *resName, |
| 57 | const BCCchar *cacheDir) { |
| 58 | return mCompiler.readBC(bitcode, bitcodeSize, |
| 59 | bitcodeFileModTime, bitcodeFileCRC32, |
| 60 | resName, cacheDir); |
| 61 | } |
| 62 | |
| 63 | int linkBC(const char *bitcode, size_t bitcodeSize) { |
| 64 | return mCompiler.linkBC(bitcode, bitcodeSize); |
| 65 | } |
| 66 | |
| 67 | int loadCacheFile() { |
| 68 | return mCompiler.loadCacheFile(); |
| 69 | } |
| 70 | |
| 71 | int compile() { |
| 72 | return mCompiler.compile(); |
| 73 | } |
| 74 | |
| 75 | char const *getCompilerErrorMessage() { |
| 76 | return mCompiler.getErrorMessage(); |
| 77 | } |
| 78 | |
| 79 | void *lookup(const char *name) { |
| 80 | return mCompiler.lookup(name); |
| 81 | } |
| 82 | |
| 83 | void getExportVars(BCCsizei *actualVarCount, |
| 84 | BCCsizei maxVarCount, |
Logan | 2a6dc82 | 2011-01-06 04:05:20 +0800 | [diff] [blame^] | 85 | BCCvoid **vars); |
Logan | cf3e521 | 2010-12-29 01:44:55 +0800 | [diff] [blame] | 86 | |
| 87 | void getExportFuncs(BCCsizei *actualFuncCount, |
| 88 | BCCsizei maxFuncCount, |
Logan | 2a6dc82 | 2011-01-06 04:05:20 +0800 | [diff] [blame^] | 89 | BCCvoid **funcs); |
Logan | cf3e521 | 2010-12-29 01:44:55 +0800 | [diff] [blame] | 90 | |
| 91 | void getPragmas(BCCsizei *actualStringCount, |
| 92 | BCCsizei maxStringCount, |
Logan | 2a6dc82 | 2011-01-06 04:05:20 +0800 | [diff] [blame^] | 93 | BCCchar **strings); |
Logan | cf3e521 | 2010-12-29 01:44:55 +0800 | [diff] [blame] | 94 | |
| 95 | void getFunctions(BCCsizei *actualFunctionCount, |
| 96 | BCCsizei maxFunctionCount, |
| 97 | BCCchar **functions) { |
| 98 | mCompiler.getFunctions(actualFunctionCount, maxFunctionCount, functions); |
| 99 | } |
| 100 | |
| 101 | void getFunctionBinary(BCCchar *function, |
| 102 | BCCvoid **base, |
| 103 | BCCsizei *length) { |
| 104 | mCompiler.getFunctionBinary(function, base, length); |
| 105 | } |
| 106 | |
| 107 | void registerSymbolCallback(BCCSymbolLookupFn pFn, BCCvoid *pContext) { |
| 108 | mCompiler.registerSymbolCallback(pFn, pContext); |
| 109 | } |
| 110 | |
| 111 | int readModule(llvm::Module *module) { |
| 112 | return mCompiler.readModule(module); |
| 113 | } |
| 114 | }; |
| 115 | |
| 116 | } // namespace bcc |
| 117 | |
| 118 | #endif // BCC_SCRIPTCOMPILED_H |