Files
revng-revng/tools/model/inject/Main.cpp
Alessandro Di Federico 3980ee3fad Introduce model tools
2022-01-31 16:28:14 +01:00

48 lines
1.5 KiB
C++

/// \file Main.cpp
/// \brief
//
// This file is distributed under the MIT License. See LICENSE.md for details.
//
#include <string>
#include "llvm/Support/CommandLine.h"
#include "revng/Model/ToolHelpers.h"
using namespace llvm;
static cl::OptionCategory ThisToolCategory("Tool options", "");
static ModelOutputOptions<false> Options(ThisToolCategory);
static cl::opt<std::string> NewModelPath(cl::Positional,
cl::cat(ThisToolCategory),
cl::desc("<new model file>"),
cl::value_desc("newmodel"));
static cl::opt<std::string> InputModulePath(cl::Positional,
cl::cat(ThisToolCategory),
cl::desc("<input module file>"),
cl::init("-"),
cl::value_desc("module"));
int main(int Argc, char *Argv[]) {
cl::HideUnrelatedOptions({ &ThisToolCategory });
cl::ParseCommandLineOptions(Argc, Argv);
auto OldModel = ModelInModule::loadModule(InputModulePath);
auto NewModel = ModelInModule::loadYAML(NewModelPath);
ExitOnError ExitOnError;
if (not OldModel)
ExitOnError(OldModel.takeError());
if (not NewModel)
ExitOnError(NewModel.takeError());
OldModel->Model = std::move(NewModel->Model);
ExitOnError(OldModel->save(Options.getPath(),
Options.getDesiredOutput(OldModel->hasModule())));
}