diff --git a/libopenfpga/libarchopenfpga/arch/sample_arch.xml b/libopenfpga/libarchopenfpga/arch/sample_arch.xml
index 56a8da59b..6d6484f7e 100644
--- a/libopenfpga/libarchopenfpga/arch/sample_arch.xml
+++ b/libopenfpga/libarchopenfpga/arch/sample_arch.xml
@@ -274,12 +274,12 @@
-
-
-
-
-
-
+
+
+
+
+
+
diff --git a/openfpga/src/base/shell_basic_cmd.cpp b/openfpga/src/base/basic_command.cpp
similarity index 97%
rename from openfpga/src/base/shell_basic_cmd.cpp
rename to openfpga/src/base/basic_command.cpp
index defb87f24..397c9272c 100644
--- a/openfpga/src/base/shell_basic_cmd.cpp
+++ b/openfpga/src/base/basic_command.cpp
@@ -3,7 +3,7 @@
* - exit
* - help
*******************************************************************/
-#include "shell_basic_cmd.h"
+#include "basic_command.h"
/* begin namespace openfpga */
namespace openfpga {
diff --git a/openfpga/src/base/shell_basic_cmd.h b/openfpga/src/base/basic_command.h
similarity index 91%
rename from openfpga/src/base/shell_basic_cmd.h
rename to openfpga/src/base/basic_command.h
index 1722c9c60..8aaf9110a 100644
--- a/openfpga/src/base/shell_basic_cmd.h
+++ b/openfpga/src/base/basic_command.h
@@ -1,5 +1,5 @@
-#ifndef SHELL_BASIC_CMD_H
-#define SHELL_BASIC_CMD_H
+#ifndef BASIC_COMMAND_H
+#define BASIC_COMMAND_H
/********************************************************************
* Include header files that are required by function declaration
diff --git a/openfpga/src/base/openfpga_context.h b/openfpga/src/base/openfpga_context.h
index a0e6272ff..c66012615 100644
--- a/openfpga/src/base/openfpga_context.h
+++ b/openfpga/src/base/openfpga_context.h
@@ -1,6 +1,7 @@
#ifndef OPENFPGA_CONTEXT_H
#define OPENFPGA_CONTEXT_H
+#include "vpr_context.h"
#include "openfpga_arch.h"
/********************************************************************
@@ -25,9 +26,17 @@
* OpenfpgaContext&
* 3. Please keep the definition of OpenfpgaContext short
* Do put ONLY well-modularized data structure under this root.
+ * 4. We build this data structure based on the Context from VPR
+ * which does NOT allow users to copy the internal members
+ * This is due to that the data structures in the OpenFPGA context
+ * are typically big in terms of memory
*******************************************************************/
-class OpenfpgaContext {
- private:
+class OpenfpgaContext : public Context {
+ public: /* Public accessors */
+ const openfpga::Arch& arch() const { return arch_; }
+ public: /* Public mutators */
+ openfpga::Arch& mutable_arch() { return arch_; }
+ private: /* Internal data */
/* Data structure to store information from read_openfpga_arch library */
openfpga::Arch arch_;
};
diff --git a/openfpga/src/base/openfpga_read_arch.cpp b/openfpga/src/base/openfpga_read_arch.cpp
new file mode 100644
index 000000000..5d1f9ac8b
--- /dev/null
+++ b/openfpga/src/base/openfpga_read_arch.cpp
@@ -0,0 +1,49 @@
+/********************************************************************
+ * This file includes functions to read an OpenFPGA architecture file
+ * which are built on the libarchopenfpga library
+ *******************************************************************/
+/* Headers from vtrutil library */
+#include "vtr_log.h"
+
+/* Headers from archopenfpga library */
+#include "read_xml_openfpga_arch.h"
+#include "check_circuit_library.h"
+
+#include "openfpga_read_arch.h"
+
+/* begin namespace openfpga */
+namespace openfpga {
+
+/********************************************************************
+ * Top-level function to read 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 read_arch(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 architecture '%s'...\n",
+ arch_file_name.c_str());
+ openfpga_context.mutable_arch() = read_xml_openfpga_arch(arch_file_name.c_str());
+
+ /* Check the architecture:
+ * 1. Circuit library
+ * 2. Technology library (TODO)
+ * 3. Simulation settings (TODO)
+ */
+ check_circuit_library(openfpga_context.arch().circuit_lib);
+}
+
+} /* end namespace openfpga */
+
diff --git a/openfpga/src/base/openfpga_read_arch.h b/openfpga/src/base/openfpga_read_arch.h
new file mode 100644
index 000000000..8b300bd54
--- /dev/null
+++ b/openfpga/src/base/openfpga_read_arch.h
@@ -0,0 +1,23 @@
+#ifndef OPENFPGA_READ_ARCH_COMMAND_H
+#define OPENFPGA_READ_ARCH_COMMAND_H
+
+/********************************************************************
+ * Include header files that are required by function declaration
+ *******************************************************************/
+#include "command.h"
+#include "command_context.h"
+#include "openfpga_context.h"
+
+/********************************************************************
+ * Function declaration
+ *******************************************************************/
+
+/* begin namespace openfpga */
+namespace openfpga {
+
+void read_arch(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
new file mode 100644
index 000000000..a974e2704
--- /dev/null
+++ b/openfpga/src/base/openfpga_setup_command.cpp
@@ -0,0 +1,28 @@
+/********************************************************************
+ * Add commands to the OpenFPGA shell interface,
+ * in purpose of setting up OpenFPGA core engine, including:
+ * - read_openfpga_arch : read OpenFPGA architecture file
+ *******************************************************************/
+#include "openfpga_read_arch.h"
+#include "openfpga_setup_command.h"
+
+/* begin namespace openfpga */
+namespace openfpga {
+
+void add_openfpga_setup_commands(openfpga::Shell& shell) {
+ /* Add a new class of commands */
+ ShellCommandClassId openfpga_setup_cmd_class = shell.add_command_class("OpenFPGA setup");
+
+ /* Command 'read_openfpga_arch' */
+ Command shell_cmd_read_arch("read_openfpga_arch");
+ /* Add an option '--file' in short '-f'*/
+ CommandOptionId read_arch_opt_file = shell_cmd_read_arch.add_option("file", true, "file path to the architecture XML");
+ 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);
+
+ 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);
+}
+
+} /* end namespace openfpga */
diff --git a/openfpga/src/base/openfpga_setup_command.h b/openfpga/src/base/openfpga_setup_command.h
new file mode 100644
index 000000000..03d4220f5
--- /dev/null
+++ b/openfpga/src/base/openfpga_setup_command.h
@@ -0,0 +1,21 @@
+#ifndef OPENFPGA_SETUP_COMMAND_H
+#define OPENFPGA_SETUP_COMMAND_H
+
+/********************************************************************
+ * Include header files that are required by function declaration
+ *******************************************************************/
+#include "shell.h"
+#include "openfpga_context.h"
+
+/********************************************************************
+ * Function declaration
+ *******************************************************************/
+
+/* begin namespace openfpga */
+namespace openfpga {
+
+void add_openfpga_setup_commands(openfpga::Shell& shell);
+
+} /* end namespace openfpga */
+
+#endif
diff --git a/openfpga/src/main.cpp b/openfpga/src/main.cpp
index 7412684b6..c7c31b00c 100644
--- a/openfpga/src/main.cpp
+++ b/openfpga/src/main.cpp
@@ -10,20 +10,19 @@
#include "shell.h"
/* Header file from openfpga */
-#include "shell_vpr_cmd.h"
-#include "shell_basic_cmd.h"
+#include "vpr_command.h"
+#include "openfpga_setup_command.h"
+#include "basic_command.h"
#include "openfpga_title.h"
#include "openfpga_context.h"
-using namespace openfpga;
-
/********************************************************************
* 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");
+ openfpga::Command start_cmd("OpenFPGA");
/* Add two options:
* '--interactive', -i': launch the interactive mode
* '--file', -f': launch the script mode
@@ -43,18 +42,21 @@ int main(int argc, char** argv) {
* 1. exit
* 2. help. This must the last to add
*/
- Shell shell("OpenFPGA");
+ openfpga::Shell shell("OpenFPGA");
shell.add_title(create_openfpga_title());
/* Add vpr commands */
- add_vpr_commands(shell);
+ openfpga::add_vpr_commands(shell);
+
+ /* Add openfpga setup commands */
+ openfpga::add_openfpga_setup_commands(shell);
/* Add basic commands: exit, help, etc.
* Note:
* This MUST be the last command group to be added!
*/
- add_basic_commands(shell);
+ openfpga::add_basic_commands(shell);
/* Create the data base for the shell */
OpenfpgaContext openfpga_context;
@@ -66,10 +68,10 @@ int main(int argc, char** argv) {
cmd_opts.push_back(std::string(argv[iarg]));
}
- CommandContext start_cmd_context(start_cmd);
+ openfpga::CommandContext start_cmd_context(start_cmd);
if (false == parse_command(cmd_opts, start_cmd, start_cmd_context)) {
/* Parse fail: Echo the command */
- print_command_options(start_cmd);
+ openfpga::print_command_options(start_cmd);
} else {
/* Parse succeed. Start a shell */
if (true == start_cmd_context.option_enable(start_cmd, opt_interactive)) {
@@ -83,7 +85,7 @@ int main(int argc, char** argv) {
return 0;
}
/* Reach here there is something wrong, show the help desk */
- print_command_options(start_cmd);
+ openfpga::print_command_options(start_cmd);
}
return 0;
diff --git a/openfpga/src/vpr_cmd/shell_vpr_cmd.cpp b/openfpga/src/vpr_wrapper/vpr_command.cpp
similarity index 97%
rename from openfpga/src/vpr_cmd/shell_vpr_cmd.cpp
rename to openfpga/src/vpr_wrapper/vpr_command.cpp
index 22bace2c5..5baa1ec84 100644
--- a/openfpga/src/vpr_cmd/shell_vpr_cmd.cpp
+++ b/openfpga/src/vpr_wrapper/vpr_command.cpp
@@ -3,7 +3,7 @@
*******************************************************************/
#include "vpr_main.h"
-#include "shell_vpr_cmd.h"
+#include "vpr_command.h"
/* begin namespace openfpga */
namespace openfpga {
diff --git a/openfpga/src/vpr_cmd/shell_vpr_cmd.h b/openfpga/src/vpr_wrapper/vpr_command.h
similarity index 92%
rename from openfpga/src/vpr_cmd/shell_vpr_cmd.h
rename to openfpga/src/vpr_wrapper/vpr_command.h
index c3aebe6dd..467e416d0 100644
--- a/openfpga/src/vpr_cmd/shell_vpr_cmd.h
+++ b/openfpga/src/vpr_wrapper/vpr_command.h
@@ -1,5 +1,5 @@
-#ifndef SHELL_VPR_CMD_H
-#define SHELL_VPR_CMD_H
+#ifndef VPR_COMMAND_H
+#define VPR_COMMAND_H
/********************************************************************
* Include header files that are required by function declaration
diff --git a/openfpga/src/vpr_cmd/vpr_main.cpp b/openfpga/src/vpr_wrapper/vpr_main.cpp
similarity index 100%
rename from openfpga/src/vpr_cmd/vpr_main.cpp
rename to openfpga/src/vpr_wrapper/vpr_main.cpp
diff --git a/openfpga/src/vpr_cmd/vpr_main.h b/openfpga/src/vpr_wrapper/vpr_main.h
similarity index 100%
rename from openfpga/src/vpr_cmd/vpr_main.h
rename to openfpga/src/vpr_wrapper/vpr_main.h