PandA-2024.02
instruction_writer.cpp
Go to the documentation of this file.
1 /*
2  *
3  * _/_/_/ _/_/ _/ _/ _/_/_/ _/_/
4  * _/ _/ _/ _/ _/_/ _/ _/ _/ _/ _/
5  * _/_/_/ _/_/_/_/ _/ _/_/ _/ _/ _/_/_/_/
6  * _/ _/ _/ _/ _/ _/ _/ _/ _/
7  * _/ _/ _/ _/ _/ _/_/_/ _/ _/
8  *
9  * ***********************************************
10  * PandA Project
11  * URL: http://panda.dei.polimi.it
12  * Politecnico di Milano - DEIB
13  * System Architectures Group
14  * ***********************************************
15  * Copyright (C) 2004-2024 Politecnico di Milano
16  *
17  * This file is part of the PandA framework.
18  *
19  * The PandA framework is free software; you can redistribute it and/or modify
20  * it under the terms of the GNU General Public License as published by
21  * the Free Software Foundation; either version 3 of the License, or
22  * (at your option) any later version.
23  *
24  * This program is distributed in the hope that it will be useful,
25  * but WITHOUT ANY WARRANTY; without even the implied warranty of
26  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27  * GNU General Public License for more details.
28  *
29  * You should have received a copy of the GNU General Public License
30  * along with this program. If not, see <http://www.gnu.org/licenses/>.
31  *
32  */
44 #include "instruction_writer.hpp"
45 
46 #include "Parameter.hpp"
47 #include "actor_graph_backend.hpp"
48 #include "application_manager.hpp"
49 #include "behavioral_helper.hpp"
50 #include "function_behavior.hpp"
52 #include "refcount.hpp"
53 #include "string_manipulation.hpp"
54 #include "tree_helper.hpp"
55 #include "tree_manager.hpp"
56 #include "var_pp_functor.hpp"
57 
59  const IndentedOutputStreamRef _indented_output_stream,
60  const ParameterConstRef _parameters)
61  : AppM(_AppM), indented_output_stream(_indented_output_stream), parameters(_parameters)
62 {
63  debug_level = parameters->get_class_debug_level(GET_CLASS(*this));
64 }
65 
70 {
71  switch(actor_graph_backend_type)
72  {
74  {
75  return InstructionWriterRef(new InstructionWriter(AppM, indented_output_stream, parameters));
76  }
77  default:
78  {
80  }
81  }
82  return InstructionWriterRef();
83 }
84 
86 
88 {
89 }
90 
91 void InstructionWriter::write(const FunctionBehaviorConstRef function_behavior, const vertex statement,
92  const var_pp_functorConstRef varFunctor)
93 {
94  const auto statement_string = function_behavior->CGetBehavioralHelper()->print_vertex(
95  function_behavior->CGetOpGraph(FunctionBehavior::CFG), statement, varFunctor);
96 
97  if(statement_string.size())
98  {
99  indented_output_stream->Append(statement_string);
100  }
101 }
102 
103 void InstructionWriter::declareFunction(const unsigned int function_id)
104 {
105  const auto TM = AppM->get_tree_manager();
106  const auto BH = AppM->CGetFunctionBehavior(function_id)->CGetBehavioralHelper();
107  const auto fdecl = tree_helper::PrintType(TM, TM->CGetTreeReindex(function_id), false, true, false, nullptr,
110 }
111 
113 {
114 }
115 
116 void InstructionWriter::WriteComment(const std::string& text)
117 {
118  indented_output_stream->Append("//" + text + "\n");
119 }
int debug_level
The debug level.
virtual ~InstructionWriter()
Destructor.
#define GET_CLASS(obj)
Macro returning the actual type of an object.
Definition of the class representing a generic C application.
Class to print indented code.
Simple class to print single instruction.
virtual void write_declarations()
Write code needed for declaration/initialization of auxiliary variables.
Auxiliary methods for manipulating string.
#define THROW_UNREACHABLE(str_expr)
helper function used to specify that some points should never be reached
Definition: exceptions.hpp:292
virtual void Initialize()
Initialize data structure.
Standard functor that returns the name of a variable.
virtual void declareFunction(const unsigned int function_id)
Write the declaration of a function.
Control flow graph.
void Append(const std::string &str)
Append a string to the output.
boost::graph_traits< graph >::vertex_descriptor vertex
vertex definition.
Definition: graph.hpp:1303
Abstract class to write an actor graphs.
const BehavioralHelperConstRef CGetBehavioralHelper() const
Returns the helper associated with the function.
InstructionWriter(const application_managerConstRef AppM, const IndentedOutputStreamRef indented_output_stream, const ParameterConstRef parameters)
Constructor; it is protected since factory method should be used.
const application_managerConstRef AppM
The application manager.
void WriteComment(const std::string &text)
Writes a comment.
This file collects some utility functions.
Template definition of refcount.
std::string print_vertex(const OpGraphConstRef g, const vertex v, const var_pp_functorConstRef vppf, const bool dot=false) const
Print the operations corrisponding to the vertex.
ActorGraphBackend_Type
C thread backend to be used.
static InstructionWriterRef CreateInstructionWriter(const ActorGraphBackend_Type actor_graph_backend_type, const application_managerConstRef AppM, const IndentedOutputStreamRef indented_output_stream, const ParameterConstRef parameters)
Factory method.
const IndentedOutputStreamRef indented_output_stream
The indented output stream.
const OpGraphConstRef CGetOpGraph(FunctionBehavior::graph_type gt) const
This method returns the operation graphs.
static std::string PrintType(const tree_managerConstRef &TM, const tree_nodeConstRef &type, bool global=false, bool print_qualifiers=false, bool print_storage=false, const tree_nodeConstRef &var=nullptr, const var_pp_functorConstRef &vppf=var_pp_functorConstRef(), const std::string &prefix="", const std::string &tail="")
Print a type and its variable in case var is not zero.
Template borrowed from the ANTLR library by Terence Parr (http://www.jGuru.com - Software rights: htt...
Definition: refcount.hpp:94
this class is used to manage the command-line or XML options.
refcount< InstructionWriter > InstructionWriterRef
virtual void write(const FunctionBehaviorConstRef function_behavior, const vertex statement, const var_pp_functorConstRef varFunctor)
Write a statement.
refcount< const var_pp_functor > var_pp_functorConstRef
Class specification of the manager of the tree structures extracted from the raw file.
A brief description of the C++ Header File.
const ParameterConstRef parameters
The set of input parameters.

Generated on Mon Feb 12 2024 13:02:51 for PandA-2024.02 by doxygen 1.8.13