7 #ifndef RETDEC_LLVMIR2HLL_HLL_HLL_WRITERS_C_HLL_WRITER_H
8 #define RETDEC_LLVMIR2HLL_HLL_HLL_WRITERS_C_HLL_WRITER_H
22 class CompoundOpManager;
35 llvm::raw_ostream &
out,
36 const std::string& outputFormat =
"");
38 virtual std::string
getId()
const override;
51 llvm::raw_ostream &
out,
52 const std::string& outputFormat =
"");
170 bool emitInline =
false);
A HLL writer for the C language (C99).
Definition: c_hll_writer.h:32
static ShPtr< HLLWriter > create(llvm::raw_ostream &out, const std::string &outputFormat="")
Creates a new C writer.
Definition: c_hll_writer.cpp:256
StructTypeNameMap structNames
Mapping of a structured type into its name.
Definition: c_hll_writer.h:184
virtual void visit(ShPtr< GlobalVarDef > varDef) override
Definition: c_hll_writer.cpp:504
void emitFunctionParameters(ShPtr< Function > func)
Emits the parameters of the given function.
Definition: c_hll_writer.cpp:1500
void emitVarWithType(ShPtr< Variable > var)
Emits the given variable alongside with its type.
Definition: c_hll_writer.cpp:1539
void emitInitializedConstArray(ShPtr< ConstArray > array)
Emits the given initialized array.
Definition: c_hll_writer.cpp:1712
void emitGotoLabelIfNeeded(ShPtr< Statement > stmt)
Emits a label of stmt if it is needed.
Definition: c_hll_writer.cpp:2030
virtual bool emitTargetCode(ShPtr< Module > module) override
Emits the code from the given module.
Definition: c_hll_writer.cpp:549
void emitBlock(ShPtr< Statement > stmt)
Recursively emits the given block.
Definition: c_hll_writer.cpp:1999
bool shouldEmitFunctionPrototypesHeader() const
Returns true if we should emit the Function Prototypes header, false otherwise.
Definition: c_hll_writer.cpp:1233
void emitStructDeclaration(ShPtr< StructType > structType, bool emitInline=false)
Emits a declaration of the given structure.
Definition: c_hll_writer.cpp:1944
void setOptionEmitFunctionPrototypesForNonLibraryFuncs(bool emit=true)
void emitAssignment(ShPtr< Expression > lhs, ShPtr< Expression > rhs)
Emits the given assignment (without leading or trailing whitespace).
Definition: c_hll_writer.cpp:855
void emitInitializedConstArrayInline(ShPtr< ConstArray > array)
Emits the given array inline.
Definition: c_hll_writer.cpp:1723
void emitConstStruct(ShPtr< ConstStruct > constant, bool emitCast=true)
Emits the given structure literal.
Definition: c_hll_writer.cpp:1862
void emitUninitializedConstArray(ShPtr< ConstArray > array)
Emits the given uninitialized array.
Definition: c_hll_writer.cpp:1763
bool emitStandardFunctionPrototypes()
Emits standard function prototypes.
Definition: c_hll_writer.cpp:1260
void emitTypeOfElementsInArray(ShPtr< ArrayType > arrayType)
Emits the type of elements in the given array.
Definition: c_hll_writer.cpp:1776
virtual bool emitFileHeader() override
Emits the file header.
Definition: c_hll_writer.cpp:272
void emitHeaderOfFuncReturningPointerToArray(ShPtr< Function > func)
A specialization of emitFunctionHeader() for functions returning a pointer to an array.
Definition: c_hll_writer.cpp:1462
void emitInitializedConstArrayInStructuredWay(ShPtr< ConstArray > array)
Emits the given array in a structured way (may span over multiple lines).
Definition: c_hll_writer.cpp:1737
virtual bool emitFunctionPrototypes() override
Emits function prototypes.
Definition: c_hll_writer.cpp:470
std::string getConstFloatSuffixIfNeeded(ShPtr< ConstFloat > constant)
Definition: c_hll_writer.cpp:2059
virtual bool emitFunctionPrototypesHeader() override
Emits the header of the function prototypes block.
Definition: c_hll_writer.cpp:462
virtual bool emitGlobalVariables() override
Emits all global variables in the module.
Definition: c_hll_writer.cpp:453
void emitFunctionHeader(ShPtr< Function > func)
Emits the header of the given function.
Definition: c_hll_writer.cpp:1371
void emitArrayDimension(std::size_t size)
Emits the given array dimension.
Definition: c_hll_writer.cpp:1695
bool emitFunctionPrototype(ShPtr< Function > func)
Emits a prototype of the given function, including the ending newline.
Definition: c_hll_writer.cpp:1317
bool emitFunctionPrototypesForNonLibraryFuncs()
Emits prototypes for functions which do not have any associated header file.
Definition: c_hll_writer.cpp:1287
std::string genNameForUnnamedStruct(const StructTypeVector &usedStructTypes)
Generates a new name for an unnamed structure.
Definition: c_hll_writer.cpp:2101
void emitCastInStandardWay(ShPtr< CastExpr > expr)
Emits the given cast in the standard way.
Definition: c_hll_writer.cpp:1783
bool emittingGlobalVarDefs
Definition: c_hll_writer.h:194
void emitStarsBeforePointedValue(ShPtr< PointerType > ptrType)
Emits '*'s before the pointed value (there can be more than one).
Definition: c_hll_writer.cpp:1793
void emitPointerToArray(ShPtr< PointerType > pointerToArrayType, ShPtr< Variable > var=nullptr)
Emits a pointer to the given array, possibly with the given variable.
Definition: c_hll_writer.cpp:1668
void emitDebugComment(std::string comment, bool indent=true)
Emits the given debug comment.
Definition: c_hll_writer.cpp:2081
void emitHeaderOfFuncReturningPointerToFunc(ShPtr< Function > func)
A specialization of emitFunctionHeader() for functions returning a pointer to a function.
Definition: c_hll_writer.cpp:1428
std::size_t unnamedStructCounter
Definition: c_hll_writer.h:188
virtual std::string getCommentPrefix() override
Returns the prefix of comments in the given language.
Definition: c_hll_writer.cpp:266
virtual std::string getId() const override
Returns the ID of the writer.
Definition: c_hll_writer.cpp:262
void emitReturnType(ShPtr< FunctionType > funcType)
Emits the return type of the given function.
Definition: c_hll_writer.cpp:1816
void emitFunctionDefinition(ShPtr< Function > func)
Emits the given function definition.
Definition: c_hll_writer.cpp:1341
void emitArrayOfFuncPointers(ShPtr< ArrayType > arrayType, ShPtr< Variable > var=nullptr)
Emits the given array of function pointers, possibly with the given variable.
Definition: c_hll_writer.cpp:1630
void emitPointerToFunc(ShPtr< PointerType > pointerToFuncType, ShPtr< Variable > var=nullptr)
Emits a pointer to the given function, possibly with the given variable.
Definition: c_hll_writer.cpp:1594
void emitGlobalDirectives(ShPtr< Function > func)
void emitInitVarDefWhenNeeded(ShPtr< UForLoopStmt > loop)
Emits the definition of the initialization variable of the given loop when it is needed.
Definition: c_hll_writer.cpp:876
virtual bool emitExternalFunction(ShPtr< Function > func) override
Emits the given linked function, including the ending newline.
Definition: c_hll_writer.cpp:490
void emitArrayDimensions(ShPtr< ArrayType > arrayType)
Emits the dimensions of the given array.
Definition: c_hll_writer.cpp:1686
bool optionEmitFunctionPrototypesForNonLibraryFuncs
Definition: c_hll_writer.h:198
std::map< ShPtr< StructType >, std::string > StructTypeNameMap
Mapping of a structured type into its name.
Definition: c_hll_writer.h:47
void emitNameOfVarIfExists(ShPtr< Variable > var)
Emits the name of var if it is a non-null pointer.
Definition: c_hll_writer.cpp:1823
ShPtr< CompoundOpManager > compoundOpManager
Optimizes AssignStmt to compound operator when possible.
Definition: c_hll_writer.h:181
CHLLWriter(llvm::raw_ostream &out, const std::string &outputFormat="")
Constructs a new C writer.
Definition: c_hll_writer.cpp:240
A base class of all HLL writers.
Definition: hll_writer.h:41
ShPtr< Module > module
The module to be written.
Definition: hll_writer.h:177
UPtr< OutputManager > out
Output where the resulting code will be generated.
Definition: hll_writer.h:180
A base class of all HLL writers.
A library providing API for working with back-end IR.
std::shared_ptr< T > ShPtr
An alias for a shared pointer.
Definition: smart_ptr.h:18
std::vector< ShPtr< StructType > > StructTypeVector
Vector of structured types.
Definition: types.h:111
std::set< ShPtr< Function > > FuncSet
Set of functions.
Definition: types.h:78
Definition: archive_wrapper.h:19
Declarations, aliases, macros, etc. for the use of smart pointers.