blob: bb3c79ab8d5794dedac8418dd698d95e04eea132 [file] [log] [blame]
Logan2a6dc822011-01-06 04:05:20 +08001/*
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
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
Loganbe79ada2011-01-13 01:33:45 +080070void ScriptCompiled::getExportFuncList(size_t funcListSize, void **funcList) {
71 if (funcList) {
72 size_t funcCount = getExportFuncCount();
73
74 if (funcCount > funcListSize) {
75 funcCount = funcListSize;
76 }
77
Logan2a6dc822011-01-06 04:05:20 +080078 for (ExportFuncList::const_iterator
Loganbe79ada2011-01-13 01:33:45 +080079 I = mExportFuncs.begin(), E = mExportFuncs.end();
80 I != E && funcCount > 0; ++I, --funcCount) {
81 *funcList++ = *I;
Logan2a6dc822011-01-06 04:05:20 +080082 }
83 }
84}
85
86
Loganbe79ada2011-01-13 01:33:45 +080087void ScriptCompiled::getPragmaList(size_t pragmaListSize,
88 char const **keyList,
89 char const **valueList) {
90 size_t pragmaCount = getPragmaCount();
Logan2a6dc822011-01-06 04:05:20 +080091
Loganbe79ada2011-01-13 01:33:45 +080092 if (pragmaCount > pragmaListSize) {
93 pragmaCount = pragmaListSize;
94 }
95
96 for (PragmaList::const_iterator
97 I = mPragmas.begin(), E = mPragmas.end();
98 I != E && pragmaCount > 0; ++I, --pragmaCount) {
99 if (keyList) { *keyList++ = I->first.c_str(); }
100 if (valueList) { *valueList++ = I->second.c_str(); }
Logan2a6dc822011-01-06 04:05:20 +0800101 }
102}
103
Logan7dcaac92011-01-06 04:26:23 +0800104
105void *ScriptCompiled::lookup(const char *name) {
Logan Chienda5e0c32011-06-13 03:47:21 +0800106#if USE_OLD_JIT
Loganf340bf72011-01-14 17:51:40 +0800107 FuncInfoMap::const_iterator I = mEmittedFunctions.find(name);
108 return (I == mEmittedFunctions.end()) ? NULL : I->second->addr;
Logan Chienda5e0c32011-06-13 03:47:21 +0800109#endif
110
111#if USE_MCJIT
112 return mCompiler.getSymbolAddress(name);
113#endif
114
115 return NULL;
Logan7dcaac92011-01-06 04:26:23 +0800116}
117
118
Loganf340bf72011-01-14 17:51:40 +0800119void ScriptCompiled::getFuncInfoList(size_t funcInfoListSize,
120 FuncInfo *funcInfoList) {
121 if (funcInfoList) {
Loganbe79ada2011-01-13 01:33:45 +0800122 size_t funcCount = getFuncCount();
Logan7dcaac92011-01-06 04:26:23 +0800123
Loganf340bf72011-01-14 17:51:40 +0800124 if (funcCount > funcInfoListSize) {
125 funcCount = funcInfoListSize;
Loganbe79ada2011-01-13 01:33:45 +0800126 }
Logan7dcaac92011-01-06 04:26:23 +0800127
Loganf340bf72011-01-14 17:51:40 +0800128 FuncInfo *info = funcInfoList;
129 for (FuncInfoMap::const_iterator
Logan7dcaac92011-01-06 04:26:23 +0800130 I = mEmittedFunctions.begin(), E = mEmittedFunctions.end();
Loganf340bf72011-01-14 17:51:40 +0800131 I != E && funcCount > 0; ++I, ++info, --funcCount) {
132 info->name = I->first.c_str();
133 info->addr = I->second->addr;
134 info->size = I->second->size;
Logan7dcaac92011-01-06 04:26:23 +0800135 }
136 }
137}
138
Stephen Hines071288a2011-01-27 14:38:26 -0800139void ScriptCompiled::getObjectSlotList(size_t objectSlotListSize,
140 uint32_t *objectSlotList) {
141 if (objectSlotList) {
142 size_t objectSlotCount = getObjectSlotCount();
143
144 if (objectSlotCount > objectSlotListSize) {
145 objectSlotCount = objectSlotListSize;
146 }
147
148 for (ObjectSlotList::const_iterator
149 I = mObjectSlots.begin(), E = mObjectSlots.end();
150 I != E && objectSlotCount > 0; ++I, --objectSlotCount) {
151 *objectSlotList++ = *I;
152 }
153 }
154
155}
Logan7dcaac92011-01-06 04:26:23 +0800156
Logan2a6dc822011-01-06 04:05:20 +0800157} // namespace bcc