blob: 8950a11866a9c71e9c82bc6772ce985ef2dffc19 [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
Loganf3c83ce2011-01-07 06:36:33 +080064 bool mLibRSThreadable;
65
Loganf7f0ac52011-01-07 03:53:43 +080066 public:
67 ScriptCached(Script *owner)
68 : mpOwner(owner), mpExportVars(NULL), mpExportFuncs(NULL),
Loganf3c83ce2011-01-07 06:36:33 +080069 mContext(NULL), mpStringPoolRaw(NULL), mLibRSThreadable(false) {
Loganf7f0ac52011-01-07 03:53:43 +080070 }
71
72 ~ScriptCached();
73
74 void *lookup(const char *name);
75
76 void getExportVars(BCCsizei *actualVarCount,
77 BCCsizei maxVarCount,
78 BCCvoid **vars);
79
80 void getExportFuncs(BCCsizei *actualFuncCount,
81 BCCsizei maxFuncCount,
82 BCCvoid **funcs);
83
84 void getPragmas(BCCsizei *actualStringCount,
85 BCCsizei maxStringCount,
86 BCCchar **strings);
87
88 void getFunctions(BCCsizei *actualFunctionCount,
89 BCCsizei maxFunctionCount,
90 BCCchar **functions);
91
92 void getFunctionBinary(BCCchar *function,
93 BCCvoid **base,
94 BCCsizei *length);
95
Logana27a83f2011-01-07 10:25:48 +080096 char *getContext() {
97 return mContext;
98 }
99
Loganf3c83ce2011-01-07 06:36:33 +0800100 // Dirty hack for libRS.
101 // TODO(all): This should be removed in the future.
102 bool isLibRSThreadable() const {
103 return mLibRSThreadable;
104 }
105
Loganf7f0ac52011-01-07 03:53:43 +0800106#if 0
107 void registerSymbolCallback(BCCSymbolLookupFn pFn, BCCvoid *pContext) {
108 mCompiler.registerSymbolCallback(pFn, pContext);
109 }
110#endif
111 };
112
113} // namespace bcc
114
115#endif // BCC_SCRIPTCACHED_H