retdec
Public Member Functions | Static Public Attributes | Private Member Functions | Private Attributes | List of all members
retdec::llvmir2hll::LlvmIr2Hll Class Reference

This class is the main chunk of code that converts an LLVM module to the specified high-level language (HLL). More...

#include <llvmir2hll.h>

Inheritance diagram for retdec::llvmir2hll::LlvmIr2Hll:
Inheritance graph
[legend]
Collaboration diagram for retdec::llvmir2hll::LlvmIr2Hll:
Collaboration graph
[legend]

Public Member Functions

 LlvmIr2Hll (retdec::config::Config *c=nullptr)
 Constructs a new decompiler. More...
 
virtual void getAnalysisUsage (llvm::AnalysisUsage &au) const override
 
virtual bool runOnModule (llvm::Module &m) override
 
void setConfig (retdec::config::Config *c)
 
void setOutputString (std::string *outString)
 

Static Public Attributes

static char ID = 0
 

Private Member Functions

bool initialize (llvm::Module &m)
 Initializes all the needed private variables. More...
 
void createSemantics ()
 Creates the used semantics. More...
 
void createSemanticsFromParameter ()
 Creates the used semantics as requested by the user. More...
 
void createSemanticsFromLLVMIR ()
 Creates the used semantics based on the data in the input LLVM IR. More...
 
bool loadConfig ()
 Loads a config for the module. More...
 
void saveConfig ()
 Saves the config file. More...
 
bool convertLLVMIRToBIR ()
 Convert the LLVM IR module into a BIR module using the instantiated converter. More...
 
void removeLibraryFuncs ()
 Removes defined functions which are from some standard library whose header file has to be included because of some function declarations. More...
 
void removeCodeUnreachableInCFG ()
 Removes code from all the functions in the module that is unreachable in the CFG. More...
 
void fixSignedUnsignedTypes ()
 Fixes signed and unsigned types in the resulting module. More...
 
void convertLLVMIntrinsicFunctions ()
 Converts LLVM intrinsic functions to functions from the standard library. More...
 
void obtainDebugInfo ()
 When available, obtains debugging information. More...
 
void initAliasAnalysis ()
 Initializes the alias analysis. More...
 
void runOptimizations ()
 Runs the optimizations over the resulting module. More...
 
void renameVariables ()
 Renames variables in the resulting module by using the selected variable renamer. More...
 
void convertConstantsToSymbolicNames ()
 Converts constants in function calls to symbolic names. More...
 
void validateResultingModule ()
 Validates the resulting module. More...
 
void findPatterns ()
 Finds patterns in the resulting module. More...
 
void emitCFGs ()
 Emits a control-flow graph (CFG) for each function in the resulting module. More...
 
void emitCG ()
 Emits a call graph (CG) for the resulting module. More...
 
void emitTargetHLLCode ()
 Emits the target HLL code. More...
 
void finalize ()
 Finalizes the run of the back-end part. More...
 
void cleanup ()
 Cleanup. More...
 
llvmir2hll::StringSet parseListOfOpts (const std::string &opts) const
 Parses the given list of optimizations. More...
 
std::string getTypeOfRunOptimizations () const
 Returns the type of optimizations that should be run (as a string). More...
 
llvmir2hll::StringVector getIdsOfPatternFindersToBeRun () const
 Returns the IDs of pattern finders to be run. More...
 
llvmir2hll::PatternFinderRunner::PatternFinders instantiatePatternFinders (const llvmir2hll::StringVector &pfsIds)
 Instantiates and returns the pattern finders described by their ID. More...
 
ShPtr< llvmir2hll::PatternFinderRunnerinstantiatePatternFinderRunner () const
 Instantiates and returns a proper PatternFinderRunner. More...
 

Private Attributes

llvm::Module * llvmModule = nullptr
 The input LLVM module. More...
 
ShPtr< llvmir2hll::ModuleresModule
 The resulting module in BIR. More...
 
ShPtr< llvmir2hll::Semanticssemantics
 The used semantics. More...
 
config::ConfigglobalConfig = nullptr
 The used config. More...
 
ShPtr< llvmir2hll::Configconfig
 
ShPtr< llvmir2hll::HLLWriterhllWriter
 The used HLL writer. More...
 
ShPtr< llvmir2hll::AliasAnalysisaliasAnalysis
 The used alias analysis. More...
 
ShPtr< llvmir2hll::CallInfoObtainercio
 The used obtainer of information about function and function calls. More...
 
ShPtr< llvmir2hll::ArithmExprEvaluatorarithmExprEvaluator
 The used evaluator of arithmetical expressions. More...
 
ShPtr< llvmir2hll::VarNameGenvarNameGen
 The used generator of variable names. More...
 
ShPtr< llvmir2hll::VarRenamervarRenamer
 The used renamer of variables. More...
 
std::unique_ptr< llvm::ToolOutputFile > outFile
 Output file stream. More...
 
std::unique_ptr< llvm::raw_string_ostream > outStringStream
 Output string stream. More...
 

Detailed Description

This class is the main chunk of code that converts an LLVM module to the specified high-level language (HLL).

The decompilation is composed of the following steps: 1) LLVM instantiates Decompiler with the output stream, where the target code will be emitted. 2) The function runOnModule() is called, which decompiles the given LLVM IR into BIR (backend IR). 3) The resulting IR is then converted into the requested HLL at the end of runOnModule().

The HLL is specified in -target-hll when running llvmir2hll. Debug comments can be enabled by using the -emit-debug-comments parameter. For more information, run llvmir2hll with -help.

Constructor & Destructor Documentation

◆ LlvmIr2Hll()

retdec::llvmir2hll::LlvmIr2Hll::LlvmIr2Hll ( retdec::config::Config c = nullptr)

Constructs a new decompiler.

Member Function Documentation

◆ cleanup()

void retdec::llvmir2hll::LlvmIr2Hll::cleanup ( )
private

Cleanup.

◆ convertConstantsToSymbolicNames()

void retdec::llvmir2hll::LlvmIr2Hll::convertConstantsToSymbolicNames ( )
private

Converts constants in function calls to symbolic names.

◆ convertLLVMIntrinsicFunctions()

void retdec::llvmir2hll::LlvmIr2Hll::convertLLVMIntrinsicFunctions ( )
private

Converts LLVM intrinsic functions to functions from the standard library.

◆ convertLLVMIRToBIR()

bool retdec::llvmir2hll::LlvmIr2Hll::convertLLVMIRToBIR ( )
private

Convert the LLVM IR module into a BIR module using the instantiated converter.

Returns
True if decompilation should continue, False if something went wrong and decompilation should abort.

◆ createSemantics()

void retdec::llvmir2hll::LlvmIr2Hll::createSemantics ( )
private

Creates the used semantics.

◆ createSemanticsFromLLVMIR()

void retdec::llvmir2hll::LlvmIr2Hll::createSemanticsFromLLVMIR ( )
private

Creates the used semantics based on the data in the input LLVM IR.

◆ createSemanticsFromParameter()

void retdec::llvmir2hll::LlvmIr2Hll::createSemanticsFromParameter ( )
private

Creates the used semantics as requested by the user.

◆ emitCFGs()

void retdec::llvmir2hll::LlvmIr2Hll::emitCFGs ( )
private

Emits a control-flow graph (CFG) for each function in the resulting module.

◆ emitCG()

void retdec::llvmir2hll::LlvmIr2Hll::emitCG ( )
private

Emits a call graph (CG) for the resulting module.

◆ emitTargetHLLCode()

void retdec::llvmir2hll::LlvmIr2Hll::emitTargetHLLCode ( )
private

Emits the target HLL code.

◆ finalize()

void retdec::llvmir2hll::LlvmIr2Hll::finalize ( )
private

Finalizes the run of the back-end part.

◆ findPatterns()

void retdec::llvmir2hll::LlvmIr2Hll::findPatterns ( )
private

Finds patterns in the resulting module.

◆ fixSignedUnsignedTypes()

void retdec::llvmir2hll::LlvmIr2Hll::fixSignedUnsignedTypes ( )
private

Fixes signed and unsigned types in the resulting module.

◆ getAnalysisUsage()

void retdec::llvmir2hll::LlvmIr2Hll::getAnalysisUsage ( llvm::AnalysisUsage &  au) const
overridevirtual

◆ getIdsOfPatternFindersToBeRun()

retdec::llvmir2hll::StringVector retdec::llvmir2hll::LlvmIr2Hll::getIdsOfPatternFindersToBeRun ( ) const
private

Returns the IDs of pattern finders to be run.

◆ getTypeOfRunOptimizations()

std::string retdec::llvmir2hll::LlvmIr2Hll::getTypeOfRunOptimizations ( ) const
private

Returns the type of optimizations that should be run (as a string).

◆ initAliasAnalysis()

void retdec::llvmir2hll::LlvmIr2Hll::initAliasAnalysis ( )
private

Initializes the alias analysis.

◆ initialize()

bool retdec::llvmir2hll::LlvmIr2Hll::initialize ( llvm::Module &  m)
private

Initializes all the needed private variables.

Returns
true if the decompilation should continue (the initialization went OK), false otherwise.

◆ instantiatePatternFinderRunner()

ShPtr< retdec::llvmir2hll::PatternFinderRunner > retdec::llvmir2hll::LlvmIr2Hll::instantiatePatternFinderRunner ( ) const
private

Instantiates and returns a proper PatternFinderRunner.

◆ instantiatePatternFinders()

retdec::llvmir2hll::PatternFinderRunner::PatternFinders retdec::llvmir2hll::LlvmIr2Hll::instantiatePatternFinders ( const llvmir2hll::StringVector pfsIds)
private

Instantiates and returns the pattern finders described by their ID.

If a pattern finder cannot be instantiated, a warning message is emitted.

◆ loadConfig()

bool retdec::llvmir2hll::LlvmIr2Hll::loadConfig ( )
private

Loads a config for the module.

Returns
true if the config was loaded successfully, false otherwise.

◆ obtainDebugInfo()

void retdec::llvmir2hll::LlvmIr2Hll::obtainDebugInfo ( )
private

When available, obtains debugging information.

◆ parseListOfOpts()

retdec::llvmir2hll::StringSet retdec::llvmir2hll::LlvmIr2Hll::parseListOfOpts ( const std::string &  opts) const
private

Parses the given list of optimizations.

opts should be a list of strings separated by a comma.

◆ removeCodeUnreachableInCFG()

void retdec::llvmir2hll::LlvmIr2Hll::removeCodeUnreachableInCFG ( )
private

Removes code from all the functions in the module that is unreachable in the CFG.

◆ removeLibraryFuncs()

void retdec::llvmir2hll::LlvmIr2Hll::removeLibraryFuncs ( )
private

Removes defined functions which are from some standard library whose header file has to be included because of some function declarations.

◆ renameVariables()

void retdec::llvmir2hll::LlvmIr2Hll::renameVariables ( )
private

Renames variables in the resulting module by using the selected variable renamer.

◆ runOnModule()

bool retdec::llvmir2hll::LlvmIr2Hll::runOnModule ( llvm::Module &  m)
overridevirtual

◆ runOptimizations()

void retdec::llvmir2hll::LlvmIr2Hll::runOptimizations ( )
private

Runs the optimizations over the resulting module.

◆ saveConfig()

void retdec::llvmir2hll::LlvmIr2Hll::saveConfig ( )
private

Saves the config file.

◆ setConfig()

void retdec::llvmir2hll::LlvmIr2Hll::setConfig ( retdec::config::Config c)

◆ setOutputString()

void retdec::llvmir2hll::LlvmIr2Hll::setOutputString ( std::string *  outString)

◆ validateResultingModule()

void retdec::llvmir2hll::LlvmIr2Hll::validateResultingModule ( )
private

Validates the resulting module.

Member Data Documentation

◆ aliasAnalysis

ShPtr<llvmir2hll::AliasAnalysis> retdec::llvmir2hll::LlvmIr2Hll::aliasAnalysis
private

The used alias analysis.

◆ arithmExprEvaluator

ShPtr<llvmir2hll::ArithmExprEvaluator> retdec::llvmir2hll::LlvmIr2Hll::arithmExprEvaluator
private

The used evaluator of arithmetical expressions.

◆ cio

ShPtr<llvmir2hll::CallInfoObtainer> retdec::llvmir2hll::LlvmIr2Hll::cio
private

The used obtainer of information about function and function calls.

◆ config

ShPtr<llvmir2hll::Config> retdec::llvmir2hll::LlvmIr2Hll::config
private

◆ globalConfig

config::Config* retdec::llvmir2hll::LlvmIr2Hll::globalConfig = nullptr
private

The used config.

◆ hllWriter

ShPtr<llvmir2hll::HLLWriter> retdec::llvmir2hll::LlvmIr2Hll::hllWriter
private

The used HLL writer.

◆ ID

char retdec::llvmir2hll::LlvmIr2Hll::ID = 0
static

◆ llvmModule

llvm::Module* retdec::llvmir2hll::LlvmIr2Hll::llvmModule = nullptr
private

The input LLVM module.

◆ outFile

std::unique_ptr<llvm::ToolOutputFile> retdec::llvmir2hll::LlvmIr2Hll::outFile
private

Output file stream.

◆ outStringStream

std::unique_ptr<llvm::raw_string_ostream> retdec::llvmir2hll::LlvmIr2Hll::outStringStream
private

Output string stream.

◆ resModule

ShPtr<llvmir2hll::Module> retdec::llvmir2hll::LlvmIr2Hll::resModule
private

The resulting module in BIR.

◆ semantics

ShPtr<llvmir2hll::Semantics> retdec::llvmir2hll::LlvmIr2Hll::semantics
private

The used semantics.

◆ varNameGen

ShPtr<llvmir2hll::VarNameGen> retdec::llvmir2hll::LlvmIr2Hll::varNameGen
private

The used generator of variable names.

◆ varRenamer

ShPtr<llvmir2hll::VarRenamer> retdec::llvmir2hll::LlvmIr2Hll::varRenamer
private

The used renamer of variables.


The documentation for this class was generated from the following files: