PandA-2024.02
Static Public Member Functions | Static Private Member Functions
prettyPrintVertex Struct Reference

Class used to print a vertex of a graph. More...

#include <prettyPrintVertex.hpp>

Static Public Member Functions

static void print_forward_declaration (std::ostream &os, unsigned int type, simple_indent &PP, const BehavioralHelperConstRef BH)
 This function prints the forward type declaration of a type. More...
 
static void get_internal_vars (const vertex &v, const OpGraphConstRef g, CustomUnorderedSet< unsigned int > &list_of_variables, const BehavioralHelperConstRef BH)
 Header include. More...
 

Static Private Member Functions

static std::string statement2string (unsigned int stm, var_pp_functor &vppf, simple_indent &PP, const BehavioralHelperConstRef BH)
 return a string for the passed statement. More...
 

Detailed Description

Class used to print a vertex of a graph.

Let us consider the following example:

   typedef int MYINT;
   void simple_add(MYINT a, int b, MYINT * res)
   {
     *res = a + b + b + a;
   }

The obtained data flow graph for this simple piece of C code is:

dot_inline_dotgraph_26.png

The expression is splitted in four vertexes each one performing an addition or a result storage. In particular, the first vertex, simple_add_1_31, compute the first addition a+b but the statements stored in the vertex are actually two: the first one compute the addition (stored in the PandA artificial variable with nodeid 31) and the second one store the result in the var written (GCC artificial variable with nodeid 30) associated with the vertex. The considered vertex has

VAR_READ(simple_add_1_31) = 4(a) 5(b) VAR_WRITTEN(simple_add_1_31) =
30(Internal_0) 

but to correctly dump a C description before write the two statements with the print_statement member function we need to declare the two variables used by the vertex. To obtain these two variables the macro VAR_READ and VAR_WRITTEN are not enough since the variable 31(Internal) is missing. To obtain all the referenced variables in the vertex simple_add_1_31 we have to use the get_referenced_vars member function. Given the list of variables referenced by the vertex of the graph we need to print the possible type declarations for the variables based on user defined types. In the example the parameter a and res are of type MYINT, therefore, before print the declarations of the variables we have to print the declaration of the user type MYINT. To do that we have first to detect the set of user type declarations and then we can print the declaration with print_type_declaration. To check if a type is a user defined type we can use behavior_helper::is_built_in_type while to get the type from a variable we can use behavior_helper::get_type. After the type definition we can print the declarations of the variables with print_var_declaration.

Definition at line 116 of file prettyPrintVertex.hpp.

Member Function Documentation

◆ get_internal_vars()

void prettyPrintVertex::get_internal_vars ( const vertex v,
const OpGraphConstRef  g,
CustomUnorderedSet< unsigned int > &  list_of_variables,
const BehavioralHelperConstRef  BH 
)
static

◆ print_forward_declaration()

void prettyPrintVertex::print_forward_declaration ( std::ostream &  os,
unsigned int  type,
simple_indent PP,
const BehavioralHelperConstRef  BH 
)
static

This function prints the forward type declaration of a type.

Parameters
osis the output stream.
typeis the nodeid of the type.
PPis the pretty print functor object used to indent the generated code.
BHis the behavioral helper.

Definition at line 100 of file prettyPrintVertex.cpp.

References BehavioralHelper::print_forward_declaration().

Here is the call graph for this function:

◆ statement2string()

static std::string prettyPrintVertex::statement2string ( unsigned int  stm,
var_pp_functor vppf,
simple_indent PP,
const BehavioralHelperConstRef  BH 
)
staticprivate

return a string for the passed statement.

The referenced variables are printed with the indenter and variable functor.

Parameters
vppfis the functor used to dump the variable var.
PPis the pretty print functor object used to indent the generated code.
BHis the behavioral helper.

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

Generated on Mon Feb 12 2024 13:04:01 for PandA-2024.02 by doxygen 1.8.13