blob: e9c1fa231e415ba33f0062f450cafeda2637851e [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
24namespace llvm {
25 class Module;
26}
27
28namespace bcc {
29 class Script;
30
31 class ScriptCompiled {
Logan2a6dc822011-01-06 04:05:20 +080032 friend class Compiler;
33
34 private:
35 typedef std::list< std::pair<std::string, std::string> > PragmaList;
36 typedef std::list<void*> ExportVarList;
37 typedef std::list<void*> ExportFuncList;
38
Logancf3e5212010-12-29 01:44:55 +080039 private:
40 Script *mpOwner;
41
42 Compiler mCompiler;
43
Logan2a6dc822011-01-06 04:05:20 +080044 PragmaList mPragmas;
45 ExportVarList mExportVars;
46 ExportFuncList mExportFuncs;
47
Logancf3e5212010-12-29 01:44:55 +080048 public:
Logan2a6dc822011-01-06 04:05:20 +080049 ScriptCompiled(Script *owner) : mpOwner(owner), mCompiler(this) {
Logancf3e5212010-12-29 01:44:55 +080050 }
51
52 int readBC(const char *bitcode,
53 size_t bitcodeSize,
54 long bitcodeFileModTime,
55 long bitcodeFileCRC32,
56 const BCCchar *resName,
57 const BCCchar *cacheDir) {
58 return mCompiler.readBC(bitcode, bitcodeSize,
59 bitcodeFileModTime, bitcodeFileCRC32,
60 resName, cacheDir);
61 }
62
63 int linkBC(const char *bitcode, size_t bitcodeSize) {
64 return mCompiler.linkBC(bitcode, bitcodeSize);
65 }
66
67 int loadCacheFile() {
68 return mCompiler.loadCacheFile();
69 }
70
71 int compile() {
72 return mCompiler.compile();
73 }
74
75 char const *getCompilerErrorMessage() {
76 return mCompiler.getErrorMessage();
77 }
78
79 void *lookup(const char *name) {
80 return mCompiler.lookup(name);
81 }
82
83 void getExportVars(BCCsizei *actualVarCount,
84 BCCsizei maxVarCount,
Logan2a6dc822011-01-06 04:05:20 +080085 BCCvoid **vars);
Logancf3e5212010-12-29 01:44:55 +080086
87 void getExportFuncs(BCCsizei *actualFuncCount,
88 BCCsizei maxFuncCount,
Logan2a6dc822011-01-06 04:05:20 +080089 BCCvoid **funcs);
Logancf3e5212010-12-29 01:44:55 +080090
91 void getPragmas(BCCsizei *actualStringCount,
92 BCCsizei maxStringCount,
Logan2a6dc822011-01-06 04:05:20 +080093 BCCchar **strings);
Logancf3e5212010-12-29 01:44:55 +080094
95 void getFunctions(BCCsizei *actualFunctionCount,
96 BCCsizei maxFunctionCount,
97 BCCchar **functions) {
98 mCompiler.getFunctions(actualFunctionCount, maxFunctionCount, functions);
99 }
100
101 void getFunctionBinary(BCCchar *function,
102 BCCvoid **base,
103 BCCsizei *length) {
104 mCompiler.getFunctionBinary(function, base, length);
105 }
106
107 void registerSymbolCallback(BCCSymbolLookupFn pFn, BCCvoid *pContext) {
108 mCompiler.registerSymbolCallback(pFn, pContext);
109 }
110
111 int readModule(llvm::Module *module) {
112 return mCompiler.readModule(module);
113 }
114 };
115
116} // namespace bcc
117
118#endif // BCC_SCRIPTCOMPILED_H