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

A converter of LLVM IR to BIR. More...

#include <llvmir2bir_converter.h>

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

Public Member Functions

ShPtr< Moduleconvert (llvm::Module *llvmModule, const std::string &moduleName, ShPtr< Semantics > semantics, ShPtr< Config > config, bool enableDebug=false)
 Converts the given LLVM module into a module in BIR. More...
 
Options
void setOptionStrictFPUSemantics (bool strict=true)
 Enables/disables the use of strict FPU semantics. More...
 

Static Public Member Functions

static ShPtr< LLVMIR2BIRConvertercreate (llvm::Pass *basePass)
 Creates a new converter. More...
 

Private Member Functions

 LLVMIR2BIRConverter (llvm::Pass *basePass)
 Constructs a new converter. More...
 
Global variables conversion
bool isExternal (const llvm::GlobalVariable &var) const
 Determines if given LLVM global variable var is external. More...
 
bool shouldBeConvertedAndAdded (const llvm::GlobalVariable &globVar) const
 Determines whether the given LLVM global variable globVar should be converted and added into the resulting module. More...
 
ShPtr< VariableconvertGlobalVariable (llvm::GlobalVariable &globVar) const
 Converts the given LLVM global variable globVar into a variable in BIR. More...
 
ShPtr< ExpressionconvertGlobalVariableInitializer (llvm::GlobalVariable &globVar) const
 Converts initializer of the given LLVM global variable globVar into an expression in BIR. More...
 
void convertAndAddGlobalVariables ()
 Converts all global variables of the input LLVM module and stores them into the resulting module. More...
 
Functions conversion
VarVector convertFuncParams (llvm::Function &func)
 Converts parameters of the given LLVM function func into a list of function parameters in BIR. More...
 
ShPtr< FunctionconvertFuncDeclaration (llvm::Function &func)
 Converts a declaration of the given LLVM function func into a function declaration in BIR. More...
 
void updateFuncToDefinition (llvm::Function &func)
 Updates the given LLVM function func from declaration to definition. More...
 
VarVector sortLocalVars (const VarSet &vars) const
 Sorts local variables set vars alphabetically by name. More...
 
void generateVarDefinitions (ShPtr< Function > func) const
 Generates variable definition statements at the beginning of func. More...
 
bool shouldBeConvertedAndAdded (const llvm::Function &func) const
 Determines whether the given LLVM function func should be converted and added into the resulting module. More...
 
void convertAndAddFuncsDeclarations ()
 Converts all functions declarations of the input LLVM module and stores them into the resulting module. More...
 
void convertFuncsBodies ()
 Goes through all functions definitions of the input LLVM module and converts their bodies and stores them into the resulting module. More...
 
Ensure that identifiers are valid
void makeIdentifiersValid ()
 Makes all identifiers valid by replacing invalid characters with valid characters. More...
 
void makeGlobVarsIdentifiersValid ()
 Makes all identifiers of the global variables valid. More...
 
void makeFuncsIdentifiersValid ()
 Makes all identifiers of the functions valid (function names, parameters and local variables). More...
 
void makeFuncIdentifiersValid (ShPtr< Function > func) const
 Makes all identifiers of the given function func valid (function name, parameters and local variables). More...
 
void makeFuncVariablesValid (ShPtr< Function > func) const
 Makes all identifiers of the local variables and parameters in the given function func valid. More...
 
- Private Member Functions inherited from retdec::utils::NonCopyable
 NonCopyable (const NonCopyable &)=delete
 
NonCopyableoperator= (const NonCopyable &)=delete
 
 NonCopyable ()=default
 
 ~NonCopyable ()=default
 

Private Attributes

llvm::Pass * basePass
 Pass that have instantiated the converter. More...
 
bool optionStrictFPUSemantics
 Use strict FPU semantics? More...
 
bool enableDebug
 Should debugging messages be enabled? More...
 
ShPtr< LLVMValueConverterconverter
 A converter from LLVM values to values in BIR. More...
 
llvm::Module * llvmModule
 The input LLVM module. More...
 
ShPtr< ModuleresModule
 The resulting module in BIR. More...
 
UPtr< StructureConverterstructConverter
 A converter of the LLVM function structure. More...
 
ShPtr< VariablesManagervariablesManager
 Variables manager. More...
 

Detailed Description

A converter of LLVM IR to BIR.

Instances of this class have reference object semantics.

Constructor & Destructor Documentation

◆ LLVMIR2BIRConverter()

retdec::llvmir2hll::LLVMIR2BIRConverter::LLVMIR2BIRConverter ( llvm::Pass *  basePass)
private

Constructs a new converter.

For more details, see create().

Member Function Documentation

◆ convert()

ShPtr< Module > retdec::llvmir2hll::LLVMIR2BIRConverter::convert ( llvm::Module *  llvmModule,
const std::string &  moduleName,
ShPtr< Semantics semantics,
ShPtr< Config config,
bool  enableDebug = false 
)

Converts the given LLVM module into a module in BIR.

Parameters
[in]llvmModuleLLVM module to be converted.
[in]moduleNameIdentifier of the resulting module.
[in]semanticsThe used semantics.
[in]configConfiguration for the module.
[in]enableDebugIf true, debugging messages will be emitted.
Preconditions
  • both llvmModule and semantics are non-null

◆ convertAndAddFuncsDeclarations()

void retdec::llvmir2hll::LLVMIR2BIRConverter::convertAndAddFuncsDeclarations ( )
private

Converts all functions declarations of the input LLVM module and stores them into the resulting module.

◆ convertAndAddGlobalVariables()

void retdec::llvmir2hll::LLVMIR2BIRConverter::convertAndAddGlobalVariables ( )
private

Converts all global variables of the input LLVM module and stores them into the resulting module.

◆ convertFuncDeclaration()

ShPtr< Function > retdec::llvmir2hll::LLVMIR2BIRConverter::convertFuncDeclaration ( llvm::Function &  func)
private

Converts a declaration of the given LLVM function func into a function declaration in BIR.

◆ convertFuncParams()

VarVector retdec::llvmir2hll::LLVMIR2BIRConverter::convertFuncParams ( llvm::Function &  func)
private

Converts parameters of the given LLVM function func into a list of function parameters in BIR.

◆ convertFuncsBodies()

void retdec::llvmir2hll::LLVMIR2BIRConverter::convertFuncsBodies ( )
private

Goes through all functions definitions of the input LLVM module and converts their bodies and stores them into the resulting module.

◆ convertGlobalVariable()

ShPtr< Variable > retdec::llvmir2hll::LLVMIR2BIRConverter::convertGlobalVariable ( llvm::GlobalVariable &  globVar) const
private

Converts the given LLVM global variable globVar into a variable in BIR.

◆ convertGlobalVariableInitializer()

ShPtr< Expression > retdec::llvmir2hll::LLVMIR2BIRConverter::convertGlobalVariableInitializer ( llvm::GlobalVariable &  globVar) const
private

Converts initializer of the given LLVM global variable globVar into an expression in BIR.

◆ create()

ShPtr< LLVMIR2BIRConverter > retdec::llvmir2hll::LLVMIR2BIRConverter::create ( llvm::Pass *  basePass)
static

Creates a new converter.

Parameters
[in]basePassPass that instantiates a concrete converter.
Preconditions
  • basePass is non-null

◆ generateVarDefinitions()

void retdec::llvmir2hll::LLVMIR2BIRConverter::generateVarDefinitions ( ShPtr< Function func) const
private

Generates variable definition statements at the beginning of func.

◆ isExternal()

bool retdec::llvmir2hll::LLVMIR2BIRConverter::isExternal ( const llvm::GlobalVariable &  var) const
private

Determines if given LLVM global variable var is external.

◆ makeFuncIdentifiersValid()

void retdec::llvmir2hll::LLVMIR2BIRConverter::makeFuncIdentifiersValid ( ShPtr< Function func) const
private

Makes all identifiers of the given function func valid (function name, parameters and local variables).

◆ makeFuncsIdentifiersValid()

void retdec::llvmir2hll::LLVMIR2BIRConverter::makeFuncsIdentifiersValid ( )
private

Makes all identifiers of the functions valid (function names, parameters and local variables).

◆ makeFuncVariablesValid()

void retdec::llvmir2hll::LLVMIR2BIRConverter::makeFuncVariablesValid ( ShPtr< Function func) const
private

Makes all identifiers of the local variables and parameters in the given function func valid.

◆ makeGlobVarsIdentifiersValid()

void retdec::llvmir2hll::LLVMIR2BIRConverter::makeGlobVarsIdentifiersValid ( )
private

Makes all identifiers of the global variables valid.

◆ makeIdentifiersValid()

void retdec::llvmir2hll::LLVMIR2BIRConverter::makeIdentifiersValid ( )
private

Makes all identifiers valid by replacing invalid characters with valid characters.

◆ setOptionStrictFPUSemantics()

void retdec::llvmir2hll::LLVMIR2BIRConverter::setOptionStrictFPUSemantics ( bool  strict = true)

Enables/disables the use of strict FPU semantics.

Parameters
[in]strictIf true, enables the use of strict FPU semantics. If false, disables the use of strict FPU semantics.

◆ shouldBeConvertedAndAdded() [1/2]

bool retdec::llvmir2hll::LLVMIR2BIRConverter::shouldBeConvertedAndAdded ( const llvm::Function &  func) const
private

Determines whether the given LLVM function func should be converted and added into the resulting module.

◆ shouldBeConvertedAndAdded() [2/2]

bool retdec::llvmir2hll::LLVMIR2BIRConverter::shouldBeConvertedAndAdded ( const llvm::GlobalVariable &  globVar) const
private

Determines whether the given LLVM global variable globVar should be converted and added into the resulting module.

◆ sortLocalVars()

VarVector retdec::llvmir2hll::LLVMIR2BIRConverter::sortLocalVars ( const VarSet vars) const
private

Sorts local variables set vars alphabetically by name.

◆ updateFuncToDefinition()

void retdec::llvmir2hll::LLVMIR2BIRConverter::updateFuncToDefinition ( llvm::Function &  func)
private

Updates the given LLVM function func from declaration to definition.

Member Data Documentation

◆ basePass

llvm::Pass* retdec::llvmir2hll::LLVMIR2BIRConverter::basePass
private

Pass that have instantiated the converter.

◆ converter

ShPtr<LLVMValueConverter> retdec::llvmir2hll::LLVMIR2BIRConverter::converter
private

A converter from LLVM values to values in BIR.

◆ enableDebug

bool retdec::llvmir2hll::LLVMIR2BIRConverter::enableDebug
private

Should debugging messages be enabled?

◆ llvmModule

llvm::Module* retdec::llvmir2hll::LLVMIR2BIRConverter::llvmModule
private

The input LLVM module.

◆ optionStrictFPUSemantics

bool retdec::llvmir2hll::LLVMIR2BIRConverter::optionStrictFPUSemantics
private

Use strict FPU semantics?

◆ resModule

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

The resulting module in BIR.

◆ structConverter

UPtr<StructureConverter> retdec::llvmir2hll::LLVMIR2BIRConverter::structConverter
private

A converter of the LLVM function structure.

◆ variablesManager

ShPtr<VariablesManager> retdec::llvmir2hll::LLVMIR2BIRConverter::variablesManager
private

Variables manager.


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