OpenFPGA/vpr7_x2p/vpr/SRC/fpga_x2p/verilog/verilog_lut.cpp

76 lines
2.6 KiB
C++
Raw Normal View History

2019-09-11 18:04:43 -05:00
/********************************************************************
* This file includes functions to generate Verilog submodules for LUTs
********************************************************************/
#include <string>
#include <algorithm>
#include "util.h"
#include "vtr_assert.h"
/* Device-level header files */
#include "mux_graph.h"
#include "module_manager.h"
#include "physical_types.h"
#include "vpr_types.h"
#include "mux_utils.h"
/* FPGA-X2P context header files */
#include "spice_types.h"
#include "fpga_x2p_naming.h"
#include "fpga_x2p_utils.h"
/* FPGA-Verilog context header files */
#include "verilog_writer_utils.h"
#include "verilog_module_writer.h"
2019-09-11 18:04:43 -05:00
#include "verilog_lut.h"
/********************************************************************
* Print Verilog modules for the Look-Up Tables (LUTs)
* in the circuit library
********************************************************************/
void print_verilog_submodule_luts(ModuleManager& module_manager,
std::vector<std::string>& netlist_names,
2019-09-11 18:04:43 -05:00
const CircuitLibrary& circuit_lib,
const std::string& verilog_dir,
2019-10-22 16:31:08 -05:00
const std::string& submodule_dir,
const bool& use_explicit_port_map) {
std::string verilog_fname = submodule_dir + luts_verilog_file_name;
2019-09-11 18:04:43 -05:00
std::fstream fp;
/* Create the file stream */
fp.open(verilog_fname, std::fstream::out | std::fstream::trunc);
/* Check if the file stream if valid or not */
check_file_handler(fp);
/* Create file */
vpr_printf(TIO_MESSAGE_INFO,
"Generating Verilog netlist for LUTs (%s)...\n",
2019-09-11 18:41:45 -05:00
verilog_fname.c_str());
2019-09-11 18:04:43 -05:00
print_verilog_file_header(fp, "Look-Up Tables");
print_verilog_include_defines_preproc_file(fp, verilog_dir);
/* Search for each LUT circuit model */
for (const auto& lut_model : circuit_lib.models()) {
2019-09-11 18:04:43 -05:00
/* Bypass user-defined and non-LUT modules */
if ( (!circuit_lib.model_verilog_netlist(lut_model).empty())
|| (SPICE_MODEL_LUT != circuit_lib.model_type(lut_model)) ) {
2019-09-11 18:04:43 -05:00
continue;
}
/* Find the module id */
ModuleId lut_module = module_manager.find_module(circuit_lib.model_name(lut_model));
VTR_ASSERT(true == module_manager.valid_module_id(lut_module));
2019-10-22 16:31:08 -05:00
write_verilog_module_to_file(fp, module_manager, lut_module,
use_explicit_port_map || circuit_lib.dump_explicit_port_map(lut_model));
2019-09-11 18:04:43 -05:00
}
/* Close the file handler */
fp.close();
/* Add fname to the netlist name list */
netlist_names.push_back(verilog_fname);
2019-09-11 18:04:43 -05:00
}