blob: 5c07d99e4c650786e21132681effd5741a8feaff [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
17#define LOG_TAG "bcc"
18#include <cutils/log.h>
19
20#include "ScriptCompiled.h"
21
Logan02286cb2011-01-07 00:30:47 +080022#include "ContextManager.h"
Logan7dcaac92011-01-06 04:26:23 +080023#include "EmittedFuncInfo.h"
24
Logan2a6dc822011-01-06 04:05:20 +080025namespace bcc {
26
Logan7dcaac92011-01-06 04:26:23 +080027ScriptCompiled::~ScriptCompiled() {
Logan02286cb2011-01-07 00:30:47 +080028 // Deallocate the BCC context
29 if (mContext) {
30 deallocateContext(mContext);
31 }
32
33 // Delete the emitted function information
Logan7dcaac92011-01-06 04:26:23 +080034 for (EmittedFunctionsMapTy::iterator I = mEmittedFunctions.begin(),
35 E = mEmittedFunctions.end(); I != E; I++) {
36 if (I->second != NULL) {
37 delete I->second;
38 }
39 }
Logan7dcaac92011-01-06 04:26:23 +080040}
41
Logan2a6dc822011-01-06 04:05:20 +080042void ScriptCompiled::getExportVars(BCCsizei *actualVarCount,
43 BCCsizei maxVarCount,
44 BCCvoid **vars) {
Logan02286cb2011-01-07 00:30:47 +080045 int varCount = mExportVars.size();
Logan2a6dc822011-01-06 04:05:20 +080046 if (actualVarCount)
47 *actualVarCount = varCount;
48 if (varCount > maxVarCount)
49 varCount = maxVarCount;
50 if (vars) {
51 for (ExportVarList::const_iterator
52 I = mExportVars.begin(), E = mExportVars.end(); I != E; I++) {
53 *vars++ = *I;
54 }
55 }
56}
57
58
59void ScriptCompiled::getExportFuncs(BCCsizei *actualFuncCount,
60 BCCsizei maxFuncCount,
61 BCCvoid **funcs) {
Logan02286cb2011-01-07 00:30:47 +080062 int funcCount = mExportFuncs.size();
Logan2a6dc822011-01-06 04:05:20 +080063 if (actualFuncCount)
64 *actualFuncCount = funcCount;
65 if (funcCount > maxFuncCount)
66 funcCount = maxFuncCount;
67 if (funcs) {
68 for (ExportFuncList::const_iterator
69 I = mExportFuncs.begin(), E = mExportFuncs.end(); I != E; I++) {
70 *funcs++ = *I;
71 }
72 }
73}
74
75
76void ScriptCompiled::getPragmas(BCCsizei *actualStringCount,
77 BCCsizei maxStringCount,
78 BCCchar **strings) {
Logan02286cb2011-01-07 00:30:47 +080079 int stringCount = mPragmas.size() * 2;
Logan2a6dc822011-01-06 04:05:20 +080080
81 if (actualStringCount)
82 *actualStringCount = stringCount;
83 if (stringCount > maxStringCount)
84 stringCount = maxStringCount;
85 if (strings) {
86 size_t i = 0;
87 for (PragmaList::const_iterator it = mPragmas.begin();
88 stringCount >= 2; stringCount -= 2, it++, ++i) {
89 *strings++ = const_cast<BCCchar*>(it->first.c_str());
90 *strings++ = const_cast<BCCchar*>(it->second.c_str());
91 }
92 }
93}
94
Logan7dcaac92011-01-06 04:26:23 +080095
96void *ScriptCompiled::lookup(const char *name) {
Logan7dcaac92011-01-06 04:26:23 +080097 EmittedFunctionsMapTy::const_iterator I = mEmittedFunctions.find(name);
98 return (I == mEmittedFunctions.end()) ? NULL : I->second->Code;
99}
100
101
102void ScriptCompiled::getFunctions(BCCsizei *actualFunctionCount,
103 BCCsizei maxFunctionCount,
104 BCCchar **functions) {
105
106 int functionCount = mEmittedFunctions.size();
107
108 if (actualFunctionCount)
109 *actualFunctionCount = functionCount;
110 if (functionCount > maxFunctionCount)
111 functionCount = maxFunctionCount;
112 if (functions) {
113 for (EmittedFunctionsMapTy::const_iterator
114 I = mEmittedFunctions.begin(), E = mEmittedFunctions.end();
115 I != E && (functionCount > 0); I++, functionCount--) {
116 *functions++ = const_cast<BCCchar*>(I->first.c_str());
117 }
118 }
119}
120
121
122void ScriptCompiled::getFunctionBinary(BCCchar *funcname,
123 BCCvoid **base,
124 BCCsizei *length) {
125 EmittedFunctionsMapTy::const_iterator I = mEmittedFunctions.find(funcname);
126 if (I == mEmittedFunctions.end()) {
127 *base = NULL;
128 *length = 0;
129 } else {
130 *base = I->second->Code;
131 *length = I->second->Size;
132 }
133}
134
135
Logan2a6dc822011-01-06 04:05:20 +0800136} // namespace bcc