7 #ifndef RETDEC_LLVMIR2HLL_HLL_HLL_WRITER_H
8 #define RETDEC_LLVMIR2HLL_HLL_HLL_WRITER_H
14 #include <llvm/Support/raw_ostream.h>
46 virtual std::string
getId()
const = 0;
59 HLLWriter(llvm::raw_ostream &
out,
const std::string& outputFormat =
"");
90 virtual bool emitClass(
const std::string &className);
120 bool spaceBefore =
true,
bool spaceAfter =
true);
145 template<
class ContainerType>
147 const std::string& space =
" ",
bool newline =
false) {
149 for (
const auto &item : seq) {
152 if (newline)
out->newLine();
A base class of all HLL writers.
Definition: hll_writer.h:41
bool emitDetectedCryptoPatternsForFuncIfAvailable(ShPtr< Function > func)
Emits a list of detected cryptographic patterns for the given function (if available).
Definition: hll_writer.cpp:964
void emitSectionHeader(const std::string §ionName)
Emits a section header comment.
Definition: hll_writer.cpp:985
bool emitCommentIfAvailable(ShPtr< Function > func)
Emits a comment of the given function (if available).
Definition: hll_writer.cpp:919
void increaseIndentLevel()
Increases the indentation level.
Definition: hll_writer.cpp:303
void emitBinaryOpExpr(const std::string &opRepr, ShPtr< BinaryOpExpr > expr, bool spaceBefore=true, bool spaceAfter=true)
Emits the given binary expression.
Definition: hll_writer.cpp:770
bool emitDetectedCryptoPatternForGlobalVarIfAvailable(ShPtr< Variable > var)
Emits a description of the detected cryptographic pattern for the given global variable.
Definition: hll_writer.cpp:792
virtual void emitExprWithBracketsIfNeeded(ShPtr< Expression > expr)
Emits the given expression with brackets around it (if needed).
Definition: hll_writer.cpp:733
virtual bool emitInstructionIdiomFunctionsHeader()
Emits the header of the instruction-idiom functions block.
Definition: hll_writer.cpp:646
bool shouldBeEmittedInStructuredWay(ShPtr< ConstArray > array) const
Checks whether the given array should be emitted in a structured way.
Definition: hll_writer.cpp:1124
ShPtr< Function > currFunc
The currently emitted function definition (if any).
Definition: hll_writer.h:203
std::string getGotoLabel(ShPtr< Statement > stmt)
Returns the goto label for the given statement.
Definition: hll_writer.cpp:1160
virtual bool emitGlobalVariables()
Emits all global variables in the module.
Definition: hll_writer.cpp:440
bool shouldBeEmittedInHexa(ShPtr< ConstInt > constant) const
Returns true if the given constant should be emitted in hexa, false otherwise.
Definition: hll_writer.cpp:1106
ShPtr< Module > module
The module to be written.
Definition: hll_writer.h:177
bool emitMetaInfoSelectedButNotFoundFuncs()
Emits functions that were selected to be decompiled but were not found (if any).
Definition: hll_writer.cpp:1213
virtual bool emitGlobalVariablesHeader()
Emits the header of the global variables block.
Definition: hll_writer.cpp:424
virtual bool emitGlobalVariable(ShPtr< GlobalVarDef > varDef)
Emits the given global variable, including the ending newline.
Definition: hll_writer.cpp:461
virtual bool emitClass(const std::string &className)
Emits the class with the given name.
Definition: hll_writer.cpp:400
void setOptionUseCompoundOperators(bool use=true)
Enables/disables usage of compound operators (like +=) instead of assignments.
Definition: hll_writer.cpp:196
virtual bool emitFileHeader()
Emits the file header.
Definition: hll_writer.cpp:358
virtual bool emitInstructionIdiomFunctions()
Emits instruction-idiom functions in the module.
Definition: hll_writer.cpp:662
bool emitDemangledNameIfAvailable(ShPtr< Function > func)
Emits demangled name of the given function (if available).
Definition: hll_writer.cpp:904
StringVector getReadableClassNames(const StringVector &classes) const
Returns the most readable names of the given classes.
Definition: hll_writer.cpp:1271
ShPtr< BracketManager > bracketsManager
Recognizes which brackets around expressions are needed.
Definition: hll_writer.h:183
void setOptionEmitDebugComments(bool emit=true)
Enables/disables the emission of debug comments.
Definition: hll_writer.cpp:166
bool emitConstantsInStructuredWay
Definition: hll_writer.h:188
virtual bool emitFunctionPrototypes()
Emits function prototypes.
Definition: hll_writer.cpp:487
virtual bool emitFunctions()
Emits functions in the module.
Definition: hll_writer.cpp:512
bool emitMetaInfoDecompilationDate()
Emits the decompilation date.
Definition: hll_writer.cpp:1231
bool emitLineRangeForFuncIfAvailable(ShPtr< Function > func)
Emits line range for the given function (if available).
Definition: hll_writer.cpp:849
virtual bool emitStaticallyLinkedFunctions()
Emits statically linked functions in the module.
Definition: hll_writer.cpp:586
HLLWriter(llvm::raw_ostream &out, const std::string &outputFormat="")
Constructs a new writer.
Definition: hll_writer.cpp:142
virtual bool emitDynamicallyLinkedFunctionsHeader()
Emits the header of the dynamically linked functions block.
Definition: hll_writer.cpp:595
virtual std::string getId() const =0
Returns the ID of the writer.
bool tryEmitVarInfoInComment(ShPtr< Variable > var, ShPtr< Statement > stmt=nullptr)
Tries to emit a comment with the information about the given variable.
Definition: hll_writer.cpp:1033
std::size_t currFuncGotoLabelCounter
Counter for goto labels for the current function.
Definition: hll_writer.h:206
bool optionEmitDebugComments
Emit also debug comments?
Definition: hll_writer.h:191
std::string getIndentForGotoLabel() const
Returns indentation for a goto label.
Definition: hll_writer.cpp:335
bool optionEmitTimeVaryingInfo
Emit time-varying information, like dates?
Definition: hll_writer.h:197
bool emitMetaInfoNumberOfDetectedFuncs()
Emits the number of detected functions.
Definition: hll_writer.cpp:1202
virtual bool emitMetaInfo()
Emits meta-information.
Definition: hll_writer.cpp:718
bool emitAddressRangeForFuncIfAvailable(ShPtr< Function > func)
Emits address range for the given function (if available).
Definition: hll_writer.cpp:829
virtual bool emitMetaInfoHeader()
Emits the header of the meta-information block.
Definition: hll_writer.cpp:705
std::string getSingleLevelIndent() const
Returns the single level of indentation.
Definition: hll_writer.cpp:328
virtual bool emitFunctionPrototypesHeader()
Emits the header of the function prototypes block.
Definition: hll_writer.cpp:476
std::string currentIndent
Spaces to indent the current block.
Definition: hll_writer.h:224
UPtr< OutputManager > out
Output where the resulting code will be generated.
Definition: hll_writer.h:180
virtual bool emitFunctionsHeader()
Emits the header of the functions block.
Definition: hll_writer.cpp:496
void decreaseIndentLevel()
Decreases the indentation level.
Definition: hll_writer.cpp:310
virtual bool emitTargetCode(ShPtr< Module > module)
Emits the code from the given module.
Definition: hll_writer.cpp:222
virtual bool emitStaticallyLinkedFunctionsHeader()
Emits the header of the statically linked functions block.
Definition: hll_writer.cpp:570
virtual bool emitFunction(ShPtr< Function > func)
Emits the given function, including the ending newline.
Definition: hll_writer.cpp:537
virtual bool emitClassesHeader()
Emits the header of the classes block.
Definition: hll_writer.cpp:372
void emitSequenceWithAccept(const ContainerType &seq, const std::string &space=" ", bool newline=false)
Emits the given sequence seq by calling accept on every value. Separator = ','.
Definition: hll_writer.h:146
virtual std::string getConstNullPointerTextRepr() const
Returns the textual representation of a null pointer.
Definition: hll_writer.cpp:1153
virtual bool emitExternalFunction(ShPtr< Function > func)
Emits the given linked function, including the ending newline.
Definition: hll_writer.cpp:694
std::string getReadableClassName(const std::string &cl) const
Returns the most readable name of the given class.
Definition: hll_writer.cpp:1263
void setOptionKeepAllBrackets(bool keep=true)
Enables/disables the keeping of all brackets.
Definition: hll_writer.cpp:176
bool optionKeepAllBrackets
Keep all (even redundant) brackets?
Definition: hll_writer.h:194
virtual bool emitExternalFunctions(const FuncSet &funcs)
Emits the given external functions.
Definition: hll_writer.cpp:674
virtual bool emitDynamicallyLinkedFunctions()
Emits dynamically linked functions in the module.
Definition: hll_writer.cpp:612
virtual bool emitSyscallFunctionsHeader()
Emits the header of the syscall functions block.
Definition: hll_writer.cpp:621
void emitUnaryOpExpr(const std::string &opRepr, ShPtr< UnaryOpExpr > expr)
Emits the given unary expression.
Definition: hll_writer.cpp:753
void sortFuncsForEmission(FuncVector &funcs)
Sort the given list of functions for emission.
Definition: hll_writer.cpp:1013
bool optionUseCompoundOperators
Use compound operators (like +=) instead of assignments?
Definition: hll_writer.h:200
void setOptionEmitTimeVaryingInfo(bool emit=true)
Enables/disables emission of time-varying information, like dates.
Definition: hll_writer.cpp:186
bool emitClassInfoIfAvailable(ShPtr< Function > func)
Emits class-related information for the given function (if available).
Definition: hll_writer.cpp:885
bool emitMetaInfoDetectedCompilerOrPacker()
Emits the detected compiler or packer (if any).
Definition: hll_writer.cpp:1172
bool emitMetaInfoDetectedLanguage()
Emits the detected language (if any).
Definition: hll_writer.cpp:1187
virtual bool emitSyscallFunctions()
Emits syscall functions in the module.
Definition: hll_writer.cpp:637
bool tryEmitVarAddressInComment(ShPtr< Variable > var)
Tries to emit the address of the given variable into a comment.
Definition: hll_writer.cpp:1090
std::string getRawGotoLabel(ShPtr< Statement > stmt)
Returns a "raw" goto label for the given statement.
Definition: hll_writer.cpp:1242
std::string getCurrentIndent() const
Returns the current indentation (to indent the current block).
Definition: hll_writer.cpp:317
virtual bool emitClasses()
Emits classes.
Definition: hll_writer.cpp:387
bool emitModuleNameForFuncIfAvailable(ShPtr< Function > func)
If there is a module name from debug information assigned to the function, emit it in a comment.
Definition: hll_writer.cpp:810
bool emitWrapperInfoForFuncIfAvailable(ShPtr< Function > func)
Emits wrapper-related information for the given function (if available).
Definition: hll_writer.cpp:870
virtual std::string getCommentPrefix()=0
Returns the prefix of comments in the given language.
A base class of all visitors.
Definition: visitor.h:95
A mixin to make classes non-copyable.
Definition: non_copyable.h:27
A representation of a complete module.
A base class of all visitors.
A library providing API for working with back-end IR.
std::vector< std::string > StringVector
Vector of strings.
Definition: types.h:87
std::shared_ptr< T > ShPtr
An alias for a shared pointer.
Definition: smart_ptr.h:18
std::unique_ptr< T > UPtr
An alias for a unique pointer.
Definition: smart_ptr.h:26
std::vector< ShPtr< Function > > FuncVector
Vector of functions.
Definition: types.h:105
std::set< ShPtr< Function > > FuncSet
Set of functions.
Definition: types.h:78
Definition: archive_wrapper.h:19
A mixin to make classes non-copyable.
A base class of all output managers.
Declarations, aliases, macros, etc. for the use of smart pointers.
Aliases for several useful types.