blob: 5c442c726ac27c22d29d2ffae52deff4d64bd46b [file] [log] [blame]
Logancf3e5212010-12-29 01:44:55 +08001/*
Stephen Hinescc366e52012-02-21 17:22:04 -08002 * Copyright 2010-2012, The Android Open Source Project
Logancf3e5212010-12-29 01:44:55 +08003 *
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"
Logan Chien7890d432011-08-03 14:55:17 +080021#include "Script.h"
Logancf3e5212010-12-29 01:44:55 +080022
23#include <bcc/bcc.h>
24
Logan7dcaac92011-01-06 04:26:23 +080025#include <list>
26#include <map>
27#include <string>
28#include <utility>
29#include <vector>
30
Logancf3e5212010-12-29 01:44:55 +080031namespace llvm {
32 class Module;
33}
34
35namespace bcc {
Zonr Chang2fcbd022012-01-06 21:04:31 +080036 struct CompilerOption;
37
Logancf3e5212010-12-29 01:44:55 +080038 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;
Stephen Hinescc366e52012-02-21 17:22:04 -080046 typedef std::list<void*> ExportForEachList;
Loganf340bf72011-01-14 17:51:40 +080047 typedef std::map<std::string, FuncInfo *> FuncInfoMap;
Stephen Hines071288a2011-01-27 14:38:26 -080048 typedef std::list<uint32_t> ObjectSlotList;
Logan2a6dc822011-01-06 04:05:20 +080049
Logancf3e5212010-12-29 01:44:55 +080050 private:
51 Script *mpOwner;
52
53 Compiler mCompiler;
54
Logan2a6dc822011-01-06 04:05:20 +080055 ExportVarList mExportVars;
Joseph Wenf36637f2011-07-06 18:27:12 -070056
57 std::vector<std::string> mExportVarsName;
58 std::vector<std::string> mExportFuncsName;
Stephen Hinescc366e52012-02-21 17:22:04 -080059 std::vector<std::string> mExportForEachName;
Joseph Wenf36637f2011-07-06 18:27:12 -070060
Logan2a6dc822011-01-06 04:05:20 +080061 ExportFuncList mExportFuncs;
Stephen Hinescc366e52012-02-21 17:22:04 -080062 ExportForEachList mExportForEach;
Logan02286cb2011-01-07 00:30:47 +080063 PragmaList mPragmas;
Stephen Hines071288a2011-01-27 14:38:26 -080064 ObjectSlotList mObjectSlots;
Logan02286cb2011-01-07 00:30:47 +080065
Loganf340bf72011-01-14 17:51:40 +080066 FuncInfoMap mEmittedFunctions;
Logan2a6dc822011-01-06 04:05:20 +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)
Logan Chiend2a5f302011-07-19 20:32:25 +080071 {
Logancf3e5212010-12-29 01:44:55 +080072 }
73
Logan7dcaac92011-01-06 04:26:23 +080074 ~ScriptCompiled();
75
Logan474cbd22011-01-31 01:47:44 +080076 int readModule(llvm::Module *module) {
Loganf340bf72011-01-14 17:51:40 +080077 return mCompiler.readModule(module);
78 }
79
Logan474cbd22011-01-31 01:47:44 +080080 int linkModule(llvm::Module *module) {
81 return mCompiler.linkModule(module);
Logancf3e5212010-12-29 01:44:55 +080082 }
83
Shih-wei Liao9e81e372012-01-17 16:38:40 -080084 int compile(const CompilerOption &option) {
Zonr Chang2fcbd022012-01-06 21:04:31 +080085 return mCompiler.compile(option);
Logancf3e5212010-12-29 01:44:55 +080086 }
87
88 char const *getCompilerErrorMessage() {
89 return mCompiler.getErrorMessage();
90 }
91
Logan7dcaac92011-01-06 04:26:23 +080092 void *lookup(const char *name);
Logancf3e5212010-12-29 01:44:55 +080093
Stephen Hinesb67c9e72012-03-22 11:02:48 -070094 uint32_t getCompilerVersion() const {
95 return mpOwner->getCompilerVersion();
96 }
97
98 uint32_t getOptimizationLevel() const {
99 return mpOwner->getOptimizationLevel();
100 }
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
Stephen Hinescc366e52012-02-21 17:22:04 -0800110 size_t getExportForEachCount() const {
111 return mExportForEach.size();
112 }
113
Loganbe79ada2011-01-13 01:33:45 +0800114 size_t getPragmaCount() const {
115 return mPragmas.size();
116 }
Logancf3e5212010-12-29 01:44:55 +0800117
Loganbe79ada2011-01-13 01:33:45 +0800118 size_t getFuncCount() const {
119 return mEmittedFunctions.size();
120 }
121
Stephen Hines071288a2011-01-27 14:38:26 -0800122 size_t getObjectSlotCount() const {
123 return mObjectSlots.size();
124 }
Loganbe79ada2011-01-13 01:33:45 +0800125
126 void getExportVarList(size_t varListSize, void **varList);
127
128 void getExportFuncList(size_t funcListSize, void **funcList);
129
Stephen Hinescc366e52012-02-21 17:22:04 -0800130 void getExportForEachList(size_t forEachListSize, void **forEachList);
131
Joseph Wenf36637f2011-07-06 18:27:12 -0700132 void getExportVarNameList(std::vector<std::string> &varList);
133
134 void getExportFuncNameList(std::vector<std::string> &funcList);
135
Stephen Hinescc366e52012-02-21 17:22:04 -0800136 void getExportForEachNameList(std::vector<std::string> &forEachList);
137
Loganbe79ada2011-01-13 01:33:45 +0800138 void getPragmaList(size_t pragmaListSize,
139 char const **keyList,
140 char const **valueList);
141
Loganf340bf72011-01-14 17:51:40 +0800142 void getFuncInfoList(size_t funcInfoListSize,
143 FuncInfo *funcInfoList);
Logancf3e5212010-12-29 01:44:55 +0800144
Stephen Hines071288a2011-01-27 14:38:26 -0800145 void getObjectSlotList(size_t objectSlotListSize,
146 uint32_t *objectSlotList);
147
Logan Chien7890d432011-08-03 14:55:17 +0800148 std::vector<char const *> const & getUserDefinedExternalSymbols() const {
149 return mpOwner->getUserDefinedExternalSymbols();
150 }
151
Shih-wei Liao5e3e0ce2011-06-17 13:59:46 -0700152 const char *getELF() const {
153 return &*mCompiler.getELF().begin();
154 }
155
156 size_t getELFSize() const {
157 return mCompiler.getELF().size();
158 }
Logan02286cb2011-01-07 00:30:47 +0800159
Loganf340bf72011-01-14 17:51:40 +0800160 void registerSymbolCallback(BCCSymbolLookupFn pFn, void *pContext) {
Logancf3e5212010-12-29 01:44:55 +0800161 mCompiler.registerSymbolCallback(pFn, pContext);
162 }
Logancf3e5212010-12-29 01:44:55 +0800163 };
164
165} // namespace bcc
166
167#endif // BCC_SCRIPTCOMPILED_H