Go to the documentation of this file.
26 #include <system_error>
31 return (
C ==
'+' ||
C ==
'-');
39 case 'E':
return true;
40 default:
return false;
46 case '0':
case '1':
case '2':
case '3':
case '4':
47 case '5':
case '6':
case '7':
case '8':
case '9':
48 case '.':
return true;
53 static const char *
BackupNumber(
const char *Pos,
const char *FirstChar) {
58 bool HasPeriod =
false;
85 const char *F1End,
const char *F2End,
86 double AbsTolerance,
double RelTolerance,
87 std::string *ErrorMsg) {
88 const char *F1NumEnd, *F2NumEnd;
89 double V1 = 0.0,
V2 = 0.0;
93 while (isSpace(
static_cast<unsigned char>(*F1P)) && F1P != F1End)
95 while (isSpace(
static_cast<unsigned char>(*F2P)) && F2P != F2End)
107 V1 = strtod(F1P,
const_cast<char**
>(&F1NumEnd));
108 V2 = strtod(F2P,
const_cast<char**
>(&F2NumEnd));
110 if (*F1NumEnd ==
'D' || *F1NumEnd ==
'd') {
114 StrTmp[
static_cast<unsigned>(F1NumEnd-F1P)] =
'e';
116 V1 = strtod(&StrTmp[0],
const_cast<char**
>(&F1NumEnd));
117 F1NumEnd = F1P + (F1NumEnd-&StrTmp[0]);
120 if (*F2NumEnd ==
'D' || *F2NumEnd ==
'd') {
124 StrTmp[
static_cast<unsigned>(F2NumEnd-F2P)] =
'e';
126 V2 = strtod(&StrTmp[0],
const_cast<char**
>(&F2NumEnd));
127 F2NumEnd = F2P + (F2NumEnd-&StrTmp[0]);
131 if (F1NumEnd == F1P || F2NumEnd == F2P) {
133 *ErrorMsg =
"FP Comparison failed, not a numeric difference between '";
135 *ErrorMsg +=
"' and '";
152 if (Diff > RelTolerance) {
155 <<
"Compared: " << V1 <<
" and " <<
V2 <<
'\n'
156 <<
"abs. diff = " <<
std::abs(V1-
V2) <<
" rel.diff = " << Diff <<
'\n'
157 <<
"Out of tolerance: rel/abs: " << RelTolerance <<
'/'
165 F1P = F1NumEnd; F2P = F2NumEnd;
179 double AbsTol,
double RelTol,
180 std::string *
Error) {
184 if (std::error_code EC = F1OrErr.
getError()) {
186 *
Error = EC.message();
192 if (std::error_code EC = F2OrErr.
getError()) {
194 *
Error = EC.message();
204 const char *F1P = File1Start;
205 const char *F2P = File2Start;
210 if (A_size == B_size &&
215 if (AbsTol == 0 && RelTol == 0) {
217 *
Error =
"Files differ without tolerance allowance";
221 bool CompareFailed =
false;
224 while (F1P < File1End && F2P < File2End && *F1P == *F2P) {
229 if (F1P >= File1End || F2P >= File2End)
break;
240 CompareFailed =
true;
247 bool F1AtEnd = F1P >= File1End;
248 bool F2AtEnd = F2P >= File2End;
249 if (!CompareFailed && (!F1AtEnd || !F2AtEnd)) {
259 CompareFailed =
true;
262 if (F1P < File1End || F2P < File2End)
263 CompareFailed =
true;
266 return CompareFailed;
270 OS <<
"atomic_write_error: ";
273 OS <<
"failed_to_create_uniq_file";
276 OS <<
"output_stream_error";
279 OS <<
"failed_to_rename_temp_file";
283 "failed_to_rename_temp_file::log()");
301 return llvm::make_error<AtomicFileWriteError>(
314 return llvm::make_error<AtomicFileWriteError>(
319 return llvm::make_error<AtomicFileWriteError>(
331 if (InputFilename !=
"-") {
346 if (OverwritePermissions)
347 Status.permissions(*OverwritePermissions);
362 FD,
Status.getLastAccessedTime(),
Status.getLastModificationTime()))
static const char * BackupNumber(const char *Pos, const char *FirstChar)
std::error_code openFileForWrite(const Twine &Name, int &ResultFD, CreationDisposition Disp=CD_CreateAlways, OpenFlags Flags=OF_None, unsigned Mode=0666)
Opens the file with the given name in a write-only or read-write mode, returning its open file descri...
This is an optimization pass for GlobalISel generic memory operations.
void close()
Manually flush the stream and close the file.
FileRemover - This class is a simple object meant to be stack allocated.
A raw_ostream that writes to an std::string.
void releaseFile()
releaseFile - Take ownership of the file away from the FileRemover so it will not be removed when the...
FilePermssionsApplier helps to copy permissions from an input file to an output one.
static ErrorSuccess success()
Create a success value.
Merge contiguous icmps into a memcmp
std::error_code createUniqueFile(const Twine &Model, int &ResultFD, SmallVectorImpl< char > &ResultPath, OpenFlags Flags=OF_None, unsigned Mode=all_read|all_write)
Create a uniquely named file.
static Expected< FilePermissionsApplier > create(StringRef InputFilename)
@ CD_OpenExisting
CD_OpenExisting - When opening a file:
Tagged union holding either a T or a Error.
std::error_code setLastAccessAndModificationTime(int FD, TimePoint<> AccessTime, TimePoint<> ModificationTime)
Set the file modification and access time.
__FakeVCSRevision h endif() endif() set(generated_files "$
This interface provides simple read-only access to a block of memory, and provides simple methods for...
static bool isExponentChar(char C)
static cl::opt< std::string > InputFilename(cl::Positional, cl::desc("<input file>"), cl::init("-"))
static ErrorOr< std::unique_ptr< MemoryBuffer > > getFile(const Twine &Filename, bool IsText=false, bool RequiresNullTerminator=true, bool IsVolatile=false)
Open the specified file as a MemoryBuffer, returning a new MemoryBuffer if successful,...
llvm::Error writeFileAtomically(StringRef TempPathModel, StringRef FinalPath, StringRef Buffer)
Creates a unique file with name according to the given TempPathModel, writes content of Buffer to the...
const char * getBufferEnd() const
bool has_error() const
Return the value of the flag in this raw_fd_ostream indicating whether an output error has been encou...
Error createFileError(const Twine &F, Error E)
Concatenate a source file path and/or name with an Error.
size_t getBufferSize() const
static bool isSignedChar(char C)
(vector float) vec_cmpeq(*A, *B) C
void clear_error()
Set the flag read by has_error() to false.
std::error_code getError() const
@ failed_to_rename_temp_file
raw_ostream & write(unsigned char C)
This class implements an extremely fast bulk output stream that can only output to a stream.
std::error_code changeFileOwnership(int FD, uint32_t Owner, uint32_t Group)
Change ownership of a file.
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
static std::error_code SafelyCloseFileDescriptor(int FD)
Represents the result of a call to sys::fs::status().
Error apply(StringRef OutputFilename, bool CopyDates=false, Optional< sys::fs::perms > OverwritePermissions=None)
Apply stored permissions to the OutputFilename.
print Print MemDeps of function
std::error_code setPermissions(const Twine &Path, perms Permissions)
Set file permissions.
StringRef - Represent a constant reference to a string, i.e.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
std::error_code rename(const Twine &from, const Twine &to)
Rename from to to.
void log(raw_ostream &OS) const override
Print an error message to an output stream.
@ failed_to_create_uniq_file
A raw_ostream that writes to a file descriptor.
constexpr LLVM_NODISCARD size_t size() const
size - Get the string size.
const char * getBufferStart() const
Lightweight error class with error context and mandatory checking.
int DiffFilesWithTolerance(StringRef FileA, StringRef FileB, double AbsTol, double RelTol, std::string *Error=nullptr)
DiffFilesWithTolerance - Compare the two files specified, returning 0 if the files match,...
static bool CompareNumbers(const char *&F1P, const char *&F2P, const char *F1End, const char *F2End, double AbsTolerance, double RelTolerance, std::string *ErrorMsg)
CompareNumbers - compare two numbers, returning true if they are different.
unsigned getUmask()
Get file creation mode mask of the process.
static cl::opt< std::string > OutputFilename("o", cl::desc("Output filename"), cl::value_desc("filename"), cl::init("-"))
std::error_code status(const Twine &path, file_status &result, bool follow=true)
Get file status as if by POSIX stat().
Represents either an error or a value T.
const LLVM_NODISCARD char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
static bool isNumberChar(char C)
static const char * EndOfNumber(const char *Pos)
EndOfNumber - Return the first character that is not part of the specified number.
APFloat abs(APFloat X)
Returns the absolute value of the argument.