PandA-2024.02
SynthesisTool.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  */
42 #include "SynthesisTool.hpp"
43 
44 #include <utility>
45 
46 #include "DesignParameters.hpp"
47 #include "Parameter.hpp"
48 #include "bash_flow_wrapper.hpp"
49 #include "exceptions.hpp"
50 #include "fileIO.hpp"
51 #include "lattice_flow_wrapper.hpp"
52 #include "map_wrapper.hpp"
53 #include "ngdbuild_wrapper.hpp"
55 #include "par_wrapper.hpp"
57 #include "quartus_13_wrapper.hpp"
60 #include "quartus_wrapper.hpp"
61 #include "trce_wrapper.hpp"
62 #include "utility.hpp"
63 #include "vivado_flow_wrapper.hpp"
64 #include "xml_dom_parser.hpp"
65 #include "xml_helper.hpp"
66 #include "xml_script_command.hpp"
67 #include "xst_wrapper.hpp"
68 #include <filesystem>
69 
70 SynthesisTool::SynthesisTool(const ParameterConstRef& _Param, std::string _tool_exec, const generic_deviceRef& _device,
71  const std::string& _flow_name, std::string _output_dir)
72  : device(_device),
73  Param(_Param),
74  debug_level(Param->getOption<int>(OPT_debug_level)),
75  output_level(Param->getOption<unsigned int>(OPT_output_level)),
76  tool_exec(std::move(_tool_exec)),
77  output_dir(std::move(_output_dir))
78 {
80  create_output_directory(_flow_name);
81 
83 }
84 
86 
88 {
89  return !script_map.empty() || !xml_script_nodes.empty();
90 }
91 
93  const std::string& _output_dir, const generic_deviceRef& _device)
94 {
95  switch(type)
96  {
97  case UNKNOWN:
98  THROW_ERROR("Synthesis tool not specified");
99  break;
100  case XST:
101  return SynthesisToolRef(new xst_wrapper(_Param, _output_dir, _device));
102  break;
103  case NGDBUILD:
104  return SynthesisToolRef(new ngdbuild_wrapper(_Param, _output_dir, _device));
105  break;
106  case MAP:
107  return SynthesisToolRef(new map_wrapper(_Param, _output_dir, _device));
108  break;
109  case TRCE:
110  return SynthesisToolRef(new trce_wrapper(_Param, _output_dir, _device));
111  break;
112  case PAR:
113  return SynthesisToolRef(new par_wrapper(_Param, _output_dir, _device));
114  break;
115  case VIVADO_FLOW:
116  return SynthesisToolRef(new vivado_flow_wrapper(_Param, _output_dir, _device));
117  break;
118  case QUARTUS_13_SETUP:
119  return SynthesisToolRef(new Quartus13Wrapper(_Param, _output_dir, _device));
120  break;
121  case QUARTUS_13_STA:
122  return SynthesisToolRef(new Quartus13ReportWrapper(_Param, _output_dir, _device));
123  break;
124  case QUARTUS_13_FLOW:
125  return SynthesisToolRef(new Quartus13Wrapper(_Param, _output_dir, _device));
126  break;
127  case QUARTUS_SETUP:
128  return SynthesisToolRef(new QuartusWrapper(_Param, _output_dir, _device));
129  break;
130  case QUARTUS_FLOW:
131  return SynthesisToolRef(new QuartusWrapper(_Param, _output_dir, _device));
132  break;
133  case QUARTUS_POW:
134  return SynthesisToolRef(new QuartusPowerWrapper(_Param, _output_dir, _device));
135  break;
136  case QUARTUS_STA:
137  return SynthesisToolRef(new QuartusReportWrapper(_Param, _output_dir, _device));
138  break;
139  case LATTICE_FLOW:
140  return SynthesisToolRef(new lattice_flow_wrapper(_Param, _output_dir, _device));
141  break;
142  case NXPYTHON_FLOW:
143  return SynthesisToolRef(new nxpython_flow_wrapper(_Param, _output_dir, _device));
144  case BASH_FLOW:
145  return SynthesisToolRef(new bash_flow_wrapper(_Param, _output_dir, _device));
146  break;
147  default:
148  THROW_ERROR("Synthesis tool currently not supported");
149  }
151  return SynthesisToolRef();
152 }
153 
155 {
156 }
157 
159 {
160 }
161 
163 {
164  return output_dir;
165 }
166 
167 void SynthesisTool::create_output_directory(const std::string& sub_dir)
168 {
169  auto general_output_dir = Param->getOption<std::string>(OPT_output_directory);
170  if(!sub_dir.empty())
171  {
172  general_output_dir += "/" + sub_dir;
173  }
174  output_dir = general_output_dir + std::string("/") + output_dir;
175 
176  std::string candidate_dir;
177  if(std::filesystem::exists(output_dir))
178  {
179  unsigned int progressive = 0;
180  do
181  {
182  candidate_dir = output_dir + "_" + std::to_string(progressive++);
183  } while(std::filesystem::exists(candidate_dir));
184  output_dir = candidate_dir;
185  }
186  std::filesystem::create_directories(output_dir);
187  std::filesystem::create_directories(output_dir + "/input");
188  std::filesystem::create_directories(output_dir + "/output");
189 }
190 
192 {
193  xml_script_nodes.clear();
194  xml_tool_options.clear();
195 
196  bool nodes_found = false;
197  const xml_node::node_list& lines = child->get_children();
198  for(const auto& line : lines)
199  {
200  const xml_element* script_element = GetPointer<xml_element>(line);
201  if(!script_element)
202  {
203  continue;
204  }
205  if(xml_script_node_t::find_type(script_element) == NODE_PARAMETER)
206  {
207  if(nodes_found)
208  {
209  THROW_ERROR("Cannot instantiate tool options after script nodes");
210  }
211  xml_parameter_tRef option = xml_parameter_tRef(new xml_parameter_t(script_element));
212  xml_tool_options.push_back(option);
213  }
214  else
215  {
217  xml_script_nodes.push_back(script_node);
218  nodes_found = true;
219  }
220  }
221 }
222 
223 void SynthesisTool::xload(const xml_element* node, const std::string& tool_config)
224 {
225  bool node_found = false;
226  const xml_node::node_list& list = node->get_children();
227  for(const auto& l : list)
228  {
229  const xml_element* child = GetPointer<xml_element>(l);
230  if(!child)
231  {
232  continue;
233  }
234  if(child->get_name() != get_tool_exec())
235  {
236  continue;
237  }
238  std::string config;
239  if(!CE_XVM(config, child))
240  {
241  THROW_ERROR("missing configuration for the tool: " + get_tool_exec());
242  }
243  LOAD_XVM(config, child);
244  if(config != tool_config)
245  {
246  continue;
247  }
248  if(node_found)
249  {
250  THROW_ERROR("double configuration for <" + get_tool_exec() + "," + tool_config);
251  }
252  node_found = true;
253 
254  xload_scripts(child);
255  }
256 }
257 
258 xml_nodeRef SynthesisTool::xwrite() const
259 {
260  xml_elementRef root = xml_elementRef(new xml_element(get_tool_exec()));
261  for(const auto& node : xml_tool_options)
262  {
263  root->add_child_element(node->create_xml_node());
264  }
265  for(const auto& node : xml_script_nodes)
266  {
267  root->add_child_element(node->create_xml_node());
268  }
269  return root;
270 }
271 
272 std::string SynthesisTool::generate_bare_script(const std::vector<xml_script_node_tRef>& nodes,
273  const DesignParametersRef& dp)
274 {
275  std::string script;
276  for(const auto& node : nodes)
277  {
278  if(node->checkCondition(dp) || node->nodeType == NODE_ITE_BLOCK)
279  {
280  script += toString(node, dp);
281  script += "\n";
282  }
283  }
284  return script;
285 }
286 
288 {
289  for(auto& node : xml_reserved_vars)
290  {
291  if(name == node->name)
292  {
293  return node;
294  }
295  }
296  THROW_ERROR("\"" + name + "\" is not a reserved tool parameter");
297  return xml_set_variable_tRef(new xml_set_variable_t(nullptr));
298 }
299 
300 void SynthesisTool::replace_parameters(const DesignParametersRef& dp, std::string& script) const
301 {
303  for(const auto& it : map)
304  {
305  const std::string& name = it.first;
306  const std::string& value = it.second;
307  boost::algorithm::replace_all(script, "${__" + name + "__}", value);
308  boost::algorithm::replace_all(script, "$__" + name + "__", value);
309  }
310 }
311 
313 {
314 }
315 
316 std::string SynthesisTool::get_tool_exec() const
317 {
318  return tool_exec;
319 }
struct Node nodes[7]
const ParameterConstRef Param
class containing all the parameters
Wrapper to trce by XILINX.
Command line parameter.
Main class for wrapping nxpython_flow tool by NANOXPLORE.
Wrapper to invoke a generic bash script.
Main class for wrapping ISE tools by Xilinx.
static SynthesisToolRef create_synthesis_tool(type_t type, const ParameterConstRef &Param, const std::string &output_dir, const generic_deviceRef &device)
Factory method.
std::map< std::string, std::string > map_t
Parameters map type.
Wrapper to invoke vivado_flow tool by XILINX.
const std::string tool_exec
name of the tool executable
virtual std::string toString(const xml_script_node_tRef node, const DesignParametersRef dp) const =0
Returns the string-based representation of the XML element.
void xload(const xml_element *node, const std::string &tool_config)
Method parsing the configuration file directly from an XML node.
exceptions managed by PandA
#define CE_XVM(variable, node)
Check existence XML Value Macro. Check if an XML attribute is present in the XML tree.
Definition: xml_helper.hpp:88
Definition of hash function for EdgeDescriptor.
Definition: graph.hpp:1321
Main class for wrapping ISE tools by Xilinx.
Definition: xst_wrapper.hpp:71
Main class for wrapping vivado_flow tool by XILINX.
virtual void init_reserved_vars()
Initializes the reserved variables.
std::string output_dir
the output directory
virtual ~SynthesisTool()
Destructor.
virtual void EvaluateVariables(const DesignParametersRef dp)
Evaluates the design variables.
Main class for wrapping quartus_pow tool by Altera.
void line(int x1, int y1, int x2, int y2, unsigned int color)
Definition: main.c:110
Main class for wrapping quartus_report tool by Altera.
void create_output_directory(const std::string &sub_dir)
Creates the directory to store the output files.
Wrapper to invoke nxpython_flow tool by NANOXPLORE.
map_t parameter_values
Map between the name of the parameter and the corresponding string-based value.
std::vector< xml_script_node_tRef > xml_script_nodes
unsigned map[NUM_VERTICES]
Definition: bfs.c:12
std::string get_name() const
Get the name of this node.
Definition: xml_node.hpp:132
bool has_scripts() const
Checks if there is a configuration script loaded.
enum { UNKNOWN=0, XST, NGDBUILD, MAP, PAR, TRCE, VIVADO_FLOW, QUARTUS_13_FLOW, QUARTUS_13_SETUP, QUARTUS_13_STA, QUARTUS_SETUP, QUARTUS_FLOW, QUARTUS_POW, QUARTUS_STA, LATTICE_FLOW, NXPYTHON_FLOW, BASH_FLOW } type_t
supported synthesis tools
std::vector< xml_set_variable_tRef > xml_reserved_vars
Main class for wrapping ISE tools by Xilinx.
This file contains the definition of the parameters for the synthesis tools.
std::string get_output_directory() const
Returns the path of the output directory.
Wrapper to XST by XILINX.
xml_set_variable_tRef get_reserved_parameter(const std::string &name)
Gets a reserved (tool) parameter by name.
XML DOM parser.
utility function used to read files.
refcount< xml_script_node_t > xml_script_node_tRef
This file collects some utility functions and macros.
void replace_parameters(const DesignParametersRef &dp, std::string &script) const
Replaces occurrences of parameters inside a script.
Wrapper to par by XILINX.
std::list< xml_nodeRef > node_list
type for list of xml nodes
Definition: xml_node.hpp:90
#define THROW_ERROR(str_expr)
helper function used to throw an error in a standard way
Definition: exceptions.hpp:263
Main class for wrapping lattice_flow tool by Lattice.
Wrapper to invoke quartus_report tool by Altera.
std::vector< xml_parameter_tRef > xml_tool_options
static xml_script_node_t * create(const xml_element *element)
Creates a script node by parsing the XML element.
Main class for wrapping ISE tools by Xilinx.
Definition: par_wrapper.hpp:58
Classes for handling configuration files.
Wrapper to ngdbuild by XILINX.
Wrapper to invoke quartus_report tool by Altera.
refcount< SynthesisTool > SynthesisToolRef
refcount definition of the class
Wrapper to invoke lattice_flow tool by Lattice.
Main class for wrapping ISE tools by Xilinx.
Definition: map_wrapper.hpp:59
refcount< xml_parameter_t > xml_parameter_tRef
Variable assignment, either single value or multiple entries set.
Template borrowed from the ANTLR library by Terence Parr (http://www.jGuru.com - Software rights: htt...
Definition: refcount.hpp:94
Main class for wrapping bash_flow tool by NANOXPLORE.
virtual std::string get_tool_exec() const
Returns the name of the tool executable.
this class is used to manage the command-line or XML options.
SynthesisTool(const ParameterConstRef &Param, std::string tool_exec, const generic_deviceRef &device, const std::string &_flow_name, std::string default_output_dir)
Constructor.
refcount< xml_set_variable_t > xml_set_variable_tRef
#define LOAD_XVM(variable, node)
LOAD XML Value Macro. Set a variable starting from an XML value. Conversion is performed if needed...
Definition: xml_helper.hpp:65
xml_nodeRef xwrite() const
Method writing the configuration file.
Wrapper to map by XILINX.
void xload_scripts(const xml_element *child)
Actual parsing of parameters and script nodes.
Some macro used to interface with the XML library.
node_list const & get_children()
Obtain the list of child nodes.
Definition: xml_node.hpp:310
Main class for wrapping quartus_report tool by Altera.
virtual void CheckExecution()
Check if the tool can be really executed; i.e., it has been properly configured.
std::map< unsigned int, std::string > script_map
map between the identifier of the script and the corresponding stream
static xml_script_node_enum_t find_type(const xml_element *element)
Finds the type of an XML element.
Wrapper to quartus 14.0 and newer.
Wrapper to quartus 13.x and newer.
Abstract class for a generic synthesis tool.
std::string generate_bare_script(const std::vector< xml_script_node_tRef > &nodes, const DesignParametersRef &dp)

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