fpcmp.cpp 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. //===- fpcmp.cpp - A fuzzy "cmp" that permits floating point noise --------===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. //
  10. // fpcmp is a tool that basically works like the 'cmp' tool, except that it can
  11. // tolerate errors due to floating point noise, with the -r and -a options.
  12. //
  13. //===----------------------------------------------------------------------===//
  14. #include "llvm/Support/CommandLine.h"
  15. #include "llvm/Support/FileUtilities.h"
  16. #include "llvm/Support/raw_ostream.h"
  17. using namespace llvm;
  18. namespace {
  19. cl::opt<std::string>
  20. File1(cl::Positional, cl::desc("<input file #1>"), cl::Required);
  21. cl::opt<std::string>
  22. File2(cl::Positional, cl::desc("<input file #2>"), cl::Required);
  23. cl::opt<double>
  24. RelTolerance("r", cl::desc("Relative error tolerated"), cl::init(0));
  25. cl::opt<double>
  26. AbsTolerance("a", cl::desc("Absolute error tolerated"), cl::init(0));
  27. }
  28. int main(int argc, char **argv) {
  29. cl::ParseCommandLineOptions(argc, argv);
  30. std::string ErrorMsg;
  31. int DF = DiffFilesWithTolerance(File1, File2, AbsTolerance, RelTolerance,
  32. &ErrorMsg);
  33. if (!ErrorMsg.empty())
  34. errs() << argv[0] << ": " << ErrorMsg << "\n";
  35. return DF;
  36. }