blob: a22bd74f81574f6cb8bf42e6168648529aef5613 [file] [log] [blame]
Logan3f3d31f2010-11-27 13:52:03 +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_SCRIPT_H
18#define BCC_SCRIPT_H
19
Loganc4395232010-11-27 18:54:17 +080020#include "Compiler.h"
21
Logan3f3d31f2010-11-27 13:52:03 +080022#include <bcc/bcc.h>
Logan3f3d31f2010-11-27 13:52:03 +080023
Loganeaa0cc32010-12-29 01:04:20 +080024namespace llvm {
25 class Module;
26}
27
Logan3f3d31f2010-11-27 13:52:03 +080028namespace bcc {
29
Logan0647e9e2010-12-29 00:21:31 +080030 class Script {
Logan39736412010-12-29 00:24:04 +080031 private:
32 BCCenum mErrorCode;
33
Loganeaa0cc32010-12-29 01:04:20 +080034 Compiler mCompiler;
35
Logan3f3d31f2010-11-27 13:52:03 +080036 public:
Logan0647e9e2010-12-29 00:21:31 +080037 Script() {
Logan39736412010-12-29 00:24:04 +080038 mErrorCode = BCC_NO_ERROR;
Logan3f3d31f2010-11-27 13:52:03 +080039 }
40
Logan0647e9e2010-12-29 00:21:31 +080041 ~Script() {
Logan3f3d31f2010-11-27 13:52:03 +080042 }
43
Loganeaa0cc32010-12-29 01:04:20 +080044 //////////////////////////////////////////////////////////////////////////
45 // Part I. Compiler
46 //////////////////////////////////////////////////////////////////////////
47
48 int readBC(const char *bitcode,
49 size_t bitcodeSize,
50 long bitcodeFileModTime,
51 long bitcodeFileCRC32,
52 const BCCchar *resName,
53 const BCCchar *cacheDir) {
54 return mCompiler.readBC(bitcode, bitcodeSize,
55 bitcodeFileModTime, bitcodeFileCRC32,
56 resName, cacheDir);
57 }
58
59 int linkBC(const char *bitcode, size_t bitcodeSize) {
60 return mCompiler.linkBC(bitcode, bitcodeSize);
61 }
62
63 int loadCacheFile() {
64 return mCompiler.loadCacheFile();
65 }
66
67 int compile() {
68 return mCompiler.compile();
69 }
70
71 char const *getCompilerErrorMessage() {
72 return mCompiler.getErrorMessage();
73 }
74
75 void *lookup(const char *name) {
76 return mCompiler.lookup(name);
77 }
78
79 void getExportVars(BCCsizei *actualVarCount,
80 BCCsizei maxVarCount,
81 BCCvoid **vars) {
82 mCompiler.getExportVars(actualVarCount, maxVarCount, vars);
83 }
84
85 void getExportFuncs(BCCsizei *actualFuncCount,
86 BCCsizei maxFuncCount,
87 BCCvoid **funcs) {
88 mCompiler.getExportFuncs(actualFuncCount, maxFuncCount, funcs);
89 }
90
91 void getPragmas(BCCsizei *actualStringCount,
92 BCCsizei maxStringCount,
93 BCCchar **strings) {
94 mCompiler.getPragmas(actualStringCount, maxStringCount, strings);
95 }
96
97 void getFunctions(BCCsizei *actualFunctionCount,
98 BCCsizei maxFunctionCount,
99 BCCchar **functions) {
100 mCompiler.getFunctions(actualFunctionCount, maxFunctionCount, functions);
101 }
102
103 void getFunctionBinary(BCCchar *function,
104 BCCvoid **base,
105 BCCsizei *length) {
106 mCompiler.getFunctionBinary(function, base, length);
107 }
108
109 void registerSymbolCallback(BCCSymbolLookupFn pFn, BCCvoid *pContext) {
110 mCompiler.registerSymbolCallback(pFn, pContext);
111 }
112
113 int readModule(llvm::Module *module) {
114 return mCompiler.readModule(module);
115 }
116
117
118 //////////////////////////////////////////////////////////////////////////
119 // Error handling
120 //////////////////////////////////////////////////////////////////////////
121
Logan3f3d31f2010-11-27 13:52:03 +0800122 void setError(BCCenum error) {
Logan39736412010-12-29 00:24:04 +0800123 if (mErrorCode == BCC_NO_ERROR && error != BCC_NO_ERROR) {
124 mErrorCode = error;
Logan3f3d31f2010-11-27 13:52:03 +0800125 }
126 }
127
128 BCCenum getError() {
Logan39736412010-12-29 00:24:04 +0800129 BCCenum result = mErrorCode;
130 mErrorCode = BCC_NO_ERROR;
Logan3f3d31f2010-11-27 13:52:03 +0800131 return result;
132 }
Logan3f3d31f2010-11-27 13:52:03 +0800133 };
134
135} // namespace bcc
136
137#endif // BCC_SCRIPT_H