blob: 26db6630ff30a785e0e1a454a598c0baaf260342 [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>
Loganf340bf72011-01-14 17:51:40 +080022#include "bcc_internal.h"
Loganf7f0ac52011-01-07 03:53:43 +080023
24#include <llvm/ADT/SmallVector.h>
25
26#include <map>
27#include <string>
28#include <utility>
29#include <vector>
30
31#include <stddef.h>
32
33namespace llvm {
34 class Module;
35}
36
37namespace bcc {
38 class Script;
39
40 class ScriptCached {
41 friend class CacheReader;
42
43 private:
44 enum { SMALL_VECTOR_QUICKN = 16 };
45
46 typedef llvm::SmallVector<std::pair<char const *, char const *>,
47 SMALL_VECTOR_QUICKN> PragmaList;
48
49 typedef std::map<std::string, std::pair<void *, size_t> > FuncTable;
50
51 private:
52 Script *mpOwner;
53
54 OBCC_ExportVarList *mpExportVars;
55 OBCC_ExportFuncList *mpExportFuncs;
56 PragmaList mPragmas;
Stephen Hines071288a2011-01-27 14:38:26 -080057 OBCC_ObjectSlotList *mpObjectSlotList;
Loganf7f0ac52011-01-07 03:53:43 +080058
59 FuncTable mFunctions;
60
61 char *mContext;
62
63 OBCC_StringPool *mpStringPoolRaw;
64 std::vector<char const *> mStringPool;
65
Loganf3c83ce2011-01-07 06:36:33 +080066 bool mLibRSThreadable;
67
Loganf7f0ac52011-01-07 03:53:43 +080068 public:
69 ScriptCached(Script *owner)
70 : mpOwner(owner), mpExportVars(NULL), mpExportFuncs(NULL),
Stephen Hines071288a2011-01-27 14:38:26 -080071 mpObjectSlotList(NULL), mContext(NULL), mpStringPoolRaw(NULL),
72 mLibRSThreadable(false) {
Loganf7f0ac52011-01-07 03:53:43 +080073 }
74
75 ~ScriptCached();
76
77 void *lookup(const char *name);
78
Loganf7f0ac52011-01-07 03:53:43 +080079
Loganbe79ada2011-01-13 01:33:45 +080080 size_t getExportVarCount() const {
81 return mpExportVars->count;
82 }
Loganf7f0ac52011-01-07 03:53:43 +080083
Loganbe79ada2011-01-13 01:33:45 +080084 size_t getExportFuncCount() const {
85 return mpExportFuncs->count;
86 }
Loganf7f0ac52011-01-07 03:53:43 +080087
Loganbe79ada2011-01-13 01:33:45 +080088 size_t getPragmaCount() const {
89 return mPragmas.size();
90 }
Loganf7f0ac52011-01-07 03:53:43 +080091
Loganbe79ada2011-01-13 01:33:45 +080092 size_t getFuncCount() const {
93 return mFunctions.size();
94 }
95
Stephen Hines071288a2011-01-27 14:38:26 -080096 size_t getObjectSlotCount() const {
97 return mpObjectSlotList->count;
98 }
Loganbe79ada2011-01-13 01:33:45 +080099
100 void getExportVarList(size_t varListSize, void **varList);
101
102 void getExportFuncList(size_t funcListSize, void **funcList);
103
104 void getPragmaList(size_t pragmaListSize,
105 char const **keyList,
106 char const **valueList);
107
Loganf340bf72011-01-14 17:51:40 +0800108 void getFuncInfoList(size_t funcInfoListSize, FuncInfo *funcNameList);
Loganbe79ada2011-01-13 01:33:45 +0800109
Stephen Hines071288a2011-01-27 14:38:26 -0800110 void getObjectSlotList(size_t objectSlotListSize,
111 uint32_t *objectSlotList);
Loganf7f0ac52011-01-07 03:53:43 +0800112
Logana27a83f2011-01-07 10:25:48 +0800113 char *getContext() {
114 return mContext;
115 }
116
Loganf3c83ce2011-01-07 06:36:33 +0800117 // Dirty hack for libRS.
118 // TODO(all): This should be removed in the future.
119 bool isLibRSThreadable() const {
120 return mLibRSThreadable;
121 }
122
Loganf7f0ac52011-01-07 03:53:43 +0800123#if 0
124 void registerSymbolCallback(BCCSymbolLookupFn pFn, BCCvoid *pContext) {
125 mCompiler.registerSymbolCallback(pFn, pContext);
126 }
127#endif
128 };
129
130} // namespace bcc
131
132#endif // BCC_SCRIPTCACHED_H