add write_openfpga_arch command to openfpga shell

This commit is contained in:
tangxifan 2020-01-23 20:58:15 -07:00
parent a03f8aa346
commit 655f84b00e
6 changed files with 55 additions and 9 deletions

View File

@ -4,6 +4,9 @@
*******************************************************************/
#include <fstream>
/* Headers from vtrutil library */
#include "vtr_time.h"
/* Headers from openfpgautil library */
#include "openfpga_digest.h"
@ -20,6 +23,8 @@
*******************************************************************/
void write_xml_openfpga_arch(const char* fname,
const openfpga::Arch& openfpga_arch) {
vtr::ScopedStartFinishTimer timer("Write OpenFPGA architecture");
/* Create a file handler */
std::fstream fp;
/* Open the file stream */

View File

@ -95,12 +95,12 @@ class Shell {
* 4. Marco function, which directly call a macro function without command parsing
* Users just need to specify the function object and its type will be automatically inferred
*/
void set_command_execute_function(const ShellCommandId& cmd_id,
void set_command_const_execute_function(const ShellCommandId& cmd_id,
std::function<void(const T&, const Command&, const CommandContext&)> exec_func);
void set_command_execute_function(const ShellCommandId& cmd_id,
std::function<void(T&, const Command&, const CommandContext&)> exec_func);
void set_command_execute_function(const ShellCommandId& cmd_id,
std::function<void(const T&)> exec_func);
void set_command_const_execute_function(const ShellCommandId& cmd_id,
std::function<void(const T&)> exec_func);
void set_command_execute_function(const ShellCommandId& cmd_id,
std::function<void(T&)> exec_func);
void set_command_execute_function(const ShellCommandId& cmd_id,

View File

@ -153,11 +153,11 @@ void Shell<T>::set_command_class(const ShellCommandId& cmd_id, const ShellComman
}
template<class T>
void Shell<T>::set_command_execute_function(const ShellCommandId& cmd_id,
std::function<void(const T&, const Command&, const CommandContext&)> exec_func) {
void Shell<T>::set_command_const_execute_function(const ShellCommandId& cmd_id,
std::function<void(const T&, const Command&, const CommandContext&)> exec_func) {
VTR_ASSERT(true == valid_command_id(cmd_id));
command_execute_function_types_[cmd_id] = CONST_STANDARD;
command_standard_execute_functions_[cmd_id] = exec_func;
command_const_execute_functions_[cmd_id] = exec_func;
}
template<class T>
@ -169,11 +169,11 @@ void Shell<T>::set_command_execute_function(const ShellCommandId& cmd_id,
}
template<class T>
void Shell<T>::set_command_execute_function(const ShellCommandId& cmd_id,
std::function<void(const T&)> exec_func) {
void Shell<T>::set_command_const_execute_function(const ShellCommandId& cmd_id,
std::function<void(const T&)> exec_func) {
VTR_ASSERT(true == valid_command_id(cmd_id));
command_execute_function_types_[cmd_id] = CONST_SHORT;
command_short_execute_functions_[cmd_id] = exec_func;
command_short_const_execute_functions_[cmd_id] = exec_func;
}
template<class T>

View File

@ -8,6 +8,7 @@
/* Headers from archopenfpga library */
#include "read_xml_openfpga_arch.h"
#include "check_circuit_library.h"
#include "write_xml_openfpga_arch.h"
#include "openfpga_read_arch.h"
@ -45,5 +46,29 @@ void read_arch(OpenfpgaContext& openfpga_context,
check_circuit_library(openfpga_context.arch().circuit_lib);
}
/********************************************************************
* A function to write an OpenFPGA architecture file
* we use the APIs from the libarchopenfpga library
*
* The command will accept an option '--file' which is the architecture
* file provided by users
*******************************************************************/
void write_arch(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 architecture to '%s'...\n",
arch_file_name.c_str());
write_xml_openfpga_arch(arch_file_name.c_str(), openfpga_context.arch());
}
} /* end namespace openfpga */

View File

@ -18,6 +18,9 @@ namespace openfpga {
void read_arch(OpenfpgaContext& openfpga_context,
const Command& cmd, const CommandContext& cmd_context);
void write_arch(const OpenfpgaContext& openfpga_context,
const Command& cmd, const CommandContext& cmd_context);
} /* end namespace openfpga */
#endif

View File

@ -20,9 +20,22 @@ void add_openfpga_setup_commands(openfpga::Shell<OpenfpgaContext>& shell) {
shell_cmd_read_arch.set_option_short_name(read_arch_opt_file, "f");
shell_cmd_read_arch.set_option_require_value(read_arch_opt_file, openfpga::OPT_STRING);
/* Add command 'read_openfpga_arch' to the Shell */
ShellCommandId shell_cmd_read_arch_id = shell.add_command(shell_cmd_read_arch, "read OpenFPGA architecture file");
shell.set_command_class(shell_cmd_read_arch_id, openfpga_setup_cmd_class);
shell.set_command_execute_function(shell_cmd_read_arch_id, read_arch);
/* Command 'write_openfpga_arch' */
Command shell_cmd_write_arch("write_openfpga_arch");
/* Add an option '--file' in short '-f'*/
CommandOptionId write_arch_opt_file = shell_cmd_write_arch.add_option("file", true, "file path to the architecture XML");
shell_cmd_write_arch.set_option_short_name(write_arch_opt_file, "f");
shell_cmd_write_arch.set_option_require_value(write_arch_opt_file, openfpga::OPT_STRING);
/* Add command 'write_openfpga_arch' to the Shell */
ShellCommandId shell_cmd_write_arch_id = shell.add_command(shell_cmd_write_arch, "write OpenFPGA architecture file");
shell.set_command_class(shell_cmd_write_arch_id, openfpga_setup_cmd_class);
shell.set_command_const_execute_function(shell_cmd_write_arch_id, write_arch);
}
} /* end namespace openfpga */