PandA-2024.02
NP_functionality.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 "NP_functionality.hpp"
45 #include "exceptions.hpp" // for THROW_AS...
46 #include "xml_attribute.hpp" // for attribut...
47 #include "xml_element.hpp" // for xml_element
48 #include "xml_helper.hpp" // for WRITE_XNVM2
49 #include <boost/iterator/iterator_facade.hpp> // for operator!=
50 #include <boost/token_functions.hpp> // for char_sep...
51 #include <boost/tokenizer.hpp> // for tokenize...
52 #include <list> // for _List_co...
53 #include <utility> // for pair
54 
56 #include <iostream>
57 
59 #include "string_manipulation.hpp"
60 
62 {
63  unsigned int i;
64  for(i = 0; i < UNKNOWN; i++)
65  {
66  if(val == NP_functionaly_typeNames[i])
67  {
68  break;
69  }
70  }
71  THROW_ASSERT(i < UNKNOWN, "Wrong NP_functionaly_typeNames specified: |" + val + "|");
72  return NP_functionaly_type(i);
73 }
74 
75 const char* NP_functionality::NP_functionaly_typeNames[] = {"TABLE",
76  "EQUATION",
77  "PORT_LIST",
78  "LIBRARY",
79  "GRAPH",
80  "FSM",
81  "FSM_CS",
82  "SC_PROVIDED",
83  "VHDL_PROVIDED",
84  "VERILOG_PROVIDED",
85  "SYSTEM_VERILOG_PROVIDED",
86  "VERILOG_GENERATOR",
87  "VHDL_GENERATOR",
88  "FLOPOCO_PROVIDED",
89  "BAMBU_PROVIDED",
90  "IP_COMPONENT",
91  "IP_INCLUDE",
92  "IP_LIBRARY",
93  "VERILOG_FILE_PROVIDED",
94  "VHDL_FILE_PROVIDED",
95  "UNKNOWN"};
96 
97 void NP_functionality::add_NP_functionality(NP_functionaly_type type, const std::string& functionality_description)
98 {
99  descriptions[type] = functionality_description;
100 }
101 
103 {
104  // Recurse through attributes:
105  const xml_element::attribute_list& list = Enode->get_attributes();
106  for(auto iter : list)
107  {
108  descriptions[to_NP_functionaly_type(iter->get_name())] = iter->get_value();
109  }
110 }
112 {
113  xml_element* Enode = rootnode->add_child_element(get_kind_text());
114  auto it_end = descriptions.end();
115  for(auto it = descriptions.begin(); it != it_end; ++it)
116  {
117  WRITE_XNVM2(NP_functionaly_typeNames[it->first], it->second, Enode);
118  }
119 }
120 
121 void NP_functionality::print(std::ostream& os) const
122 {
123  auto it_end = descriptions.end();
124  for(auto it = descriptions.begin(); it != it_end; ++it)
125  {
126  os << NP_functionaly_typeNames[it->first] << " " << it->second << std::endl;
127  }
128 }
129 
131 {
132  if(descriptions.find(type) == descriptions.end())
133  {
134  return "";
135  }
136  else
137  {
138  return descriptions.find(type)->second;
139  }
140 }
141 
143 {
144  return (descriptions.find(type) != descriptions.end() && !descriptions.find(type)->second.empty());
145 }
146 
148 {
149  std::string library_description = get_NP_functionality(NP_functionality::LIBRARY);
150  if(library_description.empty())
151  {
152  return library_description;
153  }
154  using tokenizer = boost::tokenizer<boost::char_separator<char>>;
155  boost::char_separator<char> sep(" ", nullptr);
156  tokenizer tokens(library_description, sep);
157  return *tokens.begin();
158 }
159 
160 void NP_functionality::get_library_parameters(std::vector<std::string>& parameters) const
161 {
162  std::string library_description = get_NP_functionality(NP_functionality::LIBRARY);
163  if(library_description.empty())
164  {
165  return;
166  }
167 
168  using tokenizer = boost::tokenizer<boost::char_separator<char>>;
169  boost::char_separator<char> sep(" ", nullptr);
170  tokenizer tokens(library_description, sep);
171  tokenizer::iterator tok_iter = tokens.begin();
172  for(++tok_iter; tok_iter != tokens.end(); ++tok_iter)
173  {
174  parameters.push_back(*tok_iter);
175  }
176 }
177 
178 void NP_functionality::get_port_list(std::map<unsigned int, std::map<std::string, std::string>>& InPortMap,
179  std::map<unsigned int, std::map<std::string, std::string>>& OutPortMap) const
180 {
181  std::string port_list = get_NP_functionality(NP_functionality::PORT_LIST);
182  if(port_list.empty())
183  {
184  return;
185  }
186  std::vector<std::string> splitted = SplitString(port_list, ",");
187  for(const auto& port_description : splitted)
188  {
189  if(port_description.empty())
190  {
191  continue;
192  }
193  std::vector<std::string> ports = SplitString(port_description, ":");
194  THROW_ASSERT(ports.size() == 4, "Wrong format for NP_functionality::PORT_LIST functionality");
195  if(ports[0] == "I")
196  {
197  InPortMap[static_cast<unsigned>(std::stoul(ports[1]))][ports[2]] = ports[3];
198  }
199  if(ports[0] == "O")
200  {
201  OutPortMap[static_cast<unsigned>(std::stoul(ports[1]))][ports[2]] = ports[3];
202  }
203  }
204 }
205 
207 {
208  for(unsigned int i = 0; i < UNKNOWN; i++)
209  {
210  std::string val = obj->get_NP_functionality(static_cast<NP_functionaly_type>(i));
211  if(!val.empty())
212  {
213  descriptions[static_cast<NP_functionaly_type>(i)] = val;
214  }
215  }
216 }
NP_functionality()=default
Constructor.
std::list< xml_attribute * > attribute_list
const std::vector< std::string > SplitString(const std::string &input, const std::string &separators)
Function which splits a string into tokens.
void get_port_list(std::map< unsigned int, std::map< std::string, std::string >> &InPortMap, std::map< unsigned int, std::map< std::string, std::string >> &OutPortMap) const
NP_functionaly_type to_NP_functionaly_type(const std::string &val)
Convert a string into the corresponding NP_functionaly_type enumerative type.
attribute_list get_attributes()
Remove the attribute with this name.
std::string get_NP_functionality(NP_functionaly_type type) const
Return the description provided the type.
exceptions managed by PandA
static const char * NP_functionaly_typeNames[]
store the names of the enumerative NP_functionaly_type.
Auxiliary methods for manipulating string.
void add_NP_functionality(NP_functionaly_type type, const std::string &functionality_description)
Add a non SystemC based description.
unsigned map[NUM_VERTICES]
Definition: bfs.c:12
void xload(const xml_element *Enode)
Load a NP_functionality starting from an xml file.
void print(std::ostream &os) const
Print the Non-SystemC based functionality description (for debug purpose).
std::string get_library_name() const
return the name of the library in case it there exists a LIBRARY based description.
void xwrite(xml_element *rootnode)
Add a NP_functionality to an xml tree.
#define WRITE_XNVM2(name, value, node)
WRITE XML Name Value Macro second version. Insert a value in an XML tree given the name of the attrib...
Definition: xml_helper.hpp:58
NP_functionaly_type
functionality type descriptors.
Some macro used to interface with the XML library.
Not parsed functionality manager.
std::map< NP_functionaly_type, std::string > descriptions
Store the description of the functionality.
bool exist_NP_functionality(NP_functionaly_type type) const
Return true in case there exist a functionaly of the given type.
std::string get_kind_text() const
Definition of get_kind_text()
xml_element * add_child_element(const std::string &name)
Add a child element to this node.
Definition: xml_node.cpp:54
void get_library_parameters(std::vector< std::string > &parameters) const
fill a vector with the library parameters in case it there exists a LIBRARY based description...
#define THROW_ASSERT(cond, str_expr)
helper function used to check an assert and if needed to throw an error in a standard way ...
Definition: exceptions.hpp:289

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