ScriptCompiled.cpp revision 2a6dc82a465631f82fc589c6bc68c15ed264f7eb
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#define LOG_TAG "bcc" 18#include <cutils/log.h> 19 20#include "ScriptCompiled.h" 21 22namespace bcc { 23 24void ScriptCompiled::getExportVars(BCCsizei *actualVarCount, 25 BCCsizei maxVarCount, 26 BCCvoid **vars) { 27 int varCount; 28 29#if 0 30 if (mUseCache && mCacheFd >= 0 && !mCacheNew) { 31 varCount = static_cast<int>(mCacheHdr->exportVarsCount); 32 if (actualVarCount) 33 *actualVarCount = varCount; 34 if (varCount > maxVarCount) 35 varCount = maxVarCount; 36 if (vars) { 37 uint32_t *cachedVars = (uint32_t *)(mCacheMapAddr + 38 mCacheHdr->exportVarsOffset); 39 40 for (int i = 0; i < varCount; i++) { 41 *vars = (BCCvoid *)((char *)(*cachedVars) + mCacheDiff); 42 vars++; 43 cachedVars++; 44 } 45 } 46 return; 47 } 48#endif 49 50 varCount = mExportVars.size(); 51 if (actualVarCount) 52 *actualVarCount = varCount; 53 if (varCount > maxVarCount) 54 varCount = maxVarCount; 55 if (vars) { 56 for (ExportVarList::const_iterator 57 I = mExportVars.begin(), E = mExportVars.end(); I != E; I++) { 58 *vars++ = *I; 59 } 60 } 61} 62 63 64void ScriptCompiled::getExportFuncs(BCCsizei *actualFuncCount, 65 BCCsizei maxFuncCount, 66 BCCvoid **funcs) { 67 int funcCount; 68 69#if 0 70 if (mUseCache && mCacheFd >= 0 && !mCacheNew) { 71 funcCount = static_cast<int>(mCacheHdr->exportFuncsCount); 72 if (actualFuncCount) 73 *actualFuncCount = funcCount; 74 if (funcCount > maxFuncCount) 75 funcCount = maxFuncCount; 76 if (funcs) { 77 uint32_t *cachedFuncs = (uint32_t *)(mCacheMapAddr + 78 mCacheHdr->exportFuncsOffset); 79 80 for (int i = 0; i < funcCount; i++) { 81 *funcs = (BCCvoid *)((char *)(*cachedFuncs) + mCacheDiff); 82 funcs++; 83 cachedFuncs++; 84 } 85 } 86 return; 87 } 88#endif 89 90 funcCount = mExportFuncs.size(); 91 if (actualFuncCount) 92 *actualFuncCount = funcCount; 93 if (funcCount > maxFuncCount) 94 funcCount = maxFuncCount; 95 if (funcs) { 96 for (ExportFuncList::const_iterator 97 I = mExportFuncs.begin(), E = mExportFuncs.end(); I != E; I++) { 98 *funcs++ = *I; 99 } 100 } 101} 102 103 104void ScriptCompiled::getPragmas(BCCsizei *actualStringCount, 105 BCCsizei maxStringCount, 106 BCCchar **strings) { 107 int stringCount; 108 109#if 0 110 if (mUseCache && mCacheFd >= 0 && !mCacheNew) { 111 stringCount = static_cast<int>(mCacheHdr->exportPragmasCount) * 2; 112 113 if (actualStringCount) 114 *actualStringCount = stringCount; 115 116 if (stringCount > maxStringCount) 117 stringCount = maxStringCount; 118 119 if (strings) { 120 char *pragmaTab = mCacheMapAddr + mCacheHdr->exportPragmasOffset; 121 122 oBCCPragmaEntry *cachedPragmaEntries = (oBCCPragmaEntry *)pragmaTab; 123 124 for (int i = 0; stringCount >= 2; stringCount -= 2, i++) { 125 *strings++ = pragmaTab + cachedPragmaEntries[i].pragmaNameOffset; 126 *strings++ = pragmaTab + cachedPragmaEntries[i].pragmaValueOffset; 127 } 128 } 129 130 return; 131 } 132#endif 133 134 stringCount = mPragmas.size() * 2; 135 136 if (actualStringCount) 137 *actualStringCount = stringCount; 138 if (stringCount > maxStringCount) 139 stringCount = maxStringCount; 140 if (strings) { 141 size_t i = 0; 142 for (PragmaList::const_iterator it = mPragmas.begin(); 143 stringCount >= 2; stringCount -= 2, it++, ++i) { 144 *strings++ = const_cast<BCCchar*>(it->first.c_str()); 145 *strings++ = const_cast<BCCchar*>(it->second.c_str()); 146 } 147 } 148} 149 150} // namespace bcc 151