blob: e24a714f2f46af5351eff4167bc7e7dfa84a83c7 [file] [log] [blame]
Stephen Hines4a68b1c2012-05-03 12:28:14 -07001/*
2 * Copyright 2010-2012, 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 "Config.h"
21
22#include <bcc/bcc.h>
23#include <bcc/bcc_mccache.h>
24#include "bcc_internal.h"
25
26#include "librsloader.h"
27
28#include <llvm/ADT/SmallVector.h>
29
30#include <map>
31#include <string>
32#include <utility>
33#include <vector>
34
35#include <stddef.h>
36
37namespace llvm {
38 class Module;
39}
40
41namespace bcc {
42 class Script;
43
44 class ScriptCached {
45 friend class CacheReader;
46 friend class MCCacheReader;
47
48 private:
49 enum { SMALL_VECTOR_QUICKN = 16 };
50
51 typedef llvm::SmallVector<std::pair<char const *, char const *>,
52 SMALL_VECTOR_QUICKN> PragmaList;
53
54 typedef std::map<std::string, std::pair<void *, size_t> > FuncTable;
55
56 private:
57 Script *mpOwner;
58
59 MCO_ExportVarList *mpExportVars;
60 MCO_ExportFuncList *mpExportFuncs;
61 MCO_ExportForEachList *mpExportForEach;
62 PragmaList mPragmas;
63 MCO_ObjectSlotList *mpObjectSlotList;
64
65 FuncTable mFunctions;
66
67 RSExecRef mRSExecutable;
68 llvm::SmallVector<char, 1024> mCachedELFExecutable;
69
70 MCO_StringPool *mpStringPoolRaw;
71 std::vector<char const *> mStringPool;
72
73 bool mLibRSThreadable;
74
75 public:
76 ScriptCached(Script *owner)
77 : mpOwner(owner),
78 mpExportVars(NULL),
79 mpExportFuncs(NULL),
80 mpExportForEach(NULL),
81 mpObjectSlotList(NULL),
82 mpStringPoolRaw(NULL),
83 mLibRSThreadable(false) {
84 }
85
86 ~ScriptCached();
87
88 void *lookup(const char *name);
89
90
91 size_t getExportVarCount() const {
92 return mpExportVars->count;
93 }
94
95 size_t getExportFuncCount() const {
96 return mpExportFuncs->count;
97 }
98
99 size_t getExportForEachCount() const {
100 return mpExportForEach->count;
101 }
102
103 size_t getPragmaCount() const {
104 return mPragmas.size();
105 }
106
107 size_t getFuncCount() const {
108 return mFunctions.size();
109 }
110
111 size_t getObjectSlotCount() const {
112 return mpObjectSlotList->count;
113 }
114
115 void getExportVarList(size_t varListSize, void **varList);
116
117 void getExportFuncList(size_t funcListSize, void **funcList);
118
119 void getExportForEachList(size_t forEachListSize, void **forEachList);
120
121 void getPragmaList(size_t pragmaListSize,
122 char const **keyList,
123 char const **valueList);
124
125 void getFuncInfoList(size_t funcInfoListSize, FuncInfo *funcNameList);
126
127 void getObjectSlotList(size_t objectSlotListSize,
128 uint32_t *objectSlotList);
129
130 const char *getELF() const {
131 return &*mCachedELFExecutable.begin();
132 }
133
134 size_t getELFSize() const {
135 return mCachedELFExecutable.size();
136 }
137
138 // Dirty hack for libRS.
139 // TODO(all): This should be removed in the future.
140 bool isLibRSThreadable() const {
141 return mLibRSThreadable;
142 }
143
144#if 0
145 void registerSymbolCallback(BCCSymbolLookupFn pFn, BCCvoid *pContext) {
146 mCompiler.registerSymbolCallback(pFn, pContext);
147 }
148#endif
149 };
150
151} // namespace bcc
152
153#endif // BCC_SCRIPTCACHED_H