PandA-2024.02
flopoco_wrapper.hpp
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  */
33 
47 #ifndef FLOPOCOWRAPPER_HPP
48 #define FLOPOCOWRAPPER_HPP
49 
50 #include "custom_map.hpp"
51 #include "custom_set.hpp"
52 #include "dbgPrintHelper.hpp"
53 #include "exceptions.hpp"
54 #include "refcount.hpp"
55 #include "simple_indent.hpp"
56 #include "utility.hpp"
57 
58 #include <string>
59 #include <vector>
60 
62 #define FILE_EXT ".vhdl"
63 #define ENCODE_NAME(FU_name, FU_prec_in, FU_prec_out, pipe_parameter) \
65  ((FU_name) + "_" + STR(FU_prec_in) + "_" + STR(FU_prec_out) + ((pipe_parameter) != "" ? "_" + (pipe_parameter) : ""))
66 #define FLOPOCO_ADDITIONAL_BITS 2
68 #define IN_WRAP_PREFIX "in_wrap_"
70 #define OUT_WRAP_PREFIX "out_wrap_"
72 #define WRAPPED_PREFIX "wrapped_"
74 
82 namespace flopoco
83 {
84  class Operator;
85  class Target;
86 } // namespace flopoco
88 
94 {
95  private:
96 #ifndef NDEBUG
97  int debug_level;
99 #endif
109  using port_type = enum { port_in, port_out, clk, rst };
111  using component_type = enum { top, wrapped, in_wrap, out_wrap };
113  using unit_type = enum {
114  UT_ADD,
115  UT_SUB,
116  UT_MULT,
117  UT_DIV,
118  UT_FF_CONV,
119  UT_ADDSUB,
120  UT_UFIX2FP,
121  UT_IFIX2FP,
122  UT_FP2UFIX,
123  UT_FP2IFIX,
124  UT_EXP,
125  UT_SQRT,
126  UT_compare_expr,
127  UT_LOG,
128  UT_POW,
129  UT_UNKNOWN
130  };
131 
133 
134  bool signed_p;
135 
136  std::vector<flopoco::Operator*> oplist;
137 
138  flopoco::Target* target;
139 
144  flopoco::Operator* get_FU(std::string FU_name_stored) const;
145 
153  const std::vector<std::string> get_ports(const std::string& FU_name_stored, unsigned int expected_ports,
154  port_type type, bool check_ports = true) const;
155 
160  const std::string get_port(port_type type) const;
161 
173  int InternalWriteVHDL(const std::string& FU_name, const unsigned int FU_prec_in, const unsigned int FU_prec_out,
174  const std::string& filename, const std::string& pipe_parameter);
175 
183  void outputHeaderVHDL(const std::string& FU_name_stored, std::ostream& os) const;
184  void outputWrapVHDL(const std::string& FU_name_stored, std::ostream& os, const std::string& pipe_parameter);
185  void outputPortDeclaration(const std::string& FU_prefix, const std::string& FU_name_stored, std::ostream& os,
186  component_type type, const std::string& pipe_parameter);
187  void outputSignals(const std::string& FU_name_stored, std::ostream& os);
188  void outputPortMap(const std::string& FU_name_stored, std::ostream& os, const std::string& pipe_parameter);
189 
190  public:
195  flopoco_wrapper(int _debug_level, const std::string& FU_target);
196 
200  ~flopoco_wrapper();
201 
202  // no copy constructor
203  flopoco_wrapper(const flopoco_wrapper& inst) = delete;
204 
213  void add_FU(const std::string& FU_type, unsigned int FU_prec_in, unsigned int FU_prec_out,
214  const std::string& FU_name, const std::string& pipe_parameter);
215 
222  unsigned int get_FUPipelineDepth(const std::string& FU_name, const unsigned int FU_prec_in,
223  const unsigned int FU_prec_out, const std::string& pipe_parameter) const;
224 
235  int writeVHDL(const std::string& FU_name, const unsigned int FU_prec_in, const unsigned int FU_prec_out,
236  std::string pipe_parameter, std::string& filename);
237 
242  std::string writeVHDLcommon();
243 
248  {
249  return this->FU_files;
250  }
251 
256  bool is_unit_written(const std::string& FU_name, const unsigned int FU_prec_in, const unsigned int FU_prec_out,
257  const std::string& pipe_parameter) const
258  {
259  return this->FU_files.find(ENCODE_NAME(FU_name, FU_prec_in, FU_prec_out, pipe_parameter) + FILE_EXT) !=
260  this->FU_files.end();
261  }
262 
268  const std::vector<std::string> get_in_ports(const std::string& FU_name, const unsigned int FU_prec_in,
269  const unsigned int FU_prec_out, const unsigned int expected_ports,
270  const std::string& pipe_parameter) const
271  {
272  return get_ports(ENCODE_NAME(WRAPPED_PREFIX + FU_name, FU_prec_in, FU_prec_out, pipe_parameter), expected_ports,
273  port_in);
274  }
275  const std::vector<std::string> get_out_ports(const std::string& FU_name, const unsigned int FU_prec_in,
276  const unsigned int FU_prec_out, const unsigned int expected_ports,
277  const std::string& pipe_parameter) const
278  {
279  return get_ports(ENCODE_NAME(WRAPPED_PREFIX + FU_name, FU_prec_in, FU_prec_out, pipe_parameter), expected_ports,
280  port_out);
281  }
282 
289  static void DECODE_BITS(unsigned int FU_prec, unsigned int& n_mant, unsigned int& n_exp);
290 
291  static constexpr double DEFAULT_TARGET_FREQUENCY = 100.0;
292 };
293 
296 
297 #endif /* FLOPOCOWRAPPER_H */
Forward declarations of FloPoCo classes.
void * top(node_stack *head)
Definition: tree.c:75
std::vector< flopoco::Operator * > oplist
File containing functions and utilities to support the printing of debug messagges.
bool is_unit_written(const std::string &FU_name, const unsigned int FU_prec_in, const unsigned int FU_prec_out, const std::string &pipe_parameter) const
Checks if a Functional Unit have been written to a VHDL file.
REF_FORWARD_DECL(flopoco_wrapper)
RefCount type definition of the flopoco_wrapper class structure.
const std::vector< std::string > get_out_ports(const std::string &FU_name, const unsigned int FU_prec_in, const unsigned int FU_prec_out, const unsigned int expected_ports, const std::string &pipe_parameter) const
std::string filename
Simple pretty print functor.
simple_indent PP
Pretty print functor object used to indent the generated code.
const CustomUnorderedSet< std::string > & get_files_written()
Returns the Functional Units that have been written to a VHDL file.
enum { UT_ADD, UT_SUB, UT_MULT, UT_DIV, UT_FF_CONV, UT_ADDSUB, UT_UFIX2FP, UT_IFIX2FP, UT_FP2UFIX, UT_FP2IFIX, UT_EXP, UT_SQRT, UT_compare_expr, UT_LOG, UT_POW, UT_UNKNOWN } unit_type
unit type
exceptions managed by PandA
flopoco::Target * target
enum { port_in, port_out, clk, rst } port_type
Port types.
#define ENCODE_NAME(FU_name, FU_prec_in, FU_prec_out, pipe_parameter)
Name of the stored Functional Unit.
redefinition of map to manage ordered/unordered structures
#define WRAPPED_PREFIX
Suffix appended to the internal (wrapped) Functional Unit.
CustomUnorderedSet< std::string > FU_files
Set of Functional Units written to a .vhdl file.
CustomUnorderedMap< std::string, std::pair< unsigned int, unsigned int > > FU_to_prec
Maps a Functional Unit to its precision.
#define FILE_EXT
Default extension for generated files.
const std::vector< std::string > get_in_ports(const std::string &FU_name, const unsigned int FU_prec_in, const unsigned int FU_prec_out, const unsigned int expected_ports, const std::string &pipe_parameter) const
Return the names of input and output ports (multiple names, thus a vector of strings) ...
absl::flat_hash_map< T, U, Hash, Eq, Alloc > CustomUnorderedMap
Definition: custom_map.hpp:148
redefinition of set to manage ordered/unordered structures
This file collects some utility functions and macros.
Template definition of refcount.
Very simple pretty printer functor.
Main class for wrapping the FloPoCo code generator.
Template borrowed from the ANTLR library by Terence Parr (http://www.jGuru.com - Software rights: htt...
Definition: refcount.hpp:94
enum { top, wrapped, in_wrap, out_wrap } component_type
Component types.

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