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