summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorReid Spencer <rspencer@reidspencer.com>2006-08-25 17:43:11 +0000
committerReid Spencer <rspencer@reidspencer.com>2006-08-25 17:43:11 +0000
commit0b5a504d105514178c80b886321221fbe5ac1131 (patch)
tree069c7663f74040a5d323ab404e026b4c59a2a1a9 /lib
parentac123227109303be313c3c4625b152246969e781 (diff)
For PR797:
Remove exception throwing/handling from lib/Bytecode, and adjust its users to compensate for changes in the interface. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@29875 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r--lib/Archive/ArchiveReader.cpp10
-rw-r--r--lib/Archive/ArchiveWriter.cpp5
-rw-r--r--lib/Bytecode/Archive/ArchiveReader.cpp10
-rw-r--r--lib/Bytecode/Archive/ArchiveWriter.cpp5
-rw-r--r--lib/Bytecode/Reader/ReaderWrappers.cpp237
-rw-r--r--lib/Debugger/Debugger.cpp10
6 files changed, 153 insertions, 124 deletions
diff --git a/lib/Archive/ArchiveReader.cpp b/lib/Archive/ArchiveReader.cpp
index 38aa07243c7..e4769cac888 100644
--- a/lib/Archive/ArchiveReader.cpp
+++ b/lib/Archive/ArchiveReader.cpp
@@ -475,14 +475,16 @@ Archive::findModuleDefiningSymbol(const std::string& symbol,
const char* modptr = base + fileOffset;
ArchiveMember* mbr = parseMemberHeader(modptr, base + mapfile->size(),ErrMsg);
if (!mbr)
- return false;
+ return 0;
// Now, load the bytecode module to get the ModuleProvider
std::string FullMemberName = archPath.toString() + "(" +
mbr->getPath().toString() + ")";
ModuleProvider* mp = getBytecodeBufferModuleProvider(
(const unsigned char*) mbr->getData(), mbr->getSize(),
- FullMemberName, 0);
+ FullMemberName, ErrMsg, 0);
+ if (!mp)
+ return 0;
modules.insert(std::make_pair(fileOffset, std::make_pair(mp, mbr)));
@@ -523,7 +525,7 @@ Archive::findModulesDefiningSymbols(std::set<std::string>& symbols,
std::string FullMemberName = archPath.toString() + "(" +
mbr->getPath().toString() + ")";
ModuleProvider* MP = GetBytecodeSymbols((const unsigned char*)At,
- mbr->getSize(), FullMemberName, symbols);
+ mbr->getSize(), FullMemberName, symbols, error);
if (MP) {
// Insert the module's symbols into the symbol table
@@ -537,7 +539,7 @@ Archive::findModulesDefiningSymbols(std::set<std::string>& symbols,
} else {
if (error)
*error = "Can't parse bytecode member: " +
- mbr->getPath().toString();
+ mbr->getPath().toString() + ": " + *error;
delete mbr;
return false;
}
diff --git a/lib/Archive/ArchiveWriter.cpp b/lib/Archive/ArchiveWriter.cpp
index 3746dbff8a1..096a9993a81 100644
--- a/lib/Archive/ArchiveWriter.cpp
+++ b/lib/Archive/ArchiveWriter.cpp
@@ -223,7 +223,7 @@ Archive::writeMember(
member.getPath().toString()
+ ")";
ModuleProvider* MP = GetBytecodeSymbols(
- (const unsigned char*)data,fSize,FullMemberName, symbols);
+ (const unsigned char*)data,fSize,FullMemberName, symbols, ErrMsg);
// If the bytecode parsed successfully
if ( MP ) {
@@ -247,7 +247,8 @@ Archive::writeMember(
delete mFile;
}
if (ErrMsg)
- *ErrMsg = "Can't parse bytecode member: " + member.getPath().toString();
+ *ErrMsg = "Can't parse bytecode member: " + member.getPath().toString()
+ + ": " + *ErrMsg;
return true;
}
}
diff --git a/lib/Bytecode/Archive/ArchiveReader.cpp b/lib/Bytecode/Archive/ArchiveReader.cpp
index 38aa07243c7..e4769cac888 100644
--- a/lib/Bytecode/Archive/ArchiveReader.cpp
+++ b/lib/Bytecode/Archive/ArchiveReader.cpp
@@ -475,14 +475,16 @@ Archive::findModuleDefiningSymbol(const std::string& symbol,
const char* modptr = base + fileOffset;
ArchiveMember* mbr = parseMemberHeader(modptr, base + mapfile->size(),ErrMsg);
if (!mbr)
- return false;
+ return 0;
// Now, load the bytecode module to get the ModuleProvider
std::string FullMemberName = archPath.toString() + "(" +
mbr->getPath().toString() + ")";
ModuleProvider* mp = getBytecodeBufferModuleProvider(
(const unsigned char*) mbr->getData(), mbr->getSize(),
- FullMemberName, 0);
+ FullMemberName, ErrMsg, 0);
+ if (!mp)
+ return 0;
modules.insert(std::make_pair(fileOffset, std::make_pair(mp, mbr)));
@@ -523,7 +525,7 @@ Archive::findModulesDefiningSymbols(std::set<std::string>& symbols,
std::string FullMemberName = archPath.toString() + "(" +
mbr->getPath().toString() + ")";
ModuleProvider* MP = GetBytecodeSymbols((const unsigned char*)At,
- mbr->getSize(), FullMemberName, symbols);
+ mbr->getSize(), FullMemberName, symbols, error);
if (MP) {
// Insert the module's symbols into the symbol table
@@ -537,7 +539,7 @@ Archive::findModulesDefiningSymbols(std::set<std::string>& symbols,
} else {
if (error)
*error = "Can't parse bytecode member: " +
- mbr->getPath().toString();
+ mbr->getPath().toString() + ": " + *error;
delete mbr;
return false;
}
diff --git a/lib/Bytecode/Archive/ArchiveWriter.cpp b/lib/Bytecode/Archive/ArchiveWriter.cpp
index 3746dbff8a1..096a9993a81 100644
--- a/lib/Bytecode/Archive/ArchiveWriter.cpp
+++ b/lib/Bytecode/Archive/ArchiveWriter.cpp
@@ -223,7 +223,7 @@ Archive::writeMember(
member.getPath().toString()
+ ")";
ModuleProvider* MP = GetBytecodeSymbols(
- (const unsigned char*)data,fSize,FullMemberName, symbols);
+ (const unsigned char*)data,fSize,FullMemberName, symbols, ErrMsg);
// If the bytecode parsed successfully
if ( MP ) {
@@ -247,7 +247,8 @@ Archive::writeMember(
delete mFile;
}
if (ErrMsg)
- *ErrMsg = "Can't parse bytecode member: " + member.getPath().toString();
+ *ErrMsg = "Can't parse bytecode member: " + member.getPath().toString()
+ + ": " + *ErrMsg;
return true;
}
}
diff --git a/lib/Bytecode/Reader/ReaderWrappers.cpp b/lib/Bytecode/Reader/ReaderWrappers.cpp
index 17671593925..019d7bef529 100644
--- a/lib/Bytecode/Reader/ReaderWrappers.cpp
+++ b/lib/Bytecode/Reader/ReaderWrappers.cpp
@@ -35,6 +35,7 @@ namespace {
///
class BytecodeFileReader : public BytecodeReader {
private:
+ std::string fileName;
sys::MappedFile mapFile;
BytecodeFileReader(const BytecodeFileReader&); // Do not implement
@@ -42,23 +43,30 @@ namespace {
public:
BytecodeFileReader(const std::string &Filename, llvm::BytecodeHandler* H=0);
+ bool read(std::string* ErrMsg);
};
}
BytecodeFileReader::BytecodeFileReader(const std::string &Filename,
llvm::BytecodeHandler* H )
: BytecodeReader(H)
+ , fileName(Filename)
, mapFile()
{
- std::string ErrMsg;
- if (mapFile.open(sys::Path(Filename), sys::MappedFile::READ_ACCESS, &ErrMsg))
- throw ErrMsg;
- if (!mapFile.map(&ErrMsg))
- throw ErrMsg;
+}
+
+bool BytecodeFileReader::read(std::string* ErrMsg) {
+ if (mapFile.open(sys::Path(fileName), sys::MappedFile::READ_ACCESS, ErrMsg))
+ return true;
+ if (!mapFile.map(ErrMsg)) {
+ mapFile.close();
+ return true;
+ }
unsigned char* buffer = reinterpret_cast<unsigned char*>(mapFile.base());
- if (ParseBytecode(buffer, mapFile.size(), Filename, &ErrMsg)) {
- throw ErrMsg;
+ if (ParseBytecode(buffer, mapFile.size(), fileName, ErrMsg)) {
+ return true;
}
+ return false;
}
//===----------------------------------------------------------------------===//
@@ -71,6 +79,9 @@ namespace {
class BytecodeBufferReader : public BytecodeReader {
private:
const unsigned char *Buffer;
+ const unsigned char *Buf;
+ unsigned Length;
+ std::string ModuleID;
bool MustDelete;
BytecodeBufferReader(const BytecodeBufferReader&); // Do not implement
@@ -82,15 +93,30 @@ namespace {
llvm::BytecodeHandler* Handler = 0);
~BytecodeBufferReader();
+ bool read(std::string* ErrMsg);
+
};
}
-BytecodeBufferReader::BytecodeBufferReader(const unsigned char *Buf,
- unsigned Length,
- const std::string &ModuleID,
- llvm::BytecodeHandler* H )
+BytecodeBufferReader::BytecodeBufferReader(const unsigned char *buf,
+ unsigned len,
+ const std::string &modID,
+ llvm::BytecodeHandler* H)
: BytecodeReader(H)
+ , Buffer(0)
+ , Buf(buf)
+ , Length(len)
+ , ModuleID(modID)
+ , MustDelete(false)
{
+}
+
+BytecodeBufferReader::~BytecodeBufferReader() {
+ if (MustDelete) delete [] Buffer;
+}
+
+bool
+BytecodeBufferReader::read(std::string* ErrMsg) {
// If not aligned, allocate a new buffer to hold the bytecode...
const unsigned char *ParseBegin = 0;
if (reinterpret_cast<uint64_t>(Buf) & 3) {
@@ -104,15 +130,11 @@ BytecodeBufferReader::BytecodeBufferReader(const unsigned char *Buf,
ParseBegin = Buffer = Buf;
MustDelete = false;
}
- std::string ErrMsg;
- if (ParseBytecode(ParseBegin, Length, ModuleID, &ErrMsg)) {
+ if (ParseBytecode(ParseBegin, Length, ModuleID, ErrMsg)) {
if (MustDelete) delete [] Buffer;
- throw ErrMsg;
+ return true;
}
-}
-
-BytecodeBufferReader::~BytecodeBufferReader() {
- if (MustDelete) delete [] Buffer;
+ return false;
}
//===----------------------------------------------------------------------===//
@@ -132,12 +154,18 @@ namespace {
public:
BytecodeStdinReader( llvm::BytecodeHandler* H = 0 );
+ bool read(std::string* ErrMsg);
};
}
BytecodeStdinReader::BytecodeStdinReader( BytecodeHandler* H )
: BytecodeReader(H)
{
+}
+
+bool
+BytecodeStdinReader::read(std::string* ErrMsg)
+{
sys::Program::ChangeStdinToBinary();
char Buffer[4096*4];
@@ -150,14 +178,16 @@ BytecodeStdinReader::BytecodeStdinReader( BytecodeHandler* H )
FileData.insert(FileData.end(), Buffer, Buffer+BlockSize);
}
- if (FileData.empty())
- throw std::string("Standard Input empty!");
+ if (FileData.empty()) {
+ if (ErrMsg)
+ *ErrMsg = "Standard Input is empty!";
+ return true;
+ }
FileBuf = &FileData[0];
- std::string ErrMsg;
- if (ParseBytecode(FileBuf, FileData.size(), "<stdin>", &ErrMsg)) {
- throw ErrMsg;
- }
+ if (ParseBytecode(FileBuf, FileData.size(), "<stdin>", ErrMsg))
+ return true;
+ return false;
}
//===----------------------------------------------------------------------===//
@@ -270,66 +300,71 @@ ModuleProvider*
llvm::getBytecodeBufferModuleProvider(const unsigned char *Buffer,
unsigned Length,
const std::string &ModuleID,
- BytecodeHandler* H ) {
- return CheckVarargs(
- new BytecodeBufferReader(Buffer, Length, ModuleID, H));
+ std::string* ErrMsg,
+ BytecodeHandler* H) {
+ BytecodeBufferReader* rdr =
+ new BytecodeBufferReader(Buffer, Length, ModuleID, H);
+ if (rdr->read(ErrMsg))
+ return 0;
+ return CheckVarargs(rdr);
}
/// ParseBytecodeBuffer - Parse a given bytecode buffer
///
Module *llvm::ParseBytecodeBuffer(const unsigned char *Buffer, unsigned Length,
const std::string &ModuleID,
- std::string *ErrorStr){
- try {
- std::auto_ptr<ModuleProvider>
- AMP(getBytecodeBufferModuleProvider(Buffer, Length, ModuleID));
- return AMP->releaseModule();
- } catch (std::string &err) {
- if (ErrorStr) *ErrorStr = err;
+ std::string *ErrMsg){
+ ModuleProvider* MP =
+ getBytecodeBufferModuleProvider(Buffer, Length, ModuleID, ErrMsg, 0);
+ if (!MP)
return 0;
- }
+ return MP->releaseModule();
}
/// getBytecodeModuleProvider - lazy function-at-a-time loading from a file
///
-ModuleProvider *llvm::getBytecodeModuleProvider(const std::string &Filename,
- BytecodeHandler* H) {
- if (Filename != std::string("-")) // Read from a file...
- return CheckVarargs(new BytecodeFileReader(Filename,H));
- else // Read from stdin
- return CheckVarargs(new BytecodeStdinReader(H));
+ModuleProvider *
+llvm::getBytecodeModuleProvider(const std::string &Filename,
+ std::string* ErrMsg,
+ BytecodeHandler* H) {
+ // Read from a file
+ if (Filename != std::string("-")) {
+ BytecodeFileReader* rdr = new BytecodeFileReader(Filename, H);
+ if (rdr->read(ErrMsg))
+ return 0;
+ return CheckVarargs(rdr);
+ }
+
+ // Read from stdin
+ BytecodeStdinReader* rdr = new BytecodeStdinReader(H);
+ if (rdr->read(ErrMsg))
+ return 0;
+ return CheckVarargs(rdr);
}
/// ParseBytecodeFile - Parse the given bytecode file
///
Module *llvm::ParseBytecodeFile(const std::string &Filename,
- std::string *ErrorStr) {
- try {
- std::auto_ptr<ModuleProvider> AMP(getBytecodeModuleProvider(Filename));
- return AMP->releaseModule();
- } catch (std::string &err) {
- if (ErrorStr) *ErrorStr = err;
+ std::string *ErrMsg) {
+ ModuleProvider* MP = getBytecodeModuleProvider(Filename, ErrMsg);
+ if (!MP)
return 0;
- }
+ return MP->releaseModule();
}
// AnalyzeBytecodeFile - analyze one file
Module* llvm::AnalyzeBytecodeFile(
const std::string &Filename, ///< File to analyze
BytecodeAnalysis& bca, ///< Statistical output
- std::string *ErrorStr, ///< Error output
+ std::string *ErrMsg, ///< Error output
std::ostream* output ///< Dump output
)
{
- try {
- BytecodeHandler* analyzerHandler =createBytecodeAnalyzerHandler(bca,output);
- std::auto_ptr<ModuleProvider> AMP(
- getBytecodeModuleProvider(Filename,analyzerHandler));
- return AMP->releaseModule();
- } catch (std::string &err) {
- if (ErrorStr) *ErrorStr = err;
+ BytecodeHandler* AH = createBytecodeAnalyzerHandler(bca,output);
+ ModuleProvider* MP = getBytecodeModuleProvider(Filename, ErrMsg, AH);
+ if (!MP)
return 0;
- }
+ return MP->releaseModule();
}
// AnalyzeBytecodeBuffer - analyze a buffer
@@ -338,34 +373,30 @@ Module* llvm::AnalyzeBytecodeBuffer(
unsigned Length, ///< Size of the bytecode buffer
const std::string& ModuleID, ///< Identifier for the module
BytecodeAnalysis& bca, ///< The results of the analysis
- std::string* ErrorStr, ///< Errors, if any.
+ std::string* ErrMsg, ///< Errors, if any.
std::ostream* output ///< Dump output, if any
)
{
- try {
- BytecodeHandler* hdlr = createBytecodeAnalyzerHandler(bca, output);
- std::auto_ptr<ModuleProvider>
- AMP(getBytecodeBufferModuleProvider(Buffer, Length, ModuleID, hdlr));
- return AMP->releaseModule();
- } catch (std::string &err) {
- if (ErrorStr) *ErrorStr = err;
+ BytecodeHandler* hdlr = createBytecodeAnalyzerHandler(bca, output);
+ ModuleProvider* MP =
+ getBytecodeBufferModuleProvider(Buffer, Length, ModuleID, ErrMsg, hdlr);
+ if (!MP)
return 0;
- }
+ return MP->releaseModule();
}
bool llvm::GetBytecodeDependentLibraries(const std::string &fname,
- Module::LibraryListType& deplibs) {
- try {
- std::auto_ptr<ModuleProvider> AMP( getBytecodeModuleProvider(fname));
- Module* M = AMP->releaseModule();
-
- deplibs = M->getLibraries();
- delete M;
- return true;
- } catch (...) {
+ Module::LibraryListType& deplibs,
+ std::string* ErrMsg) {
+ ModuleProvider* MP = getBytecodeModuleProvider(fname, ErrMsg);
+ if (!MP) {
deplibs.clear();
- return false;
+ return true;
}
+ Module* M = MP->releaseModule();
+ deplibs = M->getLibraries();
+ delete M;
+ return false;
}
static void getSymbols(Module*M, std::vector<std::string>& symbols) {
@@ -384,13 +415,16 @@ static void getSymbols(Module*M, std::vector<std::string>& symbols) {
// Get just the externally visible defined symbols from the bytecode
bool llvm::GetBytecodeSymbols(const sys::Path& fName,
- std::vector<std::string>& symbols) {
- std::auto_ptr<ModuleProvider> AMP(
- getBytecodeModuleProvider(fName.toString()));
+ std::vector<std::string>& symbols,
+ std::string* ErrMsg) {
+ ModuleProvider* MP = getBytecodeModuleProvider(fName.toString(), ErrMsg);
+ if (!MP)
+ return true;
// Get the module from the provider
- Module* M = AMP->materializeModule();
- if (M == 0) return false;
+ Module* M = MP->materializeModule();
+ if (M == 0)
+ return true;
// Get the symbols
getSymbols(M, symbols);
@@ -402,29 +436,26 @@ bool llvm::GetBytecodeSymbols(const sys::Path& fName,
ModuleProvider*
llvm::GetBytecodeSymbols(const unsigned char*Buffer, unsigned Length,
const std::string& ModuleID,
- std::vector<std::string>& symbols) {
-
- ModuleProvider* MP = 0;
- try {
- // Get the module provider
- MP = getBytecodeBufferModuleProvider(Buffer, Length, ModuleID);
-
- // Get the module from the provider
- Module* M = MP->materializeModule();
- if (M == 0) return 0;
-
- // Get the symbols
- getSymbols(M, symbols);
-
- // Done with the module. Note that ModuleProvider will delete the
- // Module when it is deleted. Also note that its the caller's responsibility
- // to delete the ModuleProvider.
- return MP;
+ std::vector<std::string>& symbols,
+ std::string* ErrMsg) {
+ // Get the module provider
+ ModuleProvider* MP =
+ getBytecodeBufferModuleProvider(Buffer, Length, ModuleID, ErrMsg, 0);
+ if (!MP)
+ return 0;
- } catch (...) {
- // We delete only the ModuleProvider here because its destructor will
- // also delete the Module (we used materializeModule not releaseModule).
+ // Get the module from the provider
+ Module* M = MP->materializeModule();
+ if (M == 0) {
delete MP;
+ return 0;
}
- return 0;
+
+ // Get the symbols
+ getSymbols(M, symbols);
+
+ // Done with the module. Note that ModuleProvider will delete the
+ // Module when it is deleted. Also note that its the caller's responsibility
+ // to delete the ModuleProvider.
+ return MP;
}
diff --git a/lib/Debugger/Debugger.cpp b/lib/Debugger/Debugger.cpp
index a0505bda578..613a19d2f3f 100644
--- a/lib/Debugger/Debugger.cpp
+++ b/lib/Debugger/Debugger.cpp
@@ -45,15 +45,7 @@ std::string Debugger::getProgramPath() const {
static Module *
getMaterializedModuleProvider(const std::string &Filename) {
- try {
- std::auto_ptr<ModuleProvider> Result(getBytecodeModuleProvider(Filename));
- if (!Result.get()) return 0;
-
- Result->materializeModule();
- return Result.release()->releaseModule();
- } catch (...) {
- return 0;
- }
+ return ParseBytecodeFile(Filename);
}
/// loadProgram - If a program is currently loaded, unload it. Then search