add read_openfpga_arch to OpenFPGA shell

This commit is contained in:
tangxifan 2020-01-23 19:10:53 -07:00
parent e69aa5ba30
commit cdb3b6de46
13 changed files with 157 additions and 25 deletions

View File

@ -274,12 +274,12 @@
<pb_type name="io[io_phy].iopad" circuit_model_name="iopad" mode_bits="1"/>
<pb_type name="io[io_phy].inpad" physical_pb_type_name="iopad" mode_bits="1"/>
<pb_type name="io[io_phy].outpad" physical_pb_type_name="iopad" mode_bits="0"/>
<pb_type name="clb.fle" physical_mode_name="fle_phy" idle_mode_name="n2_lut5">
<pb_type name="clb.fle[fle_phy].frac_logic.frac_lut6" mode_bits="11" circuit_model_name="frac_lut6">
<pb_type name="clb.fle[fle_phy].frac_logic.adder_phy" circuit_model_name="adder">
<pb_type name="clb.fle[fle_phy].frac_logic.ff_phy" circuit_model_name="static_dff">
<mode name="fle_phy" disabled_in_packing="true">
<pb_type name="lut5" mode_bits="01" physical_pb_type_name="frac_lut6" physical_pb_type_index_factor="0.5">
<pb_type name="clb.fle" physical_mode_name="fle_phy" idle_mode_name="n2_lut5"/>
<pb_type name="clb.fle[fle_phy].frac_logic.frac_lut6" mode_bits="11" circuit_model_name="frac_lut6"/>
<pb_type name="clb.fle[fle_phy].frac_logic.adder_phy" circuit_model_name="adder"/>
<pb_type name="clb.fle[fle_phy].frac_logic.ff_phy" circuit_model_name="static_dff"/>
<mode name="fle_phy" disabled_in_packing="true"/>
<pb_type name="lut5" mode_bits="01" physical_pb_type_name="frac_lut6" physical_pb_type_index_factor="0.5"/>
<input name="in" physical_mode_pin="in[5:0]"/>
<output name="out" physical_mode_pin="lut5_out" physical_mode_pin_rotate_offset="1"/>
</complex_blocks>

View File

@ -3,7 +3,7 @@
* - exit
* - help
*******************************************************************/
#include "shell_basic_cmd.h"
#include "basic_command.h"
/* begin namespace openfpga */
namespace openfpga {

View File

@ -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

View File

@ -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_;
};

View File

@ -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 */

View File

@ -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

View File

@ -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<OpenfpgaContext>& 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 */

View File

@ -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<OpenfpgaContext>& shell);
} /* end namespace openfpga */
#endif

View File

@ -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<OpenfpgaContext> shell("OpenFPGA");
openfpga::Shell<OpenfpgaContext> 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;

View File

@ -3,7 +3,7 @@
*******************************************************************/
#include "vpr_main.h"
#include "shell_vpr_cmd.h"
#include "vpr_command.h"
/* begin namespace openfpga */
namespace openfpga {

View File

@ -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