xref: /netbsd-src/external/apache2/llvm/dist/llvm/utils/fpcmp/fpcmp.cpp (revision 7330f729ccf0bd976a06f95fad452fe774fc7fd1)
1*7330f729Sjoerg //===- fpcmp.cpp - A fuzzy "cmp" that permits floating point noise --------===//
2*7330f729Sjoerg //
3*7330f729Sjoerg // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4*7330f729Sjoerg // See https://llvm.org/LICENSE.txt for license information.
5*7330f729Sjoerg // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6*7330f729Sjoerg //
7*7330f729Sjoerg //===----------------------------------------------------------------------===//
8*7330f729Sjoerg //
9*7330f729Sjoerg // fpcmp is a tool that basically works like the 'cmp' tool, except that it can
10*7330f729Sjoerg // tolerate errors due to floating point noise, with the -r and -a options.
11*7330f729Sjoerg //
12*7330f729Sjoerg //===----------------------------------------------------------------------===//
13*7330f729Sjoerg 
14*7330f729Sjoerg #include "llvm/Support/CommandLine.h"
15*7330f729Sjoerg #include "llvm/Support/FileUtilities.h"
16*7330f729Sjoerg #include "llvm/Support/raw_ostream.h"
17*7330f729Sjoerg using namespace llvm;
18*7330f729Sjoerg 
19*7330f729Sjoerg namespace {
20*7330f729Sjoerg   cl::opt<std::string>
21*7330f729Sjoerg   File1(cl::Positional, cl::desc("<input file #1>"), cl::Required);
22*7330f729Sjoerg   cl::opt<std::string>
23*7330f729Sjoerg   File2(cl::Positional, cl::desc("<input file #2>"), cl::Required);
24*7330f729Sjoerg 
25*7330f729Sjoerg   cl::opt<double>
26*7330f729Sjoerg   RelTolerance("r", cl::desc("Relative error tolerated"), cl::init(0));
27*7330f729Sjoerg   cl::opt<double>
28*7330f729Sjoerg   AbsTolerance("a", cl::desc("Absolute error tolerated"), cl::init(0));
29*7330f729Sjoerg }
30*7330f729Sjoerg 
main(int argc,char ** argv)31*7330f729Sjoerg int main(int argc, char **argv) {
32*7330f729Sjoerg   cl::ParseCommandLineOptions(argc, argv);
33*7330f729Sjoerg 
34*7330f729Sjoerg   std::string ErrorMsg;
35*7330f729Sjoerg   int DF = DiffFilesWithTolerance(File1, File2, AbsTolerance, RelTolerance,
36*7330f729Sjoerg                                   &ErrorMsg);
37*7330f729Sjoerg   if (!ErrorMsg.empty())
38*7330f729Sjoerg     errs() << argv[0] << ": " << ErrorMsg << "\n";
39*7330f729Sjoerg   return DF;
40*7330f729Sjoerg }
41*7330f729Sjoerg 
42