blob: 2a752d769cc9cc3d449ceddf3df79994feabe858 [file] [log] [blame]
Chris Lattner4f9ff5a2007-02-07 07:19:19 +00001//===-- Analyzer.cpp - Analysis and Dumping of Bytecode ---------*- C++ -*-===//
Misha Brukman8a96c532005-04-21 21:44:41 +00002//
Reid Spencerdac69c82004-06-07 17:53:43 +00003// The LLVM Compiler Infrastructure
4//
Misha Brukman8a96c532005-04-21 21:44:41 +00005// This file was developed by Reid Spencer and is distributed under the
Reid Spencerdac69c82004-06-07 17:53:43 +00006// University of Illinois Open Source License. See LICENSE.TXT for details.
Misha Brukman8a96c532005-04-21 21:44:41 +00007//
Reid Spencerdac69c82004-06-07 17:53:43 +00008//===----------------------------------------------------------------------===//
9//
Reid Spencerf41aa732004-06-29 23:23:12 +000010// This file implements the AnalyzerHandler class and PrintBytecodeAnalysis
11// function which together comprise the basic functionality of the llmv-abcd
12// tool. The AnalyzerHandler collects information about the bytecode file into
13// the BytecodeAnalysis structure. The PrintBytecodeAnalysis function prints
14// out the content of that structure.
15// @see include/llvm/Bytecode/Analysis.h
Reid Spencerdac69c82004-06-07 17:53:43 +000016//
17//===----------------------------------------------------------------------===//
18
Reid Spencerf41aa732004-06-29 23:23:12 +000019#include "Reader.h"
20#include "llvm/Constants.h"
21#include "llvm/DerivedTypes.h"
22#include "llvm/Module.h"
23#include "llvm/Analysis/Verifier.h"
Reid Spencerf41aa732004-06-29 23:23:12 +000024#include "llvm/Bytecode/BytecodeHandler.h"
Reid Spencer911ec6d2004-08-21 20:58:19 +000025#include "llvm/Assembly/Writer.h"
Reid Spencerf41aa732004-06-29 23:23:12 +000026#include <iomanip>
27#include <sstream>
Duraid Madina0f7bfba2005-12-26 14:23:22 +000028#include <ios>
Reid Spencerdac69c82004-06-07 17:53:43 +000029using namespace llvm;
30
Reid Spencerdac69c82004-06-07 17:53:43 +000031namespace {
32
Reid Spencerf41aa732004-06-29 23:23:12 +000033/// @brief Bytecode reading handler for analyzing bytecode.
Reid Spencerdac69c82004-06-07 17:53:43 +000034class AnalyzerHandler : public BytecodeHandler {
Reid Spencerf41aa732004-06-29 23:23:12 +000035 BytecodeAnalysis& bca; ///< The structure in which data is recorded
Reid Spencer911ec6d2004-08-21 20:58:19 +000036 std::ostream* os; ///< A convenience for osing data.
Reid Spencerf41aa732004-06-29 23:23:12 +000037 /// @brief Keeps track of current function
Misha Brukman8a96c532005-04-21 21:44:41 +000038 BytecodeAnalysis::BytecodeFunctionInfo* currFunc;
Reid Spencerf41aa732004-06-29 23:23:12 +000039 Module* M; ///< Keeps track of current module
40
41/// @name Constructor
42/// @{
Reid Spencerdac69c82004-06-07 17:53:43 +000043public:
Reid Spencerf41aa732004-06-29 23:23:12 +000044 /// The only way to construct an AnalyzerHandler. All that is needed is a
45 /// reference to the BytecodeAnalysis structure where the output will be
46 /// placed.
Misha Brukman8a96c532005-04-21 21:44:41 +000047 AnalyzerHandler(BytecodeAnalysis& TheBca, std::ostream* output)
48 : bca(TheBca)
Reid Spencer911ec6d2004-08-21 20:58:19 +000049 , os(output)
Reid Spencercbb22e22004-06-10 22:00:54 +000050 , currFunc(0)
Reid Spencer911ec6d2004-08-21 20:58:19 +000051 { }
Reid Spencer649ee572004-06-09 06:16:43 +000052
Reid Spencerf41aa732004-06-29 23:23:12 +000053/// @}
54/// @name BytecodeHandler Implementations
55/// @{
56public:
Misha Brukman8a96c532005-04-21 21:44:41 +000057 virtual void handleError(const std::string& str ) {
Reid Spencer911ec6d2004-08-21 20:58:19 +000058 if (os)
59 *os << "ERROR: " << str << "\n";
Reid Spencerdac69c82004-06-07 17:53:43 +000060 }
61
Reid Spencerf41aa732004-06-29 23:23:12 +000062 virtual void handleStart( Module* Mod, unsigned theSize ) {
63 M = Mod;
Reid Spencer911ec6d2004-08-21 20:58:19 +000064 if (os)
65 *os << "Bytecode {\n";
Reid Spencerf41aa732004-06-29 23:23:12 +000066 bca.byteSize = theSize;
Reid Spencer649ee572004-06-09 06:16:43 +000067 bca.ModuleId.clear();
Reid Spencer00c28a72004-06-10 08:09:13 +000068 bca.numBlocks = 0;
Reid Spencer649ee572004-06-09 06:16:43 +000069 bca.numTypes = 0;
70 bca.numValues = 0;
71 bca.numFunctions = 0;
72 bca.numConstants = 0;
73 bca.numGlobalVars = 0;
74 bca.numInstructions = 0;
75 bca.numBasicBlocks = 0;
76 bca.numOperands = 0;
77 bca.numCmpctnTables = 0;
78 bca.numSymTab = 0;
Reid Spencer911ec6d2004-08-21 20:58:19 +000079 bca.numLibraries = 0;
80 bca.libSize = 0;
Reid Spencer649ee572004-06-09 06:16:43 +000081 bca.maxTypeSlot = 0;
82 bca.maxValueSlot = 0;
Reid Spencer00c28a72004-06-10 08:09:13 +000083 bca.numAlignment = 0;
84 bca.fileDensity = 0.0;
85 bca.globalsDensity = 0.0;
86 bca.functionDensity = 0.0;
Reid Spencer1cf50242004-06-11 15:10:38 +000087 bca.instructionSize = 0;
88 bca.longInstructions = 0;
Reid Spencer649ee572004-06-09 06:16:43 +000089 bca.FunctionInfo.clear();
Reid Spencer911ec6d2004-08-21 20:58:19 +000090 bca.BlockSizes[BytecodeFormat::Reserved_DoNotUse] = 0;
91 bca.BlockSizes[BytecodeFormat::ModuleBlockID] = theSize;
92 bca.BlockSizes[BytecodeFormat::FunctionBlockID] = 0;
93 bca.BlockSizes[BytecodeFormat::ConstantPoolBlockID] = 0;
Reid Spencer78d033e2007-01-06 07:24:44 +000094 bca.BlockSizes[BytecodeFormat::ValueSymbolTableBlockID] = 0;
Reid Spencer911ec6d2004-08-21 20:58:19 +000095 bca.BlockSizes[BytecodeFormat::ModuleGlobalInfoBlockID] = 0;
96 bca.BlockSizes[BytecodeFormat::GlobalTypePlaneBlockID] = 0;
97 bca.BlockSizes[BytecodeFormat::InstructionListBlockID] = 0;
Reid Spencer78d033e2007-01-06 07:24:44 +000098 bca.BlockSizes[BytecodeFormat::TypeSymbolTableBlockID] = 0;
Reid Spencerdac69c82004-06-07 17:53:43 +000099 }
100
Reid Spencercbb22e22004-06-10 22:00:54 +0000101 virtual void handleFinish() {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000102 if (os)
Misha Brukman8a96c532005-04-21 21:44:41 +0000103 *os << "} End Bytecode\n";
Reid Spencerf41aa732004-06-29 23:23:12 +0000104
Reid Spencer00c28a72004-06-10 08:09:13 +0000105 bca.fileDensity = double(bca.byteSize) / double( bca.numTypes + bca.numValues );
106 double globalSize = 0.0;
Reid Spencer911ec6d2004-08-21 20:58:19 +0000107 globalSize += double(bca.BlockSizes[BytecodeFormat::ConstantPoolBlockID]);
108 globalSize += double(bca.BlockSizes[BytecodeFormat::ModuleGlobalInfoBlockID]);
109 globalSize += double(bca.BlockSizes[BytecodeFormat::GlobalTypePlaneBlockID]);
Misha Brukman8a96c532005-04-21 21:44:41 +0000110 bca.globalsDensity = globalSize / double( bca.numTypes + bca.numConstants +
Reid Spencer00c28a72004-06-10 08:09:13 +0000111 bca.numGlobalVars );
Misha Brukman8a96c532005-04-21 21:44:41 +0000112 bca.functionDensity = double(bca.BlockSizes[BytecodeFormat::FunctionBlockID]) /
Reid Spencer00c28a72004-06-10 08:09:13 +0000113 double(bca.numFunctions);
Reid Spencerf41aa732004-06-29 23:23:12 +0000114
Chris Lattner05ac92c2006-07-06 18:02:27 +0000115 if (bca.progressiveVerify) {
116 std::string msg;
117 if (verifyModule(*M, ReturnStatusAction, &msg))
Reid Spencerb61cdb72004-07-04 11:00:39 +0000118 bca.VerifyInfo += "Verify@Finish: " + msg + "\n";
Reid Spencerf41aa732004-06-29 23:23:12 +0000119 }
Reid Spencerdac69c82004-06-07 17:53:43 +0000120 }
121
Reid Spencercbb22e22004-06-10 22:00:54 +0000122 virtual void handleModuleBegin(const std::string& id) {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000123 if (os)
124 *os << " Module " << id << " {\n";
Reid Spencer649ee572004-06-09 06:16:43 +0000125 bca.ModuleId = id;
Reid Spencerdac69c82004-06-07 17:53:43 +0000126 }
127
Misha Brukman8a96c532005-04-21 21:44:41 +0000128 virtual void handleModuleEnd(const std::string& id) {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000129 if (os)
130 *os << " } End Module " << id << "\n";
Chris Lattner05ac92c2006-07-06 18:02:27 +0000131 if (bca.progressiveVerify) {
132 std::string msg;
133 if (verifyModule(*M, ReturnStatusAction, &msg))
Reid Spencerb61cdb72004-07-04 11:00:39 +0000134 bca.VerifyInfo += "Verify@EndModule: " + msg + "\n";
Reid Spencerf41aa732004-06-29 23:23:12 +0000135 }
136 }
Reid Spencerdac69c82004-06-07 17:53:43 +0000137
Reid Spencercbb22e22004-06-10 22:00:54 +0000138 virtual void handleVersionInfo(
Reid Spenceraacc35a2007-01-26 08:10:24 +0000139 unsigned char RevisionNum ///< Byte code revision number
Misha Brukman8a96c532005-04-21 21:44:41 +0000140 ) {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000141 if (os)
Reid Spenceraacc35a2007-01-26 08:10:24 +0000142 *os << " RevisionNum: " << int(RevisionNum) << "\n";
Reid Spencer911ec6d2004-08-21 20:58:19 +0000143 bca.version = RevisionNum;
Reid Spencerf41aa732004-06-29 23:23:12 +0000144 }
Reid Spencerdac69c82004-06-07 17:53:43 +0000145
Misha Brukman8a96c532005-04-21 21:44:41 +0000146 virtual void handleModuleGlobalsBegin() {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000147 if (os)
148 *os << " BLOCK: ModuleGlobalInfo {\n";
Reid Spencerf41aa732004-06-29 23:23:12 +0000149 }
Reid Spencerdac69c82004-06-07 17:53:43 +0000150
Misha Brukman8a96c532005-04-21 21:44:41 +0000151 virtual void handleGlobalVariable(
152 const Type* ElemType,
153 bool isConstant,
Reid Spencerf41aa732004-06-29 23:23:12 +0000154 GlobalValue::LinkageTypes Linkage,
Anton Korobeynikov7f705592007-01-12 19:20:47 +0000155 GlobalValue::VisibilityTypes Visibility,
Reid Spencerf41aa732004-06-29 23:23:12 +0000156 unsigned SlotNum,
Lauro Ramos Venancioc7635522007-04-12 18:32:50 +0000157 unsigned initSlot,
158 bool isThreadLocal
Reid Spencercbb22e22004-06-10 22:00:54 +0000159 ) {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000160 if (os) {
161 *os << " GV: "
162 << ( initSlot == 0 ? "Uni" : "I" ) << "nitialized, "
163 << ( isConstant? "Constant, " : "Variable, ")
Lauro Ramos Venancioc7635522007-04-12 18:32:50 +0000164 << " Thread Local = " << ( isThreadLocal? "yes, " : "no, ")
Anton Korobeynikov7f705592007-01-12 19:20:47 +0000165 << " Linkage=" << Linkage
166 << " Visibility="<< Visibility
167 << " Type=";
Reid Spencer911ec6d2004-08-21 20:58:19 +0000168 WriteTypeSymbolic(*os, ElemType, M);
Misha Brukman8a96c532005-04-21 21:44:41 +0000169 *os << " Slot=" << SlotNum << " InitSlot=" << initSlot
Reid Spencer911ec6d2004-08-21 20:58:19 +0000170 << "\n";
171 }
172
Reid Spencer649ee572004-06-09 06:16:43 +0000173 bca.numGlobalVars++;
Reid Spencer00c28a72004-06-10 08:09:13 +0000174 bca.numValues++;
Reid Spencer911ec6d2004-08-21 20:58:19 +0000175 if (SlotNum > bca.maxValueSlot)
176 bca.maxValueSlot = SlotNum;
177 if (initSlot > bca.maxValueSlot)
178 bca.maxValueSlot = initSlot;
Reid Spencerf41aa732004-06-29 23:23:12 +0000179
Reid Spencer911ec6d2004-08-21 20:58:19 +0000180 }
181
182 virtual void handleTypeList(unsigned numEntries) {
183 bca.maxTypeSlot = numEntries - 1;
Reid Spencerdac69c82004-06-07 17:53:43 +0000184 }
185
Misha Brukman8a96c532005-04-21 21:44:41 +0000186 virtual void handleType( const Type* Ty ) {
187 bca.numTypes++;
Reid Spencer911ec6d2004-08-21 20:58:19 +0000188 if (os) {
189 *os << " Type: ";
190 WriteTypeSymbolic(*os,Ty,M);
191 *os << "\n";
192 }
Reid Spencerdac69c82004-06-07 17:53:43 +0000193 }
194
Misha Brukman8a96c532005-04-21 21:44:41 +0000195 virtual void handleFunctionDeclaration(
Reid Spencerb61cdb72004-07-04 11:00:39 +0000196 Function* Func ///< The function
Reid Spencercbb22e22004-06-10 22:00:54 +0000197 ) {
Reid Spencer649ee572004-06-09 06:16:43 +0000198 bca.numFunctions++;
Reid Spencer00c28a72004-06-10 08:09:13 +0000199 bca.numValues++;
Reid Spencer911ec6d2004-08-21 20:58:19 +0000200 if (os) {
201 *os << " Function Decl: ";
202 WriteTypeSymbolic(*os,Func->getType(),M);
Anton Korobeynikov93c2b372006-09-17 13:06:18 +0000203 *os <<", Linkage=" << Func->getLinkage();
Anton Korobeynikov7f705592007-01-12 19:20:47 +0000204 *os <<", Visibility=" << Func->getVisibility();
Reid Spencer911ec6d2004-08-21 20:58:19 +0000205 *os << "\n";
206 }
Reid Spencerdac69c82004-06-07 17:53:43 +0000207 }
208
Reid Spencerf41aa732004-06-29 23:23:12 +0000209 virtual void handleGlobalInitializer(GlobalVariable* GV, Constant* CV) {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000210 if (os) {
211 *os << " Initializer: GV=";
212 GV->print(*os);
213 *os << " CV=";
214 CV->print(*os);
215 *os << "\n";
216 }
217 }
218
219 virtual void handleDependentLibrary(const std::string& libName) {
220 bca.numLibraries++;
221 bca.libSize += libName.size() + (libName.size() < 128 ? 1 : 2);
Reid Spencer3ee8eed2004-09-11 04:14:07 +0000222 if (os)
223 *os << " Library: '" << libName << "'\n";
Reid Spencerf41aa732004-06-29 23:23:12 +0000224 }
Reid Spencerdac69c82004-06-07 17:53:43 +0000225
Misha Brukman8a96c532005-04-21 21:44:41 +0000226 virtual void handleModuleGlobalsEnd() {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000227 if (os)
228 *os << " } END BLOCK: ModuleGlobalInfo\n";
Chris Lattner05ac92c2006-07-06 18:02:27 +0000229 if (bca.progressiveVerify) {
230 std::string msg;
231 if (verifyModule(*M, ReturnStatusAction, &msg))
Reid Spencerb61cdb72004-07-04 11:00:39 +0000232 bca.VerifyInfo += "Verify@EndModuleGlobalInfo: " + msg + "\n";
Reid Spencerf41aa732004-06-29 23:23:12 +0000233 }
234 }
235
Reid Spenceref9b9a72007-02-05 20:47:22 +0000236 virtual void handleTypeSymbolTableBegin(TypeSymbolTable* ST) {
Misha Brukman8a96c532005-04-21 21:44:41 +0000237 bca.numSymTab++;
Reid Spencer911ec6d2004-08-21 20:58:19 +0000238 if (os)
Reid Spenceref9b9a72007-02-05 20:47:22 +0000239 *os << " BLOCK: TypeSymbolTable {\n";
Reid Spencerf41aa732004-06-29 23:23:12 +0000240 }
Reid Spenceref9b9a72007-02-05 20:47:22 +0000241 virtual void handleValueSymbolTableBegin(Function* CF, ValueSymbolTable* ST) {
242 bca.numSymTab++;
243 if (os)
244 *os << " BLOCK: ValueSymbolTable {\n";
Reid Spencerf41aa732004-06-29 23:23:12 +0000245 }
Reid Spencercbb22e22004-06-10 22:00:54 +0000246
Misha Brukman8a96c532005-04-21 21:44:41 +0000247 virtual void handleSymbolTableType(unsigned i, unsigned TypSlot,
248 const std::string& name ) {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000249 if (os)
250 *os << " Type " << i << " Slot=" << TypSlot
Misha Brukman8a96c532005-04-21 21:44:41 +0000251 << " Name: " << name << "\n";
Reid Spencerf41aa732004-06-29 23:23:12 +0000252 }
Reid Spencercbb22e22004-06-10 22:00:54 +0000253
Reid Spenceref9b9a72007-02-05 20:47:22 +0000254 virtual void handleSymbolTableValue(unsigned TySlot, unsigned ValSlot,
Chris Lattnerdd8cec52007-02-12 18:53:43 +0000255 const char *Name, unsigned NameLen) {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000256 if (os)
Reid Spenceref9b9a72007-02-05 20:47:22 +0000257 *os << " Value " << TySlot << " Slot=" << ValSlot
Chris Lattnerdd8cec52007-02-12 18:53:43 +0000258 << " Name: " << std::string(Name, Name+NameLen) << "\n";
Reid Spencer911ec6d2004-08-21 20:58:19 +0000259 if (ValSlot > bca.maxValueSlot)
260 bca.maxValueSlot = ValSlot;
Reid Spencerf41aa732004-06-29 23:23:12 +0000261 }
Reid Spencercbb22e22004-06-10 22:00:54 +0000262
Reid Spenceref9b9a72007-02-05 20:47:22 +0000263 virtual void handleValueSymbolTableEnd() {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000264 if (os)
Reid Spenceref9b9a72007-02-05 20:47:22 +0000265 *os << " } END BLOCK: ValueSymbolTable\n";
266 }
267
268 virtual void handleTypeSymbolTableEnd() {
269 if (os)
270 *os << " } END BLOCK: TypeSymbolTable\n";
Reid Spencerf41aa732004-06-29 23:23:12 +0000271 }
Reid Spencercbb22e22004-06-10 22:00:54 +0000272
Reid Spencerf41aa732004-06-29 23:23:12 +0000273 virtual void handleFunctionBegin(Function* Func, unsigned Size) {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000274 if (os) {
275 *os << " BLOCK: Function {\n"
276 << " Linkage: " << Func->getLinkage() << "\n"
Anton Korobeynikov7f705592007-01-12 19:20:47 +0000277 << " Visibility: " << Func->getVisibility() << "\n"
Misha Brukman8a96c532005-04-21 21:44:41 +0000278 << " Type: ";
Reid Spencer911ec6d2004-08-21 20:58:19 +0000279 WriteTypeSymbolic(*os,Func->getType(),M);
280 *os << "\n";
281 }
282
Reid Spencercbb22e22004-06-10 22:00:54 +0000283 currFunc = &bca.FunctionInfo[Func];
Reid Spencer911ec6d2004-08-21 20:58:19 +0000284 std::ostringstream tmp;
285 WriteTypeSymbolic(tmp,Func->getType(),M);
286 currFunc->description = tmp.str();
Reid Spencercbb22e22004-06-10 22:00:54 +0000287 currFunc->name = Func->getName();
288 currFunc->byteSize = Size;
289 currFunc->numInstructions = 0;
290 currFunc->numBasicBlocks = 0;
291 currFunc->numPhis = 0;
292 currFunc->numOperands = 0;
293 currFunc->density = 0.0;
Reid Spencer1cf50242004-06-11 15:10:38 +0000294 currFunc->instructionSize = 0;
295 currFunc->longInstructions = 0;
Reid Spencerf41aa732004-06-29 23:23:12 +0000296
Reid Spencerdac69c82004-06-07 17:53:43 +0000297 }
298
Reid Spencercbb22e22004-06-10 22:00:54 +0000299 virtual void handleFunctionEnd( Function* Func) {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000300 if (os)
301 *os << " } END BLOCK: Function\n";
Reid Spencercbb22e22004-06-10 22:00:54 +0000302 currFunc->density = double(currFunc->byteSize) /
Reid Spencer3120e712004-08-24 22:45:32 +0000303 double(currFunc->numInstructions);
Reid Spencerf41aa732004-06-29 23:23:12 +0000304
Chris Lattner05ac92c2006-07-06 18:02:27 +0000305 if (bca.progressiveVerify) {
306 std::string msg;
307 if (verifyModule(*M, ReturnStatusAction, &msg))
Reid Spencerb61cdb72004-07-04 11:00:39 +0000308 bca.VerifyInfo += "Verify@EndFunction: " + msg + "\n";
Reid Spencerf41aa732004-06-29 23:23:12 +0000309 }
Reid Spencerdac69c82004-06-07 17:53:43 +0000310 }
311
Reid Spencercbb22e22004-06-10 22:00:54 +0000312 virtual void handleBasicBlockBegin( unsigned blocknum) {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000313 if (os)
314 *os << " BLOCK: BasicBlock #" << blocknum << "{\n";
Reid Spencer649ee572004-06-09 06:16:43 +0000315 bca.numBasicBlocks++;
Reid Spencer00c28a72004-06-10 08:09:13 +0000316 bca.numValues++;
Reid Spencercbb22e22004-06-10 22:00:54 +0000317 if ( currFunc ) currFunc->numBasicBlocks++;
Reid Spencerdac69c82004-06-07 17:53:43 +0000318 }
319
Misha Brukman8a96c532005-04-21 21:44:41 +0000320 virtual bool handleInstruction( unsigned Opcode, const Type* iType,
Chris Lattner63cf59e2007-02-07 05:08:39 +0000321 unsigned *Operands, unsigned NumOps,
Reid Spenceref9b9a72007-02-05 20:47:22 +0000322 Instruction *Inst,
323 unsigned Size){
Reid Spencer911ec6d2004-08-21 20:58:19 +0000324 if (os) {
Misha Brukman8a96c532005-04-21 21:44:41 +0000325 *os << " INST: OpCode="
Reid Spenceref9b9a72007-02-05 20:47:22 +0000326 << Instruction::getOpcodeName(Opcode);
Chris Lattner63cf59e2007-02-07 05:08:39 +0000327 for (unsigned i = 0; i != NumOps; ++i)
Reid Spenceref9b9a72007-02-05 20:47:22 +0000328 *os << " Op(" << Operands[i] << ")";
329 *os << *Inst;
Reid Spencer911ec6d2004-08-21 20:58:19 +0000330 }
Reid Spencerf41aa732004-06-29 23:23:12 +0000331
Reid Spencer649ee572004-06-09 06:16:43 +0000332 bca.numInstructions++;
Reid Spencer00c28a72004-06-10 08:09:13 +0000333 bca.numValues++;
Reid Spencer1cf50242004-06-11 15:10:38 +0000334 bca.instructionSize += Size;
335 if (Size > 4 ) bca.longInstructions++;
Chris Lattner63cf59e2007-02-07 05:08:39 +0000336 bca.numOperands += NumOps;
337 for (unsigned i = 0; i != NumOps; ++i)
Reid Spencer911ec6d2004-08-21 20:58:19 +0000338 if (Operands[i] > bca.maxValueSlot)
339 bca.maxValueSlot = Operands[i];
Reid Spencercbb22e22004-06-10 22:00:54 +0000340 if ( currFunc ) {
341 currFunc->numInstructions++;
Reid Spencer1cf50242004-06-11 15:10:38 +0000342 currFunc->instructionSize += Size;
343 if (Size > 4 ) currFunc->longInstructions++;
Chris Lattner63cf59e2007-02-07 05:08:39 +0000344 if (Opcode == Instruction::PHI) currFunc->numPhis++;
Reid Spencercbb22e22004-06-10 22:00:54 +0000345 }
Misha Brukman8a96c532005-04-21 21:44:41 +0000346 return Instruction::isTerminator(Opcode);
Reid Spencerdac69c82004-06-07 17:53:43 +0000347 }
348
Misha Brukman8a96c532005-04-21 21:44:41 +0000349 virtual void handleBasicBlockEnd(unsigned blocknum) {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000350 if (os)
Reid Spencerc6d416a2006-12-15 21:46:37 +0000351 *os << " } END BLOCK: BasicBlock #" << blocknum << "\n";
Reid Spencerf41aa732004-06-29 23:23:12 +0000352 }
Reid Spencerdac69c82004-06-07 17:53:43 +0000353
Misha Brukman8a96c532005-04-21 21:44:41 +0000354 virtual void handleGlobalConstantsBegin() {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000355 if (os)
356 *os << " BLOCK: GlobalConstants {\n";
Reid Spencerf41aa732004-06-29 23:23:12 +0000357 }
Reid Spencerdac69c82004-06-07 17:53:43 +0000358
Chris Lattner63cf59e2007-02-07 05:08:39 +0000359 virtual void handleConstantExpression(unsigned Opcode,
360 Constant**ArgVec, unsigned NumArgs, Constant* C) {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000361 if (os) {
362 *os << " EXPR: " << Instruction::getOpcodeName(Opcode) << "\n";
Chris Lattner63cf59e2007-02-07 05:08:39 +0000363 for ( unsigned i = 0; i != NumArgs; ++i ) {
Misha Brukman8a96c532005-04-21 21:44:41 +0000364 *os << " Arg#" << i << " "; ArgVec[i]->print(*os);
Reid Spencer911ec6d2004-08-21 20:58:19 +0000365 *os << "\n";
366 }
367 *os << " Value=";
368 C->print(*os);
369 *os << "\n";
Reid Spencerf41aa732004-06-29 23:23:12 +0000370 }
Reid Spencer649ee572004-06-09 06:16:43 +0000371 bca.numConstants++;
Reid Spencer00c28a72004-06-10 08:09:13 +0000372 bca.numValues++;
Reid Spencerdac69c82004-06-07 17:53:43 +0000373 }
374
Reid Spencercbb22e22004-06-10 22:00:54 +0000375 virtual void handleConstantValue( Constant * c ) {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000376 if (os) {
377 *os << " VALUE: ";
378 c->print(*os);
379 *os << "\n";
380 }
Reid Spencer649ee572004-06-09 06:16:43 +0000381 bca.numConstants++;
Reid Spencer00c28a72004-06-10 08:09:13 +0000382 bca.numValues++;
Reid Spencerdac69c82004-06-07 17:53:43 +0000383 }
384
Misha Brukman8a96c532005-04-21 21:44:41 +0000385 virtual void handleConstantArray( const ArrayType* AT,
Chris Lattner63cf59e2007-02-07 05:08:39 +0000386 Constant**Elements, unsigned NumElts,
Reid Spencerb61cdb72004-07-04 11:00:39 +0000387 unsigned TypeSlot,
388 Constant* ArrayVal ) {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000389 if (os) {
390 *os << " ARRAY: ";
Misha Brukman8a96c532005-04-21 21:44:41 +0000391 WriteTypeSymbolic(*os,AT,M);
Reid Spencer911ec6d2004-08-21 20:58:19 +0000392 *os << " TypeSlot=" << TypeSlot << "\n";
Chris Lattner63cf59e2007-02-07 05:08:39 +0000393 for (unsigned i = 0; i != NumElts; ++i) {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000394 *os << " #" << i;
395 Elements[i]->print(*os);
396 *os << "\n";
397 }
398 *os << " Value=";
399 ArrayVal->print(*os);
400 *os << "\n";
Reid Spencerf41aa732004-06-29 23:23:12 +0000401 }
Reid Spencerf41aa732004-06-29 23:23:12 +0000402
Reid Spencer649ee572004-06-09 06:16:43 +0000403 bca.numConstants++;
Reid Spencer00c28a72004-06-10 08:09:13 +0000404 bca.numValues++;
Reid Spencerdac69c82004-06-07 17:53:43 +0000405 }
406
Reid Spencercbb22e22004-06-10 22:00:54 +0000407 virtual void handleConstantStruct(
Reid Spencer00c28a72004-06-10 08:09:13 +0000408 const StructType* ST,
Chris Lattner63cf59e2007-02-07 05:08:39 +0000409 Constant**Elements, unsigned NumElts,
Reid Spencerb61cdb72004-07-04 11:00:39 +0000410 Constant* StructVal)
Reid Spencerdac69c82004-06-07 17:53:43 +0000411 {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000412 if (os) {
413 *os << " STRUC: ";
414 WriteTypeSymbolic(*os,ST,M);
415 *os << "\n";
Chris Lattner63cf59e2007-02-07 05:08:39 +0000416 for ( unsigned i = 0; i != NumElts; ++i) {
Misha Brukman8a96c532005-04-21 21:44:41 +0000417 *os << " #" << i << " "; Elements[i]->print(*os);
Reid Spencer911ec6d2004-08-21 20:58:19 +0000418 *os << "\n";
419 }
420 *os << " Value=";
421 StructVal->print(*os);
422 *os << "\n";
Reid Spencerf41aa732004-06-29 23:23:12 +0000423 }
Reid Spencer649ee572004-06-09 06:16:43 +0000424 bca.numConstants++;
Reid Spencer00c28a72004-06-10 08:09:13 +0000425 bca.numValues++;
Reid Spencerdac69c82004-06-07 17:53:43 +0000426 }
427
Reid Spencer9d6565a2007-02-15 02:26:10 +0000428 virtual void handleConstantVector(
429 const VectorType* PT,
Chris Lattner63cf59e2007-02-07 05:08:39 +0000430 Constant**Elements, unsigned NumElts,
Misha Brukman8a96c532005-04-21 21:44:41 +0000431 unsigned TypeSlot,
Reid Spencerac9dcb92007-02-15 03:39:18 +0000432 Constant* VectorVal)
Brian Gaeke715c90b2004-08-20 06:00:58 +0000433 {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000434 if (os) {
435 *os << " PACKD: ";
436 WriteTypeSymbolic(*os,PT,M);
437 *os << " TypeSlot=" << TypeSlot << "\n";
Chris Lattner63cf59e2007-02-07 05:08:39 +0000438 for ( unsigned i = 0; i != NumElts; ++i ) {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000439 *os << " #" << i;
440 Elements[i]->print(*os);
441 *os << "\n";
442 }
443 *os << " Value=";
Reid Spencerac9dcb92007-02-15 03:39:18 +0000444 VectorVal->print(*os);
Reid Spencer911ec6d2004-08-21 20:58:19 +0000445 *os << "\n";
Brian Gaeke715c90b2004-08-20 06:00:58 +0000446 }
Brian Gaeke715c90b2004-08-20 06:00:58 +0000447
448 bca.numConstants++;
449 bca.numValues++;
450 }
451
Misha Brukman8a96c532005-04-21 21:44:41 +0000452 virtual void handleConstantPointer( const PointerType* PT,
Reid Spencer3c90f9f2004-07-18 00:10:36 +0000453 unsigned Slot, GlobalValue* GV ) {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000454 if (os) {
455 *os << " PNTR: ";
456 WriteTypeSymbolic(*os,PT,M);
457 *os << " Slot=" << Slot << " GlobalValue=";
458 GV->print(*os);
459 *os << "\n";
460 }
Reid Spencer649ee572004-06-09 06:16:43 +0000461 bca.numConstants++;
Reid Spencer00c28a72004-06-10 08:09:13 +0000462 bca.numValues++;
Reid Spencerdac69c82004-06-07 17:53:43 +0000463 }
464
Reid Spencercbb22e22004-06-10 22:00:54 +0000465 virtual void handleConstantString( const ConstantArray* CA ) {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000466 if (os) {
467 *os << " STRNG: ";
Misha Brukman8a96c532005-04-21 21:44:41 +0000468 CA->print(*os);
Reid Spencer911ec6d2004-08-21 20:58:19 +0000469 *os << "\n";
470 }
Reid Spencer649ee572004-06-09 06:16:43 +0000471 bca.numConstants++;
Reid Spencer00c28a72004-06-10 08:09:13 +0000472 bca.numValues++;
Reid Spencerdac69c82004-06-07 17:53:43 +0000473 }
474
Misha Brukman8a96c532005-04-21 21:44:41 +0000475 virtual void handleGlobalConstantsEnd() {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000476 if (os)
477 *os << " } END BLOCK: GlobalConstants\n";
478
Chris Lattner05ac92c2006-07-06 18:02:27 +0000479 if (bca.progressiveVerify) {
480 std::string msg;
481 if (verifyModule(*M, ReturnStatusAction, &msg))
Reid Spencerb61cdb72004-07-04 11:00:39 +0000482 bca.VerifyInfo += "Verify@EndGlobalConstants: " + msg + "\n";
Reid Spencerf41aa732004-06-29 23:23:12 +0000483 }
484 }
Reid Spencerdac69c82004-06-07 17:53:43 +0000485
Reid Spencercbb22e22004-06-10 22:00:54 +0000486 virtual void handleAlignment(unsigned numBytes) {
Reid Spencer00c28a72004-06-10 08:09:13 +0000487 bca.numAlignment += numBytes;
Reid Spencerdac69c82004-06-07 17:53:43 +0000488 }
489
Reid Spencercbb22e22004-06-10 22:00:54 +0000490 virtual void handleBlock(
Reid Spencer00c28a72004-06-10 08:09:13 +0000491 unsigned BType, const unsigned char* StartPtr, unsigned Size) {
492 bca.numBlocks++;
Reid Spencer911ec6d2004-08-21 20:58:19 +0000493 assert(BType >= BytecodeFormat::ModuleBlockID);
494 assert(BType < BytecodeFormat::NumberOfBlockIDs);
495 bca.BlockSizes[
Reid Spencerd798a512006-11-14 04:47:22 +0000496 llvm::BytecodeFormat::BytecodeBlockIdentifiers(BType)] += Size;
Reid Spencer911ec6d2004-08-21 20:58:19 +0000497
498 if (bca.version < 3) // Check for long block headers versions
499 bca.BlockSizes[llvm::BytecodeFormat::Reserved_DoNotUse] += 8;
500 else
501 bca.BlockSizes[llvm::BytecodeFormat::Reserved_DoNotUse] += 4;
Reid Spencer00c28a72004-06-10 08:09:13 +0000502 }
503
Reid Spencerdac69c82004-06-07 17:53:43 +0000504};
Chris Lattnerc6d0b162007-02-07 23:46:55 +0000505} // end anonymous namespace
Reid Spencerf41aa732004-06-29 23:23:12 +0000506
507/// @brief Utility for printing a titled unsigned value with
508/// an aligned colon.
Misha Brukman8a96c532005-04-21 21:44:41 +0000509inline static void print(std::ostream& Out, const char*title,
Reid Spencerf41aa732004-06-29 23:23:12 +0000510 unsigned val, bool nl = true ) {
Misha Brukman8a96c532005-04-21 21:44:41 +0000511 Out << std::setw(30) << std::right << title
Reid Spencerf41aa732004-06-29 23:23:12 +0000512 << std::setw(0) << ": "
513 << std::setw(9) << val << "\n";
Reid Spencerdac69c82004-06-07 17:53:43 +0000514}
515
Reid Spencerf41aa732004-06-29 23:23:12 +0000516/// @brief Utility for printing a titled double value with an
517/// aligned colon
Misha Brukman8a96c532005-04-21 21:44:41 +0000518inline static void print(std::ostream&Out, const char*title,
Reid Spencerf41aa732004-06-29 23:23:12 +0000519 double val ) {
Misha Brukman8a96c532005-04-21 21:44:41 +0000520 Out << std::setw(30) << std::right << title
Reid Spencerf41aa732004-06-29 23:23:12 +0000521 << std::setw(0) << ": "
522 << std::setw(9) << std::setprecision(6) << val << "\n" ;
523}
524
525/// @brief Utility for printing a titled double value with a
526/// percentage and aligned colon.
Misha Brukman8a96c532005-04-21 21:44:41 +0000527inline static void print(std::ostream&Out, const char*title,
Reid Spencerf41aa732004-06-29 23:23:12 +0000528 double top, double bot ) {
Misha Brukman8a96c532005-04-21 21:44:41 +0000529 Out << std::setw(30) << std::right << title
Reid Spencerf41aa732004-06-29 23:23:12 +0000530 << std::setw(0) << ": "
Misha Brukman8a96c532005-04-21 21:44:41 +0000531 << std::setw(9) << std::setprecision(6) << top
532 << " (" << std::left << std::setw(0) << std::setprecision(4)
Reid Spencerf41aa732004-06-29 23:23:12 +0000533 << (top/bot)*100.0 << "%)\n";
534}
535
536/// @brief Utility for printing a titled string value with
537/// an aligned colon.
Misha Brukman8a96c532005-04-21 21:44:41 +0000538inline static void print(std::ostream&Out, const char*title,
Reid Spencerf41aa732004-06-29 23:23:12 +0000539 std::string val, bool nl = true) {
Misha Brukman8a96c532005-04-21 21:44:41 +0000540 Out << std::setw(30) << std::right << title
Reid Spencerf41aa732004-06-29 23:23:12 +0000541 << std::setw(0) << ": "
542 << std::left << val << (nl ? "\n" : "");
543}
544
Reid Spencerf41aa732004-06-29 23:23:12 +0000545/// This function prints the contents of rhe BytecodeAnalysis structure in
546/// a human legible form.
547/// @brief Print BytecodeAnalysis structure to an ostream
Chris Lattnerc6d0b162007-02-07 23:46:55 +0000548void llvm::PrintBytecodeAnalysis(BytecodeAnalysis& bca, std::ostream& Out )
Reid Spencerdac69c82004-06-07 17:53:43 +0000549{
Reid Spencer911ec6d2004-08-21 20:58:19 +0000550 Out << "\nSummary Analysis Of " << bca.ModuleId << ": \n\n";
Reid Spencerf41aa732004-06-29 23:23:12 +0000551 print(Out, "Bytecode Analysis Of Module", bca.ModuleId);
Reid Spencer911ec6d2004-08-21 20:58:19 +0000552 print(Out, "Bytecode Version Number", bca.version);
Reid Spencerf41aa732004-06-29 23:23:12 +0000553 print(Out, "File Size", bca.byteSize);
Reid Spencer911ec6d2004-08-21 20:58:19 +0000554 print(Out, "Module Bytes",
555 double(bca.BlockSizes[BytecodeFormat::ModuleBlockID]),
556 double(bca.byteSize));
Misha Brukman8a96c532005-04-21 21:44:41 +0000557 print(Out, "Function Bytes",
Reid Spencer911ec6d2004-08-21 20:58:19 +0000558 double(bca.BlockSizes[BytecodeFormat::FunctionBlockID]),
559 double(bca.byteSize));
Misha Brukman8a96c532005-04-21 21:44:41 +0000560 print(Out, "Global Types Bytes",
Reid Spencer911ec6d2004-08-21 20:58:19 +0000561 double(bca.BlockSizes[BytecodeFormat::GlobalTypePlaneBlockID]),
562 double(bca.byteSize));
Misha Brukman8a96c532005-04-21 21:44:41 +0000563 print(Out, "Constant Pool Bytes",
Reid Spencer911ec6d2004-08-21 20:58:19 +0000564 double(bca.BlockSizes[BytecodeFormat::ConstantPoolBlockID]),
565 double(bca.byteSize));
Misha Brukman8a96c532005-04-21 21:44:41 +0000566 print(Out, "Module Globals Bytes",
Reid Spencer911ec6d2004-08-21 20:58:19 +0000567 double(bca.BlockSizes[BytecodeFormat::ModuleGlobalInfoBlockID]),
568 double(bca.byteSize));
Misha Brukman8a96c532005-04-21 21:44:41 +0000569 print(Out, "Instruction List Bytes",
Reid Spencer911ec6d2004-08-21 20:58:19 +0000570 double(bca.BlockSizes[BytecodeFormat::InstructionListBlockID]),
571 double(bca.byteSize));
Reid Spencer78d033e2007-01-06 07:24:44 +0000572 print(Out, "Value Symbol Table Bytes",
573 double(bca.BlockSizes[BytecodeFormat::ValueSymbolTableBlockID]),
574 double(bca.byteSize));
575 print(Out, "Type Symbol Table Bytes",
576 double(bca.BlockSizes[BytecodeFormat::TypeSymbolTableBlockID]),
Reid Spencer911ec6d2004-08-21 20:58:19 +0000577 double(bca.byteSize));
Misha Brukman8a96c532005-04-21 21:44:41 +0000578 print(Out, "Alignment Bytes",
Reid Spencer911ec6d2004-08-21 20:58:19 +0000579 double(bca.numAlignment), double(bca.byteSize));
Misha Brukman8a96c532005-04-21 21:44:41 +0000580 print(Out, "Block Header Bytes",
Reid Spencer911ec6d2004-08-21 20:58:19 +0000581 double(bca.BlockSizes[BytecodeFormat::Reserved_DoNotUse]),
582 double(bca.byteSize));
Misha Brukman8a96c532005-04-21 21:44:41 +0000583 print(Out, "Dependent Libraries Bytes", double(bca.libSize),
Reid Spencer911ec6d2004-08-21 20:58:19 +0000584 double(bca.byteSize));
Reid Spencerf41aa732004-06-29 23:23:12 +0000585 print(Out, "Number Of Bytecode Blocks", bca.numBlocks);
Reid Spencer911ec6d2004-08-21 20:58:19 +0000586 print(Out, "Number Of Functions", bca.numFunctions);
Reid Spencerf41aa732004-06-29 23:23:12 +0000587 print(Out, "Number Of Types", bca.numTypes);
Reid Spencerf41aa732004-06-29 23:23:12 +0000588 print(Out, "Number Of Constants", bca.numConstants);
589 print(Out, "Number Of Global Variables", bca.numGlobalVars);
Reid Spencer911ec6d2004-08-21 20:58:19 +0000590 print(Out, "Number Of Values", bca.numValues);
Reid Spencerf41aa732004-06-29 23:23:12 +0000591 print(Out, "Number Of Basic Blocks", bca.numBasicBlocks);
592 print(Out, "Number Of Instructions", bca.numInstructions);
Reid Spencer911ec6d2004-08-21 20:58:19 +0000593 print(Out, "Number Of Long Instructions", bca.longInstructions);
Reid Spencerf41aa732004-06-29 23:23:12 +0000594 print(Out, "Number Of Operands", bca.numOperands);
Reid Spencerf41aa732004-06-29 23:23:12 +0000595 print(Out, "Number Of Symbol Tables", bca.numSymTab);
Reid Spencer911ec6d2004-08-21 20:58:19 +0000596 print(Out, "Number Of Dependent Libs", bca.numLibraries);
597 print(Out, "Total Instruction Size", bca.instructionSize);
Misha Brukman8a96c532005-04-21 21:44:41 +0000598 print(Out, "Average Instruction Size",
Reid Spencer911ec6d2004-08-21 20:58:19 +0000599 double(bca.instructionSize)/double(bca.numInstructions));
600
Reid Spencerf41aa732004-06-29 23:23:12 +0000601 print(Out, "Maximum Type Slot Number", bca.maxTypeSlot);
602 print(Out, "Maximum Value Slot Number", bca.maxValueSlot);
Reid Spencer3120e712004-08-24 22:45:32 +0000603 print(Out, "Bytes Per Value ", bca.fileDensity);
604 print(Out, "Bytes Per Global", bca.globalsDensity);
605 print(Out, "Bytes Per Function", bca.functionDensity);
Reid Spencerf41aa732004-06-29 23:23:12 +0000606
Reid Spencer911ec6d2004-08-21 20:58:19 +0000607 if (bca.detailedResults) {
608 Out << "\nDetailed Analysis Of " << bca.ModuleId << " Functions:\n";
Reid Spencerf41aa732004-06-29 23:23:12 +0000609
Misha Brukman8a96c532005-04-21 21:44:41 +0000610 std::map<const Function*,BytecodeAnalysis::BytecodeFunctionInfo>::iterator I =
Reid Spencerf41aa732004-06-29 23:23:12 +0000611 bca.FunctionInfo.begin();
Misha Brukman8a96c532005-04-21 21:44:41 +0000612 std::map<const Function*,BytecodeAnalysis::BytecodeFunctionInfo>::iterator E =
Reid Spencerf41aa732004-06-29 23:23:12 +0000613 bca.FunctionInfo.end();
614
615 while ( I != E ) {
Chris Lattner4a8167f2004-10-15 19:40:31 +0000616 Out << std::left << std::setw(0) << "\n";
617 if (I->second.numBasicBlocks == 0) Out << "External ";
618 Out << "Function: " << I->second.name << "\n";
Reid Spencerf41aa732004-06-29 23:23:12 +0000619 print(Out, "Type:", I->second.description);
620 print(Out, "Byte Size", I->second.byteSize);
Chris Lattner4a8167f2004-10-15 19:40:31 +0000621 if (I->second.numBasicBlocks) {
622 print(Out, "Basic Blocks", I->second.numBasicBlocks);
623 print(Out, "Instructions", I->second.numInstructions);
624 print(Out, "Long Instructions", I->second.longInstructions);
625 print(Out, "Operands", I->second.numOperands);
626 print(Out, "Instruction Size", I->second.instructionSize);
Misha Brukman8a96c532005-04-21 21:44:41 +0000627 print(Out, "Average Instruction Size",
Chris Lattner4a8167f2004-10-15 19:40:31 +0000628 double(I->second.instructionSize) / I->second.numInstructions);
629 print(Out, "Bytes Per Instruction", I->second.density);
Chris Lattner4a8167f2004-10-15 19:40:31 +0000630 }
Reid Spencerf41aa732004-06-29 23:23:12 +0000631 ++I;
632 }
633 }
634
Reid Spencerf41aa732004-06-29 23:23:12 +0000635 if ( bca.progressiveVerify )
636 Out << bca.VerifyInfo;
637}
638
Chris Lattnerc6d0b162007-02-07 23:46:55 +0000639// AnalyzeBytecodeFile - analyze one file
640Module* llvm::AnalyzeBytecodeFile(const std::string &Filename, ///< File to analyze
641 BytecodeAnalysis& bca, ///< Statistical output
642 BCDecompressor_t *BCDC,
643 std::string *ErrMsg, ///< Error output
644 std::ostream* output ///< Dump output
645 ) {
646 BytecodeHandler* AH = new AnalyzerHandler(bca, output);
647 ModuleProvider* MP = getBytecodeModuleProvider(Filename, BCDC, ErrMsg, AH);
648 if (!MP) return 0;
649 Module *M = MP->releaseModule(ErrMsg);
650 delete MP;
651 return M;
Reid Spencerf41aa732004-06-29 23:23:12 +0000652}