blob: 01af9741e178a047361718e4c226f3dd5160fc1a [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 {
35 class Script;
36
37 class ScriptCompiled {
Logan2a6dc822011-01-06 04:05:20 +080038 friend class Compiler;
Logan7dcaac92011-01-06 04:26:23 +080039 friend class CodeEmitter;
Logan2a6dc822011-01-06 04:05:20 +080040
41 private:
Logan7dcaac92011-01-06 04:26:23 +080042 typedef std::list<std::pair<std::string, std::string> > PragmaList;
Logan2a6dc822011-01-06 04:05:20 +080043 typedef std::list<void*> ExportVarList;
44 typedef std::list<void*> ExportFuncList;
Loganf340bf72011-01-14 17:51:40 +080045 typedef std::map<std::string, FuncInfo *> FuncInfoMap;
Logan2a6dc822011-01-06 04:05:20 +080046
Logancf3e5212010-12-29 01:44:55 +080047 private:
48 Script *mpOwner;
49
50 Compiler mCompiler;
51
Logan2a6dc822011-01-06 04:05:20 +080052 ExportVarList mExportVars;
53 ExportFuncList mExportFuncs;
Logan02286cb2011-01-07 00:30:47 +080054 PragmaList mPragmas;
55
Loganf340bf72011-01-14 17:51:40 +080056 FuncInfoMap mEmittedFunctions;
Logan2a6dc822011-01-06 04:05:20 +080057
Logan02286cb2011-01-07 00:30:47 +080058 char *mContext; // Context of BCC script (code and data)
59
Logancf3e5212010-12-29 01:44:55 +080060 public:
Logan65719812011-01-07 11:17:14 +080061 ScriptCompiled(Script *owner)
62 : mpOwner(owner), mCompiler(this), mContext(NULL) {
Logancf3e5212010-12-29 01:44:55 +080063 }
64
Logan7dcaac92011-01-06 04:26:23 +080065 ~ScriptCompiled();
66
Loganf340bf72011-01-14 17:51:40 +080067 int readBC(char const *resName,
68 char const *bitcode,
Logancf3e5212010-12-29 01:44:55 +080069 size_t bitcodeSize,
Loganf340bf72011-01-14 17:51:40 +080070 unsigned long flags) {
71 return mCompiler.readBC(bitcode, bitcodeSize);
Logancf3e5212010-12-29 01:44:55 +080072 }
73
Loganf340bf72011-01-14 17:51:40 +080074 int readModule(char const *resName,
75 llvm::Module *module,
76 unsigned long flags) {
77 return mCompiler.readModule(module);
78 }
79
80 int linkBC(char const *resName,
81 char const *bitcode,
82 size_t bitcodeSize,
83 unsigned long flags) {
Logancf3e5212010-12-29 01:44:55 +080084 return mCompiler.linkBC(bitcode, bitcodeSize);
85 }
86
Logancf3e5212010-12-29 01:44:55 +080087 int compile() {
88 return mCompiler.compile();
89 }
90
91 char const *getCompilerErrorMessage() {
92 return mCompiler.getErrorMessage();
93 }
94
Logan7dcaac92011-01-06 04:26:23 +080095 void *lookup(const char *name);
Logancf3e5212010-12-29 01:44:55 +080096
Logancf3e5212010-12-29 01:44:55 +080097
Loganbe79ada2011-01-13 01:33:45 +080098 size_t getExportVarCount() const {
99 return mExportVars.size();
100 }
Logancf3e5212010-12-29 01:44:55 +0800101
Loganbe79ada2011-01-13 01:33:45 +0800102 size_t getExportFuncCount() const {
103 return mExportFuncs.size();
104 }
Logancf3e5212010-12-29 01:44:55 +0800105
Loganbe79ada2011-01-13 01:33:45 +0800106 size_t getPragmaCount() const {
107 return mPragmas.size();
108 }
Logancf3e5212010-12-29 01:44:55 +0800109
Loganbe79ada2011-01-13 01:33:45 +0800110 size_t getFuncCount() const {
111 return mEmittedFunctions.size();
112 }
113
114
115 void getExportVarList(size_t varListSize, void **varList);
116
117 void getExportFuncList(size_t funcListSize, void **funcList);
118
119 void getPragmaList(size_t pragmaListSize,
120 char const **keyList,
121 char const **valueList);
122
Loganf340bf72011-01-14 17:51:40 +0800123 void getFuncInfoList(size_t funcInfoListSize,
124 FuncInfo *funcInfoList);
Logancf3e5212010-12-29 01:44:55 +0800125
Logana27a83f2011-01-07 10:25:48 +0800126 char *getContext() {
Logan02286cb2011-01-07 00:30:47 +0800127 return mContext;
128 }
129
Loganf340bf72011-01-14 17:51:40 +0800130 void registerSymbolCallback(BCCSymbolLookupFn pFn, void *pContext) {
Logancf3e5212010-12-29 01:44:55 +0800131 mCompiler.registerSymbolCallback(pFn, pContext);
132 }
Logancf3e5212010-12-29 01:44:55 +0800133 };
134
135} // namespace bcc
136
137#endif // BCC_SCRIPTCOMPILED_H