1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-23 03:02:36 +01:00

use the new MemoryBuffer interfaces to simplify error reporting in clients.

llvm-svn: 36900
This commit is contained in:
Chris Lattner 2007-05-06 23:45:49 +00:00
parent 112d26a164
commit e24a5def42
11 changed files with 27 additions and 48 deletions

View File

@ -72,18 +72,18 @@ BugDriver::BugDriver(const char *toolname, bool as_child, bool find_bugs,
/// ParseInputFile - Given a bytecode or assembly input filename, parse and
/// return it, or return null if not possible.
///
Module *llvm::ParseInputFile(const std::string &InputFilename) {
std::auto_ptr<MemoryBuffer> Buffer(
MemoryBuffer::getFileOrSTDIN(&InputFilename[0], InputFilename.size()));
Module *llvm::ParseInputFile(const std::string &Filename) {
std::auto_ptr<MemoryBuffer> Buffer(MemoryBuffer::getFileOrSTDIN(Filename));
Module *Result = 0;
if (Buffer.get())
Result = ParseBitcodeFile(Buffer.get());
ParseError Err;
if (!Result && !(Result = ParseAssemblyFile(InputFilename,&Err))) {
if (!Result && !(Result = ParseAssemblyFile(Filename, &Err))) {
std::cerr << "bugpoint: " << Err.getMessage() << "\n";
Result = 0;
}
return Result;
}
@ -100,6 +100,7 @@ bool BugDriver::addSources(const std::vector<std::string> &Filenames) {
// Load the first input file.
Program = ParseInputFile(Filenames[0]);
if (Program == 0) return true;
if (!run_as_child)
std::cout << "Read input file : '" << Filenames[0] << "'\n";

View File

@ -179,14 +179,10 @@ int main(int argc, char **argv) {
std::string ErrorMessage;
std::auto_ptr<Module> M;
{
std::auto_ptr<MemoryBuffer> Buffer(
MemoryBuffer::getFileOrSTDIN(&InputFilename[0], InputFilename.size()));
MemoryBuffer::getFileOrSTDIN(InputFilename, &ErrorMessage));
if (Buffer.get())
M.reset(ParseBitcodeFile(Buffer.get(), &ErrorMessage));
else
ErrorMessage = "Error reading file '" + InputFilename + "'";
}
if (M.get() == 0) {
std::cerr << argv[0] << ": bytecode didn't read correctly.\n";
std::cerr << "Reason: " << ErrorMessage << "\n";

View File

@ -77,11 +77,7 @@ int main(int argc, char **argv, char * const *envp) {
// Load the bytecode...
std::string ErrorMsg;
ModuleProvider *MP = 0;
MemoryBuffer *Buffer = MemoryBuffer::getFileOrSTDIN(&InputFile[0],
InputFile.size());
if (Buffer == 0)
ErrorMsg = "Error reading file '" + InputFile + "'";
else {
if (MemoryBuffer *Buffer = MemoryBuffer::getFileOrSTDIN(InputFile,&ErrorMsg)){
MP = getBitcodeModuleProvider(Buffer, &ErrorMsg);
if (!MP) delete Buffer;
}

View File

@ -54,14 +54,11 @@ int main(int argc, char **argv) {
std::auto_ptr<Module> M;
MemoryBuffer *Buffer
= MemoryBuffer::getFileOrSTDIN(&InputFilename[0], InputFilename.size());
if (Buffer == 0)
ErrorMessage = "Error reading file '" + InputFilename + "'";
else
if (MemoryBuffer *Buffer
= MemoryBuffer::getFileOrSTDIN(InputFilename, &ErrorMessage)) {
M.reset(ParseBitcodeFile(Buffer, &ErrorMessage));
delete Buffer;
}
if (M.get() == 0) {
cerr << argv[0] << ": ";

View File

@ -57,8 +57,7 @@ int main(int argc, char **argv) {
std::auto_ptr<Module> M;
MemoryBuffer *Buffer = MemoryBuffer::getFileOrSTDIN(&InputFilename[0],
InputFilename.size());
MemoryBuffer *Buffer = MemoryBuffer::getFileOrSTDIN(InputFilename);
if (Buffer == 0) {
cerr << "Error reading file '" + InputFilename + "'";
return 1;

View File

@ -58,13 +58,11 @@ static inline std::auto_ptr<Module> LoadFile(const std::string &FN) {
Module* Result = 0;
const std::string &FNStr = Filename.toString();
MemoryBuffer *Buffer = MemoryBuffer::getFileOrSTDIN(&FNStr[0],
FNStr.size());
if (Buffer == 0)
ErrorMessage = "Error reading file '" + FNStr + "'";
else
if (MemoryBuffer *Buffer = MemoryBuffer::getFileOrSTDIN(FNStr,
&ErrorMessage)) {
Result = ParseBitcodeFile(Buffer, &ErrorMessage);
delete Buffer;
}
if (Result) return std::auto_ptr<Module>(Result); // Load successful!
if (Verbose) {

View File

@ -124,7 +124,7 @@ static void DumpSymbolNamesFromFile(std::string &Filename) {
// Note: Currently we do not support reading an archive from stdin.
if (Filename == "-" || aPath.isBitcodeFile()) {
std::auto_ptr<MemoryBuffer> Buffer(
MemoryBuffer::getFileOrSTDIN(&Filename[0], Filename.size()));
MemoryBuffer::getFileOrSTDIN(Filename, &ErrorMessage));
Module *Result = 0;
if (Buffer.get())
Result = ParseBitcodeFile(Buffer.get(), &ErrorMessage);

View File

@ -118,13 +118,11 @@ int main(int argc, char **argv) {
// Read in the bytecode file...
std::string ErrorMessage;
Module *M;
MemoryBuffer *Buffer = MemoryBuffer::getFileOrSTDIN(&BytecodeFile[0],
BytecodeFile.size());
if (Buffer == 0)
ErrorMessage = "Error reading file '" + BytecodeFile + "'";
else
if (MemoryBuffer *Buffer = MemoryBuffer::getFileOrSTDIN(BytecodeFile,
&ErrorMessage)) {
M = ParseBitcodeFile(Buffer, &ErrorMessage);
delete Buffer;
}
if (M == 0) {
std::cerr << argv[0] << ": " << BytecodeFile << ": "
<< ErrorMessage << "\n";

View File

@ -52,11 +52,9 @@ int main(int argc, char **argv) {
std::auto_ptr<Module> M;
std::auto_ptr<MemoryBuffer> Buffer(
MemoryBuffer::getFileOrSTDIN(&InputFilename[0], InputFilename.size()));
MemoryBuffer::getFileOrSTDIN(InputFilename, &ErrorMessage));
if (Buffer.get())
M.reset(ParseBitcodeFile(Buffer.get(), &ErrorMessage));
else
ErrorMessage = "Error reading file '" + InputFilename + "'";
if (M.get() == 0) {
std::cerr << argv[0] << ": ";
if (ErrorMessage.size())

View File

@ -69,8 +69,7 @@ static bool GetBytecodeDependentLibraries(const std::string &fname,
Module::LibraryListType& deplibs,
std::string* ErrMsg) {
ModuleProvider *MP = 0;
if (MemoryBuffer *Buffer = MemoryBuffer::getFileOrSTDIN(&fname[0],
fname.size())) {
if (MemoryBuffer *Buffer = MemoryBuffer::getFileOrSTDIN(fname)) {
MP = getBitcodeModuleProvider(Buffer);
if (MP == 0) delete Buffer;
}

View File

@ -260,15 +260,12 @@ int main(int argc, char **argv) {
// Load the input module...
std::auto_ptr<Module> M;
MemoryBuffer *Buffer
= MemoryBuffer::getFileOrSTDIN(&InputFilename[0], InputFilename.size());
if (Buffer == 0)
ErrorMessage = "Error reading file '" + InputFilename + "'";
else
if (MemoryBuffer *Buffer
= MemoryBuffer::getFileOrSTDIN(InputFilename, &ErrorMessage)) {
M.reset(ParseBitcodeFile(Buffer, &ErrorMessage));
delete Buffer;
}
if (M.get() == 0) {
cerr << argv[0] << ": ";
if (ErrorMessage.size())