[core] rename command name to 'write_fabric_pin_physical_location`` and start developing exec func

This commit is contained in:
tangxifan 2024-04-10 13:30:02 -07:00
parent f1334645db
commit 47baaff94c
5 changed files with 139 additions and 8 deletions

View File

@ -24,6 +24,7 @@
#include "vtr_log.h"
#include "vtr_time.h"
#include "write_xml_module_name_map.h"
#include "write_xml_fabric_pin_physical_location.h"
/* begin namespace openfpga */
namespace openfpga {
@ -419,6 +420,41 @@ int write_module_naming_rules_template(const T& openfpga_ctx,
cmd_context.option_enable(cmd, opt_verbose));
}
/********************************************************************
* Write fabric pin physical location to a file
*******************************************************************/
template <class T>
int write_fabric_pin_physical_location_template(const T& openfpga_ctx,
const Command& cmd,
const CommandContext& cmd_context) {
CommandOptionId opt_verbose = cmd.option("verbose");
CommandOptionId opt_no_time_stamp = cmd.option("no_time_stamp");
/* Check the option '--file' is enabled or not
* Actually, it must be enabled as the shell interface will check
* before reaching this fuction
*/
CommandOptionId opt_file = cmd.option("file");
VTR_ASSERT(true == cmd_context.option_enable(cmd, opt_file));
VTR_ASSERT(false == cmd_context.option_value(cmd, opt_file).empty());
std::string file_name = cmd_context.option_value(cmd, opt_file);
std::string module_name;
CommandOptionId opt_module = cmd.option("module");
if (true == cmd_context.option_enable(cmd, opt_module)) {
module_name = cmd_context.option_value(cmd, opt_module).empty();
}
/* Write hierarchy to a file */
return write_xml_fabric_pin_physical_location(
file_name.c_str(), module_name,
openfpga_ctx.module_name_map(), openfpga_ctx.module_graph(),
!cmd_context.option_enable(cmd, opt_no_time_stamp),
cmd_context.option_enable(cmd, opt_verbose));
}
} /* end namespace openfpga */
#endif

View File

@ -864,10 +864,10 @@ ShellCommandId add_write_module_naming_rules_command_template(
* - Add command dependency
*******************************************************************/
template <class T>
ShellCommandId add_write_pin_physical_location_command_template(
ShellCommandId add_write_fabric_pin_physical_location_command_template(
openfpga::Shell<T>& shell, const ShellCommandClassId& cmd_class_id,
const std::vector<ShellCommandId>& dependent_cmds, const bool& hidden) {
Command shell_cmd("write_pin_physical_location");
Command shell_cmd("write_fabric_pin_physical_location");
/* Add an option '--file' in short '-f'*/
CommandOptionId opt_file = shell_cmd.add_option(
"file", true, "file path to the XML file that contains pin physical location");
@ -892,7 +892,7 @@ ShellCommandId add_write_pin_physical_location_command_template(
hidden);
shell.set_command_class(shell_cmd_id, cmd_class_id);
shell.set_command_const_execute_function(
shell_cmd_id, write_pin_physical_location_template<T>);
shell_cmd_id, write_fabric_pin_physical_location_template<T>);
/* Add command dependency to the Shell */
shell.set_command_dependency(shell_cmd_id, dependent_cmds);
@ -1142,13 +1142,13 @@ void add_setup_command_templates(openfpga::Shell<T>& shell,
hidden);
/********************************
* Command 'write_pin_physical_location'
* Command 'write_fabric_pin_physical_location'
*/
/* The command should NOT be executed before 'build_fabric' */
std::vector<ShellCommandId> cmd_dependency_write_pin_physical_location;
cmd_dependency_write_pin_physical_location.push_back(build_fabric_cmd_id);
add_write_pin_physical_location_command_template<T>(
shell, openfpga_setup_cmd_class, cmd_dependency_write_pin_physical_location,
std::vector<ShellCommandId> cmd_dependency_write_fabric_pin_physical_location;
cmd_dependency_write_fabric_pin_physical_location.push_back(build_fabric_cmd_id);
add_write_fabric_pin_physical_location_command_template<T>(
shell, openfpga_setup_cmd_class, cmd_dependency_write_fabric_pin_physical_location,
hidden);
}

View File

@ -0,0 +1,13 @@
#ifndef FABRIC_PIN_PHYSICAL_LOCATION_XML_CONSTANTS_H
#define FABRIC_PIN_PHYSICAL_LOCATION_XML_CONSTANTS_H
/* Constants required by XML parser */
constexpr const char* XML_PINLOC_ROOT_NAME = "pin_location";
constexpr const char* XML_MODULE_NODE_NAME = "module";
constexpr const char* XML_MODULE_ATTRIBUTE_NAME = "name";
constexpr const char* XML_MODULE_PINLOC_NODE_NAME = "loc";
constexpr const char* XML_MODULE_PINLOC_ATTRIBUTE_PIN = "pin";
constexpr const char* XML_MODULE_PINLOC_ATTRIBUTE_SIDE = "side";
#endif

View File

@ -0,0 +1,56 @@
/***************************************************************************************
* Output internal structure of DeviceRRGSB to XML format
***************************************************************************************/
/* Headers from vtrutil library */
#include "vtr_assert.h"
#include "vtr_log.h"
#include "vtr_time.h"
/* Headers from openfpgautil library */
#include "openfpga_digest.h"
#include "fabric_pin_physical_location_xml_constants.h"
#include "write_xml_fabric_pin_physical_location.h"
/* begin namespace openfpga */
namespace openfpga {
int write_xml_fabric_pin_physical_location(
const char* fname, const std::string& module_name,
const ModuleGraph& module_manager,
const bool& include_time_stamp,
const bool& verbose) {
vtr::ScopedStartFinishTimer timer("Write fabric pin physical location");
/* Create a file handler */
std::fstream fp;
/* Open the file stream */
fp.open(std::string(fname), std::fstream::out | std::fstream::trunc);
/* Validate the file stream */
openfpga::check_file_stream(fname, fp);
write_xml_fabric_pin_physical_location_file_head(fp, include_time_stamp);
/* Write the root node */
fp << "<" << XML_PINLOC_ROOT_NAME;
fp << ">"
<< "\n";
int err_code = 0;
/* Write each port */
/* Finish writing the root node */
fp << "</" << XML_PINLOC_ROOT_NAME << ">"
<< "\n";
/* Close the file stream */
fp.close();
VTR_LOGV(verbose, "Outputted %lu modules with pin physical location.\n", cnt);
return err_code;
} /* end namespace openfpga */

View File

@ -0,0 +1,26 @@
#ifndef WRITE_XML_FABRIC_PIN_PHYSICAL_LOCATION_H
#define WRITE_XML_FABRIC_PIN_PHYSICAL_LOCATION_H
/********************************************************************
* Include header files that are required by function declaration
*******************************************************************/
#include <string>
#include "module_manager.h"
/********************************************************************
* Function declaration
*******************************************************************/
/* begin namespace openfpga */
namespace openfpga {
int write_xml_fabric_pin_physical_location(
const char* fname, const std::string& module_name,
const ModuleGraph& module_manager,
const bool& include_time_stamp,
const bool& verbose);
} /* end namespace openfpga */
#endif