Files
revng-revng/tools/link-for-translation/Main.cpp
Massimo Fioravanti ce4934f48d Introduce revng-link-for-translation
`revng-link-for-translation` provides a standalone tool needed to
perform the final linking stage of the recompilation.
2022-03-28 12:17:05 +02:00

67 lines
2.0 KiB
C++

/// \file Main.cpp
//
// This file is distributed under the MIT License. See LICENSE.md for details.
//
#include <cstdlib>
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/DynamicLibrary.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/raw_os_ostream.h"
#include "revng/Recompile/LinkForTranslation.h"
#include "revng/TupleTree/TupleTree.h"
using std::string;
using namespace llvm;
using namespace llvm::cl;
class StringPositionalArgument : public opt<string> {
public:
StringPositionalArgument(const char *Description) :
opt<string>(Positional, Required, desc(Description), cat(MainCategory)) {}
};
StringPositionalArgument Input("Input binary");
StringPositionalArgument ModelFile("Input model");
StringPositionalArgument ObjectFile("Object file");
auto OutputDescription = desc("Output translated file");
static opt<string> Output("o", init("-"), OutputDescription, cat(MainCategory));
static opt<bool> Verbose("verbose",
desc("Print explanation while running"),
cat(MainCategory),
init(false));
static opt<bool> DryRun("dry-run",
desc("Don't do anything. Useful with --verbose"),
cat(MainCategory),
init(false));
static ExitOnError AbortOnError;
int main(int argc, const char *argv[]) {
HideUnrelatedOptions({ &MainCategory });
ParseCommandLineOptions(argc, argv);
auto MaybeModel = TupleTree<model::Binary>::fromFile(ModelFile);
auto ExpectedModel = llvm::errorOrToExpected(std::move(MaybeModel));
auto Model = AbortOnError(std::move(ExpectedModel));
if (Verbose) {
printLinkForTranslationCommands(llvm::outs(),
*Model,
Input,
ObjectFile,
Output);
}
if (not DryRun)
linkForTranslation(*Model, Input, ObjectFile, Output);
return EXIT_SUCCESS;
}