PandA-2024.02
XilinxWrapper.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 "XilinxWrapper.hpp"
46 
47 #include "DesignParameters.hpp"
48 #include "Parameter.hpp"
49 #include "fileIO.hpp"
50 #include "string_manipulation.hpp"
51 #include "xml_script_command.hpp"
52 #include <boost/algorithm/string.hpp>
53 #include <filesystem>
54 #include <fstream>
55 
56 XilinxWrapper::XilinxWrapper(const ParameterConstRef& _Param, const std::string& _tool_exec,
57  const generic_deviceRef& _device, const std::string& _output_dir,
58  const std::string& _default_output_dir)
59  : SynthesisTool(_Param, _tool_exec, _device, _output_dir, _default_output_dir)
60 {
61 }
62 
64 
65 void XilinxWrapper::generate_synthesis_script(const DesignParametersRef& dp, const std::string& file_name)
66 {
67  if(xml_script_nodes.empty())
68  {
69  return;
70  }
71 
72  // Export reserved (constant) values to design parameters
73  for(auto& var : xml_reserved_vars)
74  {
75  // std::cerr << "setting = " << var->name << " #" << getStringValue(var, dp) << "#" << std::endl;
76  dp->assign(var->name, getStringValue(var, dp), false);
77  }
78 
79  // Bare script generation
80  std::ostringstream script;
82 
83  // Replace all reserved variables with their value
84  std::string script_string = script.str();
85  replace_parameters(dp, script_string);
87  remove_escaped(script_string);
88 
89  // Save the generated script
90  if(std::filesystem::exists(file_name))
91  {
92  std::filesystem::remove_all(file_name);
93  }
94  dp->parameter_values[SCRIPT_FILENAME] = file_name;
95  script_name = file_name;
96  std::ofstream file_stream(file_name.c_str());
97  file_stream << script_string << std::endl;
98  file_stream.close();
99 }
100 
102 {
103  switch(node->nodeType)
104  {
105  case NODE_VARIABLE:
106  {
107  std::string result;
108  const xml_set_variable_t* var = GetPointer<xml_set_variable_t>(node);
109  if(var->singleValue)
110  {
111  result += *(var->singleValue);
112  }
113  else if(!var->multiValues.empty())
114  {
115  result += "{";
116  for(auto it = var->multiValues.begin(); it != var->multiValues.end(); ++it)
117  {
118  const xml_set_entry_tRef e = *it;
119  if(it != var->multiValues.begin())
120  {
121  result += " ";
122  }
123  result += toString(e, dp);
124  }
125  result += "}";
126  }
127  else
128  {
129  result += "\"\"";
130  }
131  return result;
132  }
133  case NODE_COMMAND:
134  case NODE_ENTRY:
135  case NODE_FOREACH:
136  case NODE_ITE_BLOCK:
137  case NODE_PARAMETER:
138  case NODE_SHELL:
139  case NODE_UNKNOWN:
140  default:
141  THROW_ERROR("Not supported node type: " + STR(node->nodeType));
142  }
143  return "";
144 }
145 
146 std::string XilinxWrapper::toString(const xml_script_node_tRef node, const DesignParametersRef dp) const
147 {
148  switch(node->nodeType)
149  {
150  case NODE_ENTRY:
151  {
152  const xml_set_entry_t* ent = GetPointer<xml_set_entry_t>(node);
153  return ent->value;
154  }
155  case NODE_VARIABLE:
156  {
157  const xml_set_variable_t* var = GetPointer<xml_set_variable_t>(node);
158  return "set -" + var->name + " " + getStringValue(node, dp);
159  }
160  case NODE_PARAMETER:
161  {
162  const xml_parameter_t* par = GetPointer<xml_parameter_t>(node);
163  std::string result;
165  {
166  return result;
167  }
168  if(par->name)
169  {
170  result += "-" + *(par->name);
171  }
172  if(par->name && (par->singleValue || !par->multiValues.empty()))
173  {
174  result += par->separator;
175  }
176  if(par->singleValue)
177  {
178  result += *(par->singleValue);
179  }
180  else if(!par->multiValues.empty())
181  {
183  }
184  return result;
185  }
186  case NODE_COMMAND:
187  {
188  const xml_command_t* comm = GetPointer<xml_command_t>(node);
189  std::string result;
190  if(comm->name)
191  {
192  result += *(comm->name);
193  }
194  if(!comm->parameters.empty())
195  {
196  for(const auto& p : comm->parameters)
197  {
198  if(p->condition && !xml_script_node_t::evaluate_condition(p->condition, dp))
199  {
200  continue;
201  }
202  result += "\n" + toString(p, dp);
203  }
204  }
205  if(comm->output)
206  {
207  THROW_ERROR("Not supported");
208  }
209  return result;
210  }
211  case NODE_UNKNOWN:
212  case NODE_SHELL:
213  case NODE_ITE_BLOCK:
214  case NODE_FOREACH:
215  default:
216  THROW_ERROR("Not supported node type: " + STR(node->nodeType));
217  }
218  return "";
219 }
std::string * condition
Command line parameter.
void remove_escaped(std::string &ioString)
Function converting all the escaped characters in the associated character.
Wrapper to synthesis tools by Xilinx.
#define STR(s)
Macro which performs a lexical_cast to a string.
Auxiliary methods for manipulating string.
static bool evaluate_condition(const std::string *condition)
Evaluates a string condition.
map_t parameter_values
Map between the name of the parameter and the corresponding string-based value.
#define NOT_YET_IMPLEMENTED()
helper function to mark points not yet implemented
Definition: exceptions.hpp:305
std::vector< xml_script_node_tRef > xml_script_nodes
std::string * name
void assign(const std::string &name, const std::string &value, bool checkExisting)
Assigns a value to a saved parameter.
std::vector< xml_set_variable_tRef > xml_reserved_vars
This file contains the definition of the parameters for the synthesis tools.
std::string script_name
name of the script
utility function used to read files.
~XilinxWrapper() override
Destructor.
void replace_parameters(const DesignParametersRef &dp, std::string &script) const
Replaces occurrences of parameters inside a script.
#define SCRIPT_FILENAME
#define THROW_ERROR(str_expr)
helper function used to throw an error in a standard way
Definition: exceptions.hpp:263
int result[SIZE]
Definition: adpcm.c:800
std::vector< xml_parameter_tRef > parameters
void generate_synthesis_script(const DesignParametersRef &dp, const std::string &file_name) override
Creates the proper configuration script.
Classes for handling configuration files.
std::string * singleValue
std::string value
std::vector< xml_set_entry_tRef > multiValues
std::vector< xml_set_entry_tRef > multiValues
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
Command line of the synthesis tool.
this class is used to manage the command-line or XML options.
XilinxWrapper(const ParameterConstRef &Param, const std::string &tool_exec, const generic_deviceRef &device, const std::string &_output_dir, const std::string &_default_output_dir)
Constructor.
std::string * output
std::string getStringValue(const xml_script_node_tRef node, const DesignParametersRef &dp) const override
Returns the string-based representation of the XML element.
std::string toString(const xml_script_node_tRef node, const DesignParametersRef dp) const override
Returns the string-based representation of the XML element.
String entry of a multiple values variable (set).
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