mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-08-25 00:29:20 +00:00
use the new MemoryBuffer interfaces to simplify error reporting in clients.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@36900 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
5499da8833
commit
065344dfd5
@ -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
|
/// ParseInputFile - Given a bytecode or assembly input filename, parse and
|
||||||
/// return it, or return null if not possible.
|
/// return it, or return null if not possible.
|
||||||
///
|
///
|
||||||
Module *llvm::ParseInputFile(const std::string &InputFilename) {
|
Module *llvm::ParseInputFile(const std::string &Filename) {
|
||||||
std::auto_ptr<MemoryBuffer> Buffer(
|
std::auto_ptr<MemoryBuffer> Buffer(MemoryBuffer::getFileOrSTDIN(Filename));
|
||||||
MemoryBuffer::getFileOrSTDIN(&InputFilename[0], InputFilename.size()));
|
|
||||||
Module *Result = 0;
|
Module *Result = 0;
|
||||||
if (Buffer.get())
|
if (Buffer.get())
|
||||||
Result = ParseBitcodeFile(Buffer.get());
|
Result = ParseBitcodeFile(Buffer.get());
|
||||||
|
|
||||||
ParseError Err;
|
ParseError Err;
|
||||||
if (!Result && !(Result = ParseAssemblyFile(InputFilename,&Err))) {
|
if (!Result && !(Result = ParseAssemblyFile(Filename, &Err))) {
|
||||||
std::cerr << "bugpoint: " << Err.getMessage() << "\n";
|
std::cerr << "bugpoint: " << Err.getMessage() << "\n";
|
||||||
Result = 0;
|
Result = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return Result;
|
return Result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -100,6 +100,7 @@ bool BugDriver::addSources(const std::vector<std::string> &Filenames) {
|
|||||||
// Load the first input file.
|
// Load the first input file.
|
||||||
Program = ParseInputFile(Filenames[0]);
|
Program = ParseInputFile(Filenames[0]);
|
||||||
if (Program == 0) return true;
|
if (Program == 0) return true;
|
||||||
|
|
||||||
if (!run_as_child)
|
if (!run_as_child)
|
||||||
std::cout << "Read input file : '" << Filenames[0] << "'\n";
|
std::cout << "Read input file : '" << Filenames[0] << "'\n";
|
||||||
|
|
||||||
|
@ -179,14 +179,10 @@ int main(int argc, char **argv) {
|
|||||||
std::string ErrorMessage;
|
std::string ErrorMessage;
|
||||||
std::auto_ptr<Module> M;
|
std::auto_ptr<Module> M;
|
||||||
|
|
||||||
{
|
|
||||||
std::auto_ptr<MemoryBuffer> Buffer(
|
std::auto_ptr<MemoryBuffer> Buffer(
|
||||||
MemoryBuffer::getFileOrSTDIN(&InputFilename[0], InputFilename.size()));
|
MemoryBuffer::getFileOrSTDIN(InputFilename, &ErrorMessage));
|
||||||
if (Buffer.get())
|
if (Buffer.get())
|
||||||
M.reset(ParseBitcodeFile(Buffer.get(), &ErrorMessage));
|
M.reset(ParseBitcodeFile(Buffer.get(), &ErrorMessage));
|
||||||
else
|
|
||||||
ErrorMessage = "Error reading file '" + InputFilename + "'";
|
|
||||||
}
|
|
||||||
if (M.get() == 0) {
|
if (M.get() == 0) {
|
||||||
std::cerr << argv[0] << ": bytecode didn't read correctly.\n";
|
std::cerr << argv[0] << ": bytecode didn't read correctly.\n";
|
||||||
std::cerr << "Reason: " << ErrorMessage << "\n";
|
std::cerr << "Reason: " << ErrorMessage << "\n";
|
||||||
|
@ -77,11 +77,7 @@ int main(int argc, char **argv, char * const *envp) {
|
|||||||
// Load the bytecode...
|
// Load the bytecode...
|
||||||
std::string ErrorMsg;
|
std::string ErrorMsg;
|
||||||
ModuleProvider *MP = 0;
|
ModuleProvider *MP = 0;
|
||||||
MemoryBuffer *Buffer = MemoryBuffer::getFileOrSTDIN(&InputFile[0],
|
if (MemoryBuffer *Buffer = MemoryBuffer::getFileOrSTDIN(InputFile,&ErrorMsg)){
|
||||||
InputFile.size());
|
|
||||||
if (Buffer == 0)
|
|
||||||
ErrorMsg = "Error reading file '" + InputFile + "'";
|
|
||||||
else {
|
|
||||||
MP = getBitcodeModuleProvider(Buffer, &ErrorMsg);
|
MP = getBitcodeModuleProvider(Buffer, &ErrorMsg);
|
||||||
if (!MP) delete Buffer;
|
if (!MP) delete Buffer;
|
||||||
}
|
}
|
||||||
|
@ -54,14 +54,11 @@ int main(int argc, char **argv) {
|
|||||||
|
|
||||||
std::auto_ptr<Module> M;
|
std::auto_ptr<Module> M;
|
||||||
|
|
||||||
MemoryBuffer *Buffer
|
if (MemoryBuffer *Buffer
|
||||||
= MemoryBuffer::getFileOrSTDIN(&InputFilename[0], InputFilename.size());
|
= MemoryBuffer::getFileOrSTDIN(InputFilename, &ErrorMessage)) {
|
||||||
|
|
||||||
if (Buffer == 0)
|
|
||||||
ErrorMessage = "Error reading file '" + InputFilename + "'";
|
|
||||||
else
|
|
||||||
M.reset(ParseBitcodeFile(Buffer, &ErrorMessage));
|
M.reset(ParseBitcodeFile(Buffer, &ErrorMessage));
|
||||||
delete Buffer;
|
delete Buffer;
|
||||||
|
}
|
||||||
|
|
||||||
if (M.get() == 0) {
|
if (M.get() == 0) {
|
||||||
cerr << argv[0] << ": ";
|
cerr << argv[0] << ": ";
|
||||||
|
@ -57,8 +57,7 @@ int main(int argc, char **argv) {
|
|||||||
|
|
||||||
std::auto_ptr<Module> M;
|
std::auto_ptr<Module> M;
|
||||||
|
|
||||||
MemoryBuffer *Buffer = MemoryBuffer::getFileOrSTDIN(&InputFilename[0],
|
MemoryBuffer *Buffer = MemoryBuffer::getFileOrSTDIN(InputFilename);
|
||||||
InputFilename.size());
|
|
||||||
if (Buffer == 0) {
|
if (Buffer == 0) {
|
||||||
cerr << "Error reading file '" + InputFilename + "'";
|
cerr << "Error reading file '" + InputFilename + "'";
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -58,13 +58,11 @@ static inline std::auto_ptr<Module> LoadFile(const std::string &FN) {
|
|||||||
Module* Result = 0;
|
Module* Result = 0;
|
||||||
|
|
||||||
const std::string &FNStr = Filename.toString();
|
const std::string &FNStr = Filename.toString();
|
||||||
MemoryBuffer *Buffer = MemoryBuffer::getFileOrSTDIN(&FNStr[0],
|
if (MemoryBuffer *Buffer = MemoryBuffer::getFileOrSTDIN(FNStr,
|
||||||
FNStr.size());
|
&ErrorMessage)) {
|
||||||
if (Buffer == 0)
|
|
||||||
ErrorMessage = "Error reading file '" + FNStr + "'";
|
|
||||||
else
|
|
||||||
Result = ParseBitcodeFile(Buffer, &ErrorMessage);
|
Result = ParseBitcodeFile(Buffer, &ErrorMessage);
|
||||||
delete Buffer;
|
delete Buffer;
|
||||||
|
}
|
||||||
if (Result) return std::auto_ptr<Module>(Result); // Load successful!
|
if (Result) return std::auto_ptr<Module>(Result); // Load successful!
|
||||||
|
|
||||||
if (Verbose) {
|
if (Verbose) {
|
||||||
|
@ -124,7 +124,7 @@ static void DumpSymbolNamesFromFile(std::string &Filename) {
|
|||||||
// Note: Currently we do not support reading an archive from stdin.
|
// Note: Currently we do not support reading an archive from stdin.
|
||||||
if (Filename == "-" || aPath.isBitcodeFile()) {
|
if (Filename == "-" || aPath.isBitcodeFile()) {
|
||||||
std::auto_ptr<MemoryBuffer> Buffer(
|
std::auto_ptr<MemoryBuffer> Buffer(
|
||||||
MemoryBuffer::getFileOrSTDIN(&Filename[0], Filename.size()));
|
MemoryBuffer::getFileOrSTDIN(Filename, &ErrorMessage));
|
||||||
Module *Result = 0;
|
Module *Result = 0;
|
||||||
if (Buffer.get())
|
if (Buffer.get())
|
||||||
Result = ParseBitcodeFile(Buffer.get(), &ErrorMessage);
|
Result = ParseBitcodeFile(Buffer.get(), &ErrorMessage);
|
||||||
|
@ -118,13 +118,11 @@ int main(int argc, char **argv) {
|
|||||||
// Read in the bytecode file...
|
// Read in the bytecode file...
|
||||||
std::string ErrorMessage;
|
std::string ErrorMessage;
|
||||||
Module *M;
|
Module *M;
|
||||||
MemoryBuffer *Buffer = MemoryBuffer::getFileOrSTDIN(&BytecodeFile[0],
|
if (MemoryBuffer *Buffer = MemoryBuffer::getFileOrSTDIN(BytecodeFile,
|
||||||
BytecodeFile.size());
|
&ErrorMessage)) {
|
||||||
if (Buffer == 0)
|
|
||||||
ErrorMessage = "Error reading file '" + BytecodeFile + "'";
|
|
||||||
else
|
|
||||||
M = ParseBitcodeFile(Buffer, &ErrorMessage);
|
M = ParseBitcodeFile(Buffer, &ErrorMessage);
|
||||||
delete Buffer;
|
delete Buffer;
|
||||||
|
}
|
||||||
if (M == 0) {
|
if (M == 0) {
|
||||||
std::cerr << argv[0] << ": " << BytecodeFile << ": "
|
std::cerr << argv[0] << ": " << BytecodeFile << ": "
|
||||||
<< ErrorMessage << "\n";
|
<< ErrorMessage << "\n";
|
||||||
|
@ -52,11 +52,9 @@ int main(int argc, char **argv) {
|
|||||||
|
|
||||||
std::auto_ptr<Module> M;
|
std::auto_ptr<Module> M;
|
||||||
std::auto_ptr<MemoryBuffer> Buffer(
|
std::auto_ptr<MemoryBuffer> Buffer(
|
||||||
MemoryBuffer::getFileOrSTDIN(&InputFilename[0], InputFilename.size()));
|
MemoryBuffer::getFileOrSTDIN(InputFilename, &ErrorMessage));
|
||||||
if (Buffer.get())
|
if (Buffer.get())
|
||||||
M.reset(ParseBitcodeFile(Buffer.get(), &ErrorMessage));
|
M.reset(ParseBitcodeFile(Buffer.get(), &ErrorMessage));
|
||||||
else
|
|
||||||
ErrorMessage = "Error reading file '" + InputFilename + "'";
|
|
||||||
if (M.get() == 0) {
|
if (M.get() == 0) {
|
||||||
std::cerr << argv[0] << ": ";
|
std::cerr << argv[0] << ": ";
|
||||||
if (ErrorMessage.size())
|
if (ErrorMessage.size())
|
||||||
|
@ -69,8 +69,7 @@ static bool GetBytecodeDependentLibraries(const std::string &fname,
|
|||||||
Module::LibraryListType& deplibs,
|
Module::LibraryListType& deplibs,
|
||||||
std::string* ErrMsg) {
|
std::string* ErrMsg) {
|
||||||
ModuleProvider *MP = 0;
|
ModuleProvider *MP = 0;
|
||||||
if (MemoryBuffer *Buffer = MemoryBuffer::getFileOrSTDIN(&fname[0],
|
if (MemoryBuffer *Buffer = MemoryBuffer::getFileOrSTDIN(fname)) {
|
||||||
fname.size())) {
|
|
||||||
MP = getBitcodeModuleProvider(Buffer);
|
MP = getBitcodeModuleProvider(Buffer);
|
||||||
if (MP == 0) delete Buffer;
|
if (MP == 0) delete Buffer;
|
||||||
}
|
}
|
||||||
|
@ -260,15 +260,12 @@ int main(int argc, char **argv) {
|
|||||||
|
|
||||||
// Load the input module...
|
// Load the input module...
|
||||||
std::auto_ptr<Module> M;
|
std::auto_ptr<Module> M;
|
||||||
MemoryBuffer *Buffer
|
if (MemoryBuffer *Buffer
|
||||||
= MemoryBuffer::getFileOrSTDIN(&InputFilename[0], InputFilename.size());
|
= MemoryBuffer::getFileOrSTDIN(InputFilename, &ErrorMessage)) {
|
||||||
|
|
||||||
if (Buffer == 0)
|
|
||||||
ErrorMessage = "Error reading file '" + InputFilename + "'";
|
|
||||||
else
|
|
||||||
M.reset(ParseBitcodeFile(Buffer, &ErrorMessage));
|
M.reset(ParseBitcodeFile(Buffer, &ErrorMessage));
|
||||||
|
|
||||||
delete Buffer;
|
delete Buffer;
|
||||||
|
}
|
||||||
|
|
||||||
if (M.get() == 0) {
|
if (M.get() == 0) {
|
||||||
cerr << argv[0] << ": ";
|
cerr << argv[0] << ": ";
|
||||||
if (ErrorMessage.size())
|
if (ErrorMessage.size())
|
||||||
|
Loading…
Reference in New Issue
Block a user