PandA-2024.02
Public Member Functions | Protected Member Functions | Protected Attributes
HLSCWriter Class Reference

#include <hls_c_writer.hpp>

Inheritance diagram for HLSCWriter:
Inheritance graph
[legend]
Collaboration diagram for HLSCWriter:
Collaboration graph
[legend]

Public Member Functions

 HLSCWriter (const CBackendInformationConstRef hls_c_backend_information, const HLS_managerConstRef _HLSMgr, const InstructionWriterRef instruction_writer, const IndentedOutputStreamRef indented_output_stream, const ParameterConstRef _parameters, bool verbose=true)
 Constructor of the class. More...
 
virtual ~HLSCWriter ()
 
void WriteFile (const std::string &file_name) override
 Writes the final C file. More...
 
void WriteHeader () override
 Writes the header of the file. More...
 
- Public Member Functions inherited from CWriter
virtual ~CWriter ()
 
virtual void Initialize ()
 Initialize data structure. More...
 
const InstructionWriterRef getInstructionWriter () const
 Returns the instruction writer. More...
 
const CustomSet< unsigned int > GetLocalVariables (const unsigned int function_id) const
 Compute the local variables of a function. More...
 
virtual void StartFunctionBody (const unsigned int function_id)
 Writes the body of the function to the specified stream. More...
 
virtual void WriteFunctionBody (const unsigned int function_id)
 Writes the body of a function. More...
 
virtual void EndFunctionBody (unsigned int funId)
 Writes the code necessary to close a function (this function was a function also present in the original specification) More...
 
virtual void writeRoutineInstructions (const unsigned int function_index, const OpVertexSet &instructions, var_pp_functorConstRef variableFunctor, vertex bb_start=NULL_VERTEX, CustomOrderedSet< vertex > bb_end=CustomOrderedSet< vertex >())
 Writes the instructions of the current routine, being it a task or a function of the original program. More...
 
virtual void WriteFunctionDeclaration (const unsigned int funId)
 Writes the declaration of the function whose id in the tree is funId. More...
 
virtual void writeInclude (const std::string &file_name)
 Writes an include directive. More...
 
virtual void DeclareType (const tree_nodeConstRef &varType, const BehavioralHelperConstRef &behavioral_helper, CustomSet< std::string > &locally_declared_type)
 This method should be called only if the type associated with the variable is a non built_in type and, in case the non built_in type hasn't been declared yet, it declares it; this method is used to declared new types with scope limited to a routine (be it a function of a task) More...
 
virtual void DeclareVariable (const tree_nodeConstRef &curVar, CustomSet< unsigned int > &already_declared_variables, CustomSet< std::string > &locally_declared_type, const BehavioralHelperConstRef &behavioral_helper, const var_pp_functorConstRef &varFunc)
 Declares the local variable; in case the variable used in the intialization of curVar hasn't been declared yet it get declared. More...
 
virtual void declare_cast_types (unsigned int funId, CustomSet< std::string > &locally_declared_types)
 Declare all the types used in conversions. More...
 
virtual void DeclareLocalVariables (const CustomSet< unsigned int > &to_be_declared, CustomSet< unsigned int > &already_declared_variables, CustomSet< std::string > &already_declared_types, const BehavioralHelperConstRef behavioral_helper, const var_pp_functorConstRef varFunc)
 Declares the local variable; in case the variable used in the intialization of curVar hasn't been declared yet it get declared. More...
 
virtual void DeclareFunctionTypes (const tree_nodeConstRef &tn)
 Declares the types of the parameters of a function. More...
 

Protected Member Functions

void WriteParamDecl (const BehavioralHelperConstRef behavioral_helper)
 Write declaration of the top function parameters. More...
 
void WriteParamInitialization (const BehavioralHelperConstRef behavioral_helper, const std::map< std::string, std::string > &curr_test_vector)
 Initialize the parameters of the function. More...
 
void WriteTestbenchFunctionCall (const BehavioralHelperConstRef behavioral_helper)
 Writes a call to the top function to be tested, using its parameters. More...
 
void WriteSimulatorInitMemory (const unsigned int function_id)
 Write some print statements used to dump the values used by the HDL to initialize the memory before the simulation. More...
 
virtual void WriteExtraInitCode ()
 Write additional initialization code needed by subclasses. More...
 
virtual void WriteExtraCodeBeforeEveryMainCall ()
 
virtual void WriteMainTestbench ()
 Writes the main() of the testbench C program. More...
 
void WriteGlobalDeclarations () override
 Writes the global declarations. More...
 
void WriteFunctionImplementation (unsigned int function_index) override
 Write function implementation. More...
 
void WriteBuiltinWaitCall () override
 Writes implementation of __builtin_wait_call. More...
 
- Protected Member Functions inherited from CWriter
void writeRoutineInstructions_rec (vertex current_vertex, bool bracket, const unsigned int function_index)
 Write recursively instructions belonging to a basic block of task or of a function. More...
 
virtual void writePreInstructionInfo (const FunctionBehaviorConstRef, const vertex)
 Write additional information on the given statement vertex, before the statement itself. More...
 
virtual void writePostInstructionInfo (const FunctionBehaviorConstRef, const vertex)
 Write additional information on the given statement vertex, after the statements itself. More...
 
virtual void WriteBodyLoop (const unsigned int function_index, const unsigned int, vertex current_vertex, bool bracket)
 Write the instructions belonging to a body loop. More...
 
void compute_phi_nodes (const FunctionBehaviorConstRef function_behavior, const OpVertexSet &instructions, var_pp_functorConstRef variableFunctor)
 Determines the instructions coming out from phi-node splitting. More...
 
void insert_copies (vertex b, const BBGraphConstRef bb_domGraph, const BBGraphConstRef bb_fcfgGraph, var_pp_functorConstRef variableFunctor, const CustomSet< unsigned int > &phi_instructions, std::map< unsigned int, unsigned int > &created_variables, std::map< unsigned int, std::string > &symbol_table, std::map< unsigned int, std::deque< std::string >> &array_of_stacks)
 Compute the copy assignments needed by the phi nodes destruction Further details can be found in: More...
 
void schedule_copies (vertex b, const BBGraphConstRef bb_domGraph, const BBGraphConstRef bb_fcfgGraph, var_pp_functorConstRef variableFunctor, const CustomSet< unsigned int > &phi_instructions, std::map< unsigned int, unsigned int > &created_variables, std::map< unsigned int, std::string > &symbol_table, std::list< unsigned int > &pushed, std::map< unsigned int, std::deque< std::string >> &array_of_stacks)
 insert copies according the algorithm described in Briggs et. More...
 
unsigned int create_new_identifier (std::map< unsigned int, std::string > &symbol_table)
 create an identifier for the temporaries created by phi node destruction More...
 
void push_stack (std::string symbol_name, unsigned int dest_i, std::list< unsigned int > &pushed, std::map< unsigned int, std::deque< std::string >> &array_of_stacks)
 push on the stack of temporary variables that has to replaced More...
 
void pop_stack (std::list< unsigned int > &pushed, std::map< unsigned int, std::deque< std::string >> &array_of_stacks)
 remove from the stack all the temporaries More...
 
void WriteHashTableImplementation ()
 Write the implementation of a hash table with long long int as key and long long int as value. More...
 
virtual void WriteBBHeader (const unsigned int bb_number, const unsigned int function_index)
 
 CWriter (const HLS_managerConstRef _HLSMgr, const InstructionWriterRef instruction_writer, const IndentedOutputStreamRef indented_output_stream, const ParameterConstRef Param, bool verbose=true)
 Constructor of the class. More...
 

Protected Attributes

const CBackendInformationConstRef c_backend_info
 Backend information. More...
 
- Protected Attributes inherited from CWriter
const HLS_managerConstRef HLSMgr
 the hls manager More...
 
const tree_managerConstRef TM
 The tree manager. More...
 
const IndentedOutputStreamRef indented_output_stream
 Represents the stream we are currently writing to. More...
 
CustomSet< std::string > globally_declared_types
 This set contains the list of the non built_in types already declared in the global scope. More...
 
CustomSet< unsigned int > globallyDeclVars
 
const InstructionWriterRef instrWriter
 Contains the class used to write instructions. More...
 
size_t bb_label_counter
 Counter of the invocations of writeRoutineInstructions; this counter allows to print different labels in differnt tasks to avoid problem due to multiple tasks inlineing. More...
 
bool verbose
 Verbosity means that a comment is printed for each line in the output file. More...
 
const ParameterConstRef Param
 set of parameters More...
 
int debug_level
 the debug level More...
 
int output_level
 the output level More...
 
unsigned int fake_max_tree_node_id
 
std::map< unsigned int, std::string > basic_block_prefix
 string to be printed at the beginning of a given basic block More...
 
std::map< unsigned int, std::string > basic_block_tail
 string to be printed at the end of a given basic block More...
 
std::map< vertex, std::map< unsigned int, std::string > > renaming_table
 renaming table used by phi node destruction procedure More...
 
CustomOrderedSet< vertexbb_frontier
 
CustomOrderedSet< vertexbb_analyzed
 
std::map< unsigned int, std::string > basic_blocks_labels
 
CustomOrderedSet< vertexgoto_list
 
var_pp_functorConstRef local_rec_variableFunctor
 
FunctionBehaviorConstRef local_rec_function_behavior
 
CustomOrderedSet< vertexlocal_rec_instructions
 
const dominance< BBGraph > * dominators
 
const dominance< BBGraph > * post_dominators
 
BBGraphConstRef local_rec_bb_fcfgGraph
 
OpGraphConstRef local_rec_cfgGraph
 
BehavioralHelperConstRef local_rec_behavioral_helper
 
std::vector< std::string > additionalIncludes
 
CustomOrderedSet< std::string > writtenIncludes
 

Additional Inherited Members

- Static Public Member Functions inherited from CWriter
static CWriterRef CreateCWriter (const CBackendInformationConstRef c_backend_information, const HLS_managerConstRef hls_man, const IndentedOutputStreamRef indented_output_stream, const ParameterConstRef parameters, const bool verbose)
 Factory method. More...
 

Detailed Description

Definition at line 52 of file hls_c_writer.hpp.

Constructor & Destructor Documentation

◆ HLSCWriter()

HLSCWriter::HLSCWriter ( const CBackendInformationConstRef  hls_c_backend_information,
const HLS_managerConstRef  _HLSMgr,
const InstructionWriterRef  instruction_writer,
const IndentedOutputStreamRef  indented_output_stream,
const ParameterConstRef  _parameters,
bool  verbose = true 
)

Constructor of the class.

Parameters
hls_c_backend_informationis the information about backend
HLSMgris the hls manager
instruction_writeris the instruction writer to use to print the single instruction
indented_output_streamis the stream where code has to be printed
Paramis the set of parameters
verbosetells if annotations

Definition at line 83 of file hls_c_writer.cpp.

References CWriter::debug_level, GET_CLASS, and ~HLSCWriter().

Here is the call graph for this function:

◆ ~HLSCWriter()

HLSCWriter::~HLSCWriter ( )
virtualdefault

Referenced by HLSCWriter().

Here is the caller graph for this function:

Member Function Documentation

◆ WriteBuiltinWaitCall()

void HLSCWriter::WriteBuiltinWaitCall ( )
overrideprotectedvirtual

Writes implementation of __builtin_wait_call.

Do nothing

Reimplemented from CWriter.

Definition at line 1174 of file hls_c_writer.cpp.

◆ WriteExtraCodeBeforeEveryMainCall()

void HLSCWriter::WriteExtraCodeBeforeEveryMainCall ( )
protectedvirtual

Reimplemented in DiscrepancyAnalysisCWriter.

Definition at line 573 of file hls_c_writer.cpp.

Referenced by WriteMainTestbench().

Here is the caller graph for this function:

◆ WriteExtraInitCode()

void HLSCWriter::WriteExtraInitCode ( )
protectedvirtual

Write additional initialization code needed by subclasses.

Reimplemented in DiscrepancyAnalysisCWriter.

Definition at line 569 of file hls_c_writer.cpp.

Referenced by WriteMainTestbench().

Here is the caller graph for this function:

◆ WriteFile()

void HLSCWriter::WriteFile ( const std::string &  file_name)
overridevirtual

Writes the final C file.

Parameters
file_nameis the name of the file to be generated

Reimplemented from CWriter.

Definition at line 1154 of file hls_c_writer.cpp.

References GET_INDEX_CONST_NODE, tree_manager::GetFunction(), CWriter::HLSMgr, INDENT_OUT_MEX, CWriter::indented_output_stream, CWriter::output_level, OUTPUT_LEVEL_VERBOSE, CWriter::Param, THROW_ASSERT, CWriter::TM, IndentedOutputStream::WriteFile(), and WriteMainTestbench().

Here is the call graph for this function:

◆ WriteFunctionImplementation()

void HLSCWriter::WriteFunctionImplementation ( unsigned int  function_index)
overrideprotectedvirtual

Write function implementation.

Parameters
function_idis the index of the function to be written

Do nothing

Reimplemented from CWriter.

Definition at line 1169 of file hls_c_writer.cpp.

◆ WriteGlobalDeclarations()

void HLSCWriter::WriteGlobalDeclarations ( )
overrideprotectedvirtual

Writes the global declarations.

Reimplemented from CWriter.

Definition at line 189 of file hls_c_writer.cpp.

References CWriter::instrWriter.

◆ WriteHeader()

void HLSCWriter::WriteHeader ( )
overridevirtual

Writes the header of the file.

Reimplemented from CWriter.

Definition at line 95 of file hls_c_writer.cpp.

References IndentedOutputStream::Append(), tree_manager::CGetTreeNode(), tree_helper::GetMangledFunctionName(), CWriter::HLSMgr, CWriter::indented_output_stream, string_to_container(), and CWriter::TM.

Here is the call graph for this function:

◆ WriteMainTestbench()

void HLSCWriter::WriteMainTestbench ( )
protectedvirtual

◆ WriteParamDecl()

void HLSCWriter::WriteParamDecl ( const BehavioralHelperConstRef  behavioral_helper)
protected

Write declaration of the top function parameters.

Declaration and initialization are separate statements.

Definition at line 194 of file hls_c_writer.cpp.

References IndentedOutputStream::Append(), tree_helper::CGetType(), BehavioralHelper::get_function_name(), BehavioralHelper::GetParameters(), CWriter::indented_output_stream, tree_helper::IsPointerType(), tree_helper::IsVectorType(), param, tree_helper::PrintType(), BehavioralHelper::PrintVariable(), THROW_ERROR, CWriter::TM, and test_panda::type.

Referenced by WriteMainTestbench(), and DiscrepancyAnalysisCWriter::WriteMainTestbench().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ WriteParamInitialization()

void HLSCWriter::WriteParamInitialization ( const BehavioralHelperConstRef  behavioral_helper,
const std::map< std::string, std::string > &  curr_test_vector 
)
protected

Initialize the parameters of the function.

Declaration and initialization are separate statements and the declaration code must be printed before the initialization code.

Parameters
behavioral_helperis the function to which the parameters are referred
curr_test_vectoris the test vector used to initialize the parameters

Definition at line 213 of file hls_c_writer.cpp.

References IndentedOutputStream::Append(), tree_helper::CGetPointedType(), tree_helper::CGetType(), CWriter::debug_level, DEBUG_LEVEL_VERY_PEDANTIC, ends_with(), GET_CONST_NODE, GET_INDEX_CONST_NODE, BehavioralHelper::GetMangledFunctionName(), BehavioralHelper::GetParameters(), tree_helper::GetRealType(), CWriter::HLSMgr, INDENT_DBG_MEX, CWriter::indented_output_stream, tree_helper::IsPointerType(), tree_helper::IsRealType(), tree_helper::IsVoidType(), param, lenet_tvm::params, tree_helper::PrintType(), BehavioralHelper::PrintVariable(), STR, THROW_ASSERT, THROW_ERROR, CWriter::TM, U, and wrapper_def().

Referenced by WriteMainTestbench(), and DiscrepancyAnalysisCWriter::WriteMainTestbench().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ WriteSimulatorInitMemory()

void HLSCWriter::WriteSimulatorInitMemory ( const unsigned int  function_id)
protected

Write some print statements used to dump the values used by the HDL to initialize the memory before the simulation.

(This function actually also reserves memory out of the top function to be tested, if needed. This should not be done here, but in a separate memory allocation step, and will be moved soon).

Definition at line 418 of file hls_c_writer.cpp.

References align(), IndentedOutputStream::Append(), CWriter::debug_level, DEBUG_LEVEL_VERY_PEDANTIC, TestbenchGeneration::generate_init_file(), CWriter::HLSMgr, INDENT_DBG_MEX, CWriter::indented_output_stream, max, CWriter::Param, test_panda::parameters, STR, and CWriter::TM.

Referenced by WriteMainTestbench().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ WriteTestbenchFunctionCall()

void HLSCWriter::WriteTestbenchFunctionCall ( const BehavioralHelperConstRef  behavioral_helper)
protected

Writes a call to the top function to be tested, using its parameters.

The code for the declaration and initialization of such parameters must be written before a call to obtain meaningful outcome.

Parameters
behavioral_helperrefers to the function to be tested

Definition at line 353 of file hls_c_writer.cpp.

References IndentedOutputStream::Append(), BehavioralHelper::get_function_index(), BehavioralHelper::get_function_name(), GET_INDEX_CONST_NODE, BehavioralHelper::GetFunctionReturnType(), BehavioralHelper::GetMangledFunctionName(), BehavioralHelper::GetParameters(), CWriter::HLSMgr, CWriter::indented_output_stream, tree_helper::IsPointerType(), param, CWriter::Param, BehavioralHelper::PrintVariable(), and RETURN_PORT_NAME.

Referenced by WriteMainTestbench(), and DiscrepancyAnalysisCWriter::WriteMainTestbench().

Here is the call graph for this function:
Here is the caller graph for this function:

Field Documentation

◆ c_backend_info

const CBackendInformationConstRef HLSCWriter::c_backend_info
protected

Backend information.

Definition at line 56 of file hls_c_writer.hpp.

Referenced by DiscrepancyAnalysisCWriter::WriteExtraInitCode().


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

Generated on Mon Feb 12 2024 13:03:55 for PandA-2024.02 by doxygen 1.8.13