diff --git a/openfpga/src/base/openfpga_context.h b/openfpga/src/base/openfpga_context.h index 0eb34c029..e18a3fd34 100644 --- a/openfpga/src/base/openfpga_context.h +++ b/openfpga/src/base/openfpga_context.h @@ -50,6 +50,7 @@ class OpenfpgaContext : public Context { public: /* Public accessors */ const openfpga::Arch& arch() const { return arch_; } + const openfpga::SimulationSetting& simulation_setting() const { return sim_setting_; } const openfpga::VprDeviceAnnotation& vpr_device_annotation() const { return vpr_device_annotation_; } const openfpga::VprNetlistAnnotation& vpr_netlist_annotation() const { return vpr_netlist_annotation_; } const openfpga::VprClusteringAnnotation& vpr_clustering_annotation() const { return vpr_clustering_annotation_; } @@ -68,6 +69,7 @@ class OpenfpgaContext : public Context { const openfpga::NetlistManager& verilog_netlists() const { return verilog_netlists_; } public: /* Public mutators */ openfpga::Arch& mutable_arch() { return arch_; } + openfpga::SimulationSetting& mutable_simulation_setting() { return sim_setting_; } openfpga::VprDeviceAnnotation& mutable_vpr_device_annotation() { return vpr_device_annotation_; } openfpga::VprNetlistAnnotation& mutable_vpr_netlist_annotation() { return vpr_netlist_annotation_; } openfpga::VprClusteringAnnotation& mutable_vpr_clustering_annotation() { return vpr_clustering_annotation_; } @@ -87,6 +89,7 @@ class OpenfpgaContext : public Context { private: /* Internal data */ /* Data structure to store information from read_openfpga_arch library */ openfpga::Arch arch_; + openfpga::SimulationSetting sim_setting_; /* Annotation to pb_type of VPR */ openfpga::VprDeviceAnnotation vpr_device_annotation_; diff --git a/openfpga/src/base/openfpga_read_arch.cpp b/openfpga/src/base/openfpga_read_arch.cpp index db9b09b5b..ce7aed6ba 100644 --- a/openfpga/src/base/openfpga_read_arch.cpp +++ b/openfpga/src/base/openfpga_read_arch.cpp @@ -87,5 +87,59 @@ int write_arch(const OpenfpgaContext& openfpga_context, return CMD_EXEC_SUCCESS; } +/******************************************************************** + * Top-level function to read an OpenFPGA simulation setting file + * we use the APIs from the libarchopenfpga library + * + * The command will accept an option '--file' which is the simulation setting + * file provided by users + *******************************************************************/ +int read_simulation_setting(OpenfpgaContext& openfpga_context, + const Command& cmd, const CommandContext& cmd_context) { + /* 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 arch_file_name = cmd_context.option_value(cmd, opt_file); + + VTR_LOG("Reading XML simulation setting '%s'...\n", + arch_file_name.c_str()); + openfpga_context.mutable_simulation_setting() = read_xml_openfpga_simulation_settings(arch_file_name.c_str()); + + /* TODO: should identify the error code from internal function execution */ + return CMD_EXEC_SUCCESS; +} + +/******************************************************************** + * A function to write an OpenFPGA simulation setting file + * we use the APIs from the libarchopenfpga library + * + * The command will accept an option '--file' which is the simulation setting + * file provided by users + *******************************************************************/ +int write_simulation_setting(const OpenfpgaContext& openfpga_context, + const Command& cmd, const CommandContext& cmd_context) { + /* 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 arch_file_name = cmd_context.option_value(cmd, opt_file); + + VTR_LOG("Writing XML simulation setting to '%s'...\n", + arch_file_name.c_str()); + write_xml_openfpga_simulation_settings(arch_file_name.c_str(), openfpga_context.simulation_setting()); + + /* TODO: should identify the error code from internal function execution */ + return CMD_EXEC_SUCCESS; +} + } /* end namespace openfpga */ diff --git a/openfpga/src/base/openfpga_read_arch.h b/openfpga/src/base/openfpga_read_arch.h index b664a7b3e..d5502db56 100644 --- a/openfpga/src/base/openfpga_read_arch.h +++ b/openfpga/src/base/openfpga_read_arch.h @@ -21,6 +21,12 @@ int read_arch(OpenfpgaContext& openfpga_context, int write_arch(const OpenfpgaContext& openfpga_context, const Command& cmd, const CommandContext& cmd_context); +int read_simulation_setting(OpenfpgaContext& openfpga_context, + const Command& cmd, const CommandContext& cmd_context); + +int write_simulation_setting(const OpenfpgaContext& openfpga_context, + const Command& cmd, const CommandContext& cmd_context); + } /* end namespace openfpga */ #endif diff --git a/openfpga/src/base/openfpga_setup_command.cpp b/openfpga/src/base/openfpga_setup_command.cpp index 8af22e7da..b47cfb97a 100644 --- a/openfpga/src/base/openfpga_setup_command.cpp +++ b/openfpga/src/base/openfpga_setup_command.cpp @@ -64,6 +64,55 @@ ShellCommandId add_openfpga_write_arch_command(openfpga::Shell& return shell_cmd_id; } +/******************************************************************** + * - Add a command to Shell environment: read_openfpga_simulation_setting + * - Add associated options + * - Add command dependency + *******************************************************************/ +static +ShellCommandId add_openfpga_read_simulation_setting_command(openfpga::Shell& shell, + const ShellCommandClassId& cmd_class_id) { + Command shell_cmd("read_openfpga_simulation_setting"); + + /* Add an option '--file' in short '-f'*/ + CommandOptionId opt_file = shell_cmd.add_option("file", true, "file path to the simulation setting XML"); + shell_cmd.set_option_short_name(opt_file, "f"); + shell_cmd.set_option_require_value(opt_file, openfpga::OPT_STRING); + + /* Add command 'read_openfpga_arch' to the Shell */ + ShellCommandId shell_cmd_id = shell.add_command(shell_cmd, "read OpenFPGA simulation setting file"); + shell.set_command_class(shell_cmd_id, cmd_class_id); + shell.set_command_execute_function(shell_cmd_id, read_simulation_setting); + + return shell_cmd_id; +} + +/******************************************************************** + * - Add a command to Shell environment: write_openfpga_simulation_setting + * - Add associated options + * - Add command dependency + *******************************************************************/ +static +ShellCommandId add_openfpga_write_simulation_setting_command(openfpga::Shell& shell, + const ShellCommandClassId& cmd_class_id, + const std::vector& dependent_cmds) { + Command shell_cmd("write_openfpga_simulation_setting"); + /* Add an option '--file' in short '-f'*/ + CommandOptionId opt_file = shell_cmd.add_option("file", true, "file path to the simulation setting XML"); + shell_cmd.set_option_short_name(opt_file, "f"); + shell_cmd.set_option_require_value(opt_file, openfpga::OPT_STRING); + + /* Add command 'write_openfpga_arch' to the Shell */ + ShellCommandId shell_cmd_id = shell.add_command(shell_cmd, "write OpenFPGA simulation setting file"); + shell.set_command_class(shell_cmd_id, cmd_class_id); + shell.set_command_const_execute_function(shell_cmd_id, write_simulation_setting); + + /* Add command dependency to the Shell */ + shell.set_command_dependency(shell_cmd_id, dependent_cmds); + + return shell_cmd_id; +} + /******************************************************************** * - Add a command to Shell environment: link_openfpga_arch * - Add associated options @@ -295,16 +344,33 @@ void add_openfpga_setup_commands(openfpga::Shell& shell) { openfpga_setup_cmd_class, write_arch_dependent_cmds); + /******************************** + * Command 'read_openfpga_simulation_setting' + */ + ShellCommandId read_sim_setting_cmd_id = add_openfpga_read_simulation_setting_command(shell, + openfpga_setup_cmd_class); + + /******************************** + * Command 'write_openfpga_simulation_setting' + */ + /* The 'write_openfpga_simulation_setting' command should NOT be executed before 'read_openfpga_simulation_setting' */ + std::vector write_sim_setting_dependent_cmds(1, read_sim_setting_cmd_id); + add_openfpga_write_simulation_setting_command(shell, + openfpga_setup_cmd_class, + write_sim_setting_dependent_cmds); + /******************************** * Command 'link_openfpga_arch' */ /* The 'link_openfpga_arch' command should NOT be executed before 'vpr' */ std::vector link_arch_dependent_cmds; link_arch_dependent_cmds.push_back(read_arch_cmd_id); + link_arch_dependent_cmds.push_back(read_sim_setting_cmd_id); link_arch_dependent_cmds.push_back(vpr_cmd_id); ShellCommandId link_arch_cmd_id = add_openfpga_link_arch_command(shell, openfpga_setup_cmd_class, link_arch_dependent_cmds); + /******************************** * Command 'write_gsb' */