diff --git a/libopenfpga/libopenfpgashell/src/shell.h b/libopenfpga/libopenfpgashell/src/shell.h index 78bd74acb..934901796 100644 --- a/libopenfpga/libopenfpgashell/src/shell.h +++ b/libopenfpga/libopenfpgashell/src/shell.h @@ -58,7 +58,9 @@ class Shell { * Built-in commands have their own execute functions inside the shell */ enum e_exec_func_type { + CONST_STANDARD, STANDARD, + CONST_SHORT, SHORT, BUILTIN, MACRO, @@ -93,8 +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, + std::function exec_func); void set_command_execute_function(const ShellCommandId& cmd_id, std::function exec_func); + void set_command_execute_function(const ShellCommandId& cmd_id, + std::function exec_func); void set_command_execute_function(const ShellCommandId& cmd_id, std::function exec_func); void set_command_execute_function(const ShellCommandId& cmd_id, @@ -156,8 +162,10 @@ class Shell { * 3. Built-in function, including only the shell envoriment variables * 4. Marco function, which directly call a macro function without command parsing */ + vtr::vector> command_const_execute_functions_; vtr::vector> command_standard_execute_functions_; - vtr::vector> command_short_execute_functions_; + vtr::vector> command_short_const_execute_functions_; + vtr::vector> command_short_execute_functions_; vtr::vector> command_builtin_execute_functions_; vtr::vector> command_macro_execute_functions_; diff --git a/libopenfpga/libopenfpgashell/src/shell.tpp b/libopenfpga/libopenfpgashell/src/shell.tpp index 8e9c32860..20787905d 100644 --- a/libopenfpga/libopenfpgashell/src/shell.tpp +++ b/libopenfpga/libopenfpgashell/src/shell.tpp @@ -125,7 +125,9 @@ ShellCommandId Shell::add_command(const Command& cmd, const char* descr) { command_description_.push_back(descr); command_classes_.push_back(ShellCommandClassId::INVALID()); command_execute_function_types_.emplace_back(); + command_const_execute_functions_.emplace_back(); command_standard_execute_functions_.emplace_back(); + command_short_const_execute_functions_.emplace_back(); command_short_execute_functions_.emplace_back(); command_builtin_execute_functions_.emplace_back(); command_macro_execute_functions_.emplace_back(); @@ -150,6 +152,14 @@ void Shell::set_command_class(const ShellCommandId& cmd_id, const ShellComman } } +template +void Shell::set_command_execute_function(const ShellCommandId& cmd_id, + std::function 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; +} + template void Shell::set_command_execute_function(const ShellCommandId& cmd_id, std::function exec_func) { @@ -158,6 +168,14 @@ void Shell::set_command_execute_function(const ShellCommandId& cmd_id, command_standard_execute_functions_[cmd_id] = exec_func; } +template +void Shell::set_command_execute_function(const ShellCommandId& cmd_id, + std::function 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; +} + template void Shell::set_command_execute_function(const ShellCommandId& cmd_id, std::function exec_func) { @@ -379,9 +397,15 @@ void Shell::execute_command(const char* cmd_line, /* Execute the command depending on the type of function ! */ switch (command_execute_function_types_[cmd_id]) { + case CONST_STANDARD: + command_const_execute_functions_[cmd_id](common_context, commands_[cmd_id], command_contexts_[cmd_id]); + break; case STANDARD: command_standard_execute_functions_[cmd_id](common_context, commands_[cmd_id], command_contexts_[cmd_id]); break; + case CONST_SHORT: + command_short_const_execute_functions_[cmd_id](common_context); + break; case SHORT: command_short_execute_functions_[cmd_id](common_context); break;