27#include <system_error>
32 return (
C ==
'+' ||
C ==
'-');
40 case 'E':
return true;
41 default:
return false;
47 case '0':
case '1':
case '2':
case '3':
case '4':
48 case '5':
case '6':
case '7':
case '8':
case '9':
49 case '.':
return true;
54static const char *
BackupNumber(
const char *Pos,
const char *FirstChar) {
59 bool HasPeriod =
false;
86 const char *F1End,
const char *F2End,
87 double AbsTolerance,
double RelTolerance,
88 std::string *ErrorMsg) {
89 const char *F1NumEnd, *F2NumEnd;
90 double V1 = 0.0, V2 = 0.0;
94 while (isSpace(
static_cast<unsigned char>(*F1P)) && F1P != F1End)
96 while (isSpace(
static_cast<unsigned char>(*F2P)) && F2P != F2End)
108 V1 = strtod(F1P,
const_cast<char**
>(&F1NumEnd));
109 V2 = strtod(F2P,
const_cast<char**
>(&F2NumEnd));
111 if (*F1NumEnd ==
'D' || *F1NumEnd ==
'd') {
115 StrTmp[
static_cast<unsigned>(F1NumEnd-F1P)] =
'e';
117 V1 = strtod(&StrTmp[0],
const_cast<char**
>(&F1NumEnd));
118 F1NumEnd = F1P + (F1NumEnd-&StrTmp[0]);
121 if (*F2NumEnd ==
'D' || *F2NumEnd ==
'd') {
125 StrTmp[
static_cast<unsigned>(F2NumEnd-F2P)] =
'e';
127 V2 = strtod(&StrTmp[0],
const_cast<char**
>(&F2NumEnd));
128 F2NumEnd = F2P + (F2NumEnd-&StrTmp[0]);
132 if (F1NumEnd == F1P || F2NumEnd == F2P) {
134 *ErrorMsg =
"FP Comparison failed, not a numeric difference between '";
136 *ErrorMsg +=
"' and '";
144 if (AbsTolerance < std::abs(V1-V2)) {
148 Diff = std::abs(V1/V2 - 1.0);
150 Diff = std::abs(V2/V1 - 1.0);
153 if (Diff > RelTolerance) {
156 <<
"Compared: " << V1 <<
" and " << V2 <<
'\n'
157 <<
"abs. diff = " << std::abs(V1-V2) <<
" rel.diff = " << Diff <<
'\n'
158 <<
"Out of tolerance: rel/abs: " << RelTolerance <<
'/'
166 F1P = F1NumEnd; F2P = F2NumEnd;
180 double AbsTol,
double RelTol,
181 std::string *
Error) {
185 if (std::error_code EC = F1OrErr.
getError()) {
187 *
Error = EC.message();
193 if (std::error_code EC = F2OrErr.
getError()) {
195 *
Error = EC.message();
205 const char *F1P = File1Start;
206 const char *F2P = File2Start;
211 if (A_size == B_size &&
212 std::memcmp(File1Start, File2Start, A_size) == 0)
216 if (AbsTol == 0 && RelTol == 0) {
218 *
Error =
"Files differ without tolerance allowance";
222 bool CompareFailed =
false;
225 while (F1P < File1End && F2P < File2End && *F1P == *F2P) {
230 if (F1P >= File1End || F2P >= File2End)
break;
241 CompareFailed =
true;
248 bool F1AtEnd = F1P >= File1End;
249 bool F2AtEnd = F2P >= File2End;
250 if (!CompareFailed && (!F1AtEnd || !F2AtEnd)) {
260 CompareFailed =
true;
263 if (F1P < File1End || F2P < File2End)
264 CompareFailed =
true;
267 return CompareFailed;
274 if (InputFilename !=
"-") {
286 std::optional<sys::fs::perms> OverwritePermissions) {
289 if (OverwritePermissions)
290 Status.permissions(*OverwritePermissions);
305 FD,
Status.getLastAccessedTime(),
Status.getLastModificationTime()))
Provides ErrorOr<T> smart pointer.
static const char * BackupNumber(const char *Pos, const char *FirstChar)
static const char * EndOfNumber(const char *Pos)
EndOfNumber - Return the first character that is not part of the specified number.
static bool isExponentChar(char C)
static bool isSignedChar(char C)
static bool isNumberChar(char C)
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.
static cl::opt< std::string > OutputFilename("o", cl::desc("Output filename"), cl::value_desc("filename"), cl::init("-"))
static cl::opt< std::string > InputFilename(cl::Positional, cl::desc("<input file>"), cl::init("-"))
Provides a library for accessing information about this process and other processes on the operating ...
This file defines the SmallString class.
Represents either an error or a value T.
std::error_code getError() const
Lightweight error class with error context and mandatory checking.
static ErrorSuccess success()
Create a success value.
Tagged union holding either a T or a Error.
FilePermssionsApplier helps to copy permissions from an input file to an output one.
Error apply(StringRef OutputFilename, bool CopyDates=false, std::optional< sys::fs::perms > OverwritePermissions=std::nullopt)
Apply stored permissions to the OutputFilename.
static Expected< FilePermissionsApplier > create(StringRef InputFilename)
This interface provides simple read-only access to a block of memory, and provides simple methods for...
size_t getBufferSize() const
static ErrorOr< std::unique_ptr< MemoryBuffer > > getFile(const Twine &Filename, bool IsText=false, bool RequiresNullTerminator=true, bool IsVolatile=false, std::optional< Align > Alignment=std::nullopt)
Open the specified file as a MemoryBuffer, returning a new MemoryBuffer if successful,...
const char * getBufferEnd() const
const char * getBufferStart() const
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
StringRef - Represent a constant reference to a string, i.e.
A raw_ostream that writes to an std::string.
static std::error_code SafelyCloseFileDescriptor(int FD)
Represents the result of a call to sys::fs::status().
@ C
The default llvm calling convention, compatible with C.
std::error_code setLastAccessAndModificationTime(int FD, TimePoint<> AccessTime, TimePoint<> ModificationTime)
Set the file modification and access time.
std::error_code status(const Twine &path, file_status &result, bool follow=true)
Get file status as if by POSIX stat().
std::error_code changeFileOwnership(int FD, uint32_t Owner, uint32_t Group)
Change ownership of a file.
@ CD_OpenExisting
CD_OpenExisting - When opening a file:
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...
unsigned getUmask()
Get file creation mode mask of the process.
std::error_code setPermissions(const Twine &Path, perms Permissions)
Set file permissions.
This is an optimization pass for GlobalISel generic memory operations.
Error createFileError(const Twine &F, Error E)
Concatenate a source file path and/or name with an Error.
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,...