blob: 49495dd7edfcbcdf0bda614138925a818c0ad697 [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
Loganf7f0ac52011-01-07 03:53:43 +080076
Loganbe79ada2011-01-13 01:33:45 +080077 size_t getExportVarCount() const {
78 return mpExportVars->count;
79 }
Loganf7f0ac52011-01-07 03:53:43 +080080
Loganbe79ada2011-01-13 01:33:45 +080081 size_t getExportFuncCount() const {
82 return mpExportFuncs->count;
83 }
Loganf7f0ac52011-01-07 03:53:43 +080084
Loganbe79ada2011-01-13 01:33:45 +080085 size_t getPragmaCount() const {
86 return mPragmas.size();
87 }
Loganf7f0ac52011-01-07 03:53:43 +080088
Loganbe79ada2011-01-13 01:33:45 +080089 size_t getFuncCount() const {
90 return mFunctions.size();
91 }
92
93
94 void getExportVarList(size_t varListSize, void **varList);
95
96 void getExportFuncList(size_t funcListSize, void **funcList);
97
98 void getPragmaList(size_t pragmaListSize,
99 char const **keyList,
100 char const **valueList);
101
102 void getFuncNameList(size_t funcNameListSize, char const **funcNameList);
103
104 void getFuncBinary(char const *function,
105 void **base,
106 size_t *length);
107
Loganf7f0ac52011-01-07 03:53:43 +0800108
Logana27a83f2011-01-07 10:25:48 +0800109 char *getContext() {
110 return mContext;
111 }
112
Loganf3c83ce2011-01-07 06:36:33 +0800113 // Dirty hack for libRS.
114 // TODO(all): This should be removed in the future.
115 bool isLibRSThreadable() const {
116 return mLibRSThreadable;
117 }
118
Loganf7f0ac52011-01-07 03:53:43 +0800119#if 0
120 void registerSymbolCallback(BCCSymbolLookupFn pFn, BCCvoid *pContext) {
121 mCompiler.registerSymbolCallback(pFn, pContext);
122 }
123#endif
124 };
125
126} // namespace bcc
127
128#endif // BCC_SCRIPTCACHED_H