comparison lib/Support/FileUtilities.cpp @ 77:54457678186b LLVM3.6

LLVM 3.6
author Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
date Mon, 08 Sep 2014 22:06:00 +0900
parents 95c75e76d11b
children 1172e4bd9c6f
comparison
equal deleted inserted replaced
34:e874dbf0ad9d 77:54457678186b
11 // various things with files. 11 // various things with files.
12 // 12 //
13 //===----------------------------------------------------------------------===// 13 //===----------------------------------------------------------------------===//
14 14
15 #include "llvm/Support/FileUtilities.h" 15 #include "llvm/Support/FileUtilities.h"
16 #include "llvm/ADT/OwningPtr.h"
17 #include "llvm/ADT/SmallString.h" 16 #include "llvm/ADT/SmallString.h"
18 #include "llvm/Support/MemoryBuffer.h" 17 #include "llvm/Support/MemoryBuffer.h"
19 #include "llvm/Support/Path.h" 18 #include "llvm/Support/Path.h"
20 #include "llvm/Support/raw_ostream.h" 19 #include "llvm/Support/raw_ostream.h"
21 #include "llvm/Support/system_error.h"
22 #include <cctype> 20 #include <cctype>
23 #include <cstdlib> 21 #include <cstdlib>
24 #include <cstring> 22 #include <cstring>
23 #include <system_error>
25 using namespace llvm; 24 using namespace llvm;
26 25
27 static bool isSignedChar(char C) { 26 static bool isSignedChar(char C) {
28 return (C == '+' || C == '-'); 27 return (C == '+' || C == '-');
29 } 28 }
175 StringRef NameB, 174 StringRef NameB,
176 double AbsTol, double RelTol, 175 double AbsTol, double RelTol,
177 std::string *Error) { 176 std::string *Error) {
178 // Now its safe to mmap the files into memory because both files 177 // Now its safe to mmap the files into memory because both files
179 // have a non-zero size. 178 // have a non-zero size.
180 OwningPtr<MemoryBuffer> F1; 179 ErrorOr<std::unique_ptr<MemoryBuffer>> F1OrErr = MemoryBuffer::getFile(NameA);
181 if (error_code ec = MemoryBuffer::getFile(NameA, F1)) { 180 if (std::error_code EC = F1OrErr.getError()) {
182 if (Error) 181 if (Error)
183 *Error = ec.message(); 182 *Error = EC.message();
184 return 2; 183 return 2;
185 } 184 }
186 OwningPtr<MemoryBuffer> F2; 185 MemoryBuffer &F1 = *F1OrErr.get();
187 if (error_code ec = MemoryBuffer::getFile(NameB, F2)) { 186
187 ErrorOr<std::unique_ptr<MemoryBuffer>> F2OrErr = MemoryBuffer::getFile(NameB);
188 if (std::error_code EC = F2OrErr.getError()) {
188 if (Error) 189 if (Error)
189 *Error = ec.message(); 190 *Error = EC.message();
190 return 2; 191 return 2;
191 } 192 }
193 MemoryBuffer &F2 = *F2OrErr.get();
192 194
193 // Okay, now that we opened the files, scan them for the first difference. 195 // Okay, now that we opened the files, scan them for the first difference.
194 const char *File1Start = F1->getBufferStart(); 196 const char *File1Start = F1.getBufferStart();
195 const char *File2Start = F2->getBufferStart(); 197 const char *File2Start = F2.getBufferStart();
196 const char *File1End = F1->getBufferEnd(); 198 const char *File1End = F1.getBufferEnd();
197 const char *File2End = F2->getBufferEnd(); 199 const char *File2End = F2.getBufferEnd();
198 const char *F1P = File1Start; 200 const char *F1P = File1Start;
199 const char *F2P = File2Start; 201 const char *F2P = File2Start;
200 uint64_t A_size = F1->getBufferSize(); 202 uint64_t A_size = F1.getBufferSize();
201 uint64_t B_size = F2->getBufferSize(); 203 uint64_t B_size = F2.getBufferSize();
202 204
203 // Are the buffers identical? Common case: Handle this efficiently. 205 // Are the buffers identical? Common case: Handle this efficiently.
204 if (A_size == B_size && 206 if (A_size == B_size &&
205 std::memcmp(File1Start, File2Start, A_size) == 0) 207 std::memcmp(File1Start, File2Start, A_size) == 0)
206 return 0; 208 return 0;