Logan | 3f3d31f | 2010-11-27 13:52:03 +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_SCRIPT_H |
| 18 | #define BCC_SCRIPT_H |
| 19 | |
Logan | c439523 | 2010-11-27 18:54:17 +0800 | [diff] [blame] | 20 | #include "Compiler.h" |
| 21 | |
Logan | 3f3d31f | 2010-11-27 13:52:03 +0800 | [diff] [blame] | 22 | #include <bcc/bcc.h> |
Logan | 3f3d31f | 2010-11-27 13:52:03 +0800 | [diff] [blame] | 23 | |
Logan | eaa0cc3 | 2010-12-29 01:04:20 +0800 | [diff] [blame^] | 24 | namespace llvm { |
| 25 | class Module; |
| 26 | } |
| 27 | |
Logan | 3f3d31f | 2010-11-27 13:52:03 +0800 | [diff] [blame] | 28 | namespace bcc { |
| 29 | |
Logan | 0647e9e | 2010-12-29 00:21:31 +0800 | [diff] [blame] | 30 | class Script { |
Logan | 3973641 | 2010-12-29 00:24:04 +0800 | [diff] [blame] | 31 | private: |
| 32 | BCCenum mErrorCode; |
| 33 | |
Logan | eaa0cc3 | 2010-12-29 01:04:20 +0800 | [diff] [blame^] | 34 | Compiler mCompiler; |
| 35 | |
Logan | 3f3d31f | 2010-11-27 13:52:03 +0800 | [diff] [blame] | 36 | public: |
Logan | 0647e9e | 2010-12-29 00:21:31 +0800 | [diff] [blame] | 37 | Script() { |
Logan | 3973641 | 2010-12-29 00:24:04 +0800 | [diff] [blame] | 38 | mErrorCode = BCC_NO_ERROR; |
Logan | 3f3d31f | 2010-11-27 13:52:03 +0800 | [diff] [blame] | 39 | } |
| 40 | |
Logan | 0647e9e | 2010-12-29 00:21:31 +0800 | [diff] [blame] | 41 | ~Script() { |
Logan | 3f3d31f | 2010-11-27 13:52:03 +0800 | [diff] [blame] | 42 | } |
| 43 | |
Logan | eaa0cc3 | 2010-12-29 01:04:20 +0800 | [diff] [blame^] | 44 | ////////////////////////////////////////////////////////////////////////// |
| 45 | // Part I. Compiler |
| 46 | ////////////////////////////////////////////////////////////////////////// |
| 47 | |
| 48 | int readBC(const char *bitcode, |
| 49 | size_t bitcodeSize, |
| 50 | long bitcodeFileModTime, |
| 51 | long bitcodeFileCRC32, |
| 52 | const BCCchar *resName, |
| 53 | const BCCchar *cacheDir) { |
| 54 | return mCompiler.readBC(bitcode, bitcodeSize, |
| 55 | bitcodeFileModTime, bitcodeFileCRC32, |
| 56 | resName, cacheDir); |
| 57 | } |
| 58 | |
| 59 | int linkBC(const char *bitcode, size_t bitcodeSize) { |
| 60 | return mCompiler.linkBC(bitcode, bitcodeSize); |
| 61 | } |
| 62 | |
| 63 | int loadCacheFile() { |
| 64 | return mCompiler.loadCacheFile(); |
| 65 | } |
| 66 | |
| 67 | int compile() { |
| 68 | return mCompiler.compile(); |
| 69 | } |
| 70 | |
| 71 | char const *getCompilerErrorMessage() { |
| 72 | return mCompiler.getErrorMessage(); |
| 73 | } |
| 74 | |
| 75 | void *lookup(const char *name) { |
| 76 | return mCompiler.lookup(name); |
| 77 | } |
| 78 | |
| 79 | void getExportVars(BCCsizei *actualVarCount, |
| 80 | BCCsizei maxVarCount, |
| 81 | BCCvoid **vars) { |
| 82 | mCompiler.getExportVars(actualVarCount, maxVarCount, vars); |
| 83 | } |
| 84 | |
| 85 | void getExportFuncs(BCCsizei *actualFuncCount, |
| 86 | BCCsizei maxFuncCount, |
| 87 | BCCvoid **funcs) { |
| 88 | mCompiler.getExportFuncs(actualFuncCount, maxFuncCount, funcs); |
| 89 | } |
| 90 | |
| 91 | void getPragmas(BCCsizei *actualStringCount, |
| 92 | BCCsizei maxStringCount, |
| 93 | BCCchar **strings) { |
| 94 | mCompiler.getPragmas(actualStringCount, maxStringCount, strings); |
| 95 | } |
| 96 | |
| 97 | void getFunctions(BCCsizei *actualFunctionCount, |
| 98 | BCCsizei maxFunctionCount, |
| 99 | BCCchar **functions) { |
| 100 | mCompiler.getFunctions(actualFunctionCount, maxFunctionCount, functions); |
| 101 | } |
| 102 | |
| 103 | void getFunctionBinary(BCCchar *function, |
| 104 | BCCvoid **base, |
| 105 | BCCsizei *length) { |
| 106 | mCompiler.getFunctionBinary(function, base, length); |
| 107 | } |
| 108 | |
| 109 | void registerSymbolCallback(BCCSymbolLookupFn pFn, BCCvoid *pContext) { |
| 110 | mCompiler.registerSymbolCallback(pFn, pContext); |
| 111 | } |
| 112 | |
| 113 | int readModule(llvm::Module *module) { |
| 114 | return mCompiler.readModule(module); |
| 115 | } |
| 116 | |
| 117 | |
| 118 | ////////////////////////////////////////////////////////////////////////// |
| 119 | // Error handling |
| 120 | ////////////////////////////////////////////////////////////////////////// |
| 121 | |
Logan | 3f3d31f | 2010-11-27 13:52:03 +0800 | [diff] [blame] | 122 | void setError(BCCenum error) { |
Logan | 3973641 | 2010-12-29 00:24:04 +0800 | [diff] [blame] | 123 | if (mErrorCode == BCC_NO_ERROR && error != BCC_NO_ERROR) { |
| 124 | mErrorCode = error; |
Logan | 3f3d31f | 2010-11-27 13:52:03 +0800 | [diff] [blame] | 125 | } |
| 126 | } |
| 127 | |
| 128 | BCCenum getError() { |
Logan | 3973641 | 2010-12-29 00:24:04 +0800 | [diff] [blame] | 129 | BCCenum result = mErrorCode; |
| 130 | mErrorCode = BCC_NO_ERROR; |
Logan | 3f3d31f | 2010-11-27 13:52:03 +0800 | [diff] [blame] | 131 | return result; |
| 132 | } |
Logan | 3f3d31f | 2010-11-27 13:52:03 +0800 | [diff] [blame] | 133 | }; |
| 134 | |
| 135 | } // namespace bcc |
| 136 | |
| 137 | #endif // BCC_SCRIPT_H |