blob: 272e493d968dce1dd58ab802ac51d7eaf14addef [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#ifndef BCC_SCRIPTCACHED_H
18#define BCC_SCRIPTCACHED_H
19
20#include <bcc/bcc.h>
21#include <bcc/bcc_cache.h>
22
23#include <llvm/ADT/SmallVector.h>
24
25#include <map>
26#include <string>
27#include <utility>
28#include <vector>
29
30#include <stddef.h>
31
32namespace llvm {
33 class Module;
34}
35
36namespace bcc {
37 class Script;
38
39 class ScriptCached {
40 friend class CacheReader;
41
42 private:
43 enum { SMALL_VECTOR_QUICKN = 16 };
44
45 typedef llvm::SmallVector<std::pair<char const *, char const *>,
46 SMALL_VECTOR_QUICKN> PragmaList;
47
48 typedef std::map<std::string, std::pair<void *, size_t> > FuncTable;
49
50 private:
51 Script *mpOwner;
52
53 OBCC_ExportVarList *mpExportVars;
54 OBCC_ExportFuncList *mpExportFuncs;
55 PragmaList mPragmas;
56
57 FuncTable mFunctions;
58
59 char *mContext;
60
61 OBCC_StringPool *mpStringPoolRaw;
62 std::vector<char const *> mStringPool;
63
64 public:
65 ScriptCached(Script *owner)
66 : mpOwner(owner), mpExportVars(NULL), mpExportFuncs(NULL),
67 mContext(NULL), mpStringPoolRaw(NULL) {
68 }
69
70 ~ScriptCached();
71
72 void *lookup(const char *name);
73
74 void getExportVars(BCCsizei *actualVarCount,
75 BCCsizei maxVarCount,
76 BCCvoid **vars);
77
78 void getExportFuncs(BCCsizei *actualFuncCount,
79 BCCsizei maxFuncCount,
80 BCCvoid **funcs);
81
82 void getPragmas(BCCsizei *actualStringCount,
83 BCCsizei maxStringCount,
84 BCCchar **strings);
85
86 void getFunctions(BCCsizei *actualFunctionCount,
87 BCCsizei maxFunctionCount,
88 BCCchar **functions);
89
90 void getFunctionBinary(BCCchar *function,
91 BCCvoid **base,
92 BCCsizei *length);
93
94#if 0
95 void registerSymbolCallback(BCCSymbolLookupFn pFn, BCCvoid *pContext) {
96 mCompiler.registerSymbolCallback(pFn, pContext);
97 }
98#endif
99 };
100
101} // namespace bcc
102
103#endif // BCC_SCRIPTCACHED_H