blob: 291bbc61a92ac2f7e8a508ed7edcb0e60349476f [file] [log] [blame]
Loganf7f0ac52011-01-07 03:53:43 +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 "ScriptCached.h"
21
22#include <bcc/bcc_cache.h>
23
24#include "ContextManager.h"
25#include "EmittedFuncInfo.h"
26
27namespace bcc {
28
29ScriptCached::~ScriptCached() {
30 // Deallocate the bcc script context
31 if (mContext) {
32 deallocateContext(mContext);
33 }
34
35 // Deallocate string pool, exported var list, exported func list
36 if (mpStringPoolRaw) { free(mpStringPoolRaw); }
37 if (mpExportVars) { free(mpExportVars); }
38 if (mpExportFuncs) { free(mpExportFuncs); }
39}
40
41void ScriptCached::getExportVars(BCCsizei *actualVarCount,
42 BCCsizei maxVarCount,
43 BCCvoid **vars) {
44 int varCount = static_cast<int>(mpExportVars->count);
45
46 if (actualVarCount)
47 *actualVarCount = varCount;
48 if (varCount > maxVarCount)
49 varCount = maxVarCount;
50 if (vars) {
51 void **ptr = mpExportVars->cached_addr_list;
52 for (int i = 0; i < varCount; i++) {
53 *vars++ = *ptr++;
54 }
55 }
56}
57
58
59void ScriptCached::getExportFuncs(BCCsizei *actualFuncCount,
60 BCCsizei maxFuncCount,
61 BCCvoid **funcs) {
62 int funcCount = static_cast<int>(mpExportFuncs->count);
63
64 if (actualFuncCount)
65 *actualFuncCount = funcCount;
66 if (funcCount > maxFuncCount)
67 funcCount = maxFuncCount;
68 if (funcs) {
69 void **ptr = mpExportFuncs->cached_addr_list;
70 for (int i = 0; i < funcCount; i++) {
71 *funcs++ = *ptr++;
72 }
73 }
74}
75
76
77void ScriptCached::getPragmas(BCCsizei *actualStringCount,
78 BCCsizei maxStringCount,
79 BCCchar **strings) {
80 int stringCount = static_cast<int>(mPragmas.size()) * 2;
81
82 if (actualStringCount)
83 *actualStringCount = stringCount;
84
85 if (stringCount > maxStringCount)
86 stringCount = maxStringCount;
87
88 if (strings) {
89 for (int i = 0; stringCount >= 2; stringCount -= 2, ++i) {
90 *strings++ = const_cast<BCCchar *>(mPragmas[i].first);
91 *strings++ = const_cast<BCCchar *>(mPragmas[i].second);
92 }
93 }
94}
95
96
97void *ScriptCached::lookup(const char *name) {
98 void *addr = NULL;
99
100 // TODO(logan): Not finished.
101 return addr;
102}
103
104
105void ScriptCached::getFunctions(BCCsizei *actualFunctionCount,
106 BCCsizei maxFunctionCount,
107 BCCchar **functions) {
108 LOGE("%s not implemented <<----------- WARNING\n", __func__);
109
110 if (actualFunctionCount) {
111 *actualFunctionCount = 0;
112 }
113}
114
115
116void ScriptCached::getFunctionBinary(BCCchar *funcname,
117 BCCvoid **base,
118 BCCsizei *length) {
119 LOGE("%s not implemented <<----------- WARNING\n", __func__);
120
121 if (base) {
122 *base = NULL;
123 }
124
125 if (length) {
126 *length = 0;
127 }
128}
129
130
131} // namespace bcc