15 #include "fletchgen/options.h"
17 #include <fletcher/common.h>
18 #include <CLI/CLI.hpp>
23 CLI::App app{
"Fletchgen - The Fletcher Design Generator"};
25 app.get_formatter()->column_width(34);
29 "List of files with Arrow Schemas to base design on."
30 "Example: --input file1.fbs file2.fbs file3.fbs")
31 ->check(CLI::ExistingFile);
34 app.add_option(
"-n,--kernel_name", options->
kernel_name,
35 "Name of the accelerator kernel.");
39 "List of files with Arrow RecordBatches to base design on and use in simulation memory models."
40 "Schemas contained in these RecordBatches may be skipped for the --input option.");
41 app.add_option(
"-s,--recordbatch_output", options->
srec_out_path,
42 "Memory model contents output file (formatted as SREC).");
44 "Path to dump memory model contents to after simulation (formatted as SREC).");
47 app.add_option(
"-o,--output_path", options->
output_dir,
48 "Path to the output directory to place the generated files. (Default: . )");
50 app.add_option(
"-l,--language", options->
languages,
51 "Select the output languages for your design. Each type of output will be stored in a "
52 "seperate subfolder (e.g. <output folder>/vhdl/...). \n"
53 "Available languages:\n"
54 " vhdl : Export as VHDL files (default).\n"
55 " dot : Export as DOT graphs.");
57 app.add_flag(
"-b,--backup", options->
backup,
58 "Backup generated source code files if they exists already. If this flag is used and the source "
59 "file exists already in the specified path, the output filename will be <filename>.bak. This "
60 "file is always overwritten.");
62 app.add_option(
"--regs", options->
regs,
63 "Names of custom registers in the following format: \"<behavior>:<width>:<name>:<init>\", "
64 "where <behavior> is one character from the following options:\n"
65 " c : (control) register content is controlled by host-side software.\n"
66 " s : (status) register content is controlled by hardware kernel.\n"
67 "<init> is optional, and can be used to automatically write to the register in the initialization "
68 "step of the simulation. Init must be a hexadecimal value in the form of 0x01234ABCD.\n"
69 "Example: \"-reg32 c:32:myh2kreg:0xDEADBEEF s:64:mk2hreg\"");
71 app.add_option(
"-e,--external", options->
externals_yaml,
"Path to YAML file describing external signals to drag "
72 "between kernel and top-level.");
74 app.add_option(
"--bus_specs", options->
bus_dims,
75 "Specify top-level bus parameters.\n"
76 "Value must be a tuple of the following form: \"aw,dw,lw,bs,bm\"\n"
78 " aw : Bus address width.\n"
79 " dw : Bus data width.\n"
80 " lw : Bus burst length width.\n"
81 " bs : Bus minimum burst size.\n"
82 " bm : Bus maximum burst size.\n"
83 "Currently supports only one top-level bus specification. Default: \"64,512,64,8,1,16\"");
85 app.add_flag(
"--mmio64", options->
mmio64,
"Use a 64-bits AXI4-lite MMIO data bus instead of 32-bits.");
86 app.add_option(
"--mmio-offset", options->
mmio_offset,
"AXI4 offset address for Fletcher registers.");
89 app.add_flag(
"--axi", options->
axi_top,
"Generate AXI top-level template (VHDL only).");
91 app.add_flag(
"--sim", options->
sim_top,
92 "Generate simulation top-level template (VHDL only).");
93 app.add_flag(
"--vivado_hls", options->
vivado_hls,
94 "Generate a Vivado HLS kernel template.");
96 app.add_flag(
"--static-vhdl", options->
static_vhdl,
"Write static VHDL support files.");
99 app.add_flag(
"-v,--version", options->
version,
112 app.parse(argc, argv);
113 }
catch (CLI::CallForHelp &e) {
114 std::cout << app.help() << std::endl;
115 options->
quit =
true;
117 }
catch (CLI::Error &e) {
118 FLETCHER_LOG(ERROR, e.get_name() +
":\n" + e.what());
124 options->
quit =
true;
133 FLETCHER_LOG(WARNING,
"SREC output flag set, but no RecordBatches were supplied.");
141 static bool HasLanguage(
const std::vector<std::string> &languages,
const std::string &lang) {
142 for (
const auto &l : languages) {
160 std::vector<std::shared_ptr<arrow::RecordBatch>> rbs;
161 FLETCHER_LOG(INFO,
"Loading RecordBatch(es) from " + path);
162 if (!fletcher::ReadRecordBatchesFromFile(path, &rbs)) {
172 std::shared_ptr<arrow::Schema> schema;
173 FLETCHER_LOG(INFO,
"Loading Schema from " + path);
174 if (!fletcher::ReadSchemaFromFile(path, &schema)) {
183 std::stringstream str;
184 str <<
"Schema paths:\n";
186 str <<
" " << p <<
"\n";
188 str <<
"RecordBatch paths:\n";
190 str <<
" " << p <<
"\n";
Contains all classes and functions related to Fletchgen.
Fletcher program options.
bool quit
Whether to quit the program without doing anything (useful for just showing help or version).
std::string output_dir
Output directory.
bool LoadSchemas()
Load all specified Schemas. Returns true if successful, false otherwise.
std::vector< std::shared_ptr< arrow::Schema > > schemas
Loaded schemas.
bool MustGenerateDesign() const
Return true if a design must be generated.
bool LoadRecordBatches()
Load all specified RecordBatches. Returns true if successful, false otherwise.
std::vector< std::string > languages
Output languages.
bool axi_top
Whether to generate an AXI top level.
bool MustGenerateSREC() const
Return true if an SREC file must be generated.
std::vector< std::string > recordbatch_paths
Paths to RecordBatches.
std::string srec_out_path
SREC output path. This is the path where an SREC file based on input RecordBatches will be placed.
bool mmio64
Use 64-bits data width for AXI4-lite MMIO bus when true.
bool backup
Whether to backup any existing generated files.
bool static_vhdl
Whether to generate static VHDL files (copied from hardware directory, embedded as resources).
bool version
Show version information.
static bool Parse(Options *options, int argc, char **argv)
Parse command line options and store the result.
std::vector< std::string > schema_paths
Paths to the schema files.
std::vector< std::string > bus_dims
Bus dimensions strings.
std::string srec_sim_dump
SREC simulation output path, where the simulation should dump the memory contents of written RecordBa...
bool sim_top
Whether to simulate an AXI top level.
bool MustGenerate(const std::string &target) const
Return true if generation must take place for some target.
std::string externals_yaml
File to parse for external signals to/from top level to kernel.
std::vector< std::string > regs
Custom 32-bit registers.
std::vector< std::shared_ptr< arrow::RecordBatch > > recordbatches
Loaded RecordBatches.
size_t mmio_offset
AXI4-lite offset address for Fletcher registers.
std::string ToString() const
Return human-readable options.
bool vivado_hls
Vivado HLS template. TODO(johanpel): not yet implemented.
std::string kernel_name
Name of the Kernel.