blob: c484546cabc847db9943d24997140ab569492cad [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;
57
58 FuncTable mFunctions;
59
60 char *mContext;
61
62 OBCC_StringPool *mpStringPoolRaw;
63 std::vector<char const *> mStringPool;
64
Loganf3c83ce2011-01-07 06:36:33 +080065 bool mLibRSThreadable;
66
Loganf7f0ac52011-01-07 03:53:43 +080067 public:
68 ScriptCached(Script *owner)
69 : mpOwner(owner), mpExportVars(NULL), mpExportFuncs(NULL),
Loganf3c83ce2011-01-07 06:36:33 +080070 mContext(NULL), mpStringPoolRaw(NULL), mLibRSThreadable(false) {
Loganf7f0ac52011-01-07 03:53:43 +080071 }
72
73 ~ScriptCached();
74
75 void *lookup(const char *name);
76
Loganf7f0ac52011-01-07 03:53:43 +080077
Loganbe79ada2011-01-13 01:33:45 +080078 size_t getExportVarCount() const {
79 return mpExportVars->count;
80 }
Loganf7f0ac52011-01-07 03:53:43 +080081
Loganbe79ada2011-01-13 01:33:45 +080082 size_t getExportFuncCount() const {
83 return mpExportFuncs->count;
84 }
Loganf7f0ac52011-01-07 03:53:43 +080085
Loganbe79ada2011-01-13 01:33:45 +080086 size_t getPragmaCount() const {
87 return mPragmas.size();
88 }
Loganf7f0ac52011-01-07 03:53:43 +080089
Loganbe79ada2011-01-13 01:33:45 +080090 size_t getFuncCount() const {
91 return mFunctions.size();
92 }
93
94
95 void getExportVarList(size_t varListSize, void **varList);
96
97 void getExportFuncList(size_t funcListSize, void **funcList);
98
99 void getPragmaList(size_t pragmaListSize,
100 char const **keyList,
101 char const **valueList);
102
Loganf340bf72011-01-14 17:51:40 +0800103 void getFuncInfoList(size_t funcInfoListSize, FuncInfo *funcNameList);
Loganbe79ada2011-01-13 01:33:45 +0800104
Loganf7f0ac52011-01-07 03:53:43 +0800105
Logana27a83f2011-01-07 10:25:48 +0800106 char *getContext() {
107 return mContext;
108 }
109
Loganf3c83ce2011-01-07 06:36:33 +0800110 // Dirty hack for libRS.
111 // TODO(all): This should be removed in the future.
112 bool isLibRSThreadable() const {
113 return mLibRSThreadable;
114 }
115
Loganf7f0ac52011-01-07 03:53:43 +0800116#if 0
117 void registerSymbolCallback(BCCSymbolLookupFn pFn, BCCvoid *pContext) {
118 mCompiler.registerSymbolCallback(pFn, pContext);
119 }
120#endif
121 };
122
123} // namespace bcc
124
125#endif // BCC_SCRIPTCACHED_H