blob: 47f2bb42e5cf5126cc8db2315cf4ab41677fd2d4 [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"
Logan Chiend2a5f302011-07-19 20:32:25 +080020#if USE_OLD_JIT
21#include "OldJIT/ContextManager.h"
22#endif
Logan4dcd6792011-02-28 05:12:00 +080023#include "DebugHelper.h"
Logan7dcaac92011-01-06 04:26:23 +080024
Logan2a6dc822011-01-06 04:05:20 +080025namespace bcc {
26
Logan7dcaac92011-01-06 04:26:23 +080027ScriptCompiled::~ScriptCompiled() {
Logan Chiend2a5f302011-07-19 20:32:25 +080028#if USE_OLD_JIT
Logan02286cb2011-01-07 00:30:47 +080029 // Deallocate the BCC context
30 if (mContext) {
Logan1dc63142011-02-25 17:14:51 +080031 ContextManager::get().deallocateContext(mContext);
Logan02286cb2011-01-07 00:30:47 +080032 }
33
34 // Delete the emitted function information
Loganf340bf72011-01-14 17:51:40 +080035 for (FuncInfoMap::iterator I = mEmittedFunctions.begin(),
Logan7dcaac92011-01-06 04:26:23 +080036 E = mEmittedFunctions.end(); I != E; I++) {
37 if (I->second != NULL) {
38 delete I->second;
39 }
40 }
Logan Chiend2a5f302011-07-19 20:32:25 +080041#endif
Logan7dcaac92011-01-06 04:26:23 +080042}
43
Loganbe79ada2011-01-13 01:33:45 +080044void ScriptCompiled::getExportVarList(size_t varListSize, void **varList) {
45 if (varList) {
46 size_t varCount = getExportVarCount();
47
48 if (varCount > varListSize) {
49 varCount = varListSize;
50 }
51
Logan2a6dc822011-01-06 04:05:20 +080052 for (ExportVarList::const_iterator
Loganbe79ada2011-01-13 01:33:45 +080053 I = mExportVars.begin(), E = mExportVars.end();
54 I != E && varCount > 0; ++I, --varCount) {
55 *varList++ = *I;
Logan2a6dc822011-01-06 04:05:20 +080056 }
57 }
58}
59
Joseph Wenf36637f2011-07-06 18:27:12 -070060void ScriptCompiled::getExportVarNameList(std::vector<std::string> &varList) {
61 varList = mExportVarsName;
62}
63
64
65void ScriptCompiled::getExportFuncNameList(std::vector<std::string> &funcList) {
66 funcList = mExportFuncsName;
67}
68
Logan2a6dc822011-01-06 04:05:20 +080069
Stephen Hinescc366e52012-02-21 17:22:04 -080070void ScriptCompiled::getExportForEachNameList(std::vector<std::string> &forEachList) {
71 forEachList = mExportForEachName;
72}
73
74
Loganbe79ada2011-01-13 01:33:45 +080075void ScriptCompiled::getExportFuncList(size_t funcListSize, void **funcList) {
76 if (funcList) {
77 size_t funcCount = getExportFuncCount();
78
79 if (funcCount > funcListSize) {
80 funcCount = funcListSize;
81 }
82
Logan2a6dc822011-01-06 04:05:20 +080083 for (ExportFuncList::const_iterator
Loganbe79ada2011-01-13 01:33:45 +080084 I = mExportFuncs.begin(), E = mExportFuncs.end();
85 I != E && funcCount > 0; ++I, --funcCount) {
86 *funcList++ = *I;
Logan2a6dc822011-01-06 04:05:20 +080087 }
88 }
89}
90
91
Stephen Hinescc366e52012-02-21 17:22:04 -080092void ScriptCompiled::getExportForEachList(size_t forEachListSize,
93 void **forEachList) {
94 if (forEachList) {
95 size_t forEachCount = getExportForEachCount();
96
97 if (forEachCount > forEachListSize) {
98 forEachCount = forEachListSize;
99 }
100
101 for (ExportForEachList::const_iterator
102 I = mExportForEach.begin(), E = mExportForEach.end();
103 I != E && forEachCount > 0; ++I, --forEachCount) {
104 *forEachList++ = *I;
105 }
106 }
107}
108
109
Loganbe79ada2011-01-13 01:33:45 +0800110void ScriptCompiled::getPragmaList(size_t pragmaListSize,
111 char const **keyList,
112 char const **valueList) {
113 size_t pragmaCount = getPragmaCount();
Logan2a6dc822011-01-06 04:05:20 +0800114
Loganbe79ada2011-01-13 01:33:45 +0800115 if (pragmaCount > pragmaListSize) {
116 pragmaCount = pragmaListSize;
117 }
118
119 for (PragmaList::const_iterator
120 I = mPragmas.begin(), E = mPragmas.end();
121 I != E && pragmaCount > 0; ++I, --pragmaCount) {
122 if (keyList) { *keyList++ = I->first.c_str(); }
123 if (valueList) { *valueList++ = I->second.c_str(); }
Logan2a6dc822011-01-06 04:05:20 +0800124 }
125}
126
Logan7dcaac92011-01-06 04:26:23 +0800127
128void *ScriptCompiled::lookup(const char *name) {
Logan Chienda5e0c32011-06-13 03:47:21 +0800129#if USE_OLD_JIT
Loganf340bf72011-01-14 17:51:40 +0800130 FuncInfoMap::const_iterator I = mEmittedFunctions.find(name);
131 return (I == mEmittedFunctions.end()) ? NULL : I->second->addr;
Logan Chienda5e0c32011-06-13 03:47:21 +0800132#endif
133
134#if USE_MCJIT
135 return mCompiler.getSymbolAddress(name);
136#endif
137
138 return NULL;
Logan7dcaac92011-01-06 04:26:23 +0800139}
140
141
Loganf340bf72011-01-14 17:51:40 +0800142void ScriptCompiled::getFuncInfoList(size_t funcInfoListSize,
143 FuncInfo *funcInfoList) {
144 if (funcInfoList) {
Loganbe79ada2011-01-13 01:33:45 +0800145 size_t funcCount = getFuncCount();
Logan7dcaac92011-01-06 04:26:23 +0800146
Loganf340bf72011-01-14 17:51:40 +0800147 if (funcCount > funcInfoListSize) {
148 funcCount = funcInfoListSize;
Loganbe79ada2011-01-13 01:33:45 +0800149 }
Logan7dcaac92011-01-06 04:26:23 +0800150
Loganf340bf72011-01-14 17:51:40 +0800151 FuncInfo *info = funcInfoList;
152 for (FuncInfoMap::const_iterator
Logan7dcaac92011-01-06 04:26:23 +0800153 I = mEmittedFunctions.begin(), E = mEmittedFunctions.end();
Loganf340bf72011-01-14 17:51:40 +0800154 I != E && funcCount > 0; ++I, ++info, --funcCount) {
155 info->name = I->first.c_str();
156 info->addr = I->second->addr;
157 info->size = I->second->size;
Logan7dcaac92011-01-06 04:26:23 +0800158 }
159 }
160}
161
Stephen Hines071288a2011-01-27 14:38:26 -0800162void ScriptCompiled::getObjectSlotList(size_t objectSlotListSize,
163 uint32_t *objectSlotList) {
164 if (objectSlotList) {
165 size_t objectSlotCount = getObjectSlotCount();
166
167 if (objectSlotCount > objectSlotListSize) {
168 objectSlotCount = objectSlotListSize;
169 }
170
171 for (ObjectSlotList::const_iterator
172 I = mObjectSlots.begin(), E = mObjectSlots.end();
173 I != E && objectSlotCount > 0; ++I, --objectSlotCount) {
174 *objectSlotList++ = *I;
175 }
176 }
177
178}
Logan7dcaac92011-01-06 04:26:23 +0800179
Logan2a6dc822011-01-06 04:05:20 +0800180} // namespace bcc