blob: 086409edc89c496b3ec63ced64d182f84fc8ecb1 [file] [log] [blame]
Misha Brukman46453792003-09-22 23:44:46 +00001//===- ReaderWrappers.cpp - Parse bytecode from file or buffer -----------===//
John Criswellb576c942003-10-20 19:43:21 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file was developed by the LLVM research group and is distributed under
6// the University of Illinois Open Source License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
Misha Brukman46453792003-09-22 23:44:46 +00009//
10// This file implements loading and parsing a bytecode file and parsing a
11// bytecode module from a given buffer.
12//
13//===----------------------------------------------------------------------===//
14
Reid Spencerdf45a542004-06-29 23:24:14 +000015#include "llvm/Bytecode/Analyzer.h"
Chris Lattnerdeab9a72003-11-19 16:06:55 +000016#include "llvm/Bytecode/Reader.h"
Reid Spencerdf45a542004-06-29 23:24:14 +000017#include "Reader.h"
Chris Lattnercb7e2e22003-10-18 05:54:18 +000018#include "llvm/Module.h"
19#include "llvm/Instructions.h"
Reid Spencer551ccae2004-09-01 22:55:40 +000020#include "llvm/ADT/StringExtras.h"
Reid Spencer9153f8f2004-12-13 18:25:27 +000021#include "llvm/System/MappedFile.h"
Chris Lattner2d6481c2003-12-29 21:35:05 +000022#include <cerrno>
Reid Spencer0a834722004-12-21 07:51:33 +000023#include <iostream>
Chris Lattnerdeab9a72003-11-19 16:06:55 +000024using namespace llvm;
Brian Gaeked0fde302003-11-11 22:41:34 +000025
Chris Lattnercb7e2e22003-10-18 05:54:18 +000026//===----------------------------------------------------------------------===//
27// BytecodeFileReader - Read from an mmap'able file descriptor.
28//
29
Misha Brukman12c29d12003-09-22 23:38:23 +000030namespace {
Misha Brukman12c29d12003-09-22 23:38:23 +000031 /// BytecodeFileReader - parses a bytecode file from a file
32 ///
Reid Spencerdf45a542004-06-29 23:24:14 +000033 class BytecodeFileReader : public BytecodeReader {
Misha Brukman12c29d12003-09-22 23:38:23 +000034 private:
Reid Spencer9153f8f2004-12-13 18:25:27 +000035 sys::MappedFile mapFile;
Misha Brukman12c29d12003-09-22 23:38:23 +000036
37 BytecodeFileReader(const BytecodeFileReader&); // Do not implement
Misha Brukman5c344412003-09-23 15:09:26 +000038 void operator=(const BytecodeFileReader &BFR); // Do not implement
Misha Brukman12c29d12003-09-22 23:38:23 +000039
40 public:
Reid Spencerdf45a542004-06-29 23:24:14 +000041 BytecodeFileReader(const std::string &Filename, llvm::BytecodeHandler* H=0);
Misha Brukman12c29d12003-09-22 23:38:23 +000042 };
Misha Brukman12c29d12003-09-22 23:38:23 +000043}
44
Reid Spencerdf45a542004-06-29 23:24:14 +000045BytecodeFileReader::BytecodeFileReader(const std::string &Filename,
46 llvm::BytecodeHandler* H )
47 : BytecodeReader(H)
Reid Spencer9153f8f2004-12-13 18:25:27 +000048 , mapFile( sys::Path(Filename))
Reid Spencerdf45a542004-06-29 23:24:14 +000049{
Reid Spencer9153f8f2004-12-13 18:25:27 +000050 mapFile.map();
51 unsigned char* buffer = reinterpret_cast<unsigned char*>(mapFile.base());
52 ParseBytecode(buffer, mapFile.size(), Filename);
Misha Brukman12c29d12003-09-22 23:38:23 +000053}
54
Chris Lattnercb7e2e22003-10-18 05:54:18 +000055//===----------------------------------------------------------------------===//
56// BytecodeBufferReader - Read from a memory buffer
57//
Misha Brukmand57308a2003-09-23 16:13:28 +000058
59namespace {
60 /// BytecodeBufferReader - parses a bytecode file from a buffer
61 ///
Reid Spencerdf45a542004-06-29 23:24:14 +000062 class BytecodeBufferReader : public BytecodeReader {
Misha Brukmand57308a2003-09-23 16:13:28 +000063 private:
64 const unsigned char *Buffer;
Misha Brukmand57308a2003-09-23 16:13:28 +000065 bool MustDelete;
66
67 BytecodeBufferReader(const BytecodeBufferReader&); // Do not implement
68 void operator=(const BytecodeBufferReader &BFR); // Do not implement
69
70 public:
71 BytecodeBufferReader(const unsigned char *Buf, unsigned Length,
Reid Spencerdf45a542004-06-29 23:24:14 +000072 const std::string &ModuleID,
Reid Spencer97c7d742004-07-04 11:03:03 +000073 llvm::BytecodeHandler* Handler = 0);
Misha Brukmand57308a2003-09-23 16:13:28 +000074 ~BytecodeBufferReader();
75
76 };
77}
78
79BytecodeBufferReader::BytecodeBufferReader(const unsigned char *Buf,
Misha Brukman34ce14b2003-09-24 22:04:02 +000080 unsigned Length,
Reid Spencerdf45a542004-06-29 23:24:14 +000081 const std::string &ModuleID,
Reid Spencer97c7d742004-07-04 11:03:03 +000082 llvm::BytecodeHandler* H )
Reid Spencerdf45a542004-06-29 23:24:14 +000083 : BytecodeReader(H)
Misha Brukmand57308a2003-09-23 16:13:28 +000084{
85 // If not aligned, allocate a new buffer to hold the bytecode...
86 const unsigned char *ParseBegin = 0;
Reid Spencer9a7e0c52004-08-04 22:56:46 +000087 if (reinterpret_cast<uint64_t>(Buf) & 3) {
Misha Brukman34ce14b2003-09-24 22:04:02 +000088 Buffer = new unsigned char[Length+4];
Chris Lattner4eed7932003-09-24 22:34:17 +000089 unsigned Offset = 4 - ((intptr_t)Buffer & 3); // Make sure it's aligned
Misha Brukmand57308a2003-09-23 16:13:28 +000090 ParseBegin = Buffer + Offset;
Misha Brukman34ce14b2003-09-24 22:04:02 +000091 memcpy((unsigned char*)ParseBegin, Buf, Length); // Copy it over
Misha Brukmand57308a2003-09-23 16:13:28 +000092 MustDelete = true;
93 } else {
94 // If we don't need to copy it over, just use the caller's copy
John Criswell4dcbd5e2003-09-23 21:19:11 +000095 ParseBegin = Buffer = Buf;
Misha Brukmand57308a2003-09-23 16:13:28 +000096 MustDelete = false;
97 }
Misha Brukman7f58de22003-10-08 19:55:47 +000098 try {
Reid Spencer4542c432004-08-21 20:52:03 +000099 ParseBytecode(ParseBegin, Length, ModuleID);
Misha Brukman7f58de22003-10-08 19:55:47 +0000100 } catch (...) {
101 if (MustDelete) delete [] Buffer;
102 throw;
103 }
Misha Brukmand57308a2003-09-23 16:13:28 +0000104}
105
106BytecodeBufferReader::~BytecodeBufferReader() {
107 if (MustDelete) delete [] Buffer;
108}
109
Chris Lattnercb7e2e22003-10-18 05:54:18 +0000110//===----------------------------------------------------------------------===//
111// BytecodeStdinReader - Read bytecode from Standard Input
112//
Misha Brukmand57308a2003-09-23 16:13:28 +0000113
114namespace {
115 /// BytecodeStdinReader - parses a bytecode file from stdin
116 ///
Reid Spencerdf45a542004-06-29 23:24:14 +0000117 class BytecodeStdinReader : public BytecodeReader {
Misha Brukmand57308a2003-09-23 16:13:28 +0000118 private:
119 std::vector<unsigned char> FileData;
120 unsigned char *FileBuf;
121
122 BytecodeStdinReader(const BytecodeStdinReader&); // Do not implement
123 void operator=(const BytecodeStdinReader &BFR); // Do not implement
124
125 public:
Reid Spencerdf45a542004-06-29 23:24:14 +0000126 BytecodeStdinReader( llvm::BytecodeHandler* H = 0 );
Misha Brukmand57308a2003-09-23 16:13:28 +0000127 };
128}
Misha Brukman12c29d12003-09-22 23:38:23 +0000129
Reid Spencerdf45a542004-06-29 23:24:14 +0000130BytecodeStdinReader::BytecodeStdinReader( BytecodeHandler* H )
131 : BytecodeReader(H)
132{
Reid Spencer0a834722004-12-21 07:51:33 +0000133 char Buffer[4096*4];
Misha Brukman12c29d12003-09-22 23:38:23 +0000134
135 // Read in all of the data from stdin, we cannot mmap stdin...
Reid Spencer0a834722004-12-21 07:51:33 +0000136 while (std::cin.good()) {
137 std::cin.read(Buffer, 4096*4);
138 int BlockSize = std::cin.gcount();
139 if (0 >= BlockSize)
140 break;
Misha Brukman12c29d12003-09-22 23:38:23 +0000141 FileData.insert(FileData.end(), Buffer, Buffer+BlockSize);
142 }
143
144 if (FileData.empty())
145 throw std::string("Standard Input empty!");
146
Misha Brukman12c29d12003-09-22 23:38:23 +0000147 FileBuf = &FileData[0];
Reid Spencer4542c432004-08-21 20:52:03 +0000148 ParseBytecode(FileBuf, FileData.size(), "<stdin>");
Misha Brukman12c29d12003-09-22 23:38:23 +0000149}
150
Chris Lattnercb7e2e22003-10-18 05:54:18 +0000151//===----------------------------------------------------------------------===//
152// Varargs transmogrification code...
Misha Brukmand57308a2003-09-23 16:13:28 +0000153//
Chris Lattnercb7e2e22003-10-18 05:54:18 +0000154
155// CheckVarargs - This is used to automatically translate old-style varargs to
156// new style varargs for backwards compatibility.
157static ModuleProvider *CheckVarargs(ModuleProvider *MP) {
158 Module *M = MP->getModule();
159
160 // Check to see if va_start takes arguments...
161 Function *F = M->getNamedFunction("llvm.va_start");
162 if (F == 0) return MP; // No varargs use, just return.
163
164 if (F->getFunctionType()->getNumParams() == 0)
165 return MP; // Modern varargs processing, just return.
166
167 // If we get to this point, we know that we have an old-style module.
168 // Materialize the whole thing to perform the rewriting.
169 MP->materializeModule();
170
171 // If the user is making use of obsolete varargs intrinsics, adjust them for
172 // the user.
173 if (Function *F = M->getNamedFunction("llvm.va_start")) {
Chris Lattnere4d5c442005-03-15 04:54:21 +0000174 assert(F->arg_size() == 1 && "Obsolete va_start takes 1 argument!");
Chris Lattnercb7e2e22003-10-18 05:54:18 +0000175
176 const Type *RetTy = F->getFunctionType()->getParamType(0);
177 RetTy = cast<PointerType>(RetTy)->getElementType();
178 Function *NF = M->getOrInsertFunction("llvm.va_start", RetTy, 0);
179
180 for (Value::use_iterator I = F->use_begin(), E = F->use_end(); I != E; )
181 if (CallInst *CI = dyn_cast<CallInst>(*I++)) {
182 Value *V = new CallInst(NF, "", CI);
183 new StoreInst(V, CI->getOperand(1), CI);
184 CI->getParent()->getInstList().erase(CI);
185 }
186 F->setName("");
187 }
188
189 if (Function *F = M->getNamedFunction("llvm.va_end")) {
Chris Lattnere4d5c442005-03-15 04:54:21 +0000190 assert(F->arg_size() == 1 && "Obsolete va_end takes 1 argument!");
Chris Lattnercb7e2e22003-10-18 05:54:18 +0000191 const Type *ArgTy = F->getFunctionType()->getParamType(0);
192 ArgTy = cast<PointerType>(ArgTy)->getElementType();
193 Function *NF = M->getOrInsertFunction("llvm.va_end", Type::VoidTy,
194 ArgTy, 0);
195
196 for (Value::use_iterator I = F->use_begin(), E = F->use_end(); I != E; )
197 if (CallInst *CI = dyn_cast<CallInst>(*I++)) {
198 Value *V = new LoadInst(CI->getOperand(1), "", CI);
199 new CallInst(NF, V, "", CI);
200 CI->getParent()->getInstList().erase(CI);
201 }
202 F->setName("");
203 }
204
205 if (Function *F = M->getNamedFunction("llvm.va_copy")) {
Chris Lattnere4d5c442005-03-15 04:54:21 +0000206 assert(F->arg_size() == 2 && "Obsolete va_copy takes 2 argument!");
Chris Lattnercb7e2e22003-10-18 05:54:18 +0000207 const Type *ArgTy = F->getFunctionType()->getParamType(0);
208 ArgTy = cast<PointerType>(ArgTy)->getElementType();
209 Function *NF = M->getOrInsertFunction("llvm.va_copy", ArgTy,
210 ArgTy, 0);
211
212 for (Value::use_iterator I = F->use_begin(), E = F->use_end(); I != E; )
213 if (CallInst *CI = dyn_cast<CallInst>(*I++)) {
214 Value *V = new CallInst(NF, CI->getOperand(2), "", CI);
215 new StoreInst(V, CI->getOperand(1), CI);
216 CI->getParent()->getInstList().erase(CI);
217 }
218 F->setName("");
219 }
220 return MP;
221}
222
Chris Lattnercb7e2e22003-10-18 05:54:18 +0000223//===----------------------------------------------------------------------===//
Misha Brukmand57308a2003-09-23 16:13:28 +0000224// Wrapper functions
Chris Lattnercb7e2e22003-10-18 05:54:18 +0000225//===----------------------------------------------------------------------===//
Misha Brukmand57308a2003-09-23 16:13:28 +0000226
227/// getBytecodeBufferModuleProvider - lazy function-at-a-time loading from a
228/// buffer
Chris Lattner00413e32003-10-04 20:14:59 +0000229ModuleProvider*
Chris Lattnerdeab9a72003-11-19 16:06:55 +0000230llvm::getBytecodeBufferModuleProvider(const unsigned char *Buffer,
231 unsigned Length,
Reid Spencerdf45a542004-06-29 23:24:14 +0000232 const std::string &ModuleID,
Reid Spencer97c7d742004-07-04 11:03:03 +0000233 BytecodeHandler* H ) {
Reid Spencerdf45a542004-06-29 23:24:14 +0000234 return CheckVarargs(
235 new BytecodeBufferReader(Buffer, Length, ModuleID, H));
Misha Brukman12c29d12003-09-22 23:38:23 +0000236}
237
Misha Brukmand57308a2003-09-23 16:13:28 +0000238/// ParseBytecodeBuffer - Parse a given bytecode buffer
239///
Chris Lattnerdeab9a72003-11-19 16:06:55 +0000240Module *llvm::ParseBytecodeBuffer(const unsigned char *Buffer, unsigned Length,
241 const std::string &ModuleID,
242 std::string *ErrorStr){
Misha Brukmand57308a2003-09-23 16:13:28 +0000243 try {
Chris Lattner00413e32003-10-04 20:14:59 +0000244 std::auto_ptr<ModuleProvider>
Chris Lattnera9833592003-10-04 19:19:37 +0000245 AMP(getBytecodeBufferModuleProvider(Buffer, Length, ModuleID));
246 return AMP->releaseModule();
Misha Brukmand57308a2003-09-23 16:13:28 +0000247 } catch (std::string &err) {
Misha Brukman134aba62003-09-24 22:10:47 +0000248 if (ErrorStr) *ErrorStr = err;
Misha Brukmand57308a2003-09-23 16:13:28 +0000249 return 0;
250 }
Misha Brukman12c29d12003-09-22 23:38:23 +0000251}
252
Misha Brukmand57308a2003-09-23 16:13:28 +0000253/// getBytecodeModuleProvider - lazy function-at-a-time loading from a file
Misha Brukman12c29d12003-09-22 23:38:23 +0000254///
Reid Spencerdf45a542004-06-29 23:24:14 +0000255ModuleProvider *llvm::getBytecodeModuleProvider(const std::string &Filename,
Reid Spencer97c7d742004-07-04 11:03:03 +0000256 BytecodeHandler* H) {
Misha Brukman12c29d12003-09-22 23:38:23 +0000257 if (Filename != std::string("-")) // Read from a file...
Reid Spencerdf45a542004-06-29 23:24:14 +0000258 return CheckVarargs(new BytecodeFileReader(Filename,H));
Misha Brukman12c29d12003-09-22 23:38:23 +0000259 else // Read from stdin
Reid Spencerdf45a542004-06-29 23:24:14 +0000260 return CheckVarargs(new BytecodeStdinReader(H));
Misha Brukman12c29d12003-09-22 23:38:23 +0000261}
262
Misha Brukmand57308a2003-09-23 16:13:28 +0000263/// ParseBytecodeFile - Parse the given bytecode file
264///
Chris Lattnerdeab9a72003-11-19 16:06:55 +0000265Module *llvm::ParseBytecodeFile(const std::string &Filename,
266 std::string *ErrorStr) {
Misha Brukmand57308a2003-09-23 16:13:28 +0000267 try {
Chris Lattner00413e32003-10-04 20:14:59 +0000268 std::auto_ptr<ModuleProvider> AMP(getBytecodeModuleProvider(Filename));
Chris Lattnera9833592003-10-04 19:19:37 +0000269 return AMP->releaseModule();
Misha Brukmand57308a2003-09-23 16:13:28 +0000270 } catch (std::string &err) {
Misha Brukman134aba62003-09-24 22:10:47 +0000271 if (ErrorStr) *ErrorStr = err;
Misha Brukmand57308a2003-09-23 16:13:28 +0000272 return 0;
273 }
Misha Brukman12c29d12003-09-22 23:38:23 +0000274}
Brian Gaeked0fde302003-11-11 22:41:34 +0000275
Reid Spencerdf45a542004-06-29 23:24:14 +0000276// AnalyzeBytecodeFile - analyze one file
Reid Spencer4542c432004-08-21 20:52:03 +0000277Module* llvm::AnalyzeBytecodeFile(
278 const std::string &Filename, ///< File to analyze
279 BytecodeAnalysis& bca, ///< Statistical output
280 std::string *ErrorStr, ///< Error output
Misha Brukman5adf0ca2004-09-12 20:56:38 +0000281 std::ostream* output ///< Dump output
282)
Reid Spencerdf45a542004-06-29 23:24:14 +0000283{
284 try {
Misha Brukman7df00742004-09-12 20:47:33 +0000285 BytecodeHandler* analyzerHandler =createBytecodeAnalyzerHandler(bca,output);
Reid Spencerdf45a542004-06-29 23:24:14 +0000286 std::auto_ptr<ModuleProvider> AMP(
287 getBytecodeModuleProvider(Filename,analyzerHandler));
288 return AMP->releaseModule();
289 } catch (std::string &err) {
290 if (ErrorStr) *ErrorStr = err;
291 return 0;
292 }
293}
294
295// AnalyzeBytecodeBuffer - analyze a buffer
296Module* llvm::AnalyzeBytecodeBuffer(
Reid Spencer4542c432004-08-21 20:52:03 +0000297 const unsigned char* Buffer, ///< Pointer to start of bytecode buffer
298 unsigned Length, ///< Size of the bytecode buffer
299 const std::string& ModuleID, ///< Identifier for the module
300 BytecodeAnalysis& bca, ///< The results of the analysis
301 std::string* ErrorStr, ///< Errors, if any.
Misha Brukman5adf0ca2004-09-12 20:56:38 +0000302 std::ostream* output ///< Dump output, if any
303)
Reid Spencerdf45a542004-06-29 23:24:14 +0000304{
305 try {
Reid Spencer4542c432004-08-21 20:52:03 +0000306 BytecodeHandler* hdlr = createBytecodeAnalyzerHandler(bca, output);
Reid Spencerdf45a542004-06-29 23:24:14 +0000307 std::auto_ptr<ModuleProvider>
308 AMP(getBytecodeBufferModuleProvider(Buffer, Length, ModuleID, hdlr));
309 return AMP->releaseModule();
310 } catch (std::string &err) {
311 if (ErrorStr) *ErrorStr = err;
312 return 0;
313 }
314}
315
Reid Spencere0cf59e2004-08-24 22:46:20 +0000316bool llvm::GetBytecodeDependentLibraries(const std::string &fname,
Misha Brukman7df00742004-09-12 20:47:33 +0000317 Module::LibraryListType& deplibs) {
Reid Spencere0cf59e2004-08-24 22:46:20 +0000318 try {
319 std::auto_ptr<ModuleProvider> AMP( getBytecodeModuleProvider(fname));
320 Module* M = AMP->releaseModule();
Reid Spencer2bcfcbe2004-11-06 08:56:40 +0000321
Reid Spencere0cf59e2004-08-24 22:46:20 +0000322 deplibs = M->getLibraries();
323 delete M;
324 return true;
325 } catch (...) {
326 deplibs.clear();
327 return false;
328 }
329}
330
Chris Lattnere5cea5e2005-02-13 17:42:11 +0000331static void getSymbols(Module*M, std::vector<std::string>& symbols) {
Reid Spencer565ff3d2004-11-14 22:00:48 +0000332 // Loop over global variables
Chris Lattnere4d5c442005-03-15 04:54:21 +0000333 for (Module::global_iterator GI = M->global_begin(), GE=M->global_end(); GI != GE; ++GI)
Reid Spencer818827d2005-02-13 18:12:20 +0000334 if (!GI->isExternal() && !GI->hasInternalLinkage())
Chris Lattnere5cea5e2005-02-13 17:42:11 +0000335 if (!GI->getName().empty())
336 symbols.push_back(GI->getName());
Reid Spencer565ff3d2004-11-14 22:00:48 +0000337
Chris Lattnere5cea5e2005-02-13 17:42:11 +0000338 // Loop over functions.
339 for (Module::iterator FI = M->begin(), FE = M->end(); FI != FE; ++FI)
340 if (!FI->isExternal() && !FI->hasInternalLinkage())
341 if (!FI->getName().empty())
342 symbols.push_back(FI->getName());
Reid Spencer565ff3d2004-11-14 22:00:48 +0000343}
344
Reid Spencer2bcfcbe2004-11-06 08:56:40 +0000345// Get just the externally visible defined symbols from the bytecode
346bool llvm::GetBytecodeSymbols(const sys::Path& fName,
347 std::vector<std::string>& symbols) {
348 try {
Reid Spencer1fce0912004-12-11 00:14:15 +0000349 std::auto_ptr<ModuleProvider> AMP(
350 getBytecodeModuleProvider(fName.toString()));
Reid Spencer2bcfcbe2004-11-06 08:56:40 +0000351
352 // Get the module from the provider
Reid Spencer5a885782004-11-16 06:41:05 +0000353 Module* M = AMP->materializeModule();
Reid Spencer2bcfcbe2004-11-06 08:56:40 +0000354
Reid Spencer565ff3d2004-11-14 22:00:48 +0000355 // Get the symbols
356 getSymbols(M, symbols);
Reid Spencer2bcfcbe2004-11-06 08:56:40 +0000357
358 // Done with the module
Reid Spencer2bcfcbe2004-11-06 08:56:40 +0000359 return true;
360
361 } catch (...) {
362 return false;
363 }
364}
365
Reid Spencer766b7932004-11-15 01:20:11 +0000366ModuleProvider*
367llvm::GetBytecodeSymbols(const unsigned char*Buffer, unsigned Length,
Reid Spencer5a885782004-11-16 06:41:05 +0000368 const std::string& ModuleID,
369 std::vector<std::string>& symbols) {
Reid Spencer565ff3d2004-11-14 22:00:48 +0000370
Reid Spencer5a885782004-11-16 06:41:05 +0000371 ModuleProvider* MP = 0;
Reid Spencer565ff3d2004-11-14 22:00:48 +0000372 try {
Reid Spencer5a885782004-11-16 06:41:05 +0000373 // Get the module provider
374 MP = getBytecodeBufferModuleProvider(Buffer, Length, ModuleID);
Reid Spencer565ff3d2004-11-14 22:00:48 +0000375
376 // Get the module from the provider
Reid Spencer766b7932004-11-15 01:20:11 +0000377 Module* M = MP->materializeModule();
Reid Spencer565ff3d2004-11-14 22:00:48 +0000378
379 // Get the symbols
380 getSymbols(M, symbols);
381
Reid Spencer5a885782004-11-16 06:41:05 +0000382 // Done with the module. Note that ModuleProvider will delete the
383 // Module when it is deleted. Also note that its the caller's responsibility
384 // to delete the ModuleProvider.
Reid Spencer766b7932004-11-15 01:20:11 +0000385 return MP;
Reid Spencer565ff3d2004-11-14 22:00:48 +0000386
387 } catch (...) {
Reid Spencer93ee7dc2004-11-22 02:58:47 +0000388 // We delete only the ModuleProvider here because its destructor will
Reid Spencer5a885782004-11-16 06:41:05 +0000389 // also delete the Module (we used materializeModule not releaseModule).
390 delete MP;
Reid Spencer565ff3d2004-11-14 22:00:48 +0000391 }
Reid Spencer766b7932004-11-15 01:20:11 +0000392 return 0;
Reid Spencer565ff3d2004-11-14 22:00:48 +0000393}
Reid Spencerdf45a542004-06-29 23:24:14 +0000394// vim: sw=2 ai