15 #include "fletchgen/fletchgen.h"
17 #include <cerata/api.h>
18 #include <cerata/dot/dot.h>
19 #include <cerata/vhdl/vhdl.h>
20 #include <fletcher/common.h>
25 #include "fletchgen/options.h"
26 #include "fletchgen/design.h"
27 #include "fletchgen/utils.h"
28 #include "fletchgen/srec/recordbatch.h"
29 #include "fletchgen/top/sim.h"
30 #include "fletchgen/top/axi.h"
31 #include "fletchgen/static_vhdl.h"
39 fletcher::StartLogging(program_name, FLETCHER_LOG_DEBUG, program_name +
".log");
45 auto options = std::make_shared<fletchgen::Options>();
47 FLETCHER_LOG(ERROR,
"Error parsing arguments. Exiting Fletchgen.");
52 if (options->version) {
53 std::cout <<
version() <<
" (using " << cerata::version() <<
")" << std::endl;
58 fletcher::StopLogging();
63 if (!options->LoadRecordBatches())
return false;
64 if (!options->LoadSchemas())
return false;
67 std::vector<fletcher::RecordBatchDescription> srec_batch_desc;
70 if (!options->MustGenerateDesign()) {
71 FLETCHER_LOG(INFO,
"No schemas or recordbatches were supplied. No design was generated.");
82 if (options->MustGenerateSREC()) {
83 FLETCHER_LOG(INFO,
"Generating SREC output.");
84 auto srec_out = std::ofstream(options->srec_out_path);
85 fletchgen::srec::GenerateReadSREC(design.
batch_desc, &srec_batch_desc, &srec_out, 64);
89 auto &l = options->languages;
92 if (options->MustGenerate(
"dot")) {
93 FLETCHER_LOG(INFO,
"Generating DOT output.");
94 auto dot = cerata::dot::DOTOutputGenerator(options->output_dir, design.
GetOutputSpec());
97 l.erase(std::remove(l.begin(), l.end(), std::string(
"dot")), l.end());
101 if (options->MustGenerate(
"vhdl")) {
102 FLETCHER_LOG(INFO,
"Generating VHDL output.");
103 auto vhdl = cerata::vhdl::VHDLOutputGenerator(options->output_dir,
108 l.erase(std::remove(l.begin(), l.end(), std::string(
"vhdl")), l.end());
115 for (
const auto &t : l) {
116 FLETCHER_LOG(WARNING,
"Unknown target language: " << t);
121 if (options->MustGenerateDesign() && options->sim_top) {
122 std::ofstream sim_file;
123 std::string sim_file_path = options->output_dir +
"/vhdl/SimTop_tc.gen.vhd";
124 FLETCHER_LOG(INFO,
"Saving simulation top-level design to: " + sim_file_path);
125 sim_file = std::ofstream(sim_file_path);
127 if (!cerata::FileExists(options->srec_sim_dump)) {
129 std::ofstream srec_out(options->srec_sim_dump);
132 fletchgen::top::GenerateSimTop(design,
134 options->srec_out_path,
135 options->srec_sim_dump,
141 if (options->axi_top) {
142 std::ofstream axi_file;
143 std::string axi_file_path = options->output_dir +
"/vhdl/AxiTop.gen.vhd";
144 FLETCHER_LOG(INFO,
"Saving AXI top-level design to: " + axi_file_path);
145 axi_file = std::ofstream(axi_file_path);
146 fletchgen::top::GenerateAXITop(*design.
mantle_comp,
155 if (options->vivado_hls) {
156 FLETCHER_LOG(WARNING,
"Vivado HLS template output not yet implemented.");
167 if (options->static_vhdl) {
172 if (!vhdmmio.joinable()) {
173 FLETCHER_LOG(INFO,
"Waiting for vhdmmio to complete...");
177 FLETCHER_LOG(INFO, program_name +
" completed.");
180 fletcher::StopLogging();
Contains all classes and functions related to Fletchgen.
void LogCerata(cerata::LogLevel level, std::string const &message, char const *source_function, char const *source_file, int line_number)
Callback function for the Cerata logger.
constexpr char DEFAULT_NOTICE[]
Default copyright notice.
std::string GetProgramName(char *argv0)
Return the name of this program executable.
void write_static_vhdl(const std::string &real_dir, const std::string &emb_dir)
Writes Fletcher's static VHDL files to the given directory.
std::string version()
Return Fletchgen version string.
int fletchgen(int argc, char **argv)
Fletchgen main entry. Used to wrap into PyFletchgen.
A structure for all components in a Fletcher design.
std::shared_ptr< Mantle > mantle_comp
std::vector< cerata::OutputSpec > GetOutputSpec()
Obtain a Cerata OutputSpec from this design for Cerata back-ends to generate output.
static void RunVhdmmio(const std::vector< std::vector< MmioReg > * > ®s, Axi4LiteSpec axi_spec)
Generate vhdmmio yaml and run it.
std::vector< std::vector< MmioReg > * > all_regs
Pointers to all registers vectors.
std::shared_ptr< SchemaSet > schema_set
The SchemaSet to base the design on.
std::optional< std::shared_ptr< Type > > external
External signals type.
std::vector< fletcher::RecordBatchDescription > batch_desc
The RecordBatchDescriptions to use in SREC generation.
static bool Parse(Options *options, int argc, char **argv)
Parse command line options and store the result.