blob: 7b7b62abd960ecac40770d481aebcbacfa6c8d46 [file] [log] [blame]
Stephen Hines4a68b1c2012-05-03 12:28:14 -07001/*
2 * Copyright 2010-2012, 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
Stephen Hinesead5ccb2012-05-03 12:30:38 -070020#include "Compiler.h"
21#include "Script.h"
22
23#include <bcc/bcc.h>
24
Stephen Hines4a68b1c2012-05-03 12:28:14 -070025#include <list>
26#include <map>
27#include <string>
28#include <utility>
29#include <vector>
30
Stephen Hines4a68b1c2012-05-03 12:28:14 -070031namespace llvm {
32 class Module;
33}
34
35namespace bcc {
36 struct CompilerOption;
37
38 class ScriptCompiled {
39 friend class Compiler;
40 friend class CodeEmitter;
41
42 private:
43 typedef std::list<std::pair<std::string, std::string> > PragmaList;
44 typedef std::list<void*> ExportVarList;
45 typedef std::list<void*> ExportFuncList;
46 typedef std::list<void*> ExportForEachList;
47 typedef std::map<std::string, FuncInfo *> FuncInfoMap;
48 typedef std::list<uint32_t> ObjectSlotList;
49
50 private:
Stephen Hines97c92c22012-05-03 12:30:24 -070051 Script *mpOwner;
Stephen Hines4a68b1c2012-05-03 12:28:14 -070052
53 Compiler mCompiler;
54
55 ExportVarList mExportVars;
56
57 std::vector<std::string> mExportVarsName;
58 std::vector<std::string> mExportFuncsName;
59 std::vector<std::string> mExportForEachName;
60
61 ExportFuncList mExportFuncs;
62 ExportForEachList mExportForEach;
63 PragmaList mPragmas;
64 ObjectSlotList mObjectSlots;
65
66 FuncInfoMap mEmittedFunctions;
67
68 public:
Stephen Hines97c92c22012-05-03 12:30:24 -070069 ScriptCompiled(Script *owner)
Stephen Hines4a68b1c2012-05-03 12:28:14 -070070 : mpOwner(owner), mCompiler(this)
71 {
72 }
73
74 ~ScriptCompiled();
75
Stephen Hinesead5ccb2012-05-03 12:30:38 -070076 int readModule(llvm::Module *module) {
77 return mCompiler.readModule(module);
78 }
79
80 int linkModule(llvm::Module *module) {
81 return mCompiler.linkModule(module);
Stephen Hines4a68b1c2012-05-03 12:28:14 -070082 }
83
84 int compile(const CompilerOption &option) {
85 return mCompiler.compile(option);
86 }
87
88 char const *getCompilerErrorMessage() {
89 return mCompiler.getErrorMessage();
90 }
91
92 void *lookup(const char *name);
93
94 size_t getExportVarCount() const {
95 return mExportVars.size();
96 }
97
98 size_t getExportFuncCount() const {
99 return mExportFuncs.size();
100 }
101
102 size_t getExportForEachCount() const {
103 return mExportForEach.size();
104 }
105
106 size_t getPragmaCount() const {
107 return mPragmas.size();
108 }
109
110 size_t getFuncCount() const {
111 return mEmittedFunctions.size();
112 }
113
114 size_t getObjectSlotCount() const {
115 return mObjectSlots.size();
116 }
117
118 void getExportVarList(size_t varListSize, void **varList);
119
120 void getExportFuncList(size_t funcListSize, void **funcList);
121
122 void getExportForEachList(size_t forEachListSize, void **forEachList);
123
124 void getExportVarNameList(std::vector<std::string> &varList);
125
126 void getExportFuncNameList(std::vector<std::string> &funcList);
127
128 void getExportForEachNameList(std::vector<std::string> &forEachList);
129
130 void getPragmaList(size_t pragmaListSize,
131 char const **keyList,
132 char const **valueList);
133
134 void getFuncInfoList(size_t funcInfoListSize,
135 FuncInfo *funcInfoList);
136
137 void getObjectSlotList(size_t objectSlotListSize,
138 uint32_t *objectSlotList);
139
140 std::vector<char const *> const & getUserDefinedExternalSymbols() const {
141 return mpOwner->getUserDefinedExternalSymbols();
142 }
143
144 const char *getELF() const {
145 return &*mCompiler.getELF().begin();
146 }
147
148 size_t getELFSize() const {
149 return mCompiler.getELF().size();
150 }
151
152 void registerSymbolCallback(BCCSymbolLookupFn pFn, void *pContext) {
153 mCompiler.registerSymbolCallback(pFn, pContext);
154 }
155 };
156
157} // namespace bcc
158
159#endif // BCC_SCRIPTCOMPILED_H