Chris Lattner | 337481a | 2004-04-13 20:55:49 +0000 | [diff] [blame] | 1 | //===- fpcmp.cpp - A fuzzy "cmp" that permits floating point noise --------===// |
Misha Brukman | 3da94ae | 2005-04-22 00:00:37 +0000 | [diff] [blame] | 2 | // |
Chris Lattner | 337481a | 2004-04-13 20:55:49 +0000 | [diff] [blame] | 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file was developed by the LLVM research group and is distributed under |
| 6 | // the University of Illinois Open Source License. See LICENSE.TXT for details. |
Misha Brukman | 3da94ae | 2005-04-22 00:00:37 +0000 | [diff] [blame] | 7 | // |
Chris Lattner | 337481a | 2004-04-13 20:55:49 +0000 | [diff] [blame] | 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // fpcmp is a tool that basically works like the 'cmp' tool, except that it can |
Chris Lattner | 537a49a | 2005-01-23 03:15:47 +0000 | [diff] [blame] | 11 | // tolerate errors due to floating point noise, with the -r and -a options. |
Chris Lattner | 337481a | 2004-04-13 20:55:49 +0000 | [diff] [blame] | 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
Reid Spencer | 551ccae | 2004-09-01 22:55:40 +0000 | [diff] [blame] | 15 | #include "llvm/Support/CommandLine.h" |
Chris Lattner | 537a49a | 2005-01-23 03:15:47 +0000 | [diff] [blame] | 16 | #include "llvm/Support/FileUtilities.h" |
Chris Lattner | 337481a | 2004-04-13 20:55:49 +0000 | [diff] [blame] | 17 | #include <iostream> |
Chris Lattner | 337481a | 2004-04-13 20:55:49 +0000 | [diff] [blame] | 18 | using namespace llvm; |
| 19 | |
| 20 | namespace { |
| 21 | cl::opt<std::string> |
| 22 | File1(cl::Positional, cl::desc("<input file #1>"), cl::Required); |
| 23 | cl::opt<std::string> |
| 24 | File2(cl::Positional, cl::desc("<input file #2>"), cl::Required); |
| 25 | |
| 26 | cl::opt<double> |
| 27 | RelTolerance("r", cl::desc("Relative error tolerated"), cl::init(0)); |
| 28 | cl::opt<double> |
| 29 | AbsTolerance("a", cl::desc("Absolute error tolerated"), cl::init(0)); |
| 30 | } |
| 31 | |
Chris Lattner | 337481a | 2004-04-13 20:55:49 +0000 | [diff] [blame] | 32 | int main(int argc, char **argv) { |
| 33 | cl::ParseCommandLineOptions(argc, argv); |
| 34 | |
Chris Lattner | 537a49a | 2005-01-23 03:15:47 +0000 | [diff] [blame] | 35 | std::string ErrorMsg; |
Chris Lattner | 417c4d5 | 2005-01-23 03:32:16 +0000 | [diff] [blame] | 36 | int DF = DiffFilesWithTolerance(sys::Path(File1), sys::Path(File2), |
| 37 | AbsTolerance, RelTolerance, &ErrorMsg); |
Chris Lattner | 537a49a | 2005-01-23 03:15:47 +0000 | [diff] [blame] | 38 | if (!ErrorMsg.empty()) |
| 39 | std::cerr << argv[0] << ": " << ErrorMsg << "\n"; |
| 40 | return DF; |
Chris Lattner | 337481a | 2004-04-13 20:55:49 +0000 | [diff] [blame] | 41 | } |
| 42 | |