[FPGA-SPICE] Add SPICE writer for LUT
This commit is contained in:
parent
0f9fce92b2
commit
6801d260e9
|
@ -10,6 +10,7 @@ constexpr char* TRANSISTOR_WRAPPER_POSTFIX = "_wrapper";
|
||||||
constexpr char* TRANSISTORS_SPICE_FILE_NAME = "transistor.sp";
|
constexpr char* TRANSISTORS_SPICE_FILE_NAME = "transistor.sp";
|
||||||
constexpr char* SUPPLY_WRAPPER_SPICE_FILE_NAME = "supply_wrapper.sp";
|
constexpr char* SUPPLY_WRAPPER_SPICE_FILE_NAME = "supply_wrapper.sp";
|
||||||
constexpr char* MUXES_SPICE_FILE_NAME = "muxes.sp";
|
constexpr char* MUXES_SPICE_FILE_NAME = "muxes.sp";
|
||||||
|
constexpr char* LUTS_SPICE_FILE_NAME = "luts.sp";
|
||||||
|
|
||||||
constexpr char* SPICE_SUBCKT_VDD_PORT_NAME = "VDD";
|
constexpr char* SPICE_SUBCKT_VDD_PORT_NAME = "VDD";
|
||||||
constexpr char* SPICE_SUBCKT_GND_PORT_NAME = "VSS";
|
constexpr char* SPICE_SUBCKT_GND_PORT_NAME = "VSS";
|
||||||
|
|
|
@ -0,0 +1,82 @@
|
||||||
|
/********************************************************************
|
||||||
|
* This file includes functions to generate SPICE subcircuits for LUTs
|
||||||
|
********************************************************************/
|
||||||
|
#include <string>
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
/* Headers from vtrutil library */
|
||||||
|
#include "vtr_assert.h"
|
||||||
|
#include "vtr_log.h"
|
||||||
|
|
||||||
|
/* Headers from openfpgautil library */
|
||||||
|
#include "openfpga_digest.h"
|
||||||
|
|
||||||
|
/* Headers from openfpgashell library */
|
||||||
|
#include "command_exit_codes.h"
|
||||||
|
|
||||||
|
#include "mux_graph.h"
|
||||||
|
#include "module_manager.h"
|
||||||
|
#include "mux_utils.h"
|
||||||
|
|
||||||
|
#include "openfpga_naming.h"
|
||||||
|
|
||||||
|
#include "spice_constants.h"
|
||||||
|
#include "spice_writer_utils.h"
|
||||||
|
#include "spice_subckt_writer.h"
|
||||||
|
#include "spice_lut.h"
|
||||||
|
|
||||||
|
/* begin namespace openfpga */
|
||||||
|
namespace openfpga {
|
||||||
|
|
||||||
|
/********************************************************************
|
||||||
|
* Print SPICE modules for the Look-Up Tables (LUTs)
|
||||||
|
* in the circuit library
|
||||||
|
********************************************************************/
|
||||||
|
int print_spice_submodule_luts(NetlistManager& netlist_manager,
|
||||||
|
const ModuleManager& module_manager,
|
||||||
|
const CircuitLibrary& circuit_lib,
|
||||||
|
const std::string& submodule_dir) {
|
||||||
|
int status = CMD_EXEC_SUCCESS;
|
||||||
|
|
||||||
|
std::string spice_fname = submodule_dir + std::string(LUTS_SPICE_FILE_NAME);
|
||||||
|
|
||||||
|
std::fstream fp;
|
||||||
|
|
||||||
|
/* Create the file stream */
|
||||||
|
fp.open(spice_fname, std::fstream::out | std::fstream::trunc);
|
||||||
|
/* Check if the file stream if valid or not */
|
||||||
|
check_file_stream(spice_fname.c_str(), fp);
|
||||||
|
|
||||||
|
/* Create file */
|
||||||
|
VTR_LOG("Writing SPICE netlist for LUTs '%s'...",
|
||||||
|
spice_fname.c_str());
|
||||||
|
|
||||||
|
print_spice_file_header(fp, "Look-Up Tables");
|
||||||
|
|
||||||
|
/* Search for each LUT circuit model */
|
||||||
|
for (const auto& lut_model : circuit_lib.models()) {
|
||||||
|
/* Bypass user-defined and non-LUT modules */
|
||||||
|
if ( (!circuit_lib.model_circuit_netlist(lut_model).empty())
|
||||||
|
|| (CIRCUIT_MODEL_LUT != circuit_lib.model_type(lut_model)) ) {
|
||||||
|
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));
|
||||||
|
write_spice_subckt_to_file(fp, module_manager, lut_module);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Close the file handler */
|
||||||
|
fp.close();
|
||||||
|
|
||||||
|
/* Add fname to the netlist name list */
|
||||||
|
NetlistId nlist_id = netlist_manager.add_netlist(spice_fname);
|
||||||
|
VTR_ASSERT(NetlistId::INVALID() != nlist_id);
|
||||||
|
netlist_manager.set_netlist_type(nlist_id, NetlistManager::SUBMODULE_NETLIST);
|
||||||
|
|
||||||
|
VTR_LOG("Done\n");
|
||||||
|
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
} /* end namespace openfpga */
|
|
@ -0,0 +1,28 @@
|
||||||
|
#ifndef SPICE_LUT_H
|
||||||
|
#define SPICE_LUT_H
|
||||||
|
|
||||||
|
/********************************************************************
|
||||||
|
* Include header files that are required by function declaration
|
||||||
|
*******************************************************************/
|
||||||
|
#include <fstream>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include "circuit_library.h"
|
||||||
|
#include "module_manager.h"
|
||||||
|
#include "netlist_manager.h"
|
||||||
|
|
||||||
|
/********************************************************************
|
||||||
|
* Function declaration
|
||||||
|
*******************************************************************/
|
||||||
|
|
||||||
|
/* begin namespace openfpga */
|
||||||
|
namespace openfpga {
|
||||||
|
|
||||||
|
int print_spice_submodule_luts(NetlistManager& netlist_manager,
|
||||||
|
const ModuleManager& module_manager,
|
||||||
|
const CircuitLibrary& circuit_lib,
|
||||||
|
const std::string& submodule_dir);
|
||||||
|
|
||||||
|
} /* end namespace openfpga */
|
||||||
|
|
||||||
|
#endif
|
|
@ -13,6 +13,7 @@
|
||||||
#include "spice_transistor_wrapper.h"
|
#include "spice_transistor_wrapper.h"
|
||||||
#include "spice_essential_gates.h"
|
#include "spice_essential_gates.h"
|
||||||
#include "spice_mux.h"
|
#include "spice_mux.h"
|
||||||
|
#include "spice_lut.h"
|
||||||
|
|
||||||
#include "spice_constants.h"
|
#include "spice_constants.h"
|
||||||
#include "spice_submodule.h"
|
#include "spice_submodule.h"
|
||||||
|
@ -87,6 +88,17 @@ int print_spice_submodule(NetlistManager& netlist_manager,
|
||||||
return CMD_EXEC_FATAL_ERROR;
|
return CMD_EXEC_FATAL_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Look-Up Tables */
|
||||||
|
status = print_spice_submodule_luts(netlist_manager,
|
||||||
|
module_manager,
|
||||||
|
openfpga_arch.circuit_lib,
|
||||||
|
submodule_dir);
|
||||||
|
|
||||||
|
/* Error out if fatal errors have been reported */
|
||||||
|
if (CMD_EXEC_SUCCESS != status) {
|
||||||
|
return CMD_EXEC_FATAL_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue