[core] adding new options and rewrite options for bitfile writer
This commit is contained in:
parent
32513c73eb
commit
80856f1b70
|
@ -190,6 +190,23 @@ ShellCommandId add_write_fabric_bitstream_command_template(
|
|||
"file format of fabric bitstream [plain_text|xml]. Default: plain_text");
|
||||
shell_cmd.set_option_require_value(opt_file_format, openfpga::OPT_STRING);
|
||||
|
||||
CommandOptionId opt_filter_value = shell_cmd.add_option(
|
||||
"filter_value", false,
|
||||
"Specify what values should be written out in the resulting fabric bitstream [0|1|none]. Only applicable to XML file format. Default: none");
|
||||
shell_cmd.set_option_require_value(opt_filter_value, openfpga::OPT_STRING);
|
||||
|
||||
shell_cmd.add_option(
|
||||
"path_only", false,
|
||||
"Only paths will be written out in the resulting fabric bitstream. Only applicable to XML file format. Default: off");
|
||||
|
||||
shell_cmd.add_option(
|
||||
"value_only", false,
|
||||
"Only values will be written out in the resulting fabric bitstream. Only applicable to XML file format. Default: off");
|
||||
|
||||
shell_cmd.add_option(
|
||||
"trim_path", false,
|
||||
"Trim the path by a level of 1 in the resulting fabric bitstream. Only applicable to XML file format. Default: off");
|
||||
|
||||
/* Add an option '--fast_configuration' */
|
||||
shell_cmd.add_option("fast_configuration", false,
|
||||
"Reduce the size of bitstream to be downloaded");
|
||||
|
|
|
@ -94,6 +94,9 @@ int write_fabric_bitstream_template(const T& openfpga_ctx, const Command& cmd,
|
|||
CommandOptionId opt_keep_dont_care_bits = cmd.option("keep_dont_care_bits");
|
||||
CommandOptionId opt_wl_decremental_order = cmd.option("wl_decremental_order");
|
||||
CommandOptionId opt_no_time_stamp = cmd.option("no_time_stamp");
|
||||
CommandOptionId opt_filter_value = cmd.option("filter_value");
|
||||
CommandOptionId opt_path_only = cmd.option("path_only");
|
||||
CommandOptionId opt_value_only = cmd.option("value_only");
|
||||
|
||||
/* Write fabric bitstream if required */
|
||||
int status = CMD_EXEC_SUCCESS;
|
||||
|
|
|
@ -0,0 +1,172 @@
|
|||
/******************************************************************************
|
||||
* Memember functions for data structure BitstreamWriterOption
|
||||
******************************************************************************/
|
||||
#include "bitstream_writer_options.h"
|
||||
|
||||
#include "vtr_assert.h"
|
||||
#include "vtr_log.h"
|
||||
|
||||
/* begin namespace openfpga */
|
||||
namespace openfpga {
|
||||
|
||||
/**************************************************
|
||||
* Public Constructors
|
||||
*************************************************/
|
||||
BitstreamWriterOption::BitstreamWriterOption() {
|
||||
file_type_ = BitstreamWriterOption::e_bitfile_type::NUM_TYPES;
|
||||
BITFILE_TYPE_STRING_ = {"plain_text", "xml"};
|
||||
output_file_.clear();
|
||||
time_stamp_ = true;
|
||||
verbose_output_ = false;
|
||||
|
||||
filter_value_ = "";
|
||||
trim_path_ = false;
|
||||
path_only_ = false;
|
||||
value_only_ = false;
|
||||
|
||||
fast_config_ = false;
|
||||
keep_dont_care_bits_ = false;
|
||||
wl_decremental_order_ = false;
|
||||
}
|
||||
|
||||
/**************************************************
|
||||
* Public Accessors
|
||||
*************************************************/
|
||||
BitstreamWriterOption::e_bitfile_type output_file_type() const {
|
||||
return file_type_;
|
||||
}
|
||||
|
||||
std::string BitstreamWriterOption::output_file_name() const {
|
||||
return output_file_;
|
||||
}
|
||||
|
||||
bool BitstreamWriterOption::time_stamp() const { return time_stamp_; }
|
||||
|
||||
bool BitstreamWriterOption::verbose_output() const { return verbose_output_; }
|
||||
|
||||
bool BitstreamWriterOption:filter_value() const {
|
||||
return !filter_value_.empty();
|
||||
}
|
||||
|
||||
bool BitstreamWriterOption:value_to_skip(const size_t& val) const {
|
||||
return std::to_string(val) == filter_value_;
|
||||
}
|
||||
|
||||
bool trim_path() const { return trim_path_; }
|
||||
bool output_path() const { return path_only_; }
|
||||
bool output_value() const { return value_only_; }
|
||||
|
||||
bool fast_configuration() const { return fast_config_; }
|
||||
bool keep_dont_care_bits() const { return keep_dont_care_bits_; }
|
||||
bool wl_decremental_order() const { return wl_decremental_order_; }
|
||||
|
||||
/******************************************************************************
|
||||
* Private Mutators
|
||||
******************************************************************************/
|
||||
void BitstreamWriterOption::set_output_file_type(const std::string& val) {
|
||||
file_type_ = str2bitfile_type(val);
|
||||
}
|
||||
|
||||
void BitstreamWriterOption::set_output_file_name(const std::string& output_file) {
|
||||
output_file_ = output_file;
|
||||
}
|
||||
|
||||
void BitstreamWriterOption::set_time_stamp(const bool& enabled) {
|
||||
time_stamp_ = enabled;
|
||||
}
|
||||
|
||||
void BitstreamWriterOption::set_verbose_output(const bool& enabled) {
|
||||
verbose_output_ = enabled;
|
||||
}
|
||||
|
||||
void BitstreamWriterOption::set_filter_value(const std::string& val) {
|
||||
filter_value_ = val;
|
||||
}
|
||||
|
||||
void BitstreamWriterOption::set_trim_path(const bool& enabled) {
|
||||
trim_path_ = enabled;
|
||||
}
|
||||
|
||||
void BitstreamWriterOption::set_path_only(const bool& enabled) {
|
||||
path_only_ = enabled;
|
||||
}
|
||||
|
||||
void BitstreamWriterOption::set_value_only(const bool& enabled) {
|
||||
value_only_ = enabled;
|
||||
}
|
||||
|
||||
void BitstreamWriterOption::set_fast_configuration(const bool& enabled) {
|
||||
fast_config_ = enabled;
|
||||
}
|
||||
|
||||
void BitstreamWriterOption::set_keep_dont_care_bits(const bool& enabled) {
|
||||
keep_dont_care_bits_ = enabled;
|
||||
}
|
||||
|
||||
void BitstreamWriterOption::set_wl_decremental_order(const bool& enabled) {
|
||||
wl_decremental_order_ = enabled;
|
||||
}
|
||||
|
||||
bool BitstreamWriterOption::validate(bool show_err_msg) const {
|
||||
/* Check file type */
|
||||
if (!valid_file_type(file_type_)) {
|
||||
VTR_LOGV_ERROR(show_err_msg, "Invalid file type!\n");
|
||||
return false;
|
||||
}
|
||||
if (output_file_.empty()) {
|
||||
VTR_LOGV_ERROR(show_err_msg, "Empty file name!\n");
|
||||
return false;
|
||||
}
|
||||
if (file_type_ == BitstreamWriterOption::e_bitfile_type::XML) {
|
||||
/* All the options in the XML format should be off */
|
||||
if (path_only_ && value_only) {
|
||||
VTR_LOGV_ERROR(show_err_msg, "Both path and value are specifed as only inputs! If specified, please define one of them\n");
|
||||
return false;
|
||||
}
|
||||
if (!filter_value_.empty() && (filter_value_ != std::to_string(0) || filter_value_ != std::to_string(1))) {
|
||||
VTR_LOGV_ERROR(show_err_msg, "Invalid value '%s' for filter values. Expect [0|1]!\n", filter_value_);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
e_bitfile_type BitstreamWriterOption::str2bitfile_type(const std::string& type_str, const bool& verbose) const {
|
||||
for (int itype = size_t(BitstreamWriterOption::e_bitfile_type::TEXT);
|
||||
itype != size_t(BitstreamWriterOption::e_bitfile_type::NUM_TYPES); ++itype) {
|
||||
if (type_str == std::string(BITFILE_TYPE_STRING_[itype])) {
|
||||
return static_cast<BitstreamWriterOption::e_bitfile_type::>(itype);
|
||||
}
|
||||
}
|
||||
VTR_LOGV_ERROR(verbose, "Invalid type for bitstream file! Expect %s\n",
|
||||
bitfile_type_all2str().c_str());
|
||||
return BitstreamWriterOption::e_bitfile_type::NUM_TYPES;
|
||||
}
|
||||
|
||||
std::string BitstreamWriterOption::bitfile_type2str(const BitstreamWriterOption::e_bitfile_type& type,
|
||||
const bool& verbose) const {
|
||||
if (!valid_file_type(type)) {
|
||||
VTR_LOGV_ERROR(verbose, "Invalid type for bitstream file! Expect %s\n",
|
||||
file_type_all2str().c_str());
|
||||
return std::string();
|
||||
}
|
||||
return std::string(BITFILE_TYPE_STRING_[size_t(type)]);
|
||||
}
|
||||
|
||||
std::string BitstreamWriterOption::file_type_all2str() const {
|
||||
std::string full_types = "[";
|
||||
for (int itype = size_t(BitstreamWriterOption::e_bitfile_type::TEXT);
|
||||
itype != size_t(BitstreamWriterOption::e_bitfile_type::NUM_TYPES); ++itype) {
|
||||
full_types += std::string(BITFILE_TYPE_STRING_[itype]) + std::string("|");
|
||||
}
|
||||
full_types.pop_back();
|
||||
full_types += "]";
|
||||
return full_types;
|
||||
}
|
||||
|
||||
|
||||
bool BitstreamWriterOption::valid_file_type(const BitstreamWriterOption::e_bitfile_type bitfile_type) const {
|
||||
return bitfile_type != BitstreamWriterOption::e_bitfile_type::NUM_TYPES;
|
||||
}
|
||||
|
||||
} /* end namespace openfpga */
|
|
@ -0,0 +1,99 @@
|
|||
#ifndef BITSTREAM_WRITER_OPTIONS_H
|
||||
#define BITSTREAM_WRITER_OPTIONS_H
|
||||
|
||||
/********************************************************************
|
||||
* Include header files required by the data structure definition
|
||||
*******************************************************************/
|
||||
#include <string>
|
||||
|
||||
/* Begin namespace openfpga */
|
||||
namespace openfpga {
|
||||
|
||||
/********************************************************************
|
||||
* Options for Bitstream Writer
|
||||
*******************************************************************/
|
||||
class BitstreamWriterOption {
|
||||
public: /* Private data structures */
|
||||
/* A type to define the bitstream file format */
|
||||
enum class e_bitfile_type {
|
||||
TEXT,
|
||||
XML,
|
||||
NUM_TYPES
|
||||
};
|
||||
public: /* Public constructor */
|
||||
/* Set default options */
|
||||
BitstreamWriterOption();
|
||||
|
||||
public: /* Public accessors */
|
||||
e_bitfile_type output_file_type() const;
|
||||
std::string output_file_name() const;
|
||||
bool time_stamp() const;
|
||||
bool verbose_output() const;
|
||||
|
||||
/* Check if a filter on value is applied */
|
||||
bool filter_value() const;
|
||||
/* Check if a given value should be skipped */
|
||||
bool value_to_skip(const size_t& val) const;
|
||||
/* Check if path trimming should be applied or not */
|
||||
bool trim_path() const;
|
||||
/* Check if path should be outputted in the resulting file */
|
||||
bool output_path() const;
|
||||
/* Check if value should be outputted in the resulting file */
|
||||
bool output_value() const;
|
||||
|
||||
bool fast_configuration() const;
|
||||
bool keep_dont_care_bits() const;
|
||||
bool wl_decremental_order() const;
|
||||
|
||||
public: /* Public mutators */
|
||||
void set_output_file_type(const std::string& val);
|
||||
void set_output_file_name(const std::string& output_file);
|
||||
void set_time_stamp(const bool& enabled);
|
||||
void set_verbose_output(const bool& enabled);
|
||||
|
||||
void set_filter_value(const std::string& val);
|
||||
|
||||
public: /* Public validator */
|
||||
bool validate(bool show_err_msg = false) const;
|
||||
|
||||
public: /* Internal utility */
|
||||
/** @brief Parse the file type from string to valid type. Parser
|
||||
* error can be turned on */
|
||||
e_bitfile_type str2bitfile_type(const std::string& type_str,
|
||||
const bool& verbose = false) const;
|
||||
|
||||
/** @brief Output the string representing file_type */
|
||||
std::string bitfile_type2str(const e_bitfile_type& type,
|
||||
const bool& verbose = false) const;
|
||||
/** @brief Validate the file_type */
|
||||
bool valid_file_type(const e_bitfile_type& bitfile_type) const;
|
||||
|
||||
/* Generate a string include all the valid style
|
||||
* Useful for printing debugging messages */
|
||||
std::string file_type_all2str() const;
|
||||
|
||||
private: /* Internal Data */
|
||||
/* Universal options */
|
||||
e_bitfile_type file_type_;
|
||||
std::string output_file_;
|
||||
bool time_stamp_;
|
||||
bool verbose_output_;
|
||||
|
||||
/* XML-specific options */
|
||||
std::string filter_value_;
|
||||
bool trim_path_;
|
||||
bool path_only_;
|
||||
bool value_only_;
|
||||
|
||||
/* Plain-text options */
|
||||
bool fast_config_;
|
||||
bool keep_dont_care_bits_;
|
||||
bool wl_decremental_order_;
|
||||
|
||||
/* Constants */
|
||||
std::array<const char*, size_t(e_bitfile_type::NUM_TYPES)> BITFILE_TYPE_STRING_;
|
||||
};
|
||||
|
||||
} /* End namespace openfpga*/
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue