Files
revng-revng/tests/Unit/DecompileFunction.cpp
T
Pietro Fezzardi a23a89fd61 DecompileFunction: improve test efficiency
Now we don't iterate over all the Functions in a Module, but we use the
Model to detect the first isolated function.
2021-02-23 11:09:36 +01:00

37 lines
1.0 KiB
C++

//
// Copyright rev.ng Srls. See LICENSE.md for details.
//
#include <iostream>
#include <string>
#include "llvm/IR/Function.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/Module.h"
#include "llvm/IRReader/IRReader.h"
#include "llvm/Support/SourceMgr.h"
#include "revng/Model/LoadModelPass.h"
#include "revng/Support/Debug.h"
#include "revng-c/Decompiler/CDecompiler.h"
int main(int argc, char **argv) {
revng_check(argc == 2);
llvm::SMDiagnostic Errors;
llvm::LLVMContext TestContext;
std::unique_ptr<llvm::Module> M = llvm::parseIRFile(argv[1],
Errors,
TestContext);
model::Binary Model = LoadModelPass::getModel(*M);
revng_check(not Model.Functions.empty(),
"Unable to find an isolated function");
const model::Function &F = *Model.Functions.begin();
std::string CCode = decompileFunction(M.get(), F.Name);
revng_check(not CCode.empty(), "Decompiled function is empty");
return 0;
}