PandA-2024.02
language_writer.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  */
45 #ifndef LANGUAGE_WRITER_HPP
46 #define LANGUAGE_WRITER_HPP
47 
49 #include "config_HAVE_FROM_C_BUILT.hpp"
50 
52 #include "custom_set.hpp"
53 #include "dbgPrintHelper.hpp"
54 #include "refcount.hpp"
55 
56 #include <list>
57 #include <map>
58 #include <set>
59 #include <string>
60 #include <vector>
61 
74 
75 #define BITSIZE_PREFIX "BITSIZE_"
76 #define PORTSIZE_PREFIX "PORTSIZE_"
77 #define NUM_ELEM_PREFIX "NUM_ELEM_"
79 {
80  VERILOG = 0,
82  VHDL
83 };
84 
89 {
90  protected:
91  inline std::string encode_one_hot(unsigned int n_states, unsigned int val) const
92  {
93  std::string res;
94  for(unsigned int i = 0; i < n_states; ++i)
95  {
96  res = (val == i ? "1" : "0") + res;
97  }
98  return res;
99  }
100 
103 
106 
109 
112 
115 
116  public:
120  language_writer(char open_char, char close_char, const ParameterConstRef parameters);
121 
125  virtual ~language_writer();
126 
133  static language_writerRef create_writer(HDLWriter_Language language, const technology_managerConstRef TM,
134  const ParameterConstRef parameters);
135 
139  virtual std::string get_name() const = 0;
140 
144  virtual std::string get_extension() const = 0;
145 
150  virtual void write(const std::string& rawString);
151 
155  virtual void write_header();
156 
161  virtual void write_comment(const std::string& comment_string) = 0;
162 
167  virtual std::string type_converter(structural_type_descriptorRef Type) = 0;
168 
173  virtual std::string type_converter_size(const structural_objectRef& cir) = 0;
174 
179  virtual void write_library_declaration(const structural_objectRef& cir) = 0;
184  virtual void write_module_declaration(const structural_objectRef& cir) = 0;
189  virtual void write_module_internal_declaration(const structural_objectRef& cir) = 0;
194  virtual void write_port_declaration(const structural_objectRef& cir, bool first_port_analyzed) = 0;
199  virtual void write_component_declaration(const structural_objectRef& cir) = 0;
204  virtual void write_signal_declaration(const structural_objectRef& cir) = 0;
209  virtual void write_module_definition_begin(const structural_objectRef& cir) = 0;
216  virtual void write_module_instance_begin(const structural_objectRef& cir, const std::string& module_name,
217  bool write_parametrization) = 0;
222  virtual void write_module_instance_end(const structural_objectRef& cir) = 0;
228  virtual void write_port_binding(const structural_objectRef& port, const structural_objectRef& top,
229  bool first_port_analyzed) = 0;
230 
231  virtual void write_vector_port_binding(const structural_objectRef& port, bool first_port_analyzed) = 0;
236  virtual void write_module_definition_end(const structural_objectRef& cir) = 0;
248  virtual void write_io_signal_post_fix(const structural_objectRef& port, const structural_objectRef& sig) = 0;
249  virtual void write_io_signal_post_fix_vector(const structural_objectRef& port, const structural_objectRef& sig) = 0;
259  virtual void write_module_parametrization(const structural_objectRef& cir) = 0;
264  virtual void write_state_declaration(const structural_objectRef& cir, const std::list<std::string>& list_of_states,
265  const std::string& reset_port, const std::string& reset_state,
266  bool one_hot) = 0;
274  virtual void write_present_state_update(const structural_objectRef cir, const std::string& reset_state,
275  const std::string& reset_port, const std::string& clock_port,
276  const std::string& reset_type, bool connect_present_next_state_signals) = 0;
286  virtual void write_transition_output_functions(
287  bool single_proc, unsigned int output_index, const structural_objectRef& cir, const std::string& reset_state,
288  const std::string& reset_port, const std::string& start_port, const std::string& clock_port,
289  std::vector<std::string>::const_iterator& first, std::vector<std::string>::const_iterator& end, bool is_yosys,
290  const std::map<unsigned int, std::map<std::string, std::set<unsigned int>>>& bypass_signals) = 0;
291 
296  virtual void write_NP_functionalities(const structural_objectRef& cir) = 0;
297 
301  virtual void write_port_decl_header() = 0;
302 
306  virtual void write_port_decl_tail() = 0;
307 
311  virtual void write_module_parametrization_decl(const structural_objectRef& cir) = 0;
312 
313  virtual void write_assign(const std::string& op0, const std::string& op1) = 0;
314 
315  virtual bool has_output_prefix() const = 0;
316 
321  static unsigned int bitnumber(unsigned long long n);
322 
323  virtual bool check_keyword(const std::string& id) const = 0;
324 
329  virtual void WriteBuiltin(const structural_objectConstRef component) = 0;
330 
334  const std::string WriteString() const;
335 
340  void WriteFile(const std::string& filename) const;
341 
345  CustomSet<std::string> GetHDLReservedNames() const;
346 
350  void WriteLicense();
351 };
354 
355 #endif
void * top(node_stack *head)
Definition: tree.c:75
File containing functions and utilities to support the printing of debug messagges.
Structure representing the most relevant information about the type of a structural object...
std::string filename
int debug_level
debugging level of the class
CONSTREF_FORWARD_DECL(Parameter)
const IndentedOutputStreamRef indented_output_stream
Represents the stream we are currently writing to.
HDLWriter_Language
CustomOrderedSet< std::string > list_of_customized_gates
list of customized gates
unsigned map[NUM_VERTICES]
Definition: bfs.c:12
CustomOrderedSet< std::string > list_of_lib
list of library imported (e.g., includes).
This class manages the technology library structures.
redefinition of set to manage ordered/unordered structures
REF_FORWARD_DECL(IndentedOutputStream)
Template definition of refcount.
std::string encode_one_hot(unsigned int n_states, unsigned int val) const
const ParameterConstRef parameters
the set of input parameters
HDL writer base class used to specify the interface of the different language writers.
Class to print indented code.
Base object for all the structural objects.

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