Merge branch 'refactoring' into dev

This commit is contained in:
tangxifan 2020-01-24 17:08:36 -07:00
commit 95d477a20a
6 changed files with 31 additions and 9 deletions

View File

@ -108,7 +108,7 @@ class Shell {
void set_command_execute_function(const ShellCommandId& cmd_id,
std::function<int(int, char**)> exec_func);
void set_command_dependency(const ShellCommandId& cmd_id,
const std::vector<ShellCommandId> cmd_dependency);
const std::vector<ShellCommandId>& cmd_dependency);
ShellCommandClassId add_command_class(const char* name);
public: /* Public validators */
bool valid_command_id(const ShellCommandId& cmd_id) const;
@ -174,6 +174,9 @@ class Shell {
*/
vtr::vector<ShellCommandId, e_exec_func_type> command_execute_function_types_;
/* A flag to indicate if the command has been executed */
vtr::vector<ShellCommandId, bool> command_status_;
/* Dependency graph for different commands,
* This helps the shell interface to check if a command need other commands to be run before its execution
*/

View File

@ -131,6 +131,7 @@ ShellCommandId Shell<T>::add_command(const Command& cmd, const char* descr) {
command_short_execute_functions_.emplace_back();
command_builtin_execute_functions_.emplace_back();
command_macro_execute_functions_.emplace_back();
command_status_.push_back(false); /* By default, the command should be marked as never executed */
command_dependencies_.emplace_back();
/* Register the name in the name2id map */
@ -202,7 +203,7 @@ void Shell<T>::set_command_execute_function(const ShellCommandId& cmd_id,
template<class T>
void Shell<T>::set_command_dependency(const ShellCommandId& cmd_id,
const std::vector<ShellCommandId> dependent_cmds) {
const std::vector<ShellCommandId>& dependent_cmds) {
/* Validate the command id as well as each of the command dependency */
VTR_ASSERT(true == valid_command_id(cmd_id));
for (ShellCommandId dependent_cmd : dependent_cmds) {
@ -362,7 +363,14 @@ void Shell<T>::execute_command(const char* cmd_line,
return;
}
/* TODO: Check the dependency graph to see if all the prequistics have been met */
/* Check the dependency graph to see if all the prequistics have been met */
for (const ShellCommandId& dep_cmd : command_dependencies_[cmd_id]) {
if (false == command_status_[dep_cmd]) {
VTR_LOG("Command '%s' is required to be executed before command '%s'!\n",
commands_[dep_cmd].name().c_str(), commands_[cmd_id].name().c_str());
return;
}
}
/* Find the command! Parse the options
* Note:
@ -391,10 +399,10 @@ void Shell<T>::execute_command(const char* cmd_line,
print_command_options(commands_[cmd_id]);
return;
}
/* Parse succeed. Let user to confirm selected options */
print_command_context(commands_[cmd_id], command_contexts_[cmd_id]);
/* Execute the command depending on the type of function ! */
switch (command_execute_function_types_[cmd_id]) {
case CONST_STANDARD:
@ -420,6 +428,9 @@ void Shell<T>::execute_command(const char* cmd_line,
/* Exit the shell using the exit() function inside this class! */
exit();
}
/* Change the status of the command */
command_status_[cmd_id] = true;
}
/************************************************************************

View File

@ -102,11 +102,13 @@ int main(int argc, char** argv) {
/* Create a command of 'print'
* This function will print the value of an internal variable of ShellContext
* We set a dependency to this command as it MUST be executed after 'set'
*/
Command shell_cmd_print("print");
ShellCommandId shell_cmd_print_id = shell.add_command(shell_cmd_print, "Print the value of internal variable 'a'");
shell.set_command_class(shell_cmd_print_id, arith_cmd_class);
shell.set_command_execute_function(shell_cmd_print_id, shell_execute_print);
shell.set_command_dependency(shell_cmd_print_id, std::vector<ShellCommandId>(1, shell_cmd_set_id));
/* Create a macro command of 'print_macro'
* This function will print the value of an internal variable of ShellContext

View File

@ -36,6 +36,8 @@ void add_openfpga_setup_commands(openfpga::Shell<OpenfpgaContext>& 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);
/* The 'write_openfpga_arch' command should be executed before 'read_openfpga_arch' */
shell.set_command_dependency(shell_cmd_write_arch_id, std::vector<ShellCommandId>(1, shell_cmd_read_arch_id));
}
} /* end namespace openfpga */

View File

@ -13,12 +13,15 @@ const char* create_openfpga_title() {
title += std::string("\n");
title += std::string(" OpenFPGA: An Open-source FPGA IP Generator\n");
title += std::string(" Versatile Place and Route (VPR)\n");
title += std::string(" FPGA-Verilog\n");
title += std::string(" FPGA-SPICE\n");
title += std::string(" FPGA-SDC\n");
title += std::string(" FPGA-Bitstream\n");
title += std::string("\n");
title += std::string("Contributors: Xifan Tang\tAurelien Alacchi\tBaudouin Chauviere\n");
title += std::string(" This is a free software under the MIT License\n");
title += std::string("\n");
title += std::string("The MIT License\n");
title += std::string("\n");
title += std::string("Copyright (c) 2018 LNIS - The University of Utah\n");
title += std::string(" Copyright (c) 2018 LNIS - The University of Utah\n");
title += std::string("\n");
title += std::string("Permission is hereby granted, free of charge, to any person obtaining a copy\n");
title += std::string("of this software and associated documentation files (the \"Software\"), to deal\n");

1
openfpga/src/ctag_src.sh Normal file
View File

@ -0,0 +1 @@
ctags -R . ../../libopenfpga/*/src/* ../../libs/*/src/* ../../vpr/src/*/*