1 /* 2 * Copyright 2010-2012, 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 #include "ScriptCompiled.h" 18 19 #include "bcc_internal.h" 20 #include "DebugHelper.h" 21 22 namespace bcc { 23 24 ScriptCompiled::~ScriptCompiled() { 25 } 26 27 void ScriptCompiled::getExportVarList(size_t varListSize, void **varList) { 28 if (varList) { 29 size_t varCount = getExportVarCount(); 30 31 if (varCount > varListSize) { 32 varCount = varListSize; 33 } 34 35 for (ExportVarList::const_iterator 36 I = mExportVars.begin(), E = mExportVars.end(); 37 I != E && varCount > 0; ++I, --varCount) { 38 *varList++ = *I; 39 } 40 } 41 } 42 43 void ScriptCompiled::getExportVarNameList(std::vector<std::string> &varList) { 44 varList = mExportVarsName; 45 } 46 47 48 void ScriptCompiled::getExportFuncNameList(std::vector<std::string> &funcList) { 49 funcList = mExportFuncsName; 50 } 51 52 53 void ScriptCompiled::getExportForEachNameList(std::vector<std::string> &forEachList) { 54 forEachList = mExportForEachName; 55 } 56 57 58 void ScriptCompiled::getExportFuncList(size_t funcListSize, void **funcList) { 59 if (funcList) { 60 size_t funcCount = getExportFuncCount(); 61 62 if (funcCount > funcListSize) { 63 funcCount = funcListSize; 64 } 65 66 for (ExportFuncList::const_iterator 67 I = mExportFuncs.begin(), E = mExportFuncs.end(); 68 I != E && funcCount > 0; ++I, --funcCount) { 69 *funcList++ = *I; 70 } 71 } 72 } 73 74 75 void ScriptCompiled::getExportForEachList(size_t forEachListSize, 76 void **forEachList) { 77 if (forEachList) { 78 size_t forEachCount = getExportForEachCount(); 79 80 if (forEachCount > forEachListSize) { 81 forEachCount = forEachListSize; 82 } 83 84 for (ExportForEachList::const_iterator 85 I = mExportForEach.begin(), E = mExportForEach.end(); 86 I != E && forEachCount > 0; ++I, --forEachCount) { 87 *forEachList++ = *I; 88 } 89 } 90 } 91 92 93 void ScriptCompiled::getPragmaList(size_t pragmaListSize, 94 char const **keyList, 95 char const **valueList) { 96 size_t pragmaCount = getPragmaCount(); 97 98 if (pragmaCount > pragmaListSize) { 99 pragmaCount = pragmaListSize; 100 } 101 102 for (PragmaList::const_iterator 103 I = mPragmas.begin(), E = mPragmas.end(); 104 I != E && pragmaCount > 0; ++I, --pragmaCount) { 105 if (keyList) { *keyList++ = I->first.c_str(); } 106 if (valueList) { *valueList++ = I->second.c_str(); } 107 } 108 } 109 110 111 void *ScriptCompiled::lookup(const char *name) { 112 return mCompiler.getSymbolAddress(name); 113 } 114 115 116 void ScriptCompiled::getFuncInfoList(size_t funcInfoListSize, 117 FuncInfo *funcInfoList) { 118 if (funcInfoList) { 119 size_t funcCount = getFuncCount(); 120 121 if (funcCount > funcInfoListSize) { 122 funcCount = funcInfoListSize; 123 } 124 125 FuncInfo *info = funcInfoList; 126 for (FuncInfoMap::const_iterator 127 I = mEmittedFunctions.begin(), E = mEmittedFunctions.end(); 128 I != E && funcCount > 0; ++I, ++info, --funcCount) { 129 info->name = I->first.c_str(); 130 info->addr = I->second->addr; 131 info->size = I->second->size; 132 } 133 } 134 } 135 136 void ScriptCompiled::getObjectSlotList(size_t objectSlotListSize, 137 uint32_t *objectSlotList) { 138 if (objectSlotList) { 139 size_t objectSlotCount = getObjectSlotCount(); 140 141 if (objectSlotCount > objectSlotListSize) { 142 objectSlotCount = objectSlotListSize; 143 } 144 145 for (ObjectSlotList::const_iterator 146 I = mObjectSlots.begin(), E = mObjectSlots.end(); 147 I != E && objectSlotCount > 0; ++I, --objectSlotCount) { 148 *objectSlotList++ = *I; 149 } 150 } 151 152 } 153 154 } // namespace bcc 155