blob: f676b3cadbec6d73a4cdf4a024355a7758f39ff2 [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:
Logan2a6dc822011-01-06 04:05:20 +080062 ScriptCompiled(Script *owner) : mpOwner(owner), mCompiler(this) {
Logancf3e5212010-12-29 01:44:55 +080063 }
64
Logan7dcaac92011-01-06 04:26:23 +080065 ~ScriptCompiled();
66
Logancf3e5212010-12-29 01:44:55 +080067 int readBC(const char *bitcode,
68 size_t bitcodeSize,
Logancf3e5212010-12-29 01:44:55 +080069 const BCCchar *resName,
70 const BCCchar *cacheDir) {
Loganf30a6712011-01-06 05:55:34 +080071 return mCompiler.readBC(bitcode, bitcodeSize, resName, cacheDir);
Logancf3e5212010-12-29 01:44:55 +080072 }
73
74 int linkBC(const char *bitcode, size_t bitcodeSize) {
75 return mCompiler.linkBC(bitcode, bitcodeSize);
76 }
77
Logancf3e5212010-12-29 01:44:55 +080078 int compile() {
79 return mCompiler.compile();
80 }
81
82 char const *getCompilerErrorMessage() {
83 return mCompiler.getErrorMessage();
84 }
85
Logan7dcaac92011-01-06 04:26:23 +080086 void *lookup(const char *name);
Logancf3e5212010-12-29 01:44:55 +080087
88 void getExportVars(BCCsizei *actualVarCount,
89 BCCsizei maxVarCount,
Logan2a6dc822011-01-06 04:05:20 +080090 BCCvoid **vars);
Logancf3e5212010-12-29 01:44:55 +080091
92 void getExportFuncs(BCCsizei *actualFuncCount,
93 BCCsizei maxFuncCount,
Logan2a6dc822011-01-06 04:05:20 +080094 BCCvoid **funcs);
Logancf3e5212010-12-29 01:44:55 +080095
96 void getPragmas(BCCsizei *actualStringCount,
97 BCCsizei maxStringCount,
Logan2a6dc822011-01-06 04:05:20 +080098 BCCchar **strings);
Logancf3e5212010-12-29 01:44:55 +080099
100 void getFunctions(BCCsizei *actualFunctionCount,
101 BCCsizei maxFunctionCount,
Logan7dcaac92011-01-06 04:26:23 +0800102 BCCchar **functions);
Logancf3e5212010-12-29 01:44:55 +0800103
104 void getFunctionBinary(BCCchar *function,
105 BCCvoid **base,
Logan7dcaac92011-01-06 04:26:23 +0800106 BCCsizei *length);
Logancf3e5212010-12-29 01:44:55 +0800107
Logana27a83f2011-01-07 10:25:48 +0800108 char *getContext() {
Logan02286cb2011-01-07 00:30:47 +0800109 return mContext;
110 }
111
Logancf3e5212010-12-29 01:44:55 +0800112 void registerSymbolCallback(BCCSymbolLookupFn pFn, BCCvoid *pContext) {
113 mCompiler.registerSymbolCallback(pFn, pContext);
114 }
115
116 int readModule(llvm::Module *module) {
117 return mCompiler.readModule(module);
118 }
119 };
120
121} // namespace bcc
122
123#endif // BCC_SCRIPTCOMPILED_H