retdec
Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions | Private Attributes | List of all members
retdec::llvmir2hll::HLLWriter Class Referenceabstract

A base class of all HLL writers. More...

#include <hll_writer.h>

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

Public Member Functions

virtual std::string getId () const =0
 Returns the ID of the writer. More...
 
virtual bool emitTargetCode (ShPtr< Module > module)
 Emits the code from the given module. More...
 
Options
void setOptionEmitDebugComments (bool emit=true)
 Enables/disables the emission of debug comments. More...
 
void setOptionKeepAllBrackets (bool keep=true)
 Enables/disables the keeping of all brackets. More...
 
void setOptionEmitTimeVaryingInfo (bool emit=true)
 Enables/disables emission of time-varying information, like dates. More...
 
void setOptionUseCompoundOperators (bool use=true)
 Enables/disables usage of compound operators (like +=) instead of assignments. More...
 
- Public Member Functions inherited from retdec::llvmir2hll::Visitor
virtual ~Visitor ()=default
 
virtual void visit (ShPtr< GlobalVarDef > varDef)=0
 
virtual void visit (ShPtr< Function > func)=0
 
virtual void visit (ShPtr< AssignStmt > stmt)=0
 
virtual void visit (ShPtr< BreakStmt > stmt)=0
 
virtual void visit (ShPtr< CallStmt > stmt)=0
 
virtual void visit (ShPtr< ContinueStmt > stmt)=0
 
virtual void visit (ShPtr< EmptyStmt > stmt)=0
 
virtual void visit (ShPtr< ForLoopStmt > stmt)=0
 
virtual void visit (ShPtr< UForLoopStmt > stmt)=0
 
virtual void visit (ShPtr< GotoStmt > stmt)=0
 
virtual void visit (ShPtr< IfStmt > stmt)=0
 
virtual void visit (ShPtr< ReturnStmt > stmt)=0
 
virtual void visit (ShPtr< SwitchStmt > stmt)=0
 
virtual void visit (ShPtr< UnreachableStmt > stmt)=0
 
virtual void visit (ShPtr< VarDefStmt > stmt)=0
 
virtual void visit (ShPtr< WhileLoopStmt > stmt)=0
 
virtual void visit (ShPtr< AddOpExpr > expr)=0
 
virtual void visit (ShPtr< AddressOpExpr > expr)=0
 
virtual void visit (ShPtr< AndOpExpr > expr)=0
 
virtual void visit (ShPtr< ArrayIndexOpExpr > expr)=0
 
virtual void visit (ShPtr< AssignOpExpr > expr)=0
 
virtual void visit (ShPtr< BitAndOpExpr > expr)=0
 
virtual void visit (ShPtr< BitOrOpExpr > expr)=0
 
virtual void visit (ShPtr< BitShlOpExpr > expr)=0
 
virtual void visit (ShPtr< BitShrOpExpr > expr)=0
 
virtual void visit (ShPtr< BitXorOpExpr > expr)=0
 
virtual void visit (ShPtr< CallExpr > expr)=0
 
virtual void visit (ShPtr< CommaOpExpr > expr)=0
 
virtual void visit (ShPtr< DerefOpExpr > expr)=0
 
virtual void visit (ShPtr< DivOpExpr > expr)=0
 
virtual void visit (ShPtr< EqOpExpr > expr)=0
 
virtual void visit (ShPtr< GtEqOpExpr > expr)=0
 
virtual void visit (ShPtr< GtOpExpr > expr)=0
 
virtual void visit (ShPtr< LtEqOpExpr > expr)=0
 
virtual void visit (ShPtr< LtOpExpr > expr)=0
 
virtual void visit (ShPtr< ModOpExpr > expr)=0
 
virtual void visit (ShPtr< MulOpExpr > expr)=0
 
virtual void visit (ShPtr< NegOpExpr > expr)=0
 
virtual void visit (ShPtr< NeqOpExpr > expr)=0
 
virtual void visit (ShPtr< NotOpExpr > expr)=0
 
virtual void visit (ShPtr< OrOpExpr > expr)=0
 
virtual void visit (ShPtr< StructIndexOpExpr > expr)=0
 
virtual void visit (ShPtr< SubOpExpr > expr)=0
 
virtual void visit (ShPtr< TernaryOpExpr > expr)=0
 
virtual void visit (ShPtr< Variable > var)=0
 
virtual void visit (ShPtr< BitCastExpr > expr)=0
 
virtual void visit (ShPtr< ExtCastExpr > expr)=0
 
virtual void visit (ShPtr< FPToIntCastExpr > expr)=0
 
virtual void visit (ShPtr< IntToFPCastExpr > expr)=0
 
virtual void visit (ShPtr< IntToPtrCastExpr > expr)=0
 
virtual void visit (ShPtr< PtrToIntCastExpr > expr)=0
 
virtual void visit (ShPtr< TruncCastExpr > expr)=0
 
virtual void visit (ShPtr< ConstArray > constant)=0
 
virtual void visit (ShPtr< ConstBool > constant)=0
 
virtual void visit (ShPtr< ConstFloat > constant)=0
 
virtual void visit (ShPtr< ConstInt > constant)=0
 
virtual void visit (ShPtr< ConstNullPointer > constant)=0
 
virtual void visit (ShPtr< ConstString > constant)=0
 
virtual void visit (ShPtr< ConstStruct > constant)=0
 
virtual void visit (ShPtr< ConstSymbol > constant)=0
 
virtual void visit (ShPtr< ArrayType > type)=0
 
virtual void visit (ShPtr< FloatType > type)=0
 
virtual void visit (ShPtr< IntType > type)=0
 
virtual void visit (ShPtr< PointerType > type)=0
 
virtual void visit (ShPtr< StringType > type)=0
 
virtual void visit (ShPtr< StructType > type)=0
 
virtual void visit (ShPtr< FunctionType > type)=0
 
virtual void visit (ShPtr< VoidType > type)=0
 
virtual void visit (ShPtr< UnknownType > type)=0
 

Protected Member Functions

 HLLWriter (llvm::raw_ostream &out, const std::string &outputFormat="")
 Constructs a new writer. More...
 
void sortFuncsForEmission (FuncVector &funcs)
 Sort the given list of functions for emission. More...
 
bool tryEmitVarInfoInComment (ShPtr< Variable > var, ShPtr< Statement > stmt=nullptr)
 Tries to emit a comment with the information about the given variable. More...
 
bool tryEmitVarAddressInComment (ShPtr< Variable > var)
 Tries to emit the address of the given variable into a comment. More...
 
bool shouldBeEmittedInHexa (ShPtr< ConstInt > constant) const
 Returns true if the given constant should be emitted in hexa, false otherwise. More...
 
bool shouldBeEmittedInStructuredWay (ShPtr< ConstArray > array) const
 Checks whether the given array should be emitted in a structured way. More...
 
bool shouldBeEmittedInStructuredWay (ShPtr< ConstStruct > structure) const
 Checks whether the given structure should be emitted in a structured way. More...
 
std::string getGotoLabel (ShPtr< Statement > stmt)
 Returns the goto label for the given statement. More...
 
Commenting
virtual std::string getCommentPrefix ()=0
 Returns the prefix of comments in the given language. More...
 
Indentation
void increaseIndentLevel ()
 Increases the indentation level. More...
 
void decreaseIndentLevel ()
 Decreases the indentation level. More...
 
std::string getCurrentIndent () const
 Returns the current indentation (to indent the current block). More...
 
std::string getSingleLevelIndent () const
 Returns the single level of indentation. More...
 
std::string getIndentForGotoLabel () const
 Returns indentation for a goto label. More...
 
Emission
virtual bool emitFileHeader ()
 Emits the file header. More...
 
virtual bool emitGlobalVariablesHeader ()
 Emits the header of the global variables block. More...
 
virtual bool emitGlobalVariables ()
 Emits all global variables in the module. More...
 
virtual bool emitGlobalVariable (ShPtr< GlobalVarDef > varDef)
 Emits the given global variable, including the ending newline. More...
 
virtual bool emitClassesHeader ()
 Emits the header of the classes block. More...
 
virtual bool emitClasses ()
 Emits classes. More...
 
virtual bool emitClass (const std::string &className)
 Emits the class with the given name. More...
 
virtual bool emitFunctionPrototypesHeader ()
 Emits the header of the function prototypes block. More...
 
virtual bool emitFunctionPrototypes ()
 Emits function prototypes. More...
 
virtual bool emitFunctionsHeader ()
 Emits the header of the functions block. More...
 
virtual bool emitFunctions ()
 Emits functions in the module. More...
 
virtual bool emitFunction (ShPtr< Function > func)
 Emits the given function, including the ending newline. More...
 
virtual bool emitStaticallyLinkedFunctionsHeader ()
 Emits the header of the statically linked functions block. More...
 
virtual bool emitStaticallyLinkedFunctions ()
 Emits statically linked functions in the module. More...
 
virtual bool emitDynamicallyLinkedFunctionsHeader ()
 Emits the header of the dynamically linked functions block. More...
 
virtual bool emitDynamicallyLinkedFunctions ()
 Emits dynamically linked functions in the module. More...
 
virtual bool emitSyscallFunctionsHeader ()
 Emits the header of the syscall functions block. More...
 
virtual bool emitSyscallFunctions ()
 Emits syscall functions in the module. More...
 
virtual bool emitInstructionIdiomFunctionsHeader ()
 Emits the header of the instruction-idiom functions block. More...
 
virtual bool emitInstructionIdiomFunctions ()
 Emits instruction-idiom functions in the module. More...
 
virtual bool emitExternalFunctions (const FuncSet &funcs)
 Emits the given external functions. More...
 
virtual bool emitExternalFunction (ShPtr< Function > func)
 Emits the given linked function, including the ending newline. More...
 
virtual bool emitMetaInfoHeader ()
 Emits the header of the meta-information block. More...
 
virtual bool emitMetaInfo ()
 Emits meta-information. More...
 
virtual void emitExprWithBracketsIfNeeded (ShPtr< Expression > expr)
 Emits the given expression with brackets around it (if needed). More...
 
void emitUnaryOpExpr (const std::string &opRepr, ShPtr< UnaryOpExpr > expr)
 Emits the given unary expression. More...
 
void emitBinaryOpExpr (const std::string &opRepr, ShPtr< BinaryOpExpr > expr, bool spaceBefore=true, bool spaceAfter=true)
 Emits the given binary expression. More...
 
bool emitDetectedCryptoPatternForGlobalVarIfAvailable (ShPtr< Variable > var)
 Emits a description of the detected cryptographic pattern for the given global variable. More...
 
bool emitModuleNameForFuncIfAvailable (ShPtr< Function > func)
 If there is a module name from debug information assigned to the function, emit it in a comment. More...
 
bool emitAddressRangeForFuncIfAvailable (ShPtr< Function > func)
 Emits address range for the given function (if available). More...
 
bool emitLineRangeForFuncIfAvailable (ShPtr< Function > func)
 Emits line range for the given function (if available). More...
 
bool emitWrapperInfoForFuncIfAvailable (ShPtr< Function > func)
 Emits wrapper-related information for the given function (if available). More...
 
bool emitClassInfoIfAvailable (ShPtr< Function > func)
 Emits class-related information for the given function (if available). More...
 
bool emitDemangledNameIfAvailable (ShPtr< Function > func)
 Emits demangled name of the given function (if available). More...
 
bool emitCommentIfAvailable (ShPtr< Function > func)
 Emits a comment of the given function (if available). More...
 
bool emitDetectedCryptoPatternsForFuncIfAvailable (ShPtr< Function > func)
 Emits a list of detected cryptographic patterns for the given function (if available). More...
 
void emitSectionHeader (const std::string &sectionName)
 Emits a section header comment. More...
 
template<class ContainerType >
void emitSequenceWithAccept (const ContainerType &seq, const std::string &space=" ", bool newline=false)
 Emits the given sequence seq by calling accept on every value. Separator = ','. More...
 
Representations
virtual std::string getConstNullPointerTextRepr () const
 Returns the textual representation of a null pointer. More...
 
- Protected Member Functions inherited from retdec::llvmir2hll::Visitor
 Visitor ()=default
 

Protected Attributes

ShPtr< Modulemodule
 The module to be written. More...
 
UPtr< OutputManagerout
 Output where the resulting code will be generated. More...
 
ShPtr< BracketManagerbracketsManager
 Recognizes which brackets around expressions are needed. More...
 
bool emitConstantsInStructuredWay
 
bool optionEmitDebugComments
 Emit also debug comments? More...
 
bool optionKeepAllBrackets
 Keep all (even redundant) brackets? More...
 
bool optionEmitTimeVaryingInfo
 Emit time-varying information, like dates? More...
 
bool optionUseCompoundOperators
 Use compound operators (like +=) instead of assignments? More...
 
ShPtr< FunctioncurrFunc
 The currently emitted function definition (if any). More...
 
std::size_t currFuncGotoLabelCounter
 Counter for goto labels for the current function. More...
 

Private Member Functions

std::string getRawGotoLabel (ShPtr< Statement > stmt)
 Returns a "raw" goto label for the given statement. More...
 
std::string getReadableClassName (const std::string &cl) const
 Returns the most readable name of the given class. More...
 
StringVector getReadableClassNames (const StringVector &classes) const
 Returns the most readable names of the given classes. More...
 
Emission of Meta-Information
bool emitMetaInfoDetectedCompilerOrPacker ()
 Emits the detected compiler or packer (if any). More...
 
bool emitMetaInfoDetectedLanguage ()
 Emits the detected language (if any). More...
 
bool emitMetaInfoNumberOfDetectedFuncs ()
 Emits the number of detected functions. More...
 
bool emitMetaInfoSelectedButNotFoundFuncs ()
 Emits functions that were selected to be decompiled but were not found (if any). More...
 
bool emitMetaInfoDecompilationDate ()
 Emits the decompilation date. More...
 
- Private Member Functions inherited from retdec::utils::NonCopyable
 NonCopyable (const NonCopyable &)=delete
 
NonCopyableoperator= (const NonCopyable &)=delete
 
 NonCopyable ()=default
 
 ~NonCopyable ()=default
 

Private Attributes

std::string currentIndent
 Spaces to indent the current block. More...
 

Detailed Description

A base class of all HLL writers.

Every HLL writer should subclass this class and override at least the needed protected emit*() functions. If the writer needs to do some more magic, like changing the order in which the blocks are emitted, then override emitTargetCode().

Instances of this class have reference object semantics.

Constructor & Destructor Documentation

◆ HLLWriter()

retdec::llvmir2hll::HLLWriter::HLLWriter ( llvm::raw_ostream &  o,
const std::string &  outputFormat = "" 
)
protected

Constructs a new writer.

Parameters
[in]oOutput into which the HLL code will be emitted.
[in]outputFormatOutput format in which to emit the HLL.

Member Function Documentation

◆ decreaseIndentLevel()

void retdec::llvmir2hll::HLLWriter::decreaseIndentLevel ( )
protected

Decreases the indentation level.

◆ emitAddressRangeForFuncIfAvailable()

bool retdec::llvmir2hll::HLLWriter::emitAddressRangeForFuncIfAvailable ( ShPtr< Function func)
protected

Emits address range for the given function (if available).

If there is address range available, emit it in a comment.

Returns
true if some code was emitted, false otherwise.

◆ emitBinaryOpExpr()

void retdec::llvmir2hll::HLLWriter::emitBinaryOpExpr ( const std::string &  opRepr,
ShPtr< BinaryOpExpr expr,
bool  spaceBefore = true,
bool  spaceAfter = true 
)
protected

Emits the given binary expression.

Parameters
[in]opReprTextual representation of the operator (without spaces).
[in]exprExpression to be emitted.
[in]spaceBeforeShould there be a space before operator?
[in]spaceAfterShould there be a space after operator?

Brackets are emitted when needed. Use this function if you simply need to emit the operator without any specialties.

◆ emitClass()

bool retdec::llvmir2hll::HLLWriter::emitClass ( const std::string &  className)
protectedvirtual

Emits the class with the given name.

Returns
true if some code has been emitted, false otherwise.

◆ emitClasses()

bool retdec::llvmir2hll::HLLWriter::emitClasses ( )
protectedvirtual

Emits classes.

Returns
true if some code has been emitted, false otherwise.

By default (if it is not overridden), it calls emitClass() for each class.

◆ emitClassesHeader()

bool retdec::llvmir2hll::HLLWriter::emitClassesHeader ( )
protectedvirtual

Emits the header of the classes block.

Returns
true if some code has been emitted, false otherwise.

◆ emitClassInfoIfAvailable()

bool retdec::llvmir2hll::HLLWriter::emitClassInfoIfAvailable ( ShPtr< Function func)
protected

Emits class-related information for the given function (if available).

Returns
true if some code was emitted, false otherwise.

◆ emitCommentIfAvailable()

bool retdec::llvmir2hll::HLLWriter::emitCommentIfAvailable ( ShPtr< Function func)
protected

Emits a comment of the given function (if available).

Returns
true if some code was emitted, false otherwise.

◆ emitDemangledNameIfAvailable()

bool retdec::llvmir2hll::HLLWriter::emitDemangledNameIfAvailable ( ShPtr< Function func)
protected

Emits demangled name of the given function (if available).

Returns
true if some code was emitted, false otherwise.

◆ emitDetectedCryptoPatternForGlobalVarIfAvailable()

bool retdec::llvmir2hll::HLLWriter::emitDetectedCryptoPatternForGlobalVarIfAvailable ( ShPtr< Variable var)
protected

Emits a description of the detected cryptographic pattern for the given global variable.

The description is emitted in a comment and ended with an new line.

Returns
true if some code was emitted, false otherwise.

◆ emitDetectedCryptoPatternsForFuncIfAvailable()

bool retdec::llvmir2hll::HLLWriter::emitDetectedCryptoPatternsForFuncIfAvailable ( ShPtr< Function func)
protected

Emits a list of detected cryptographic patterns for the given function (if available).

Returns
true if some code was emitted, false otherwise.

◆ emitDynamicallyLinkedFunctions()

bool retdec::llvmir2hll::HLLWriter::emitDynamicallyLinkedFunctions ( )
protectedvirtual

Emits dynamically linked functions in the module.

Returns
true if some code has been emitted, false otherwise.

By default (if it is not overridden), it sort all dynamically linked functions in the module by their name and calls emitExternalFunction() on each of them.

◆ emitDynamicallyLinkedFunctionsHeader()

bool retdec::llvmir2hll::HLLWriter::emitDynamicallyLinkedFunctionsHeader ( )
protectedvirtual

Emits the header of the dynamically linked functions block.

Returns
true if some code has been emitted, false otherwise.

◆ emitExprWithBracketsIfNeeded()

void retdec::llvmir2hll::HLLWriter::emitExprWithBracketsIfNeeded ( ShPtr< Expression expr)
protectedvirtual

Emits the given expression with brackets around it (if needed).

◆ emitExternalFunction()

bool retdec::llvmir2hll::HLLWriter::emitExternalFunction ( ShPtr< Function func)
protectedvirtual

Emits the given linked function, including the ending newline.

Parameters
[in]funcLinked function to be emitted.
Preconditions
  • func is non-null

By default (if it is not overridden), it emits nothing.

Reimplemented in retdec::llvmir2hll::CHLLWriter.

◆ emitExternalFunctions()

bool retdec::llvmir2hll::HLLWriter::emitExternalFunctions ( const FuncSet funcs)
protectedvirtual

Emits the given external functions.

Returns
true if some code has been emitted, false otherwise.

By default (if it is not overridden), it sort all the given functions and calls emitExternalFunction() on each of them.

◆ emitFileHeader()

bool retdec::llvmir2hll::HLLWriter::emitFileHeader ( )
protectedvirtual

Emits the file header.

Returns
true if some code has been emitted, false otherwise.

By default (if it is not overridden), it emits the default header.

Reimplemented in retdec::llvmir2hll::CHLLWriter.

◆ emitFunction()

bool retdec::llvmir2hll::HLLWriter::emitFunction ( ShPtr< Function func)
protectedvirtual

Emits the given function, including the ending newline.

Parameters
[in]funcFunction to be emitted.

By default, it emits information about func (like address range, module, etc., if available), and then calls func->accept(this).

Preconditions
  • func is non-null

◆ emitFunctionPrototypes()

bool retdec::llvmir2hll::HLLWriter::emitFunctionPrototypes ( )
protectedvirtual

Emits function prototypes.

Returns
true if some code has been emitted, false otherwise.

By default (if it is not overridden), it emits nothing.

Reimplemented in retdec::llvmir2hll::CHLLWriter.

◆ emitFunctionPrototypesHeader()

bool retdec::llvmir2hll::HLLWriter::emitFunctionPrototypesHeader ( )
protectedvirtual

Emits the header of the function prototypes block.

Returns
true if some code has been emitted, false otherwise.

By default (if it is not overridden), it emits nothing.

Reimplemented in retdec::llvmir2hll::CHLLWriter.

◆ emitFunctions()

bool retdec::llvmir2hll::HLLWriter::emitFunctions ( )
protectedvirtual

Emits functions in the module.

Returns
true if some code has been emitted, false otherwise.

By default (if it is not overridden), it tries to sort the functions in the module and calls emitFunction() on each of them.

◆ emitFunctionsHeader()

bool retdec::llvmir2hll::HLLWriter::emitFunctionsHeader ( )
protectedvirtual

Emits the header of the functions block.

Returns
true if some code has been emitted, false otherwise.

◆ emitGlobalVariable()

bool retdec::llvmir2hll::HLLWriter::emitGlobalVariable ( ShPtr< GlobalVarDef varDef)
protectedvirtual

Emits the given global variable, including the ending newline.

Parameters
[in]varDefDefinition of the variable.
Preconditions
  • varDef is non-null

By default (if it is not overridden), it calls varDef->accept(this) and returns true.

◆ emitGlobalVariables()

bool retdec::llvmir2hll::HLLWriter::emitGlobalVariables ( )
protectedvirtual

Emits all global variables in the module.

Returns
true if some code has been emitted, false otherwise.

By default (if it is not overridden), it it calls emitGlobalVariable() on each global variable in the module.

Reimplemented in retdec::llvmir2hll::CHLLWriter.

◆ emitGlobalVariablesHeader()

bool retdec::llvmir2hll::HLLWriter::emitGlobalVariablesHeader ( )
protectedvirtual

Emits the header of the global variables block.

Returns
true if some code has been emitted, false otherwise.

By default (if it is not overridden), it emits nothing.

◆ emitInstructionIdiomFunctions()

bool retdec::llvmir2hll::HLLWriter::emitInstructionIdiomFunctions ( )
protectedvirtual

Emits instruction-idiom functions in the module.

Returns
true if some code has been emitted, false otherwise.

By default (if it is not overridden), it sort all instruction-idiom functions in the module by their name and calls emitExternalFunction() on each of them.

◆ emitInstructionIdiomFunctionsHeader()

bool retdec::llvmir2hll::HLLWriter::emitInstructionIdiomFunctionsHeader ( )
protectedvirtual

Emits the header of the instruction-idiom functions block.

Returns
true if some code has been emitted, false otherwise.

◆ emitLineRangeForFuncIfAvailable()

bool retdec::llvmir2hll::HLLWriter::emitLineRangeForFuncIfAvailable ( ShPtr< Function func)
protected

Emits line range for the given function (if available).

If there is line information available, emit the line range in a comment.

Returns
true if some code was emitted, false otherwise.

◆ emitMetaInfo()

bool retdec::llvmir2hll::HLLWriter::emitMetaInfo ( )
protectedvirtual

Emits meta-information.

Returns
true if some code has been emitted, false otherwise.

By default (if it is not overridden), it emits several meta-information concerning the generated code.

◆ emitMetaInfoDecompilationDate()

bool retdec::llvmir2hll::HLLWriter::emitMetaInfoDecompilationDate ( )
private

Emits the decompilation date.

Returns
true if some code was emitted, false otherwise.

◆ emitMetaInfoDetectedCompilerOrPacker()

bool retdec::llvmir2hll::HLLWriter::emitMetaInfoDetectedCompilerOrPacker ( )
private

Emits the detected compiler or packer (if any).

Returns
true if some code was emitted, false otherwise.

◆ emitMetaInfoDetectedLanguage()

bool retdec::llvmir2hll::HLLWriter::emitMetaInfoDetectedLanguage ( )
private

Emits the detected language (if any).

Returns
true if some code was emitted, false otherwise.

◆ emitMetaInfoHeader()

bool retdec::llvmir2hll::HLLWriter::emitMetaInfoHeader ( )
protectedvirtual

Emits the header of the meta-information block.

Returns
true if some code has been emitted, false otherwise.

By default (if it is not overridden), it emits nothing.

◆ emitMetaInfoNumberOfDetectedFuncs()

bool retdec::llvmir2hll::HLLWriter::emitMetaInfoNumberOfDetectedFuncs ( )
private

Emits the number of detected functions.

Returns
true if some code was emitted, false otherwise.

◆ emitMetaInfoSelectedButNotFoundFuncs()

bool retdec::llvmir2hll::HLLWriter::emitMetaInfoSelectedButNotFoundFuncs ( )
private

Emits functions that were selected to be decompiled but were not found (if any).

◆ emitModuleNameForFuncIfAvailable()

bool retdec::llvmir2hll::HLLWriter::emitModuleNameForFuncIfAvailable ( ShPtr< Function func)
protected

If there is a module name from debug information assigned to the function, emit it in a comment.

Returns
true if some code was emitted, false otherwise.

◆ emitSectionHeader()

void retdec::llvmir2hll::HLLWriter::emitSectionHeader ( const std::string &  sectionName)
protected

Emits a section header comment.

Parameters
[in]sectionNameName of the section.

The emitted comment is ended with a newline.

◆ emitSequenceWithAccept()

template<class ContainerType >
void retdec::llvmir2hll::HLLWriter::emitSequenceWithAccept ( const ContainerType &  seq,
const std::string &  space = " ",
bool  newline = false 
)
inlineprotected

Emits the given sequence seq by calling accept on every value. Separator = ','.

Parameters
[in]seqSequence of values to be emitted.
[in]spaceSpace to insert after separator.
[in]newlineIf true, newline is inserted after separator and before space.
Template Parameters
ContainerTypeContainer of Visitable values.

◆ emitStaticallyLinkedFunctions()

bool retdec::llvmir2hll::HLLWriter::emitStaticallyLinkedFunctions ( )
protectedvirtual

Emits statically linked functions in the module.

Returns
true if some code has been emitted, false otherwise.

By default (if it is not overridden), it sort all statically linked functions in the module by their name and calls emitExternalFunction() on each of them.

◆ emitStaticallyLinkedFunctionsHeader()

bool retdec::llvmir2hll::HLLWriter::emitStaticallyLinkedFunctionsHeader ( )
protectedvirtual

Emits the header of the statically linked functions block.

Returns
true if some code has been emitted, false otherwise.

◆ emitSyscallFunctions()

bool retdec::llvmir2hll::HLLWriter::emitSyscallFunctions ( )
protectedvirtual

Emits syscall functions in the module.

Returns
true if some code has been emitted, false otherwise.

By default (if it is not overridden), it sort all syscall functions in the module by their name and calls emitExternalFunction() on each of them.

◆ emitSyscallFunctionsHeader()

bool retdec::llvmir2hll::HLLWriter::emitSyscallFunctionsHeader ( )
protectedvirtual

Emits the header of the syscall functions block.

Returns
true if some code has been emitted, false otherwise.

◆ emitTargetCode()

bool retdec::llvmir2hll::HLLWriter::emitTargetCode ( ShPtr< Module module)
virtual

Emits the code from the given module.

Parameters
[in]moduleModule to be written.
Returns
true if some code has been emitted, false otherwise.

The functions prints the code blocks in the following order (by calling appropriate emit*() functions):

  • file header
  • function prototypes header, function prototypes
  • global header, global variables
  • functions header, functions
  • external functions header, external functions (there are many types of external functions; a separate section is emitted for each type)
  • meta-information header, meta-information

Each block is separated by a blank line. A subclass of this class can just override the appropriate emit*() functions. To change the order of blocks, override this function.

Reimplemented in retdec::llvmir2hll::CHLLWriter.

◆ emitUnaryOpExpr()

void retdec::llvmir2hll::HLLWriter::emitUnaryOpExpr ( const std::string &  opRepr,
ShPtr< UnaryOpExpr expr 
)
protected

Emits the given unary expression.

Parameters
[in]opReprTextual representation of the operator (without spaces).
[in]exprExpression to be emitted.

Brackets are emitted when needed. Use this function if you simply need to emit the operator without any specialties.

◆ emitWrapperInfoForFuncIfAvailable()

bool retdec::llvmir2hll::HLLWriter::emitWrapperInfoForFuncIfAvailable ( ShPtr< Function func)
protected

Emits wrapper-related information for the given function (if available).

See the description of Module::getWrappedFuncName() for more details.

Returns
true if some code was emitted, false otherwise.

◆ getCommentPrefix()

virtual std::string retdec::llvmir2hll::HLLWriter::getCommentPrefix ( )
protectedpure virtual

Returns the prefix of comments in the given language.

For example, in C, it should return "//".

Implemented in retdec::llvmir2hll::CHLLWriter.

◆ getConstNullPointerTextRepr()

std::string retdec::llvmir2hll::HLLWriter::getConstNullPointerTextRepr ( ) const
protectedvirtual

Returns the textual representation of a null pointer.

By default, it returns "NULL".

◆ getCurrentIndent()

std::string retdec::llvmir2hll::HLLWriter::getCurrentIndent ( ) const
protected

Returns the current indentation (to indent the current block).

◆ getGotoLabel()

std::string retdec::llvmir2hll::HLLWriter::getGotoLabel ( ShPtr< Statement stmt)
protected

Returns the goto label for the given statement.

◆ getId()

virtual std::string retdec::llvmir2hll::HLLWriter::getId ( ) const
pure virtual

Returns the ID of the writer.

Implemented in retdec::llvmir2hll::CHLLWriter.

◆ getIndentForGotoLabel()

std::string retdec::llvmir2hll::HLLWriter::getIndentForGotoLabel ( ) const
protected

Returns indentation for a goto label.

◆ getRawGotoLabel()

std::string retdec::llvmir2hll::HLLWriter::getRawGotoLabel ( ShPtr< Statement stmt)
private

Returns a "raw" goto label for the given statement.

"raw" means without any prefix.

◆ getReadableClassName()

std::string retdec::llvmir2hll::HLLWriter::getReadableClassName ( const std::string &  cl) const
private

Returns the most readable name of the given class.

◆ getReadableClassNames()

StringVector retdec::llvmir2hll::HLLWriter::getReadableClassNames ( const StringVector classes) const
private

Returns the most readable names of the given classes.

◆ getSingleLevelIndent()

std::string retdec::llvmir2hll::HLLWriter::getSingleLevelIndent ( ) const
protected

Returns the single level of indentation.

The returned value is the string that is used in increaseIndentLevel() and decreaseIndentLevel() to increase and decrease the current indentation, respectively.

◆ increaseIndentLevel()

void retdec::llvmir2hll::HLLWriter::increaseIndentLevel ( )
protected

Increases the indentation level.

◆ setOptionEmitDebugComments()

void retdec::llvmir2hll::HLLWriter::setOptionEmitDebugComments ( bool  emit = true)

Enables/disables the emission of debug comments.

Parameters
[in]emitIf true, enables the emission of debug comments. If false, disables the emission of debug comments.

◆ setOptionEmitTimeVaryingInfo()

void retdec::llvmir2hll::HLLWriter::setOptionEmitTimeVaryingInfo ( bool  emit = true)

Enables/disables emission of time-varying information, like dates.

Parameters
[in]emitIf true, time-varying information, like dates, will be emitted.

◆ setOptionKeepAllBrackets()

void retdec::llvmir2hll::HLLWriter::setOptionKeepAllBrackets ( bool  keep = true)

Enables/disables the keeping of all brackets.

Parameters
[in]keepIf true, all brackets will be kept. If false, redundant brackets will be eliminated.

◆ setOptionUseCompoundOperators()

void retdec::llvmir2hll::HLLWriter::setOptionUseCompoundOperators ( bool  use = true)

Enables/disables usage of compound operators (like +=) instead of assignments.

Parameters
[in]useIf true, compound operators will be used.

◆ shouldBeEmittedInHexa()

bool retdec::llvmir2hll::HLLWriter::shouldBeEmittedInHexa ( ShPtr< ConstInt constant) const
protected

Returns true if the given constant should be emitted in hexa, false otherwise.

Preconditions
  • constant is non-null

◆ shouldBeEmittedInStructuredWay() [1/2]

bool retdec::llvmir2hll::HLLWriter::shouldBeEmittedInStructuredWay ( ShPtr< ConstArray array) const
protected

Checks whether the given array should be emitted in a structured way.

◆ shouldBeEmittedInStructuredWay() [2/2]

bool retdec::llvmir2hll::HLLWriter::shouldBeEmittedInStructuredWay ( ShPtr< ConstStruct structure) const
protected

Checks whether the given structure should be emitted in a structured way.

◆ sortFuncsForEmission()

void retdec::llvmir2hll::HLLWriter::sortFuncsForEmission ( FuncVector funcs)
protected

Sort the given list of functions for emission.

If there is line information from debug information available, the functions are sorted by their position in the original source code. If line information is not available but there are address ranges, they are sorted by them. Otherwise, the order is left untouched.

◆ tryEmitVarAddressInComment()

bool retdec::llvmir2hll::HLLWriter::tryEmitVarAddressInComment ( ShPtr< Variable var)
protected

Tries to emit the address of the given variable into a comment.

Returns
true if some code has been emitted, false otherwise.

◆ tryEmitVarInfoInComment()

bool retdec::llvmir2hll::HLLWriter::tryEmitVarInfoInComment ( ShPtr< Variable var,
ShPtr< Statement stmt = nullptr 
)
protected

Tries to emit a comment with the information about the given variable.

Returns
true if some code has been emitted, false otherwise.

If the emission of debug comments is disabled, this function does nothing and returns false;

Member Data Documentation

◆ bracketsManager

ShPtr<BracketManager> retdec::llvmir2hll::HLLWriter::bracketsManager
protected

Recognizes which brackets around expressions are needed.

◆ currentIndent

std::string retdec::llvmir2hll::HLLWriter::currentIndent
private

Spaces to indent the current block.

◆ currFunc

ShPtr<Function> retdec::llvmir2hll::HLLWriter::currFunc
protected

The currently emitted function definition (if any).

◆ currFuncGotoLabelCounter

std::size_t retdec::llvmir2hll::HLLWriter::currFuncGotoLabelCounter
protected

Counter for goto labels for the current function.

◆ emitConstantsInStructuredWay

bool retdec::llvmir2hll::HLLWriter::emitConstantsInStructuredWay
protected

Should we emit constants in a structured way? This variable is used to structure large initializations so that they are properly generated over multiple lines, not on a single line.

◆ module

ShPtr<Module> retdec::llvmir2hll::HLLWriter::module
protected

The module to be written.

◆ optionEmitDebugComments

bool retdec::llvmir2hll::HLLWriter::optionEmitDebugComments
protected

Emit also debug comments?

◆ optionEmitTimeVaryingInfo

bool retdec::llvmir2hll::HLLWriter::optionEmitTimeVaryingInfo
protected

Emit time-varying information, like dates?

◆ optionKeepAllBrackets

bool retdec::llvmir2hll::HLLWriter::optionKeepAllBrackets
protected

Keep all (even redundant) brackets?

◆ optionUseCompoundOperators

bool retdec::llvmir2hll::HLLWriter::optionUseCompoundOperators
protected

Use compound operators (like +=) instead of assignments?

◆ out

UPtr<OutputManager> retdec::llvmir2hll::HLLWriter::out
protected

Output where the resulting code will be generated.


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