Files
revng-revng/tools/model/diff/Main.cpp
Alessandro Di Federico 0742699a81 s/OutputFilename/OutputPath/g
2026-04-23 13:40:42 +02:00

71 lines
2.4 KiB
C++

//
// This file is distributed under the MIT License. See LICENSE.md for details.
//
#include <string>
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/ToolOutputFile.h"
#include "llvm/Support/raw_ostream.h"
#include "revng/Model/Binary.h"
#include "revng/Support/InitRevng.h"
#include "revng/Support/MetaAddress/YAMLTraits.h"
#include "revng/Support/YAMLTraits.h"
#include "revng/TupleTree/TupleTreeDiff.h"
namespace cl = llvm::cl;
static cl::OptionCategory ThisToolCategory("Tool options", "");
static cl::opt<std::string> LeftModelPath(cl::Positional,
cl::cat(ThisToolCategory),
cl::desc("<left input model>"),
cl::init("-"),
cl::value_desc("left model"));
static cl::opt<std::string> RightModelPath(cl::Positional,
cl::cat(ThisToolCategory),
cl::desc("<right input model>"),
cl::value_desc("right model"));
static cl::opt<std::string> OutputPath("o",
cl::cat(ThisToolCategory),
cl::init("-"),
llvm::cl::desc("Override "
"output "
"filename"),
llvm::cl::value_desc("filename"));
int main(int Argc, char *Argv[]) {
revng::InitRevng X(Argc, Argv, "", { &ThisToolCategory });
llvm::ExitOnError ExitOnError;
auto LeftModel = TupleTree<model::Binary>::fromFileOrSTDIN(LeftModelPath);
if (not LeftModel)
ExitOnError(LeftModel.takeError());
auto RightModel = TupleTree<model::Binary>::fromFileOrSTDIN(RightModelPath);
if (not RightModel)
ExitOnError(RightModel.takeError());
std::error_code EC;
llvm::ToolOutputFile OutputFile(OutputPath,
EC,
llvm::sys::fs::OpenFlags::OF_Text);
if (EC)
ExitOnError(llvm::createStringError(EC, EC.message()));
auto &Stream = OutputFile.os();
auto Diff = diff(**LeftModel, **RightModel);
Diff.dump(Stream);
OutputFile.keep();
if (Diff.Changes.empty())
return EXIT_SUCCESS;
else
return EXIT_FAILURE;
}