blob: a160b78157fb0422e20022d25de05e4684a71106 [file] [log] [blame]
Logancf3e5212010-12-29 01:44:55 +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_SCRIPTCOMPILED_H
18#define BCC_SCRIPTCOMPILED_H
19
20#include "Compiler.h"
21
22#include <bcc/bcc.h>
23
Logan7dcaac92011-01-06 04:26:23 +080024#include <list>
25#include <map>
26#include <string>
27#include <utility>
28#include <vector>
29
Logancf3e5212010-12-29 01:44:55 +080030namespace llvm {
31 class Module;
32}
33
34namespace bcc {
Logan7dcaac92011-01-06 04:26:23 +080035 class EmittedFuncInfo;
Logancf3e5212010-12-29 01:44:55 +080036 class Script;
37
38 class ScriptCompiled {
Logan2a6dc822011-01-06 04:05:20 +080039 friend class Compiler;
Logan7dcaac92011-01-06 04:26:23 +080040 friend class CodeEmitter;
Logan2a6dc822011-01-06 04:05:20 +080041
42 private:
Logan7dcaac92011-01-06 04:26:23 +080043 typedef std::list<std::pair<std::string, std::string> > PragmaList;
Logan2a6dc822011-01-06 04:05:20 +080044 typedef std::list<void*> ExportVarList;
45 typedef std::list<void*> ExportFuncList;
Logan7dcaac92011-01-06 04:26:23 +080046 typedef std::map<std::string, EmittedFuncInfo *> EmittedFunctionsMapTy;
Logan2a6dc822011-01-06 04:05:20 +080047
Logancf3e5212010-12-29 01:44:55 +080048 private:
49 Script *mpOwner;
50
51 Compiler mCompiler;
52
Logan2a6dc822011-01-06 04:05:20 +080053 ExportVarList mExportVars;
54 ExportFuncList mExportFuncs;
Logan02286cb2011-01-07 00:30:47 +080055 PragmaList mPragmas;
56
Logan7dcaac92011-01-06 04:26:23 +080057 EmittedFunctionsMapTy mEmittedFunctions;
Logan2a6dc822011-01-06 04:05:20 +080058
Logan02286cb2011-01-07 00:30:47 +080059 char *mContext; // Context of BCC script (code and data)
60
Logancf3e5212010-12-29 01:44:55 +080061 public:
Logan65719812011-01-07 11:17:14 +080062 ScriptCompiled(Script *owner)
63 : mpOwner(owner), mCompiler(this), mContext(NULL) {
Logancf3e5212010-12-29 01:44:55 +080064 }
65
Logan7dcaac92011-01-06 04:26:23 +080066 ~ScriptCompiled();
67
Logancf3e5212010-12-29 01:44:55 +080068 int readBC(const char *bitcode,
69 size_t bitcodeSize,
Logancf3e5212010-12-29 01:44:55 +080070 const BCCchar *resName,
71 const BCCchar *cacheDir) {
Loganf30a6712011-01-06 05:55:34 +080072 return mCompiler.readBC(bitcode, bitcodeSize, resName, cacheDir);
Logancf3e5212010-12-29 01:44:55 +080073 }
74
75 int linkBC(const char *bitcode, size_t bitcodeSize) {
76 return mCompiler.linkBC(bitcode, bitcodeSize);
77 }
78
Logancf3e5212010-12-29 01:44:55 +080079 int compile() {
80 return mCompiler.compile();
81 }
82
83 char const *getCompilerErrorMessage() {
84 return mCompiler.getErrorMessage();
85 }
86
Logan7dcaac92011-01-06 04:26:23 +080087 void *lookup(const char *name);
Logancf3e5212010-12-29 01:44:55 +080088
Logancf3e5212010-12-29 01:44:55 +080089
Loganbe79ada2011-01-13 01:33:45 +080090 size_t getExportVarCount() const {
91 return mExportVars.size();
92 }
Logancf3e5212010-12-29 01:44:55 +080093
Loganbe79ada2011-01-13 01:33:45 +080094 size_t getExportFuncCount() const {
95 return mExportFuncs.size();
96 }
Logancf3e5212010-12-29 01:44:55 +080097
Loganbe79ada2011-01-13 01:33:45 +080098 size_t getPragmaCount() const {
99 return mPragmas.size();
100 }
Logancf3e5212010-12-29 01:44:55 +0800101
Loganbe79ada2011-01-13 01:33:45 +0800102 size_t getFuncCount() const {
103 return mEmittedFunctions.size();
104 }
105
106
107 void getExportVarList(size_t varListSize, void **varList);
108
109 void getExportFuncList(size_t funcListSize, void **funcList);
110
111 void getPragmaList(size_t pragmaListSize,
112 char const **keyList,
113 char const **valueList);
114
115 void getFuncNameList(size_t funcNameListSize, char const **funcNameList);
116
117 void getFuncBinary(char const *function,
118 void **base,
119 size_t *length);
Logancf3e5212010-12-29 01:44:55 +0800120
Logana27a83f2011-01-07 10:25:48 +0800121 char *getContext() {
Logan02286cb2011-01-07 00:30:47 +0800122 return mContext;
123 }
124
Logancf3e5212010-12-29 01:44:55 +0800125 void registerSymbolCallback(BCCSymbolLookupFn pFn, BCCvoid *pContext) {
126 mCompiler.registerSymbolCallback(pFn, pContext);
127 }
128
129 int readModule(llvm::Module *module) {
130 return mCompiler.readModule(module);
131 }
132 };
133
134} // namespace bcc
135
136#endif // BCC_SCRIPTCOMPILED_H