blob: 786865d932252f9c4e2df57e293b623b716cc621 [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 PragmaList mPragmas;
54 ExportVarList mExportVars;
55 ExportFuncList mExportFuncs;
Logan7dcaac92011-01-06 04:26:23 +080056 EmittedFunctionsMapTy mEmittedFunctions;
Logan2a6dc822011-01-06 04:05:20 +080057
Logancf3e5212010-12-29 01:44:55 +080058 public:
Logan2a6dc822011-01-06 04:05:20 +080059 ScriptCompiled(Script *owner) : mpOwner(owner), mCompiler(this) {
Logancf3e5212010-12-29 01:44:55 +080060 }
61
Logan7dcaac92011-01-06 04:26:23 +080062 ~ScriptCompiled();
63
Logancf3e5212010-12-29 01:44:55 +080064 int readBC(const char *bitcode,
65 size_t bitcodeSize,
Logancf3e5212010-12-29 01:44:55 +080066 const BCCchar *resName,
67 const BCCchar *cacheDir) {
Loganf30a6712011-01-06 05:55:34 +080068 return mCompiler.readBC(bitcode, bitcodeSize, resName, cacheDir);
Logancf3e5212010-12-29 01:44:55 +080069 }
70
71 int linkBC(const char *bitcode, size_t bitcodeSize) {
72 return mCompiler.linkBC(bitcode, bitcodeSize);
73 }
74
Logancf3e5212010-12-29 01:44:55 +080075 int compile() {
76 return mCompiler.compile();
77 }
78
79 char const *getCompilerErrorMessage() {
80 return mCompiler.getErrorMessage();
81 }
82
Logan7dcaac92011-01-06 04:26:23 +080083 void *lookup(const char *name);
Logancf3e5212010-12-29 01:44:55 +080084
85 void getExportVars(BCCsizei *actualVarCount,
86 BCCsizei maxVarCount,
Logan2a6dc822011-01-06 04:05:20 +080087 BCCvoid **vars);
Logancf3e5212010-12-29 01:44:55 +080088
89 void getExportFuncs(BCCsizei *actualFuncCount,
90 BCCsizei maxFuncCount,
Logan2a6dc822011-01-06 04:05:20 +080091 BCCvoid **funcs);
Logancf3e5212010-12-29 01:44:55 +080092
93 void getPragmas(BCCsizei *actualStringCount,
94 BCCsizei maxStringCount,
Logan2a6dc822011-01-06 04:05:20 +080095 BCCchar **strings);
Logancf3e5212010-12-29 01:44:55 +080096
97 void getFunctions(BCCsizei *actualFunctionCount,
98 BCCsizei maxFunctionCount,
Logan7dcaac92011-01-06 04:26:23 +080099 BCCchar **functions);
Logancf3e5212010-12-29 01:44:55 +0800100
101 void getFunctionBinary(BCCchar *function,
102 BCCvoid **base,
Logan7dcaac92011-01-06 04:26:23 +0800103 BCCsizei *length);
Logancf3e5212010-12-29 01:44:55 +0800104
105 void registerSymbolCallback(BCCSymbolLookupFn pFn, BCCvoid *pContext) {
106 mCompiler.registerSymbolCallback(pFn, pContext);
107 }
108
109 int readModule(llvm::Module *module) {
110 return mCompiler.readModule(module);
111 }
112 };
113
114} // namespace bcc
115
116#endif // BCC_SCRIPTCOMPILED_H