blob: 66d8ab159b931dabe35e749585987e57838a175f [file] [log] [blame]
Chris Lattner337481a2004-04-13 20:55:49 +00001//===- fpcmp.cpp - A fuzzy "cmp" that permits floating point noise --------===//
Misha Brukman3da94ae2005-04-22 00:00:37 +00002//
Chris Lattner337481a2004-04-13 20:55:49 +00003// The LLVM Compiler Infrastructure
4//
Chris Lattner30609102007-12-29 20:37:13 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Misha Brukman3da94ae2005-04-22 00:00:37 +00007//
Chris Lattner337481a2004-04-13 20:55:49 +00008//===----------------------------------------------------------------------===//
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>
Chris Lattner337481a2004-04-13 20:55:49 +000018using namespace llvm;
19
20namespace {
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 Lattner337481a2004-04-13 20:55:49 +000032int main(int argc, char **argv) {
33 cl::ParseCommandLineOptions(argc, argv);
34
Chris Lattner537a49a2005-01-23 03:15:47 +000035 std::string ErrorMsg;
Reid Spencer8e27acf2007-04-07 19:49:35 +000036 int DF = DiffFilesWithTolerance(sys::PathWithStatus(File1),
37 sys::PathWithStatus(File2),
Chris Lattner417c4d52005-01-23 03:32:16 +000038 AbsTolerance, RelTolerance, &ErrorMsg);
Chris Lattner537a49a2005-01-23 03:15:47 +000039 if (!ErrorMsg.empty())
40 std::cerr << argv[0] << ": " << ErrorMsg << "\n";
41 return DF;
Chris Lattner337481a2004-04-13 20:55:49 +000042}
43