blob: 3de7a7fc84ec5973837f686aba06e66e096ba8f3 [file] [log] [blame]
Logan2a6dc822011-01-06 04:05:20 +08001/*
Stephen Hinescc366e52012-02-21 17:22:04 -08002 * Copyright 2010-2012, The Android Open Source Project
Logan2a6dc822011-01-06 04:05:20 +08003 *
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
Logan2a6dc822011-01-06 04:05:20 +080017#include "ScriptCompiled.h"
18
Loganf340bf72011-01-14 17:51:40 +080019#include "bcc_internal.h"
Logan4dcd6792011-02-28 05:12:00 +080020#include "DebugHelper.h"
Logan7dcaac92011-01-06 04:26:23 +080021
Logan2a6dc822011-01-06 04:05:20 +080022namespace bcc {
23
Logan7dcaac92011-01-06 04:26:23 +080024ScriptCompiled::~ScriptCompiled() {
Logan7dcaac92011-01-06 04:26:23 +080025}
26
Loganbe79ada2011-01-13 01:33:45 +080027void 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
Logan2a6dc822011-01-06 04:05:20 +080035 for (ExportVarList::const_iterator
Loganbe79ada2011-01-13 01:33:45 +080036 I = mExportVars.begin(), E = mExportVars.end();
37 I != E && varCount > 0; ++I, --varCount) {
38 *varList++ = *I;
Logan2a6dc822011-01-06 04:05:20 +080039 }
40 }
41}
42
Joseph Wenf36637f2011-07-06 18:27:12 -070043void ScriptCompiled::getExportVarNameList(std::vector<std::string> &varList) {
44 varList = mExportVarsName;
45}
46
47
48void ScriptCompiled::getExportFuncNameList(std::vector<std::string> &funcList) {
49 funcList = mExportFuncsName;
50}
51
Logan2a6dc822011-01-06 04:05:20 +080052
Stephen Hinescc366e52012-02-21 17:22:04 -080053void ScriptCompiled::getExportForEachNameList(std::vector<std::string> &forEachList) {
54 forEachList = mExportForEachName;
55}
56
57
Loganbe79ada2011-01-13 01:33:45 +080058void 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
Logan2a6dc822011-01-06 04:05:20 +080066 for (ExportFuncList::const_iterator
Loganbe79ada2011-01-13 01:33:45 +080067 I = mExportFuncs.begin(), E = mExportFuncs.end();
68 I != E && funcCount > 0; ++I, --funcCount) {
69 *funcList++ = *I;
Logan2a6dc822011-01-06 04:05:20 +080070 }
71 }
72}
73
74
Stephen Hinescc366e52012-02-21 17:22:04 -080075void 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
Loganbe79ada2011-01-13 01:33:45 +080093void ScriptCompiled::getPragmaList(size_t pragmaListSize,
94 char const **keyList,
95 char const **valueList) {
96 size_t pragmaCount = getPragmaCount();
Logan2a6dc822011-01-06 04:05:20 +080097
Loganbe79ada2011-01-13 01:33:45 +080098 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(); }
Logan2a6dc822011-01-06 04:05:20 +0800107 }
108}
109
Logan7dcaac92011-01-06 04:26:23 +0800110
111void *ScriptCompiled::lookup(const char *name) {
Logan Chienda5e0c32011-06-13 03:47:21 +0800112#if USE_MCJIT
113 return mCompiler.getSymbolAddress(name);
114#endif
115
116 return NULL;
Logan7dcaac92011-01-06 04:26:23 +0800117}
118
119
Loganf340bf72011-01-14 17:51:40 +0800120void ScriptCompiled::getFuncInfoList(size_t funcInfoListSize,
121 FuncInfo *funcInfoList) {
122 if (funcInfoList) {
Loganbe79ada2011-01-13 01:33:45 +0800123 size_t funcCount = getFuncCount();
Logan7dcaac92011-01-06 04:26:23 +0800124
Loganf340bf72011-01-14 17:51:40 +0800125 if (funcCount > funcInfoListSize) {
126 funcCount = funcInfoListSize;
Loganbe79ada2011-01-13 01:33:45 +0800127 }
Logan7dcaac92011-01-06 04:26:23 +0800128
Loganf340bf72011-01-14 17:51:40 +0800129 FuncInfo *info = funcInfoList;
130 for (FuncInfoMap::const_iterator
Logan7dcaac92011-01-06 04:26:23 +0800131 I = mEmittedFunctions.begin(), E = mEmittedFunctions.end();
Loganf340bf72011-01-14 17:51:40 +0800132 I != E && funcCount > 0; ++I, ++info, --funcCount) {
133 info->name = I->first.c_str();
134 info->addr = I->second->addr;
135 info->size = I->second->size;
Logan7dcaac92011-01-06 04:26:23 +0800136 }
137 }
138}
139
Stephen Hines071288a2011-01-27 14:38:26 -0800140void ScriptCompiled::getObjectSlotList(size_t objectSlotListSize,
141 uint32_t *objectSlotList) {
142 if (objectSlotList) {
143 size_t objectSlotCount = getObjectSlotCount();
144
145 if (objectSlotCount > objectSlotListSize) {
146 objectSlotCount = objectSlotListSize;
147 }
148
149 for (ObjectSlotList::const_iterator
150 I = mObjectSlots.begin(), E = mObjectSlots.end();
151 I != E && objectSlotCount > 0; ++I, --objectSlotCount) {
152 *objectSlotList++ = *I;
153 }
154 }
155
156}
Logan7dcaac92011-01-06 04:26:23 +0800157
Logan2a6dc822011-01-06 04:05:20 +0800158} // namespace bcc