blob: c8958ad19c301e6b9aaf7a5269e8972d17d7b88d [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/Support/FileUtilities.h"
21#include "llvm/ADT/StringExtras.h"
22#include "llvm/Config/unistd.h"
Chris Lattner2d6481c2003-12-29 21:35:05 +000023#include <cerrno>
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:
35 unsigned char *Buffer;
Chris Lattnerfb777c22004-05-28 00:24:41 +000036 unsigned Length;
Misha Brukman12c29d12003-09-22 23:38:23 +000037
38 BytecodeFileReader(const BytecodeFileReader&); // Do not implement
Misha Brukman5c344412003-09-23 15:09:26 +000039 void operator=(const BytecodeFileReader &BFR); // Do not implement
Misha Brukman12c29d12003-09-22 23:38:23 +000040
41 public:
Reid Spencerdf45a542004-06-29 23:24:14 +000042 BytecodeFileReader(const std::string &Filename, llvm::BytecodeHandler* H=0);
Misha Brukman12c29d12003-09-22 23:38:23 +000043 ~BytecodeFileReader();
Misha Brukman12c29d12003-09-22 23:38:23 +000044 };
Misha Brukman12c29d12003-09-22 23:38:23 +000045}
46
Brian Gaeke27b40bc2003-12-12 00:47:44 +000047static std::string ErrnoMessage (int savedErrNum, std::string descr) {
48 return ::strerror(savedErrNum) + std::string(", while trying to ") + descr;
49}
50
Reid Spencerdf45a542004-06-29 23:24:14 +000051BytecodeFileReader::BytecodeFileReader(const std::string &Filename,
52 llvm::BytecodeHandler* H )
53 : BytecodeReader(H)
54{
Chris Lattnerfb777c22004-05-28 00:24:41 +000055 Buffer = (unsigned char*)ReadFileIntoAddressSpace(Filename, Length);
56 if (Buffer == 0)
57 throw "Error reading file '" + Filename + "'.";
Misha Brukman12c29d12003-09-22 23:38:23 +000058
Misha Brukman7f58de22003-10-08 19:55:47 +000059 try {
60 // Parse the bytecode we mmapped in
Reid Spencer4542c432004-08-21 20:52:03 +000061 ParseBytecode(Buffer, Length, Filename);
Misha Brukman7f58de22003-10-08 19:55:47 +000062 } catch (...) {
Chris Lattnerfb777c22004-05-28 00:24:41 +000063 UnmapFileFromAddressSpace(Buffer, Length);
Misha Brukman7f58de22003-10-08 19:55:47 +000064 throw;
65 }
Misha Brukman12c29d12003-09-22 23:38:23 +000066}
67
68BytecodeFileReader::~BytecodeFileReader() {
69 // Unmmap the bytecode...
Chris Lattnerfb777c22004-05-28 00:24:41 +000070 UnmapFileFromAddressSpace(Buffer, Length);
Misha Brukman12c29d12003-09-22 23:38:23 +000071}
72
Chris Lattnercb7e2e22003-10-18 05:54:18 +000073//===----------------------------------------------------------------------===//
74// BytecodeBufferReader - Read from a memory buffer
75//
Misha Brukmand57308a2003-09-23 16:13:28 +000076
77namespace {
78 /// BytecodeBufferReader - parses a bytecode file from a buffer
79 ///
Reid Spencerdf45a542004-06-29 23:24:14 +000080 class BytecodeBufferReader : public BytecodeReader {
Misha Brukmand57308a2003-09-23 16:13:28 +000081 private:
82 const unsigned char *Buffer;
Misha Brukmand57308a2003-09-23 16:13:28 +000083 bool MustDelete;
84
85 BytecodeBufferReader(const BytecodeBufferReader&); // Do not implement
86 void operator=(const BytecodeBufferReader &BFR); // Do not implement
87
88 public:
89 BytecodeBufferReader(const unsigned char *Buf, unsigned Length,
Reid Spencerdf45a542004-06-29 23:24:14 +000090 const std::string &ModuleID,
Reid Spencer97c7d742004-07-04 11:03:03 +000091 llvm::BytecodeHandler* Handler = 0);
Misha Brukmand57308a2003-09-23 16:13:28 +000092 ~BytecodeBufferReader();
93
94 };
95}
96
97BytecodeBufferReader::BytecodeBufferReader(const unsigned char *Buf,
Misha Brukman34ce14b2003-09-24 22:04:02 +000098 unsigned Length,
Reid Spencerdf45a542004-06-29 23:24:14 +000099 const std::string &ModuleID,
Reid Spencer97c7d742004-07-04 11:03:03 +0000100 llvm::BytecodeHandler* H )
Reid Spencerdf45a542004-06-29 23:24:14 +0000101 : BytecodeReader(H)
Misha Brukmand57308a2003-09-23 16:13:28 +0000102{
103 // If not aligned, allocate a new buffer to hold the bytecode...
104 const unsigned char *ParseBegin = 0;
Reid Spencer9a7e0c52004-08-04 22:56:46 +0000105 if (reinterpret_cast<uint64_t>(Buf) & 3) {
Misha Brukman34ce14b2003-09-24 22:04:02 +0000106 Buffer = new unsigned char[Length+4];
Chris Lattner4eed7932003-09-24 22:34:17 +0000107 unsigned Offset = 4 - ((intptr_t)Buffer & 3); // Make sure it's aligned
Misha Brukmand57308a2003-09-23 16:13:28 +0000108 ParseBegin = Buffer + Offset;
Misha Brukman34ce14b2003-09-24 22:04:02 +0000109 memcpy((unsigned char*)ParseBegin, Buf, Length); // Copy it over
Misha Brukmand57308a2003-09-23 16:13:28 +0000110 MustDelete = true;
111 } else {
112 // If we don't need to copy it over, just use the caller's copy
John Criswell4dcbd5e2003-09-23 21:19:11 +0000113 ParseBegin = Buffer = Buf;
Misha Brukmand57308a2003-09-23 16:13:28 +0000114 MustDelete = false;
115 }
Misha Brukman7f58de22003-10-08 19:55:47 +0000116 try {
Reid Spencer4542c432004-08-21 20:52:03 +0000117 ParseBytecode(ParseBegin, Length, ModuleID);
Misha Brukman7f58de22003-10-08 19:55:47 +0000118 } catch (...) {
119 if (MustDelete) delete [] Buffer;
120 throw;
121 }
Misha Brukmand57308a2003-09-23 16:13:28 +0000122}
123
124BytecodeBufferReader::~BytecodeBufferReader() {
125 if (MustDelete) delete [] Buffer;
126}
127
Chris Lattnercb7e2e22003-10-18 05:54:18 +0000128//===----------------------------------------------------------------------===//
129// BytecodeStdinReader - Read bytecode from Standard Input
130//
Misha Brukmand57308a2003-09-23 16:13:28 +0000131
132namespace {
133 /// BytecodeStdinReader - parses a bytecode file from stdin
134 ///
Reid Spencerdf45a542004-06-29 23:24:14 +0000135 class BytecodeStdinReader : public BytecodeReader {
Misha Brukmand57308a2003-09-23 16:13:28 +0000136 private:
137 std::vector<unsigned char> FileData;
138 unsigned char *FileBuf;
139
140 BytecodeStdinReader(const BytecodeStdinReader&); // Do not implement
141 void operator=(const BytecodeStdinReader &BFR); // Do not implement
142
143 public:
Reid Spencerdf45a542004-06-29 23:24:14 +0000144 BytecodeStdinReader( llvm::BytecodeHandler* H = 0 );
Misha Brukmand57308a2003-09-23 16:13:28 +0000145 };
146}
Misha Brukman12c29d12003-09-22 23:38:23 +0000147
Reid Spencerdf45a542004-06-29 23:24:14 +0000148BytecodeStdinReader::BytecodeStdinReader( BytecodeHandler* H )
149 : BytecodeReader(H)
150{
Misha Brukman12c29d12003-09-22 23:38:23 +0000151 int BlockSize;
152 unsigned char Buffer[4096*4];
153
154 // Read in all of the data from stdin, we cannot mmap stdin...
Brian Gaeked0fde302003-11-11 22:41:34 +0000155 while ((BlockSize = ::read(0 /*stdin*/, Buffer, 4096*4))) {
Misha Brukman12c29d12003-09-22 23:38:23 +0000156 if (BlockSize == -1)
Brian Gaeke27b40bc2003-12-12 00:47:44 +0000157 throw ErrnoMessage(errno, "read from standard input");
Misha Brukmand57308a2003-09-23 16:13:28 +0000158
Misha Brukman12c29d12003-09-22 23:38:23 +0000159 FileData.insert(FileData.end(), Buffer, Buffer+BlockSize);
160 }
161
162 if (FileData.empty())
163 throw std::string("Standard Input empty!");
164
Misha Brukman12c29d12003-09-22 23:38:23 +0000165 FileBuf = &FileData[0];
Reid Spencer4542c432004-08-21 20:52:03 +0000166 ParseBytecode(FileBuf, FileData.size(), "<stdin>");
Misha Brukman12c29d12003-09-22 23:38:23 +0000167}
168
Chris Lattnercb7e2e22003-10-18 05:54:18 +0000169//===----------------------------------------------------------------------===//
170// Varargs transmogrification code...
Misha Brukmand57308a2003-09-23 16:13:28 +0000171//
Chris Lattnercb7e2e22003-10-18 05:54:18 +0000172
173// CheckVarargs - This is used to automatically translate old-style varargs to
174// new style varargs for backwards compatibility.
175static ModuleProvider *CheckVarargs(ModuleProvider *MP) {
176 Module *M = MP->getModule();
177
178 // Check to see if va_start takes arguments...
179 Function *F = M->getNamedFunction("llvm.va_start");
180 if (F == 0) return MP; // No varargs use, just return.
181
182 if (F->getFunctionType()->getNumParams() == 0)
183 return MP; // Modern varargs processing, just return.
184
185 // If we get to this point, we know that we have an old-style module.
186 // Materialize the whole thing to perform the rewriting.
187 MP->materializeModule();
188
189 // If the user is making use of obsolete varargs intrinsics, adjust them for
190 // the user.
191 if (Function *F = M->getNamedFunction("llvm.va_start")) {
192 assert(F->asize() == 1 && "Obsolete va_start takes 1 argument!");
193
194 const Type *RetTy = F->getFunctionType()->getParamType(0);
195 RetTy = cast<PointerType>(RetTy)->getElementType();
196 Function *NF = M->getOrInsertFunction("llvm.va_start", RetTy, 0);
197
198 for (Value::use_iterator I = F->use_begin(), E = F->use_end(); I != E; )
199 if (CallInst *CI = dyn_cast<CallInst>(*I++)) {
200 Value *V = new CallInst(NF, "", CI);
201 new StoreInst(V, CI->getOperand(1), CI);
202 CI->getParent()->getInstList().erase(CI);
203 }
204 F->setName("");
205 }
206
207 if (Function *F = M->getNamedFunction("llvm.va_end")) {
208 assert(F->asize() == 1 && "Obsolete va_end takes 1 argument!");
209 const Type *ArgTy = F->getFunctionType()->getParamType(0);
210 ArgTy = cast<PointerType>(ArgTy)->getElementType();
211 Function *NF = M->getOrInsertFunction("llvm.va_end", Type::VoidTy,
212 ArgTy, 0);
213
214 for (Value::use_iterator I = F->use_begin(), E = F->use_end(); I != E; )
215 if (CallInst *CI = dyn_cast<CallInst>(*I++)) {
216 Value *V = new LoadInst(CI->getOperand(1), "", CI);
217 new CallInst(NF, V, "", CI);
218 CI->getParent()->getInstList().erase(CI);
219 }
220 F->setName("");
221 }
222
223 if (Function *F = M->getNamedFunction("llvm.va_copy")) {
224 assert(F->asize() == 2 && "Obsolete va_copy takes 2 argument!");
225 const Type *ArgTy = F->getFunctionType()->getParamType(0);
226 ArgTy = cast<PointerType>(ArgTy)->getElementType();
227 Function *NF = M->getOrInsertFunction("llvm.va_copy", ArgTy,
228 ArgTy, 0);
229
230 for (Value::use_iterator I = F->use_begin(), E = F->use_end(); I != E; )
231 if (CallInst *CI = dyn_cast<CallInst>(*I++)) {
232 Value *V = new CallInst(NF, CI->getOperand(2), "", CI);
233 new StoreInst(V, CI->getOperand(1), CI);
234 CI->getParent()->getInstList().erase(CI);
235 }
236 F->setName("");
237 }
238 return MP;
239}
240
Chris Lattnercb7e2e22003-10-18 05:54:18 +0000241//===----------------------------------------------------------------------===//
Misha Brukmand57308a2003-09-23 16:13:28 +0000242// Wrapper functions
Chris Lattnercb7e2e22003-10-18 05:54:18 +0000243//===----------------------------------------------------------------------===//
Misha Brukmand57308a2003-09-23 16:13:28 +0000244
245/// getBytecodeBufferModuleProvider - lazy function-at-a-time loading from a
246/// buffer
Chris Lattner00413e32003-10-04 20:14:59 +0000247ModuleProvider*
Chris Lattnerdeab9a72003-11-19 16:06:55 +0000248llvm::getBytecodeBufferModuleProvider(const unsigned char *Buffer,
249 unsigned Length,
Reid Spencerdf45a542004-06-29 23:24:14 +0000250 const std::string &ModuleID,
Reid Spencer97c7d742004-07-04 11:03:03 +0000251 BytecodeHandler* H ) {
Reid Spencerdf45a542004-06-29 23:24:14 +0000252 return CheckVarargs(
253 new BytecodeBufferReader(Buffer, Length, ModuleID, H));
Misha Brukman12c29d12003-09-22 23:38:23 +0000254}
255
Misha Brukmand57308a2003-09-23 16:13:28 +0000256/// ParseBytecodeBuffer - Parse a given bytecode buffer
257///
Chris Lattnerdeab9a72003-11-19 16:06:55 +0000258Module *llvm::ParseBytecodeBuffer(const unsigned char *Buffer, unsigned Length,
259 const std::string &ModuleID,
260 std::string *ErrorStr){
Misha Brukmand57308a2003-09-23 16:13:28 +0000261 try {
Chris Lattner00413e32003-10-04 20:14:59 +0000262 std::auto_ptr<ModuleProvider>
Chris Lattnera9833592003-10-04 19:19:37 +0000263 AMP(getBytecodeBufferModuleProvider(Buffer, Length, ModuleID));
264 return AMP->releaseModule();
Misha Brukmand57308a2003-09-23 16:13:28 +0000265 } catch (std::string &err) {
Misha Brukman134aba62003-09-24 22:10:47 +0000266 if (ErrorStr) *ErrorStr = err;
Misha Brukmand57308a2003-09-23 16:13:28 +0000267 return 0;
268 }
Misha Brukman12c29d12003-09-22 23:38:23 +0000269}
270
Misha Brukmand57308a2003-09-23 16:13:28 +0000271/// getBytecodeModuleProvider - lazy function-at-a-time loading from a file
Misha Brukman12c29d12003-09-22 23:38:23 +0000272///
Reid Spencerdf45a542004-06-29 23:24:14 +0000273ModuleProvider *llvm::getBytecodeModuleProvider(const std::string &Filename,
Reid Spencer97c7d742004-07-04 11:03:03 +0000274 BytecodeHandler* H) {
Misha Brukman12c29d12003-09-22 23:38:23 +0000275 if (Filename != std::string("-")) // Read from a file...
Reid Spencerdf45a542004-06-29 23:24:14 +0000276 return CheckVarargs(new BytecodeFileReader(Filename,H));
Misha Brukman12c29d12003-09-22 23:38:23 +0000277 else // Read from stdin
Reid Spencerdf45a542004-06-29 23:24:14 +0000278 return CheckVarargs(new BytecodeStdinReader(H));
Misha Brukman12c29d12003-09-22 23:38:23 +0000279}
280
Misha Brukmand57308a2003-09-23 16:13:28 +0000281/// ParseBytecodeFile - Parse the given bytecode file
282///
Chris Lattnerdeab9a72003-11-19 16:06:55 +0000283Module *llvm::ParseBytecodeFile(const std::string &Filename,
284 std::string *ErrorStr) {
Misha Brukmand57308a2003-09-23 16:13:28 +0000285 try {
Chris Lattner00413e32003-10-04 20:14:59 +0000286 std::auto_ptr<ModuleProvider> AMP(getBytecodeModuleProvider(Filename));
Chris Lattnera9833592003-10-04 19:19:37 +0000287 return AMP->releaseModule();
Misha Brukmand57308a2003-09-23 16:13:28 +0000288 } catch (std::string &err) {
Misha Brukman134aba62003-09-24 22:10:47 +0000289 if (ErrorStr) *ErrorStr = err;
Misha Brukmand57308a2003-09-23 16:13:28 +0000290 return 0;
291 }
Misha Brukman12c29d12003-09-22 23:38:23 +0000292}
Brian Gaeked0fde302003-11-11 22:41:34 +0000293
Reid Spencerdf45a542004-06-29 23:24:14 +0000294// AnalyzeBytecodeFile - analyze one file
Reid Spencer4542c432004-08-21 20:52:03 +0000295Module* llvm::AnalyzeBytecodeFile(
296 const std::string &Filename, ///< File to analyze
297 BytecodeAnalysis& bca, ///< Statistical output
298 std::string *ErrorStr, ///< Error output
Misha Brukman5adf0ca2004-09-12 20:56:38 +0000299 std::ostream* output ///< Dump output
300)
Reid Spencerdf45a542004-06-29 23:24:14 +0000301{
302 try {
Misha Brukman7df00742004-09-12 20:47:33 +0000303 BytecodeHandler* analyzerHandler =createBytecodeAnalyzerHandler(bca,output);
Reid Spencerdf45a542004-06-29 23:24:14 +0000304 std::auto_ptr<ModuleProvider> AMP(
305 getBytecodeModuleProvider(Filename,analyzerHandler));
306 return AMP->releaseModule();
307 } catch (std::string &err) {
308 if (ErrorStr) *ErrorStr = err;
309 return 0;
310 }
311}
312
313// AnalyzeBytecodeBuffer - analyze a buffer
314Module* llvm::AnalyzeBytecodeBuffer(
Reid Spencer4542c432004-08-21 20:52:03 +0000315 const unsigned char* Buffer, ///< Pointer to start of bytecode buffer
316 unsigned Length, ///< Size of the bytecode buffer
317 const std::string& ModuleID, ///< Identifier for the module
318 BytecodeAnalysis& bca, ///< The results of the analysis
319 std::string* ErrorStr, ///< Errors, if any.
Misha Brukman5adf0ca2004-09-12 20:56:38 +0000320 std::ostream* output ///< Dump output, if any
321)
Reid Spencerdf45a542004-06-29 23:24:14 +0000322{
323 try {
Reid Spencer4542c432004-08-21 20:52:03 +0000324 BytecodeHandler* hdlr = createBytecodeAnalyzerHandler(bca, output);
Reid Spencerdf45a542004-06-29 23:24:14 +0000325 std::auto_ptr<ModuleProvider>
326 AMP(getBytecodeBufferModuleProvider(Buffer, Length, ModuleID, hdlr));
327 return AMP->releaseModule();
328 } catch (std::string &err) {
329 if (ErrorStr) *ErrorStr = err;
330 return 0;
331 }
332}
333
Reid Spencere0cf59e2004-08-24 22:46:20 +0000334bool llvm::GetBytecodeDependentLibraries(const std::string &fname,
Misha Brukman7df00742004-09-12 20:47:33 +0000335 Module::LibraryListType& deplibs) {
Reid Spencere0cf59e2004-08-24 22:46:20 +0000336 try {
337 std::auto_ptr<ModuleProvider> AMP( getBytecodeModuleProvider(fname));
338 Module* M = AMP->releaseModule();
Reid Spencer2bcfcbe2004-11-06 08:56:40 +0000339
Reid Spencere0cf59e2004-08-24 22:46:20 +0000340 deplibs = M->getLibraries();
341 delete M;
342 return true;
343 } catch (...) {
344 deplibs.clear();
345 return false;
346 }
347}
348
Reid Spencer565ff3d2004-11-14 22:00:48 +0000349namespace {
350void getSymbols(Module*M, std::vector<std::string>& symbols) {
351 // Loop over global variables
352 for (Module::giterator GI = M->gbegin(), GE=M->gend(); GI != GE; ++GI) {
353 if (GI->hasInitializer()) {
354 std::string name ( GI->getName() );
355 if (!name.empty()) {
356 symbols.push_back(name);
357 }
358 }
359 }
360
361 //Loop over functions
362 for (Module::iterator FI = M->begin(), FE=M->end(); FI != FE; ++FI) {
363 if (!FI->isExternal()) {
364 std::string name ( FI->getName() );
365 if (!name.empty()) {
366 symbols.push_back(name);
367 }
368 }
369 }
370}
371}
372
Reid Spencer2bcfcbe2004-11-06 08:56:40 +0000373// Get just the externally visible defined symbols from the bytecode
374bool llvm::GetBytecodeSymbols(const sys::Path& fName,
375 std::vector<std::string>& symbols) {
376 try {
377 std::auto_ptr<ModuleProvider> AMP( getBytecodeModuleProvider(fName.get()));
378
379 // Get the module from the provider
Reid Spencer5a885782004-11-16 06:41:05 +0000380 Module* M = AMP->materializeModule();
Reid Spencer2bcfcbe2004-11-06 08:56:40 +0000381
Reid Spencer565ff3d2004-11-14 22:00:48 +0000382 // Get the symbols
383 getSymbols(M, symbols);
Reid Spencer2bcfcbe2004-11-06 08:56:40 +0000384
385 // Done with the module
Reid Spencer2bcfcbe2004-11-06 08:56:40 +0000386 return true;
387
388 } catch (...) {
389 return false;
390 }
391}
392
Reid Spencer766b7932004-11-15 01:20:11 +0000393ModuleProvider*
394llvm::GetBytecodeSymbols(const unsigned char*Buffer, unsigned Length,
Reid Spencer5a885782004-11-16 06:41:05 +0000395 const std::string& ModuleID,
396 std::vector<std::string>& symbols) {
Reid Spencer565ff3d2004-11-14 22:00:48 +0000397
Reid Spencer5a885782004-11-16 06:41:05 +0000398 ModuleProvider* MP = 0;
Reid Spencer565ff3d2004-11-14 22:00:48 +0000399 try {
Reid Spencer5a885782004-11-16 06:41:05 +0000400 // Get the module provider
401 MP = getBytecodeBufferModuleProvider(Buffer, Length, ModuleID);
Reid Spencer565ff3d2004-11-14 22:00:48 +0000402
403 // Get the module from the provider
Reid Spencer766b7932004-11-15 01:20:11 +0000404 Module* M = MP->materializeModule();
Reid Spencer565ff3d2004-11-14 22:00:48 +0000405
406 // Get the symbols
407 getSymbols(M, symbols);
408
Reid Spencer5a885782004-11-16 06:41:05 +0000409 // Done with the module. Note that ModuleProvider will delete the
410 // Module when it is deleted. Also note that its the caller's responsibility
411 // to delete the ModuleProvider.
Reid Spencer766b7932004-11-15 01:20:11 +0000412 return MP;
Reid Spencer565ff3d2004-11-14 22:00:48 +0000413
414 } catch (...) {
Reid Spencer5a885782004-11-16 06:41:05 +0000415 // We only delete the ModuleProvider here because its destructor will
416 // also delete the Module (we used materializeModule not releaseModule).
417 delete MP;
Reid Spencer565ff3d2004-11-14 22:00:48 +0000418 }
Reid Spencer766b7932004-11-15 01:20:11 +0000419 return 0;
Reid Spencer565ff3d2004-11-14 22:00:48 +0000420}
Reid Spencerdf45a542004-06-29 23:24:14 +0000421// vim: sw=2 ai