Shih-wei Liao | 77ed614 | 2010-04-07 12:21:42 -0700 | [diff] [blame] | 1 | /* |
Zonr Chang | 932648d | 2010-10-13 22:23:56 +0800 | [diff] [blame] | 2 | * Copyright 2010, The Android Open Source Project |
Shih-wei Liao | 77ed614 | 2010-04-07 12:21:42 -0700 | [diff] [blame] | 3 | * |
Zonr Chang | 932648d | 2010-10-13 22:23:56 +0800 | [diff] [blame] | 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. |
Shih-wei Liao | 77ed614 | 2010-04-07 12:21:42 -0700 | [diff] [blame] | 15 | */ |
| 16 | |
Zonr Chang | 932648d | 2010-10-13 22:23:56 +0800 | [diff] [blame] | 17 | // Bitcode compiler (bcc) for Android: |
| 18 | // This is an eager-compilation JIT running on Android. |
| 19 | |
Shih-wei Liao | 77ed614 | 2010-04-07 12:21:42 -0700 | [diff] [blame] | 20 | #define LOG_TAG "bcc" |
| 21 | #include <cutils/log.h> |
| 22 | |
Logan | c439523 | 2010-11-27 18:54:17 +0800 | [diff] [blame] | 23 | #include "Compiler.h" |
| 24 | #include "Script.h" |
Shih-wei Liao | 77ed614 | 2010-04-07 12:21:42 -0700 | [diff] [blame] | 25 | |
Logan | c439523 | 2010-11-27 18:54:17 +0800 | [diff] [blame] | 26 | #include <bcc/bcc.h> |
Logan | 39a2ca5 | 2010-11-27 01:03:06 +0800 | [diff] [blame] | 27 | |
Shih-wei Liao | 7c5a5f7 | 2010-11-08 01:59:13 -0800 | [diff] [blame] | 28 | #include <utils/StopWatch.h> |
Shih-wei Liao | 77ed614 | 2010-04-07 12:21:42 -0700 | [diff] [blame] | 29 | |
Shih-wei Liao | 77ed614 | 2010-04-07 12:21:42 -0700 | [diff] [blame] | 30 | |
Logan | 39a2ca5 | 2010-11-27 01:03:06 +0800 | [diff] [blame] | 31 | namespace llvm { |
| 32 | class Module; |
Shih-wei Liao | 7c5a5f7 | 2010-11-08 01:59:13 -0800 | [diff] [blame] | 33 | } |
| 34 | |
Logan | 39a2ca5 | 2010-11-27 01:03:06 +0800 | [diff] [blame] | 35 | |
Logan | 3f3d31f | 2010-11-27 13:52:03 +0800 | [diff] [blame] | 36 | extern "C" BCCscript *bccCreateScript() { |
| 37 | return new BCCscript(); |
| 38 | } |
Shih-wei Liao | 77ed614 | 2010-04-07 12:21:42 -0700 | [diff] [blame] | 39 | |
Logan | 3f3d31f | 2010-11-27 13:52:03 +0800 | [diff] [blame] | 40 | extern "C" BCCenum bccGetError(BCCscript *script) { |
| 41 | return script->getError(); |
| 42 | } |
Shih-wei Liao | 77ed614 | 2010-04-07 12:21:42 -0700 | [diff] [blame] | 43 | |
Logan | 3f3d31f | 2010-11-27 13:52:03 +0800 | [diff] [blame] | 44 | extern "C" void bccDeleteScript(BCCscript *script) { |
| 45 | delete script; |
| 46 | } |
Shih-wei Liao | 77ed614 | 2010-04-07 12:21:42 -0700 | [diff] [blame] | 47 | |
Logan | 3f3d31f | 2010-11-27 13:52:03 +0800 | [diff] [blame] | 48 | extern "C" void bccRegisterSymbolCallback(BCCscript *script, |
| 49 | BCCSymbolLookupFn pFn, |
| 50 | BCCvoid *pContext) { |
| 51 | script->registerSymbolCallback(pFn, pContext); |
| 52 | } |
Shih-wei Liao | 77ed614 | 2010-04-07 12:21:42 -0700 | [diff] [blame] | 53 | |
Logan | 3f3d31f | 2010-11-27 13:52:03 +0800 | [diff] [blame] | 54 | extern "C" int bccReadModule(BCCscript *script, BCCvoid *module) { |
| 55 | return script->compiler.readModule(reinterpret_cast<llvm::Module*>(module)); |
| 56 | } |
Shih-wei Liao | 77ed614 | 2010-04-07 12:21:42 -0700 | [diff] [blame] | 57 | |
Logan | 3f3d31f | 2010-11-27 13:52:03 +0800 | [diff] [blame] | 58 | extern "C" int bccReadBC(BCCscript *script, |
| 59 | const BCCchar *bitcode, |
| 60 | BCCint size, |
| 61 | const BCCchar *resName) { |
| 62 | return script->compiler.readBC(bitcode, size, resName); |
| 63 | } |
Zonr Chang | 932648d | 2010-10-13 22:23:56 +0800 | [diff] [blame] | 64 | |
Logan | 3f3d31f | 2010-11-27 13:52:03 +0800 | [diff] [blame] | 65 | extern "C" void bccLinkBC(BCCscript *script, |
| 66 | const BCCchar *bitcode, |
| 67 | BCCint size) { |
| 68 | script->compiler.linkBC(bitcode, size); |
| 69 | } |
Shih-wei Liao | 77ed614 | 2010-04-07 12:21:42 -0700 | [diff] [blame] | 70 | |
Logan | 3f3d31f | 2010-11-27 13:52:03 +0800 | [diff] [blame] | 71 | extern "C" int bccLoadBinary(BCCscript *script) { |
| 72 | int result = script->compiler.loadCacheFile(); |
| 73 | if (result) |
| 74 | script->setError(BCC_INVALID_OPERATION); |
| 75 | return result; |
| 76 | } |
Shih-wei Liao | 77ed614 | 2010-04-07 12:21:42 -0700 | [diff] [blame] | 77 | |
Logan | 3f3d31f | 2010-11-27 13:52:03 +0800 | [diff] [blame] | 78 | extern "C" void bccCompileBC(BCCscript *script) { |
| 79 | { |
| 80 | #if defined(__arm__) |
| 81 | android::StopWatch compileTimer("RenderScript compile time"); |
| 82 | #endif |
| 83 | int result = script->compiler.compile(); |
Shih-wei Liao | 7c5a5f7 | 2010-11-08 01:59:13 -0800 | [diff] [blame] | 84 | if (result) |
| 85 | script->setError(BCC_INVALID_OPERATION); |
| 86 | } |
Logan | 3f3d31f | 2010-11-27 13:52:03 +0800 | [diff] [blame] | 87 | } |
Shih-wei Liao | 7c5a5f7 | 2010-11-08 01:59:13 -0800 | [diff] [blame] | 88 | |
Logan | 3f3d31f | 2010-11-27 13:52:03 +0800 | [diff] [blame] | 89 | extern "C" void bccGetScriptInfoLog(BCCscript *script, |
| 90 | BCCsizei maxLength, |
| 91 | BCCsizei *length, |
| 92 | BCCchar *infoLog) { |
| 93 | char *message = script->compiler.getErrorMessage(); |
| 94 | int messageLength = strlen(message) + 1; |
| 95 | if (length) |
| 96 | *length = messageLength; |
| 97 | |
| 98 | if (infoLog && maxLength > 0) { |
| 99 | int trimmedLength = maxLength < messageLength ? maxLength : messageLength; |
| 100 | memcpy(infoLog, message, trimmedLength); |
| 101 | infoLog[trimmedLength] = 0; |
Shih-wei Liao | 77ed614 | 2010-04-07 12:21:42 -0700 | [diff] [blame] | 102 | } |
Logan | 3f3d31f | 2010-11-27 13:52:03 +0800 | [diff] [blame] | 103 | } |
Shih-wei Liao | 77ed614 | 2010-04-07 12:21:42 -0700 | [diff] [blame] | 104 | |
Logan | 3f3d31f | 2010-11-27 13:52:03 +0800 | [diff] [blame] | 105 | extern "C" void bccGetScriptLabel(BCCscript *script, |
| 106 | const BCCchar *name, |
| 107 | BCCvoid **address) { |
| 108 | void *value = script->compiler.lookup(name); |
| 109 | if (value) |
| 110 | *address = value; |
| 111 | else |
| 112 | script->setError(BCC_INVALID_VALUE); |
| 113 | } |
Shih-wei Liao | 77ed614 | 2010-04-07 12:21:42 -0700 | [diff] [blame] | 114 | |
Logan | 3f3d31f | 2010-11-27 13:52:03 +0800 | [diff] [blame] | 115 | extern "C" void bccGetExportVars(BCCscript *script, |
| 116 | BCCsizei *actualVarCount, |
| 117 | BCCsizei maxVarCount, |
| 118 | BCCvoid **vars) { |
| 119 | script->compiler.getExportVars(actualVarCount, maxVarCount, vars); |
| 120 | } |
Shih-wei Liao | abd1e3d | 2010-04-28 01:47:00 -0700 | [diff] [blame] | 121 | |
Logan | 3f3d31f | 2010-11-27 13:52:03 +0800 | [diff] [blame] | 122 | extern "C" void bccGetExportFuncs(BCCscript *script, |
| 123 | BCCsizei *actualFuncCount, |
| 124 | BCCsizei maxFuncCount, |
| 125 | BCCvoid **funcs) { |
| 126 | script->compiler.getExportFuncs(actualFuncCount, maxFuncCount, funcs); |
| 127 | } |
Shih-wei Liao | 6bfd542 | 2010-05-07 05:20:22 -0700 | [diff] [blame] | 128 | |
Logan | 3f3d31f | 2010-11-27 13:52:03 +0800 | [diff] [blame] | 129 | extern "C" void bccGetPragmas(BCCscript *script, |
| 130 | BCCsizei *actualStringCount, |
| 131 | BCCsizei maxStringCount, |
| 132 | BCCchar **strings) { |
| 133 | script->compiler.getPragmas(actualStringCount, maxStringCount, strings); |
| 134 | } |
Shih-wei Liao | 77ed614 | 2010-04-07 12:21:42 -0700 | [diff] [blame] | 135 | |
Logan | 3f3d31f | 2010-11-27 13:52:03 +0800 | [diff] [blame] | 136 | extern "C" void bccGetFunctions(BCCscript *script, |
| 137 | BCCsizei *actualFunctionCount, |
| 138 | BCCsizei maxFunctionCount, |
| 139 | BCCchar **functions) { |
| 140 | script->compiler.getFunctions(actualFunctionCount, |
| 141 | maxFunctionCount, |
| 142 | functions); |
| 143 | } |
Shih-wei Liao | 77ed614 | 2010-04-07 12:21:42 -0700 | [diff] [blame] | 144 | |
Logan | 3f3d31f | 2010-11-27 13:52:03 +0800 | [diff] [blame] | 145 | extern "C" void bccGetFunctionBinary(BCCscript *script, |
| 146 | BCCchar *function, |
| 147 | BCCvoid **base, |
| 148 | BCCsizei *length) { |
| 149 | script->compiler.getFunctionBinary(function, base, length); |
| 150 | } |