blob: 1663692e8b9c5dafbd3806cb6ed4c5f084cf5974 [file] [log] [blame]
Chris Lattner337481a2004-04-13 20:55:49 +00001//===- fpcmp.cpp - A fuzzy "cmp" that permits floating point noise --------===//
2//
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.
7//
8//===----------------------------------------------------------------------===//
9//
10// fpcmp is a tool that basically works like the 'cmp' tool, except that it can
Chris Lattner537a49a2005-01-23 03:15:47 +000011// tolerate errors due to floating point noise, with the -r and -a options.
Chris Lattner337481a2004-04-13 20:55:49 +000012//
13//===----------------------------------------------------------------------===//
14
Reid Spencer551ccae2004-09-01 22:55:40 +000015#include "llvm/Support/CommandLine.h"
Chris Lattner537a49a2005-01-23 03:15:47 +000016#include "llvm/Support/FileUtilities.h"
Chris Lattner337481a2004-04-13 20:55:49 +000017#include <iostream>
18#include <cmath>
19
20using namespace llvm;
21
22namespace {
23 cl::opt<std::string>
24 File1(cl::Positional, cl::desc("<input file #1>"), cl::Required);
25 cl::opt<std::string>
26 File2(cl::Positional, cl::desc("<input file #2>"), cl::Required);
27
28 cl::opt<double>
29 RelTolerance("r", cl::desc("Relative error tolerated"), cl::init(0));
30 cl::opt<double>
31 AbsTolerance("a", cl::desc("Absolute error tolerated"), cl::init(0));
32}
33
Chris Lattner337481a2004-04-13 20:55:49 +000034int main(int argc, char **argv) {
35 cl::ParseCommandLineOptions(argc, argv);
36
Chris Lattner537a49a2005-01-23 03:15:47 +000037 std::string ErrorMsg;
38 int DF = DiffFilesWithTolerance(File1, File2, AbsTolerance, RelTolerance,
39 &ErrorMsg);
40 if (!ErrorMsg.empty())
41 std::cerr << argv[0] << ": " << ErrorMsg << "\n";
42 return DF;
Chris Lattner337481a2004-04-13 20:55:49 +000043}
44