PandA-2024.02
OpenModuleGenerator.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) 2022-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  */
47 #include "OpenModuleGenerator.hpp"
48 
49 #include "language_writer.hpp"
50 #include <fcntl.h>
51 
52 OpenModuleGenerator::OpenModuleGenerator(const HLS_managerRef& _HLSMgr) : Registrar(_HLSMgr)
53 {
54 }
55 
56 void OpenModuleGenerator::InternalExec(std::ostream& out, structural_objectRef /* mod */,
57  unsigned int /* function_id */, vertex /* op_v */,
58  const HDLWriter_Language /* language */,
59  const std::vector<ModuleGenerator::parameter>& /* _p */,
60  const std::vector<ModuleGenerator::parameter>& /* _ports_in */,
61  const std::vector<ModuleGenerator::parameter>& /* _ports_out */,
62  const std::vector<ModuleGenerator::parameter>& /* _ports_inout */)
63 {
64  out << " // verilator lint_off LITENDIAN\n";
65  out << "parameter MAX_BUFF_SIZE = 256;\n";
66  out << "reg [0:8*MAX_BUFF_SIZE-1] buffer_name;\n";
67  out << "reg [0:8*MAX_BUFF_SIZE-1] buffer_name_old;\n";
68  out << "\n";
69  out << " `ifndef _SIM_HAVE_CLOG2\n";
70  out << " function integer log2;\n";
71  out << " input integer value;\n";
72  out << " integer temp_value;\n";
73  out << " begin\n";
74  out << " temp_value = value-1;\n";
75  out << " for (log2=0; temp_value>0; log2=log2+1)\n";
76  out << " temp_value = temp_value>>1;\n";
77  out << " end\n";
78  out << " endfunction\n";
79  out << " `endif\n";
80  out << "\n";
81  out << " `ifdef _SIM_HAVE_CLOG2\n";
82  out << " parameter nbits_buffer = $clog2(MAX_BUFF_SIZE);\n";
83  out << " `else\n";
84  out << " parameter nbits_buffer = log2(MAX_BUFF_SIZE);\n";
85  out << " `endif\n";
86 
87  std::string modes = "in2";
88 
89  std::string flags_string = "(" + modes + " & " + STR(O_RDWR) + ") != 0 && (" + modes + " & " + STR(O_APPEND) +
90  ") ? \"a+b\" : ((" + modes + " & " + STR(O_RDWR) + ") != 0 ? \"r+b\" : ((" + modes +
91  " & " + STR(O_WRONLY) + ") != 0 && (" + modes + " & " + STR(O_APPEND) + ") ? \"ab\" : (" +
92  modes + " & " + STR(O_WRONLY) + ") != 0 ? \"wb\" : \"rb\"" + "))";
93 
94  const auto fsm =
95  " reg [nbits_buffer-1:0] _present_index;\n"
96  " reg [nbits_buffer-1:0] _next_index;\n"
97  " reg [BITSIZE_Mout_addr_ram-1:0] _present_pointer;\n"
98  " reg [BITSIZE_Mout_addr_ram-1:0] _next_pointer;\n"
99  " reg done_port;\n"
100  " reg signed [BITSIZE_out1-1:0] temp_out1;\n"
101  " reg Mout_oe_ram;\n"
102  " reg Mout_we_ram;\n"
103  " reg [BITSIZE_Mout_addr_ram-1:0] Mout_addr_ram;\n"
104  " reg [BITSIZE_Mout_Wdata_ram-1:0] Mout_Wdata_ram;\n"
105  " reg [BITSIZE_Mout_data_ram_size-1:0] Mout_data_ram_size;\n"
106  " reg active_request;\n"
107  " reg active_request_now;\n"
108  " reg active_request_next;\n"
109  " reg M_DataRdy_reg;\n"
110  " reg [BITSIZE_M_Rdata_ram-1:0]M_Rdata_ram_reg;\n"
111  " \n"
112  " parameter [1:0] S_0 = 2'd0,\n"
113  " S_1 = 2'd1,\n"
114  " S_2 = 2'd2;\n"
115  " reg [1:0] _present_state 1INIT_ZERO_VALUE;\n"
116  " reg [1:0] _next_state;\n"
117  " reg [63:0] data1;\n"
118  " reg [7:0] data1_size;\n"
119  " \n"
120  " assign out1 = {1'b0,temp_out1[30:0]};\n"
121  " always @(posedge clock 1RESET_EDGE)\n"
122  " begin\n"
123  " if (1RESET_VALUE)\n"
124  " begin\n"
125  " active_request <= 0;\n"
126  " end\n"
127  " else\n"
128  " begin\n"
129  " active_request <= active_request_next;\n"
130  " end\n"
131  " end\n"
132  " always @(posedge clock 1RESET_EDGE)\n"
133  " if (1RESET_VALUE)\n"
134  " begin\n"
135  " _present_state <= S_0;\n"
136  " _present_pointer <= {BITSIZE_Mout_addr_ram{1'b0}};\n"
137  " _present_index <= {nbits_buffer{1'b0}};\n"
138  " buffer_name_old <= {8*MAX_BUFF_SIZE{1'b0}};\n"
139  " M_DataRdy_reg <= 0;\n"
140  " M_Rdata_ram_reg <= 0;\n"
141  " end\n"
142  " else\n"
143  " begin\n"
144  " _present_state <= _next_state;\n"
145  " _present_pointer <= _next_pointer;\n"
146  " _present_index <= _next_index;\n"
147  " buffer_name_old <= buffer_name;\n"
148  " M_DataRdy_reg <= M_DataRdy;\n"
149  " M_Rdata_ram_reg <= M_Rdata_ram;\n"
150  " end\n"
151  " \n"
152  " always @(*)\n"
153  " begin\n"
154  " Mout_we_ram = Min_we_ram;\n"
155  " Mout_Wdata_ram = Min_Wdata_ram;\n"
156  " Mout_oe_ram = Min_oe_ram;\n"
157  " Mout_addr_ram = Min_addr_ram;\n"
158  " Mout_data_ram_size = Min_data_ram_size;\n"
159  " Mout_oe_ram = Min_oe_ram;\n"
160  " Mout_addr_ram = Min_addr_ram;\n"
161  " Mout_data_ram_size = Min_data_ram_size;\n"
162  " done_port = 1'b0;\n"
163  " _next_state = _present_state;\n"
164  " _next_pointer = _present_pointer;\n"
165  " _next_index = _present_index;\n"
166  " active_request_next = 1'b0;\n"
167  " active_request_now = 1'b0;\n"
168  " buffer_name = buffer_name_old;\n"
169  " case (_present_state)\n"
170  " S_0:\n"
171  " if(start_port)\n"
172  " begin\n"
173  " _next_pointer = 0;\n"
174  " _next_index = {nbits_buffer{1'b0}};\n"
175  " _next_state = S_1; \n"
176  " active_request_next = 1'b1;\n"
177  " buffer_name = 0; \n"
178  " _next_pointer = 0;\n"
179  " _next_index = {nbits_buffer{1'b0}};\n"
180  " _next_state = S_1; \n"
181  " active_request_next = 1'b1;\n"
182  " buffer_name = 0; \n"
183  " end\n"
184  " S_1:\n"
185  " begin\n"
186  " if(M_DataRdy_reg)\n"
187  " begin\n"
188  " buffer_name[_present_index*8 +:8] = M_Rdata_ram_reg[7:0];\n"
189  " if(M_Rdata_ram_reg[7:0] == 8'd0)\n"
190  " _next_state = S_2;\n"
191  " else\n"
192  " begin\n"
193  " _next_state = S_1;\n"
194  " _next_pointer = _present_pointer+1'd1;\n"
195  " _next_index = _present_index+1'd1;\n"
196  " active_request_now = 1'b1;\n"
197  " end\n"
198  " end\n"
199  " Mout_addr_ram[BITSIZE_Mout_addr_ram-1:0] = (in1[BITSIZE_Mout_addr_ram-1:0] + _next_pointer) & "
200  "{BITSIZE_Mout_addr_ram{active_request || active_request_now}};\n"
201  " Mout_data_ram_size = {{BITSIZE_Mout_data_ram_size-4{1'b0}}, 4'd8} & "
202  "{BITSIZE_Mout_data_ram_size{active_request || active_request_now}};\n"
203  " Mout_oe_ram = active_request || active_request_now;\n"
204  " end\n"
205  " S_2:\n"
206  " begin\n"
207  "// synthesis translate_off\n"
208  " temp_out1 = $fopen(buffer_name, " +
209  flags_string +
210  ");\n"
211  "// synthesis translate_on\n"
212  " done_port = 1'b1;\n"
213  " _next_state = S_0;\n"
214  " end\n"
215  " endcase\n"
216  " end\n";
217 
218  out << fsm;
219  out << " // verilator lint_on LITENDIAN\n";
220 }
void InternalExec(std::ostream &out, structural_objectRef mod, unsigned int function_id, vertex op_v, const HDLWriter_Language language, const std::vector< ModuleGenerator::parameter > &_p, const std::vector< ModuleGenerator::parameter > &_ports_in, const std::vector< ModuleGenerator::parameter > &_ports_out, const std::vector< ModuleGenerator::parameter > &_ports_inout) final
OpenModuleGenerator(const HLS_managerRef &HLSMgr)
#define STR(s)
Macro which performs a lexical_cast to a string.
HDLWriter_Language
This class writes different HDL based descriptions (VHDL, Verilog, SystemC) starting from a structura...
boost::graph_traits< graph >::vertex_descriptor vertex
vertex definition.
Definition: graph.hpp:1303
Template borrowed from the ANTLR library by Terence Parr (http://www.jGuru.com - Software rights: htt...
Definition: refcount.hpp:94

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