49 #define TOOL_OPT_BASE 256 50 #define INPUT_OPT_CHARACTERIZE (1 + TOOL_OPT_BASE) 51 #define INPUT_OPT_TARGET_DATAFILE (1 + INPUT_OPT_CHARACTERIZE) 52 #define INPUT_OPT_TARGET_SCRIPTFILE (1 + INPUT_OPT_TARGET_DATAFILE) 53 #define OPT_LATTICE_ROOT (1 + INPUT_OPT_TARGET_SCRIPTFILE) 54 #define OPT_XILINX_ROOT (1 + OPT_LATTICE_ROOT) 55 #define OPT_MENTOR_ROOT (1 + OPT_XILINX_ROOT) 56 #define OPT_MENTOR_OPTIMIZER (1 + OPT_MENTOR_ROOT) 57 #define OPT_ALTERA_ROOT (1 + OPT_MENTOR_OPTIMIZER) 58 #define OPT_NANOXPLORE_ROOT (1 + OPT_ALTERA_ROOT) 59 #define OPT_NANOXPLORE_BYPASS (1 + OPT_NANOXPLORE_ROOT) 60 #define OPT_PARALLEL_BACKEND (1 + OPT_NANOXPLORE_BYPASS) 69 os <<
"" << std::endl;
70 os <<
"********************************************************************************" << std::endl;
71 os <<
" _____ _ _" << std::endl;
72 os <<
" | ____| _ ___ __ _| |_ _ _ __ | |_ _ _ ___" << std::endl;
73 os <<
" | _|| | | |/ __/ _` | | | | | '_ \\| __| | | / __|" << std::endl;
74 os <<
" | |__| |_| | (_| (_| | | |_| | |_) | |_| |_| \\__ \\" << std::endl;
75 os << R
"( |_____\__,_|\___\__,_|_|\__, | .__/ \__|\__,_|___/)" << std::endl; 76 os << " |___/|_|" << std::endl;
77 os <<
"********************************************************************************" << std::endl;
82 os <<
"Usage: " << std::endl;
83 os <<
" " << getOption<std::string>(OPT_program_name) <<
" [options]" << std::endl;
88 <<
" Library Estimation:\n" 89 <<
" --target-device=<file> Specify the type of the device, separated by commas (e.g.,: " 90 "\"xc7z020,-1,clg484\")\n" 91 <<
" --target-datafile=file Specify a data XML file describing some defaults value for the target " 93 <<
" --target-scriptfile=file Specify a script XML file including the scripts for the synthesis w.r.t. " 94 "the target device.\n" 95 <<
" --clock-period=value Specify the period of the clock signal (default 10 nanoseconds)\n" 96 <<
" --characterize=<component_name> Characterize the given component\n" 99 os <<
" Backend configuration:\n\n" 100 <<
" --mentor-visualizer\n" 101 <<
" Simulate the RTL implementation and then open Mentor Visualizer.\n" 102 <<
" (Mentor root has to be correctly set, see --mentor-root)\n\n" 103 <<
" --mentor-optimizer=<0|1>\n" 104 <<
" Enable or disable mentor optimizer. (default=enabled)\n\n" 105 <<
" --nanoxplore-bypass=<name>\n" 106 <<
" Define NanoXplore bypass when using NanoXplore. User may set NANOXPLORE_BYPASS\n" 107 <<
" variable otherwise.\n\n" 108 <<
" --altera-root=<path>\n" 109 <<
" Define Altera tools path. Given path is searched for Quartus.\n" 110 <<
" (default=/opt/altera:/opt/intelFPGA)\n\n" 111 <<
" --lattice-root=<path>\n" 112 <<
" Define Lattice tools path. Given path is searched for Diamond.\n" 113 <<
" (default=/opt/diamond:/usr/local/diamond)\n\n" 114 <<
" --mentor-root=<path>\n" 115 <<
" Define Mentor tools path. Given directory is searched for Modelsim and Visualizer\n" 116 <<
" (default=/opt/mentor)\n\n" 117 <<
" --nanoxplore-root=<path>\n" 118 <<
" Define NanoXplore tools path. Given directory is searched for NXMap.\n" 119 <<
" (default=/opt/NanoXplore)\n\n" 120 <<
" --xilinx-root=<path>\n" 121 <<
" Define Xilinx tools path. Given directory is searched for both ISE and Vivado\n" 122 <<
" (default=/opt/Xilinx)\n\n" 146 {
"clock-period", required_argument,
nullptr, 0},
148 {
"target-device", required_argument,
nullptr, 0},
150 {
"writer", required_argument,
nullptr,
'w'},
159 {
nullptr, 0,
nullptr, 0}};
169 int next_option = getopt_long(
argc,
argv, short_options, long_options, &option_index);
172 if(next_option == -1)
186 setOption(OPT_target_device_file, optarg);
191 setOption(OPT_target_device_script, optarg);
211 setOption(OPT_mentor_optimizer, static_cast<bool>(std::stoi(optarg)));
221 setOption(OPT_nanoxplore_bypass, std::string(optarg));
237 if(std::string(optarg) ==
"V")
241 else if(std::string(optarg) ==
"H")
247 throw "BadParameters: backend language not correctly specified";
253 if(long_options[option_index].name == std::string(
"target-device"))
255 std::string tmp_string = optarg;
256 std::vector<std::string> values =
257 string_to_container<std::vector<std::string>>(tmp_string, std::string(
","));
262 if(values.size() == 2)
266 else if(values.size() == 3)
272 else if(values.size() == 4)
277 setOption(
"device_synthesis_tool", values[3]);
284 else if(long_options[option_index].name == std::string(
"clock-period"))
290 THROW_ERROR(
"Not supported option: " + std::string(long_options[option_index].name));
297 bool exit_success =
false;
305 std::cerr << optarg << std::endl;
311 std::string cat_args;
313 for(
int i = 0; i <
argc; i++)
315 cat_args += std::string(
argv[i]) +
" ";
320 std::cerr <<
" == Eucalyptus executed with: ";
321 std::cerr << cat_args;
322 std::cerr << std::endl << std::endl;
332 const auto sorted_dirs = [](
const std::string& parent_dir) {
333 std::vector<std::filesystem::path> sorted_paths;
334 std::copy(std::filesystem::directory_iterator(parent_dir), std::filesystem::directory_iterator(),
335 std::back_inserter(sorted_paths));
340 const auto altera_dirs =
SplitString(getOption<std::string>(OPT_altera_root),
":");
342 const auto search_quartus = [&](
const std::string& dir) {
343 if(std::filesystem::exists(dir +
"/quartus/bin/quartus_sh"))
345 if(system(
STR(
"bash -c \"if [ $(" + dir +
346 "/quartus/bin/quartus_sh --version | grep Version | sed -E 's/Version ([0-9]+).*/\\1/') -lt 14 " 347 "]; then exit 1; else exit 0; fi\" > /dev/null 2>&1")
350 setOption(OPT_quartus_13_settings,
"export PATH=$PATH:" + dir +
"/quartus/bin/");
351 if(system(
STR(
"bash -c \"" + dir +
"/quartus/bin/quartus_sh --help | grep '--64bit'\" > /dev/null 2>&1")
363 setOption(OPT_quartus_settings,
"export PATH=$PATH:" + dir +
"/quartus/bin/");
367 for(
const auto& altera_dir : altera_dirs)
369 if(std::filesystem::is_directory(altera_dir))
371 for(
const auto& ver_dir : sorted_dirs(altera_dir))
373 if(std::filesystem::is_directory(ver_dir))
375 search_quartus(ver_dir.string());
378 search_quartus(altera_dir);
383 const auto lattice_dirs =
SplitString(getOption<std::string>(OPT_lattice_root),
":");
385 auto has_lattice = 0;
386 const auto search_lattice = [&](
const std::string& dir) {
387 if(std::filesystem::exists(dir +
"/bin/lin/diamondc"))
392 else if(std::filesystem::exists(dir +
"/bin/lin64/diamondc"))
397 if(std::filesystem::exists(dir +
"/cae_library/synthesis/verilog/pmi_def.v"))
399 setOption(OPT_lattice_pmi_def, dir +
"/cae_library/synthesis/verilog/pmi_def.v");
401 if(std::filesystem::exists(dir +
"/cae_library/simulation/verilog/pmi/pmi_dsp_mult.v") &&
402 std::filesystem::exists(dir +
"/cae_library/simulation/verilog/pmi/pmi_ram_dp_true_be.v"))
404 setOption(OPT_lattice_inc_dirs, dir +
"/cae_library/");
407 for(
const auto& lattice_dir : lattice_dirs)
409 if(std::filesystem::is_directory(lattice_dir))
411 for(
const auto& ver_dir : sorted_dirs(lattice_dir))
413 if(std::filesystem::is_directory(ver_dir))
415 search_lattice(ver_dir.string());
418 search_lattice(lattice_dir);
423 const auto lattice_dir = getOption<std::string>(OPT_lattice_root);
424 setOption(OPT_lattice_settings,
"export TEMP=/tmp;export LSC_INI_PATH=\"\";" 425 "export LSC_DIAMOND=true;" 426 "export TCL_LIBRARY=" +
432 "export PATH=$FOUNDRY/bin/lin:" +
433 lattice_dir +
"/bin/lin:$PATH");
435 else if(has_lattice == 2)
437 const auto lattice_dir = getOption<std::string>(OPT_lattice_root);
438 setOption(OPT_lattice_settings,
"export TEMP=/tmp;export LSC_INI_PATH=\"\";" 439 "export LSC_DIAMOND=true;" 440 "export TCL_LIBRARY=" +
446 "export PATH=$FOUNDRY/bin/lin64:" +
447 lattice_dir +
"/bin/lin64:$PATH");
451 const auto mentor_dirs =
SplitString(getOption<std::string>(OPT_mentor_root),
":");
453 const auto search_mentor = [&](
const std::string& dir) {
454 if(std::filesystem::exists(dir +
"/bin/vsim"))
456 setOption(OPT_mentor_modelsim_bin, dir +
"/bin");
459 for(
const auto& mentor_dir : mentor_dirs)
461 if(std::filesystem::is_directory(mentor_dir))
463 for(
const auto& ver_dir : sorted_dirs(mentor_dir))
465 if(std::filesystem::is_directory(ver_dir))
467 search_mentor(ver_dir.string());
470 search_mentor(mentor_dir);
475 const auto nanox_dirs =
SplitString(getOption<std::string>(OPT_nanoxplore_root),
":");
477 const auto search_xmap = [&](
const std::string& dir) {
478 if(std::filesystem::exists(dir +
"/bin/nxpython"))
483 for(
const auto& nanox_dir : nanox_dirs)
485 if(std::filesystem::is_directory(nanox_dir))
487 for(
const auto& ver_dir : sorted_dirs(nanox_dir))
489 if(std::filesystem::is_directory(ver_dir))
491 search_xmap(ver_dir.string());
494 search_xmap(nanox_dir);
499 const auto target_64 =
true;
500 const auto xilinx_dirs =
SplitString(getOption<std::string>(OPT_xilinx_root),
":");
502 const auto search_xilinx = [&](
const std::string& dir) {
503 if(std::filesystem::exists(dir +
"/ISE"))
505 if(target_64 && std::filesystem::exists(dir +
"/settings64.sh"))
507 setOption(OPT_xilinx_settings, dir +
"/settings64.sh");
509 else if(std::filesystem::exists(dir +
"/settings32.sh"))
511 setOption(OPT_xilinx_settings, dir +
"/settings32.sh");
513 if(std::filesystem::exists(dir +
"/ISE/verilog/src/glbl.v"))
515 setOption(OPT_xilinx_glbl, dir +
"/ISE/verilog/src/glbl.v");
519 const auto search_xilinx_vivado = [&](
const std::string& dir) {
520 if(std::filesystem::exists(dir +
"/ids_lite"))
522 if(target_64 && std::filesystem::exists(dir +
"/settings64.sh"))
524 setOption(OPT_xilinx_vivado_settings, dir +
"/settings64.sh");
526 else if(std::filesystem::exists(dir +
"/settings32.sh"))
528 setOption(OPT_xilinx_vivado_settings, dir +
"/settings32.sh");
530 if(std::filesystem::exists(dir +
"/data/verilog/src/glbl.v"))
532 setOption(OPT_xilinx_glbl, dir +
"/data/verilog/src/glbl.v");
536 for(
const auto& xilinx_dir : xilinx_dirs)
538 if(std::filesystem::is_directory(xilinx_dir))
540 for(
const auto& ver_dir : sorted_dirs(xilinx_dir))
542 if(std::filesystem::is_directory(ver_dir))
544 for(
const auto& ise_dir : std::filesystem::directory_iterator(ver_dir))
546 const auto ise_path = ise_dir.path().string();
547 if(std::filesystem::is_directory(ise_dir) && ise_path.find(
"ISE") > ise_path.find_last_of(
'/'))
549 search_xilinx(ise_path);
554 search_xilinx(xilinx_dir);
557 for(
const auto& xilinx_dir : xilinx_dirs)
559 if(std::filesystem::is_directory(xilinx_dir))
561 for(
const auto& vivado_dir : std::filesystem::directory_iterator(xilinx_dir))
563 const auto vivado_path = vivado_dir.path().string();
564 if(std::filesystem::is_directory(vivado_dir) && vivado_path.find(
"Vivado") > vivado_path.find_last_of(
'/'))
566 for(
const auto& ver_dir : sorted_dirs(vivado_path))
568 if(std::filesystem::is_directory(ver_dir))
570 search_xilinx_vivado(ver_dir.string());
575 search_xilinx_vivado(xilinx_dir);
580 setOption(OPT_verilator, system(
"which verilator > /dev/null 2>&1") == 0);
584 if(getOption<std::string>(OPT_simulator) ==
"MODELSIM" && !
isOption(OPT_mentor_modelsim_bin))
586 THROW_ERROR(
"Mentor Modelsim was not detected by Bambu. Please check --mentor-root option is correct.");
588 else if(getOption<std::string>(OPT_simulator) ==
"XSIM" && !
isOption(OPT_xilinx_vivado_settings))
590 THROW_ERROR(
"Xilinx XSim was not detected by Bambu. Please check --xilinx-root option is correct.");
592 else if(getOption<std::string>(OPT_simulator) ==
"VERILATOR" && !
isOption(OPT_verilator))
594 THROW_ERROR(
"Verilator was not detected by Bambu. Please make sure it is installed in the system.");
599 if(
isOption(OPT_mentor_modelsim_bin))
603 else if(
isOption(OPT_xilinx_vivado_settings))
613 THROW_ERROR(
"No valid simulator was found in the system.");
619 std::string device_string = getOption<std::string>(
"device_name") + getOption<std::string>(
"device_speed") +
620 getOption<std::string>(
"device_package");
621 if(
isOption(
"device_synthesis_tool") && !getOption<std::string>(
"device_synthesis_tool").empty())
623 device_string +=
"-" + getOption<std::string>(
"device_synthesis_tool");
625 setOption(OPT_device_string, device_string);
636 setOption(OPT_altera_root,
"/opt/altera:/opt/intelFPGA");
637 setOption(OPT_lattice_root,
"/opt/diamond:/usr/local/diamond");
638 setOption(OPT_mentor_root,
"/opt/mentor");
640 setOption(OPT_nanoxplore_root,
"/opt/NanoXplore");
641 setOption(OPT_xilinx_root,
"/opt/Xilinx");
647 setOption(
"device_synthesis_tool",
"VVD");
649 setOption(OPT_clock_period_resource_fraction, 1.0);
#define INPUT_OPT_TARGET_SCRIPTFILE
int exit_code
NOTE: this file must be included only by source code of the executable (i.e., the file with the main)...
void setOption(const std::string &name, const G value)
Sets the value of an option.
EucalyptusParameter(const std::string &program_name, int argc, char **const argv)
Constructor.
char **const argv
The input parameters;.
const std::vector< std::string > SplitString(const std::string &input, const std::string &separators)
Function which splits a string into tokens.
#define COMMON_SHORT_OPTIONS_STRING
define the default tool short option string
bool NaturalVersionOrder(const std::filesystem::path &_x, const std::filesystem::path &_y)
#define OPT_NANOXPLORE_BYPASS
#define OUTPUT_LEVEL_MINIMUM
minimum debugging print is performed.
void PrintUsage(std::ostream &os) const
Print the usage of this tool = PrintHeader() + PrintHelp()
#define STR(s)
Macro which performs a lexical_cast to a string.
This class writes different HDL based descriptions (VHDL, Verilog, SystemC) starting from a structura...
#define INPUT_OPT_CHARACTERIZE
#define PARAMETER_PARSED
An integer value to return if parameters have been right parsed.
virtual void CheckParameters()=0
Checks the compatibility among the different parameters and determines the implications.
utility function used to read files.
This file collects some utility functions and macros.
#define THROW_ERROR(str_expr)
helper function used to throw an error in a standard way
int Exec() override
Execute parameter parsing.
#define COMMON_LONG_OPTIONS
define default TOOL long options
#define INPUT_OPT_TARGET_DATAFILE
std::string GetPath(std::filesystem::path path)
void PrintHelp(std::ostream &os) const override
Print the usage of this tool.
#define OPT_NANOXPLORE_ROOT
void CheckParameters() override
Check the compatibility among the different parameters and compute implicated parameters.
std::string GetCurrentPath()
void SetDefaults() override
Sets the default values with respect to the tool.
void PrintGeneralOptionsUsage(std::ostream &os) const
Print the usage of the general common options.
Generic device description.
bool isOption(const std::string &name) const
Tests if an option has been stored.
int argc
The number of input paramters.
#define OPT_MENTOR_OPTIMIZER
bool ManageDefaultOptions(int next_option, char *optarg_param, bool &exit_success)
Manage default options (common to all tools)
void PrintProgramName(std::ostream &os) const override
Print the name of the program to be included in the header.
#define OPT_PARALLEL_BACKEND
#define DEBUG_LEVEL_MINIMUM
minimum debugging print is performed.
#define PARAMETER_NOTPARSED
bool removeOption(const enum enum_option name)
Remove an option.