blob: 189f94aa11d27fc07fce92ddb36b07f6b92e1127 [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"
Logan02286cb2011-01-07 00:30:47 +080020#include "ContextManager.h"
Logan4dcd6792011-02-28 05:12:00 +080021#include "DebugHelper.h"
Logan7dcaac92011-01-06 04:26:23 +080022
Logan2a6dc822011-01-06 04:05:20 +080023namespace bcc {
24
Logan7dcaac92011-01-06 04:26:23 +080025ScriptCompiled::~ScriptCompiled() {
Logan02286cb2011-01-07 00:30:47 +080026 // Deallocate the BCC context
27 if (mContext) {
Logan1dc63142011-02-25 17:14:51 +080028 ContextManager::get().deallocateContext(mContext);
Logan02286cb2011-01-07 00:30:47 +080029 }
30
31 // Delete the emitted function information
Loganf340bf72011-01-14 17:51:40 +080032 for (FuncInfoMap::iterator I = mEmittedFunctions.begin(),
Logan7dcaac92011-01-06 04:26:23 +080033 E = mEmittedFunctions.end(); I != E; I++) {
34 if (I->second != NULL) {
35 delete I->second;
36 }
37 }
Logan7dcaac92011-01-06 04:26:23 +080038}
39
Loganbe79ada2011-01-13 01:33:45 +080040void ScriptCompiled::getExportVarList(size_t varListSize, void **varList) {
41 if (varList) {
42 size_t varCount = getExportVarCount();
43
44 if (varCount > varListSize) {
45 varCount = varListSize;
46 }
47
Logan2a6dc822011-01-06 04:05:20 +080048 for (ExportVarList::const_iterator
Loganbe79ada2011-01-13 01:33:45 +080049 I = mExportVars.begin(), E = mExportVars.end();
50 I != E && varCount > 0; ++I, --varCount) {
51 *varList++ = *I;
Logan2a6dc822011-01-06 04:05:20 +080052 }
53 }
54}
55
56
Loganbe79ada2011-01-13 01:33:45 +080057void ScriptCompiled::getExportFuncList(size_t funcListSize, void **funcList) {
58 if (funcList) {
59 size_t funcCount = getExportFuncCount();
60
61 if (funcCount > funcListSize) {
62 funcCount = funcListSize;
63 }
64
Logan2a6dc822011-01-06 04:05:20 +080065 for (ExportFuncList::const_iterator
Loganbe79ada2011-01-13 01:33:45 +080066 I = mExportFuncs.begin(), E = mExportFuncs.end();
67 I != E && funcCount > 0; ++I, --funcCount) {
68 *funcList++ = *I;
Logan2a6dc822011-01-06 04:05:20 +080069 }
70 }
71}
72
73
Loganbe79ada2011-01-13 01:33:45 +080074void ScriptCompiled::getPragmaList(size_t pragmaListSize,
75 char const **keyList,
76 char const **valueList) {
77 size_t pragmaCount = getPragmaCount();
Logan2a6dc822011-01-06 04:05:20 +080078
Loganbe79ada2011-01-13 01:33:45 +080079 if (pragmaCount > pragmaListSize) {
80 pragmaCount = pragmaListSize;
81 }
82
83 for (PragmaList::const_iterator
84 I = mPragmas.begin(), E = mPragmas.end();
85 I != E && pragmaCount > 0; ++I, --pragmaCount) {
86 if (keyList) { *keyList++ = I->first.c_str(); }
87 if (valueList) { *valueList++ = I->second.c_str(); }
Logan2a6dc822011-01-06 04:05:20 +080088 }
89}
90
Logan7dcaac92011-01-06 04:26:23 +080091
92void *ScriptCompiled::lookup(const char *name) {
Logan Chienda5e0c32011-06-13 03:47:21 +080093#if USE_OLD_JIT
Loganf340bf72011-01-14 17:51:40 +080094 FuncInfoMap::const_iterator I = mEmittedFunctions.find(name);
95 return (I == mEmittedFunctions.end()) ? NULL : I->second->addr;
Logan Chienda5e0c32011-06-13 03:47:21 +080096#endif
97
98#if USE_MCJIT
99 return mCompiler.getSymbolAddress(name);
100#endif
101
102 return NULL;
Logan7dcaac92011-01-06 04:26:23 +0800103}
104
105
Loganf340bf72011-01-14 17:51:40 +0800106void ScriptCompiled::getFuncInfoList(size_t funcInfoListSize,
107 FuncInfo *funcInfoList) {
108 if (funcInfoList) {
Loganbe79ada2011-01-13 01:33:45 +0800109 size_t funcCount = getFuncCount();
Logan7dcaac92011-01-06 04:26:23 +0800110
Loganf340bf72011-01-14 17:51:40 +0800111 if (funcCount > funcInfoListSize) {
112 funcCount = funcInfoListSize;
Loganbe79ada2011-01-13 01:33:45 +0800113 }
Logan7dcaac92011-01-06 04:26:23 +0800114
Loganf340bf72011-01-14 17:51:40 +0800115 FuncInfo *info = funcInfoList;
116 for (FuncInfoMap::const_iterator
Logan7dcaac92011-01-06 04:26:23 +0800117 I = mEmittedFunctions.begin(), E = mEmittedFunctions.end();
Loganf340bf72011-01-14 17:51:40 +0800118 I != E && funcCount > 0; ++I, ++info, --funcCount) {
119 info->name = I->first.c_str();
120 info->addr = I->second->addr;
121 info->size = I->second->size;
Logan7dcaac92011-01-06 04:26:23 +0800122 }
123 }
124}
125
Stephen Hines071288a2011-01-27 14:38:26 -0800126void ScriptCompiled::getObjectSlotList(size_t objectSlotListSize,
127 uint32_t *objectSlotList) {
128 if (objectSlotList) {
129 size_t objectSlotCount = getObjectSlotCount();
130
131 if (objectSlotCount > objectSlotListSize) {
132 objectSlotCount = objectSlotListSize;
133 }
134
135 for (ObjectSlotList::const_iterator
136 I = mObjectSlots.begin(), E = mObjectSlots.end();
137 I != E && objectSlotCount > 0; ++I, --objectSlotCount) {
138 *objectSlotList++ = *I;
139 }
140 }
141
142}
Logan7dcaac92011-01-06 04:26:23 +0800143
Logan2a6dc822011-01-06 04:05:20 +0800144} // namespace bcc