llvm.org GIT mirror llvm / 065344d
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 Chris Lattner 12 years ago
11 changed file(s) with 28 addition(s) and 49 deletion(s). Raw diff Collapse all Expand all
7171 /// ParseInputFile - Given a bytecode or assembly input filename, parse and
7272 /// return it, or return null if not possible.
7373 ///
74 Module *llvm::ParseInputFile(const std::string &InputFilename) {
75 std::auto_ptr Buffer(
76 MemoryBuffer::getFileOrSTDIN(&InputFilename[0], InputFilename.size()));
74 Module *llvm::ParseInputFile(const std::string &Filename) {
75 std::auto_ptr Buffer(MemoryBuffer::getFileOrSTDIN(Filename));
7776 Module *Result = 0;
7877 if (Buffer.get())
7978 Result = ParseBitcodeFile(Buffer.get());
8079
8180 ParseError Err;
82 if (!Result && !(Result = ParseAssemblyFile(InputFilename,&Err))) {
81 if (!Result && !(Result = ParseAssemblyFile(Filename, &Err))) {
8382 std::cerr << "bugpoint: " << Err.getMessage() << "\n";
8483 Result = 0;
8584 }
85
8686 return Result;
8787 }
8888
9999 // Load the first input file.
100100 Program = ParseInputFile(Filenames[0]);
101101 if (Program == 0) return true;
102
102103 if (!run_as_child)
103104 std::cout << "Read input file : '" << Filenames[0] << "'\n";
104105
178178 std::string ErrorMessage;
179179 std::auto_ptr M;
180180
181 {
182181 std::auto_ptr Buffer(
183 MemoryBuffer::getFileOrSTDIN(&InputFilename[0], InputFilename.size()));
182 MemoryBuffer::getFileOrSTDIN(InputFilename, &ErrorMessage));
184183 if (Buffer.get())
185184 M.reset(ParseBitcodeFile(Buffer.get(), &ErrorMessage));
186 else
187 ErrorMessage = "Error reading file '" + InputFilename + "'";
188 }
189185 if (M.get() == 0) {
190186 std::cerr << argv[0] << ": bytecode didn't read correctly.\n";
191187 std::cerr << "Reason: " << ErrorMessage << "\n";
7676 // Load the bytecode...
7777 std::string ErrorMsg;
7878 ModuleProvider *MP = 0;
79 MemoryBuffer *Buffer = MemoryBuffer::getFileOrSTDIN(&InputFile[0],
80 InputFile.size());
81 if (Buffer == 0)
82 ErrorMsg = "Error reading file '" + InputFile + "'";
83 else {
79 if (MemoryBuffer *Buffer = MemoryBuffer::getFileOrSTDIN(InputFile,&ErrorMsg)){
8480 MP = getBitcodeModuleProvider(Buffer, &ErrorMsg);
8581 if (!MP) delete Buffer;
8682 }
5353
5454 std::auto_ptr M;
5555
56 MemoryBuffer *Buffer
57 = MemoryBuffer::getFileOrSTDIN(&InputFilename[0], InputFilename.size());
58
59 if (Buffer == 0)
60 ErrorMessage = "Error reading file '" + InputFilename + "'";
61 else
56 if (MemoryBuffer *Buffer
57 = MemoryBuffer::getFileOrSTDIN(InputFilename, &ErrorMessage)) {
6258 M.reset(ParseBitcodeFile(Buffer, &ErrorMessage));
63 delete Buffer;
59 delete Buffer;
60 }
6461
6562 if (M.get() == 0) {
6663 cerr << argv[0] << ": ";
5656
5757 std::auto_ptr M;
5858
59 MemoryBuffer *Buffer = MemoryBuffer::getFileOrSTDIN(&InputFilename[0],
60 InputFilename.size());
59 MemoryBuffer *Buffer = MemoryBuffer::getFileOrSTDIN(InputFilename);
6160 if (Buffer == 0) {
6261 cerr << "Error reading file '" + InputFilename + "'";
6362 return 1;
5757 Module* Result = 0;
5858
5959 const std::string &FNStr = Filename.toString();
60 MemoryBuffer *Buffer = MemoryBuffer::getFileOrSTDIN(&FNStr[0],
61 FNStr.size());
62 if (Buffer == 0)
63 ErrorMessage = "Error reading file '" + FNStr + "'";
64 else
60 if (MemoryBuffer *Buffer = MemoryBuffer::getFileOrSTDIN(FNStr,
61 &ErrorMessage)) {
6562 Result = ParseBitcodeFile(Buffer, &ErrorMessage);
66 delete Buffer;
63 delete Buffer;
64 }
6765 if (Result) return std::auto_ptr(Result); // Load successful!
6866
6967 if (Verbose) {
123123 // Note: Currently we do not support reading an archive from stdin.
124124 if (Filename == "-" || aPath.isBitcodeFile()) {
125125 std::auto_ptr Buffer(
126 MemoryBuffer::getFileOrSTDIN(&Filename[0], Filename.size()));
126 MemoryBuffer::getFileOrSTDIN(Filename, &ErrorMessage));
127127 Module *Result = 0;
128128 if (Buffer.get())
129129 Result = ParseBitcodeFile(Buffer.get(), &ErrorMessage);
117117 // Read in the bytecode file...
118118 std::string ErrorMessage;
119119 Module *M;
120 MemoryBuffer *Buffer = MemoryBuffer::getFileOrSTDIN(&BytecodeFile[0],
121 BytecodeFile.size());
122 if (Buffer == 0)
123 ErrorMessage = "Error reading file '" + BytecodeFile + "'";
124 else
120 if (MemoryBuffer *Buffer = MemoryBuffer::getFileOrSTDIN(BytecodeFile,
121 &ErrorMessage)) {
125122 M = ParseBitcodeFile(Buffer, &ErrorMessage);
126 delete Buffer;
123 delete Buffer;
124 }
127125 if (M == 0) {
128126 std::cerr << argv[0] << ": " << BytecodeFile << ": "
129127 << ErrorMessage << "\n";
5151
5252 std::auto_ptr M;
5353 std::auto_ptr Buffer(
54 MemoryBuffer::getFileOrSTDIN(&InputFilename[0], InputFilename.size()));
54 MemoryBuffer::getFileOrSTDIN(InputFilename, &ErrorMessage));
5555 if (Buffer.get())
5656 M.reset(ParseBitcodeFile(Buffer.get(), &ErrorMessage));
57 else
58 ErrorMessage = "Error reading file '" + InputFilename + "'";
5957 if (M.get() == 0) {
6058 std::cerr << argv[0] << ": ";
6159 if (ErrorMessage.size())
6868 Module::LibraryListType& deplibs,
6969 std::string* ErrMsg) {
7070 ModuleProvider *MP = 0;
71 if (MemoryBuffer *Buffer = MemoryBuffer::getFileOrSTDIN(&fname[0],
72 fname.size())) {
71 if (MemoryBuffer *Buffer = MemoryBuffer::getFileOrSTDIN(fname)) {
7372 MP = getBitcodeModuleProvider(Buffer);
7473 if (MP == 0) delete Buffer;
7574 }
259259
260260 // Load the input module...
261261 std::auto_ptr M;
262 MemoryBuffer *Buffer
263 = MemoryBuffer::getFileOrSTDIN(&InputFilename[0], InputFilename.size());
262 if (MemoryBuffer *Buffer
263 = MemoryBuffer::getFileOrSTDIN(InputFilename, &ErrorMessage)) {
264 M.reset(ParseBitcodeFile(Buffer, &ErrorMessage));
265 delete Buffer;
266 }
264267
265 if (Buffer == 0)
266 ErrorMessage = "Error reading file '" + InputFilename + "'";
267 else
268 M.reset(ParseBitcodeFile(Buffer, &ErrorMessage));
269
270 delete Buffer;
271268 if (M.get() == 0) {
272269 cerr << argv[0] << ": ";
273270 if (ErrorMessage.size())