blob: 9593be85fe98ee4c4bb81d8280919607fc3950dd [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;
Stephen Hines071288a2011-01-27 14:38:26 -080046 typedef std::list<uint32_t> ObjectSlotList;
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;
Joseph Wenf36637f2011-07-06 18:27:12 -070054
55 std::vector<std::string> mExportVarsName;
56 std::vector<std::string> mExportFuncsName;
57
Logan2a6dc822011-01-06 04:05:20 +080058 ExportFuncList mExportFuncs;
Logan02286cb2011-01-07 00:30:47 +080059 PragmaList mPragmas;
Stephen Hines071288a2011-01-27 14:38:26 -080060 ObjectSlotList mObjectSlots;
Logan02286cb2011-01-07 00:30:47 +080061
Loganf340bf72011-01-14 17:51:40 +080062 FuncInfoMap mEmittedFunctions;
Logan2a6dc822011-01-06 04:05:20 +080063
Logan Chiend2a5f302011-07-19 20:32:25 +080064#if USE_OLD_JIT
Logan02286cb2011-01-07 00:30:47 +080065 char *mContext; // Context of BCC script (code and data)
Logan Chiend2a5f302011-07-19 20:32:25 +080066#endif
Logan02286cb2011-01-07 00:30:47 +080067
Logancf3e5212010-12-29 01:44:55 +080068 public:
Logan65719812011-01-07 11:17:14 +080069 ScriptCompiled(Script *owner)
Logan Chiend2a5f302011-07-19 20:32:25 +080070 : mpOwner(owner), mCompiler(this)
71#if USE_OLD_JIT
72 , mContext(NULL)
73#endif
74 {
Logancf3e5212010-12-29 01:44:55 +080075 }
76
Logan7dcaac92011-01-06 04:26:23 +080077 ~ScriptCompiled();
78
Logan474cbd22011-01-31 01:47:44 +080079 llvm::Module *parseBitcodeFile(llvm::MemoryBuffer *MEM) {
80 return mCompiler.parseBitcodeFile(MEM);
Logancf3e5212010-12-29 01:44:55 +080081 }
82
Logan474cbd22011-01-31 01:47:44 +080083 int readModule(llvm::Module *module) {
Loganf340bf72011-01-14 17:51:40 +080084 return mCompiler.readModule(module);
85 }
86
Logan474cbd22011-01-31 01:47:44 +080087 int linkModule(llvm::Module *module) {
88 return mCompiler.linkModule(module);
Logancf3e5212010-12-29 01:44:55 +080089 }
90
Logancf3e5212010-12-29 01:44:55 +080091 int compile() {
92 return mCompiler.compile();
93 }
94
95 char const *getCompilerErrorMessage() {
96 return mCompiler.getErrorMessage();
97 }
98
Logan7dcaac92011-01-06 04:26:23 +080099 void *lookup(const char *name);
Logancf3e5212010-12-29 01:44:55 +0800100
Logancf3e5212010-12-29 01:44:55 +0800101
Loganbe79ada2011-01-13 01:33:45 +0800102 size_t getExportVarCount() const {
103 return mExportVars.size();
104 }
Logancf3e5212010-12-29 01:44:55 +0800105
Loganbe79ada2011-01-13 01:33:45 +0800106 size_t getExportFuncCount() const {
107 return mExportFuncs.size();
108 }
Logancf3e5212010-12-29 01:44:55 +0800109
Loganbe79ada2011-01-13 01:33:45 +0800110 size_t getPragmaCount() const {
111 return mPragmas.size();
112 }
Logancf3e5212010-12-29 01:44:55 +0800113
Loganbe79ada2011-01-13 01:33:45 +0800114 size_t getFuncCount() const {
115 return mEmittedFunctions.size();
116 }
117
Stephen Hines071288a2011-01-27 14:38:26 -0800118 size_t getObjectSlotCount() const {
119 return mObjectSlots.size();
120 }
Loganbe79ada2011-01-13 01:33:45 +0800121
122 void getExportVarList(size_t varListSize, void **varList);
123
124 void getExportFuncList(size_t funcListSize, void **funcList);
125
Joseph Wenf36637f2011-07-06 18:27:12 -0700126 void getExportVarNameList(std::vector<std::string> &varList);
127
128 void getExportFuncNameList(std::vector<std::string> &funcList);
129
Loganbe79ada2011-01-13 01:33:45 +0800130 void getPragmaList(size_t pragmaListSize,
131 char const **keyList,
132 char const **valueList);
133
Loganf340bf72011-01-14 17:51:40 +0800134 void getFuncInfoList(size_t funcInfoListSize,
135 FuncInfo *funcInfoList);
Logancf3e5212010-12-29 01:44:55 +0800136
Stephen Hines071288a2011-01-27 14:38:26 -0800137 void getObjectSlotList(size_t objectSlotListSize,
138 uint32_t *objectSlotList);
139
Logan Chiend2a5f302011-07-19 20:32:25 +0800140#if USE_OLD_JIT
Logana27a83f2011-01-07 10:25:48 +0800141 char *getContext() {
Logan02286cb2011-01-07 00:30:47 +0800142 return mContext;
143 }
Logan Chiend2a5f302011-07-19 20:32:25 +0800144#endif
145
Shih-wei Liao5e3e0ce2011-06-17 13:59:46 -0700146#if USE_MCJIT
147 const char *getELF() const {
148 return &*mCompiler.getELF().begin();
149 }
150
151 size_t getELFSize() const {
152 return mCompiler.getELF().size();
153 }
154#endif
Logan02286cb2011-01-07 00:30:47 +0800155
Loganf340bf72011-01-14 17:51:40 +0800156 void registerSymbolCallback(BCCSymbolLookupFn pFn, void *pContext) {
Logancf3e5212010-12-29 01:44:55 +0800157 mCompiler.registerSymbolCallback(pFn, pContext);
158 }
Logancf3e5212010-12-29 01:44:55 +0800159 };
160
161} // namespace bcc
162
163#endif // BCC_SCRIPTCOMPILED_H