diff --git a/openfpga/src/base/openfpga_context.h b/openfpga/src/base/openfpga_context.h new file mode 100644 index 000000000..a0e6272ff --- /dev/null +++ b/openfpga/src/base/openfpga_context.h @@ -0,0 +1,35 @@ +#ifndef OPENFPGA_CONTEXT_H +#define OPENFPGA_CONTEXT_H + +#include "openfpga_arch.h" + +/******************************************************************** + * This file includes the declaration of the date structure + * OpenfpgaContext, which is used for data exchange between + * different modules in OpenFPGA shell environment + * + * If a command of OpenFPGA needs to exchange data with other commands, + * it must use this data structure to access/mutate. + * In such case, you must add data structures to OpenfpgaContext + * + * Note: + * Please respect to the following rules when using the OpenfpgaContext + * 1. This data structure will be created only once in the main() function + * The data structure is design to be large and contain all the + * data structure required by each module of OpenFPGA core engine. + * Do NOT create or duplicate in your own module! + * 2. Be clear in your mind if you want to access/mutate the data inside OpenfpgaContext + * Read-only data should be accessed by + * const OpenfpgaContext& + * Mutate should use reference + * OpenfpgaContext& + * 3. Please keep the definition of OpenfpgaContext short + * Do put ONLY well-modularized data structure under this root. + *******************************************************************/ +class OpenfpgaContext { + private: + /* Data structure to store information from read_openfpga_arch library */ + openfpga::Arch arch_; +}; + +#endif diff --git a/openfpga/src/base/openfpga_title.cpp b/openfpga/src/base/openfpga_title.cpp new file mode 100644 index 000000000..4a33bb72e --- /dev/null +++ b/openfpga/src/base/openfpga_title.cpp @@ -0,0 +1,43 @@ +/******************************************************************** + * This file includes the functions to create the title page + * which introduces generality of OpenFPGA framework + *******************************************************************/ +#include "openfpga_title.h" + +/******************************************************************** + * Generate a string of openfpga title introduction + * This is mainly used when launching OpenFPGA shell + *******************************************************************/ +const char* create_openfpga_title() { + std::string title; + + title += std::string("\n"); + title += std::string(" OpenFPGA: An Open-source FPGA IP Generator\n"); + title += std::string("\n"); + title += std::string("Contributors: Xifan Tang\tAurelien Alacchi\tBaudouin Chauviere\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("\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"); + title += std::string("in the Software without restriction, including without limitation the rights\n"); + title += std::string("to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n"); + title += std::string("copies of the Software, and to permit persons to whom the Software is\n"); + title += std::string("furnished to do so, subject to the following conditions:\n"); + title += std::string("\n"); + title += std::string("The above copyright notice and this permission notice shall be included in\n"); + title += std::string("all copies or substantial portions of the Software.\n"); + title += std::string("\n"); + title += std::string("THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n"); + title += std::string("IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n"); + title += std::string("FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n"); + title += std::string("AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n"); + title += std::string("LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n"); + title += std::string("OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n"); + title += std::string("THE SOFTWARE.\n"); + title += std::string("\n"); + + return title.c_str(); +} diff --git a/openfpga/src/base/openfpga_title.h b/openfpga/src/base/openfpga_title.h new file mode 100644 index 000000000..b4826964a --- /dev/null +++ b/openfpga/src/base/openfpga_title.h @@ -0,0 +1,14 @@ +#ifndef OPENFPGA_TITLE_H +#define OPENFPGA_TITLE_H + +/******************************************************************** + * Include header files that are required by function declaration + *******************************************************************/ +#include + +/******************************************************************** + * Function declaration + *******************************************************************/ +const char* create_openfpga_title(); + +#endif diff --git a/openfpga/src/main.cpp b/openfpga/src/main.cpp index ec445f46e..d3698d18d 100644 --- a/openfpga/src/main.cpp +++ b/openfpga/src/main.cpp @@ -1,34 +1,27 @@ /******************************************************************** * Build the OpenFPGA shell interface *******************************************************************/ +/* Header file from vtrutil library */ #include "vtr_log.h" + +/* Header file from libopenfpgashell library */ #include "command_parser.h" #include "command_echo.h" #include "shell.h" +/* Header file from openfpga */ #include "vpr_main.h" +#include "openfpga_title.h" +#include "openfpga_context.h" + using namespace openfpga; -class ShellContext { - public: - int a; -}; - -static -void shell_execute_set(ShellContext& context, - const Command& cmd, const CommandContext& cmd_context) { - CommandOptionId opt_id = cmd.option("value"); - /* Get the value of a in the command context */ - context.a = std::atoi(cmd_context.option_value(cmd, opt_id).c_str()); -} - -static -void shell_execute_print(ShellContext& context) { - VTR_LOG("a=%d\n", context.a); -} - +/******************************************************************** + * Main function to start OpenFPGA shell interface + *******************************************************************/ int main(int argc, char** argv) { + /* Create the command to launch shell in different modes */ Command start_cmd("OpenFPGA"); /* Add two options: @@ -47,70 +40,23 @@ int main(int argc, char** argv) { /* Create a shell object * Add two commands, which are - * 1. help - * 2. exit + * 1. exit + * 2. help. This must the last to add */ - Shell shell("OpenFPGA"); - std::string shell_title; + Shell shell("OpenFPGA"); - shell_title += std::string("\n"); - shell_title += std::string(" OpenFPGA: An Open-source FPGA IP Generator\n"); - shell_title += std::string("\n"); - shell_title += std::string("Contributors: Xifan Tang\tAurelien Alacchi\tBaudouin Chauviere\n"); - shell_title += std::string("\n"); - shell_title += std::string("The MIT License\n"); - shell_title += std::string("\n"); - shell_title += std::string("Copyright (c) 2018 LNIS - The University of Utah\n"); - shell_title += std::string("\n"); - shell_title += std::string("Permission is hereby granted, free of charge, to any person obtaining a copy\n"); - shell_title += std::string("of this software and associated documentation files (the \"Software\"), to deal\n"); - shell_title += std::string("in the Software without restriction, including without limitation the rights\n"); - shell_title += std::string("to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n"); - shell_title += std::string("copies of the Software, and to permit persons to whom the Software is\n"); - shell_title += std::string("furnished to do so, subject to the following conditions:\n"); - shell_title += std::string("\n"); - shell_title += std::string("The above copyright notice and this permission notice shall be included in\n"); - shell_title += std::string("all copies or substantial portions of the Software.\n"); - shell_title += std::string("\n"); - shell_title += std::string("THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n"); - shell_title += std::string("IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n"); - shell_title += std::string("FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n"); - shell_title += std::string("AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n"); - shell_title += std::string("LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n"); - shell_title += std::string("OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n"); - shell_title += std::string("THE SOFTWARE.\n"); - - shell.add_title(shell_title.c_str()); + shell.add_title(create_openfpga_title()); /* Add a new class of commands */ - ShellCommandClassId arith_cmd_class = shell.add_command_class("Arithmetic"); - - /* Create a command of 'set' with a required option 'value' with a value - * This function sets a value to an internal variable of ShellContext - */ - Command shell_cmd_set("set"); - CommandOptionId set_opt_value = shell_cmd_set.add_option("value", true, "value of variable"); - shell_cmd_set.set_option_require_value(set_opt_value, OPT_STRING); - ShellCommandId shell_cmd_set_id = shell.add_command(shell_cmd_set, "Set a value to internal variable 'a'"); - shell.set_command_class(shell_cmd_set_id, arith_cmd_class); - shell.set_command_execute_function(shell_cmd_set_id, shell_execute_set); - - /* Create a command of 'print' - * This function will print the value of an internal variable of ShellContext - */ - 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); + ShellCommandClassId arith_cmd_class = shell.add_command_class("VPR"); /* Create a macro command of 'vpr' which will call the main engine of vpr */ Command shell_cmd_vpr("vpr"); - ShellCommandId shell_cmd_vpr_id = shell.add_command(shell_cmd_vpr, "A macro function to print arguments"); + ShellCommandId shell_cmd_vpr_id = shell.add_command(shell_cmd_vpr, "Start VPR core engine to pack, place and route a BLIF design on a FPGA architecture"); shell.set_command_class(shell_cmd_vpr_id, arith_cmd_class); shell.set_command_execute_function(shell_cmd_vpr_id, vpr::vpr); - /* Add a new class of commands */ ShellCommandClassId basic_cmd_class = shell.add_command_class("Basic"); @@ -126,7 +72,7 @@ int main(int argc, char** argv) { shell.set_command_execute_function(shell_cmd_help_id, [shell](){shell.print_commands();}); /* Create the data base for the shell */ - ShellContext shell_context; + OpenfpgaContext openfpga_context; /* Parse the option, to avoid issues, we use the command name to replace the argv[0] */ std::vector cmd_opts; @@ -142,13 +88,13 @@ int main(int argc, char** argv) { } else { /* Parse succeed. Start a shell */ if (true == start_cmd_context.option_enable(start_cmd, opt_interactive)) { - shell.run_interactive_mode(shell_context); + shell.run_interactive_mode(openfpga_context); return 0; } if (true == start_cmd_context.option_enable(start_cmd, opt_script_mode)) { shell.run_script_mode(start_cmd_context.option_value(start_cmd, opt_script_mode).c_str(), - shell_context); + openfpga_context); return 0; } /* Reach here there is something wrong, show the help desk */ diff --git a/openfpga/src/vpr_cmd/vpr_main.cpp b/openfpga/src/vpr_cmd/vpr_main.cpp index 08b8348c4..5b9db0455 100644 --- a/openfpga/src/vpr_cmd/vpr_main.cpp +++ b/openfpga/src/vpr_cmd/vpr_main.cpp @@ -19,6 +19,8 @@ #include "vpr_signal_handler.h" #include "vpr_tatum_error.h" +#include "vpr_main.h" + #include "globals.h" namespace vpr {