[lib] update parser
This commit is contained in:
parent
346aacefa9
commit
8429c4b836
|
@ -20,6 +20,7 @@
|
|||
#include "read_xml_bitstream_setting.h"
|
||||
#include "read_xml_openfpga_arch_utils.h"
|
||||
#include "read_xml_util.h"
|
||||
#include "bitstream_setting_xml_constants.h"
|
||||
|
||||
/********************************************************************
|
||||
* Parse XML description for a pb_type annotation under a <pb_type> XML node
|
||||
|
@ -28,11 +29,11 @@ static void read_xml_bitstream_pb_type_setting(
|
|||
pugi::xml_node& xml_pb_type, const pugiutil::loc_data& loc_data,
|
||||
openfpga::BitstreamSetting& bitstream_setting) {
|
||||
const std::string& name_attr =
|
||||
get_attribute(xml_pb_type, "name", loc_data).as_string();
|
||||
get_attribute(xml_pb_type, XML_PB_TYPE_ATTRIBUTE_NAME, loc_data).as_string();
|
||||
const std::string& source_attr =
|
||||
get_attribute(xml_pb_type, "source", loc_data).as_string();
|
||||
get_attribute(xml_pb_type, XML_PB_TYPE_ATTRIBUTE_SOURCE, loc_data).as_string();
|
||||
const std::string& content_attr =
|
||||
get_attribute(xml_pb_type, "content", loc_data).as_string();
|
||||
get_attribute(xml_pb_type, XML_PB_TYPE_ATTRIBUTE_CONTENT, loc_data).as_string();
|
||||
|
||||
/* Parse the attributes for operating pb_type */
|
||||
openfpga::PbParser operating_pb_parser(name_attr);
|
||||
|
@ -45,13 +46,13 @@ static void read_xml_bitstream_pb_type_setting(
|
|||
|
||||
/* Parse if the bitstream overwritting is applied to mode bits of a pb_type */
|
||||
const bool& is_mode_select_bitstream =
|
||||
get_attribute(xml_pb_type, "is_mode_select_bitstream", loc_data,
|
||||
get_attribute(xml_pb_type, XML_PB_TYPE_ATTRIBUTE_IS_MODE_SELECT_BITSTREAM, loc_data,
|
||||
pugiutil::ReqOpt::OPTIONAL)
|
||||
.as_bool(false);
|
||||
bitstream_setting.set_mode_select_bitstream(bitstream_pb_type_id,
|
||||
is_mode_select_bitstream);
|
||||
|
||||
const int& offset = get_attribute(xml_pb_type, "bitstream_offset", loc_data,
|
||||
const int& offset = get_attribute(xml_pb_type, XML_PB_TYPE_ATTRIBUTE_BITSTREAM_OFFSET, loc_data,
|
||||
pugiutil::ReqOpt::OPTIONAL)
|
||||
.as_int(0);
|
||||
bitstream_setting.set_bitstream_offset(bitstream_pb_type_id, offset);
|
||||
|
@ -65,12 +66,12 @@ static void read_xml_bitstream_default_mode_setting(
|
|||
pugi::xml_node& xml_pb_type, const pugiutil::loc_data& loc_data,
|
||||
openfpga::BitstreamSetting& bitstream_setting) {
|
||||
const std::string& name_attr =
|
||||
get_attribute(xml_pb_type, "name", loc_data).as_string();
|
||||
get_attribute(xml_pb_type, XML_DEFAULT_MODE_BITS_ATTRIBUTE_NAME, loc_data).as_string();
|
||||
/* Parse the attributes for operating pb_type */
|
||||
openfpga::PbParser operating_pb_parser(name_attr);
|
||||
|
||||
const std::string& mode_bits_attr =
|
||||
get_attribute(xml_pb_type, "mode_bits", loc_data).as_string();
|
||||
get_attribute(xml_pb_type, XML_DEFAULT_MODE_BITS_ATTRIBUTE_MODE_BITS, loc_data).as_string();
|
||||
std::vector<size_t> mode_bits =
|
||||
parse_mode_bits(xml_pb_type, loc_data, mode_bits_attr);
|
||||
|
||||
|
@ -87,9 +88,9 @@ static void read_xml_bitstream_interconnect_setting(
|
|||
pugi::xml_node& xml_pb_type, const pugiutil::loc_data& loc_data,
|
||||
openfpga::BitstreamSetting& bitstream_setting) {
|
||||
const std::string& name_attr =
|
||||
get_attribute(xml_pb_type, "name", loc_data).as_string();
|
||||
get_attribute(xml_pb_type, XML_INTERCONNECT_ATTRIBUTE_NAME, loc_data).as_string();
|
||||
const std::string& default_path_attr =
|
||||
get_attribute(xml_pb_type, "default_path", loc_data).as_string();
|
||||
get_attribute(xml_pb_type, XML_INTERCONNECT_ATTRIBUTE_DEFAULT_PATH, loc_data).as_string();
|
||||
|
||||
/* Parse the attributes for operating pb_type */
|
||||
openfpga::PbParser operating_pb_parser(name_attr);
|
||||
|
@ -108,19 +109,19 @@ static void read_xml_non_fabric_bitstream_setting(
|
|||
pugi::xml_node& xml_non_fabric, const pugiutil::loc_data& loc_data,
|
||||
openfpga::BitstreamSetting& bitstream_setting) {
|
||||
const std::string& name_attr =
|
||||
get_attribute(xml_non_fabric, "name", loc_data).as_string();
|
||||
get_attribute(xml_non_fabric, XML_NON_FABRIC_ATTRIBUTE_NAME, loc_data).as_string();
|
||||
const std::string& file_attr =
|
||||
get_attribute(xml_non_fabric, "file", loc_data).as_string();
|
||||
get_attribute(xml_non_fabric, XML_NON_FABRIC_ATTRIBUTE_FILE, loc_data).as_string();
|
||||
/* Add to non-fabric */
|
||||
bitstream_setting.add_non_fabric(name_attr, file_attr);
|
||||
for (pugi::xml_node xml_child : xml_non_fabric.children()) {
|
||||
if (xml_child.name() != std::string("pb")) {
|
||||
bad_tag(xml_child, loc_data, xml_non_fabric, {"pb"});
|
||||
if (xml_child.name() != std::string(XML_NON_FABRIC_PB_NODE_NAME)) {
|
||||
bad_tag(xml_child, loc_data, xml_non_fabric, {XML_NON_FABRIC_PB_NODE_NAME});
|
||||
}
|
||||
const std::string& pb_name_attr =
|
||||
get_attribute(xml_child, "name", loc_data).as_string();
|
||||
get_attribute(xml_child, XML_NON_FABRIC_PB_ATTRIBUTE_NAME, loc_data).as_string();
|
||||
const std::string& content_attr =
|
||||
get_attribute(xml_child, "content", loc_data).as_string();
|
||||
get_attribute(xml_child, XML_NON_FABRIC_PB_ATTRIBUTE_CONTENT, loc_data).as_string();
|
||||
/* Add PB to non-fabric */
|
||||
bitstream_setting.add_non_fabric_pb(pb_name_attr, content_attr);
|
||||
}
|
||||
|
@ -134,13 +135,13 @@ static void read_xml_overwrite_bitstream_setting(
|
|||
openfpga::BitstreamSetting& bitstream_setting) {
|
||||
// Loopthrough bit
|
||||
for (pugi::xml_node xml_bit : xml_overwrite_bitstream.children()) {
|
||||
if (xml_bit.name() != std::string("bit")) {
|
||||
bad_tag(xml_bit, loc_data, xml_overwrite_bitstream, {"bit"});
|
||||
if (xml_bit.name() != std::string(XML_OVERWRITE_BITSTREAM_ATTRIBUTE_BIT)) {
|
||||
bad_tag(xml_bit, loc_data, xml_overwrite_bitstream, {XML_OVERWRITE_BITSTREAM_ATTRIBUTE_BIT});
|
||||
}
|
||||
const std::string& path_attr =
|
||||
get_attribute(xml_bit, "path", loc_data).as_string();
|
||||
get_attribute(xml_bit, XML_OVERWRITE_BITSTREAM_ATTRIBUTE_PATH, loc_data).as_string();
|
||||
const std::string& value_attr =
|
||||
get_attribute(xml_bit, "value", loc_data).as_string();
|
||||
get_attribute(xml_bit, XML_OVERWRITE_BITSTREAM_ATTRIBUTE_VALUE, loc_data).as_string();
|
||||
if (value_attr != "0" && value_attr != "1") {
|
||||
archfpga_throw(loc_data.filename_c_str(), loc_data.line(xml_bit),
|
||||
"Invalid value of overwrite_bitstream bit. Expect [0|1]");
|
||||
|
@ -161,33 +162,31 @@ openfpga::BitstreamSetting read_xml_bitstream_setting(
|
|||
* each child should be named after <pb_type>
|
||||
*/
|
||||
for (pugi::xml_node xml_child : Node.children()) {
|
||||
/* Error out if the XML child has an invalid name!
|
||||
* TODO: Use std::map or something similar to apply checks!
|
||||
*/
|
||||
if ((xml_child.name() != std::string("pb_type")) &&
|
||||
(xml_child.name() != std::string("default_mode_bits")) &&
|
||||
(xml_child.name() != std::string("interconnect")) &&
|
||||
(xml_child.name() != std::string("non_fabric")) &&
|
||||
(xml_child.name() != std::string("overwrite_bitstream"))) {
|
||||
bad_tag(xml_child, loc_data, Node,
|
||||
{"pb_type | interconnect | default_mode_bits | non_fabric | "
|
||||
"overwrite_bitstream"});
|
||||
bool valid_node = false;
|
||||
for (auto valid_node_name : XML_VALID_NODE_NAMES) {
|
||||
if (xml_child.name() == std::string(valid_node_name)) {
|
||||
valid_node = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!valid_node) {
|
||||
bad_tag(xml_child, loc_data, Node, XML_VALID_NODE_NAMES);
|
||||
}
|
||||
|
||||
if (xml_child.name() == std::string("pb_type")) {
|
||||
if (xml_child.name() == std::string(XML_PB_TYPE_NODE_NAME)) {
|
||||
read_xml_bitstream_pb_type_setting(xml_child, loc_data,
|
||||
bitstream_setting);
|
||||
} else if (xml_child.name() == std::string("default_mode_bits")) {
|
||||
} else if (xml_child.name() == std::string(XML_DEFAULT_MODE_BITS_NODE_NAME)) {
|
||||
read_xml_bitstream_default_mode_setting(xml_child, loc_data,
|
||||
bitstream_setting);
|
||||
} else if (xml_child.name() == std::string("interconnect")) {
|
||||
} else if (xml_child.name() == std::string(XML_INTERCONNECT_NODE_NAME)) {
|
||||
read_xml_bitstream_interconnect_setting(xml_child, loc_data,
|
||||
bitstream_setting);
|
||||
} else if (xml_child.name() == std::string("non_fabric")) {
|
||||
} else if (xml_child.name() == std::string(XML_NON_FABRIC_NODE_NAME)) {
|
||||
read_xml_non_fabric_bitstream_setting(xml_child, loc_data,
|
||||
bitstream_setting);
|
||||
} else {
|
||||
VTR_ASSERT_SAFE(xml_child.name() == std::string("overwrite_bitstream"));
|
||||
VTR_ASSERT_SAFE(xml_child.name() == std::string(XML_OVERWRITE_BITSTREAM_NODE_NAME));
|
||||
read_xml_overwrite_bitstream_setting(xml_child, loc_data,
|
||||
bitstream_setting);
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
/* Headers from readarchopenfpga library */
|
||||
#include "write_xml_bitstream_setting.h"
|
||||
#include "write_xml_utils.h"
|
||||
#include "bitstream_setting_xml_constants.h"
|
||||
|
||||
/********************************************************************
|
||||
* Generate the full hierarchy name for a pb_type in bitstream setting
|
||||
|
@ -128,27 +129,27 @@ static void write_xml_bitstream_pb_type_setting(
|
|||
openfpga::check_file_stream(fname, fp);
|
||||
|
||||
fp << "\t"
|
||||
<< "<pb_type";
|
||||
<< "<" << XML_PB_TYPE_NODE_NAME;
|
||||
|
||||
/* Generate the full hierarchy name of the pb_type */
|
||||
write_xml_attribute(fp, "name",
|
||||
write_xml_attribute(fp, XML_PB_TYPE_ATTRIBUTE_NAME,
|
||||
generate_bitstream_setting_pb_type_hierarchy_name(
|
||||
bitstream_setting, bitstream_pb_type_setting_id)
|
||||
.c_str());
|
||||
|
||||
write_xml_attribute(
|
||||
fp, "source",
|
||||
fp, XML_PB_TYPE_ATTRIBUTE_SOURCE,
|
||||
bitstream_setting.pb_type_bitstream_source(bitstream_pb_type_setting_id)
|
||||
.c_str());
|
||||
write_xml_attribute(
|
||||
fp, "content",
|
||||
fp, XML_PB_TYPE_ATTRIBUTE_CONTENT,
|
||||
bitstream_setting.pb_type_bitstream_content(bitstream_pb_type_setting_id)
|
||||
.c_str());
|
||||
write_xml_attribute(
|
||||
fp, "is_mode_select_bitstream",
|
||||
fp, XML_PB_TYPE_ATTRIBUTE_IS_MODE_SELECT_BITSTREAM,
|
||||
bitstream_setting.is_mode_select_bitstream(bitstream_pb_type_setting_id));
|
||||
write_xml_attribute(
|
||||
fp, "bitstream_offset",
|
||||
fp, XML_PB_TYPE_ATTRIBUTE_BITSTREAM_OFFSET,
|
||||
bitstream_setting.bitstream_offset(bitstream_pb_type_setting_id));
|
||||
|
||||
fp << "/>"
|
||||
|
@ -166,16 +167,16 @@ static void write_xml_bitstream_default_mode_setting(
|
|||
openfpga::check_file_stream(fname, fp);
|
||||
|
||||
fp << "\t"
|
||||
<< "<default_mode_bits";
|
||||
<< "<" << XML_DEFAULT_MODE_BITS_NODE_NAME;
|
||||
|
||||
/* Generate the full hierarchy name of the pb_type */
|
||||
write_xml_attribute(fp, "name",
|
||||
write_xml_attribute(fp, XML_DEFAULT_MODE_BITS_ATTRIBUTE_NAME,
|
||||
generate_bitstream_setting_pb_type_hierarchy_name(
|
||||
bitstream_setting, bitstream_default_mode_setting_id)
|
||||
.c_str());
|
||||
|
||||
write_xml_attribute(
|
||||
fp, "mode_bits",
|
||||
fp, XML_DEFAULT_MODE_BITS_ATTRIBUTE_MODE_BITS,
|
||||
bitstream_setting
|
||||
.default_mode_bits_to_string(bitstream_default_mode_setting_id)
|
||||
.c_str());
|
||||
|
@ -194,16 +195,16 @@ static void write_xml_bitstream_interconnect_setting(
|
|||
openfpga::check_file_stream(fname, fp);
|
||||
|
||||
fp << "\t"
|
||||
<< "<pb_type";
|
||||
<< "<" << XML_INTERCONNECT_NODE_NAME;
|
||||
|
||||
/* Generate the full hierarchy name of the pb_type */
|
||||
write_xml_attribute(fp, "name",
|
||||
write_xml_attribute(fp, XML_INTERCONNECT_ATTRIBUTE_NAME,
|
||||
generate_bitstream_setting_interconnect_hierarchy_name(
|
||||
bitstream_setting, bitstream_interc_setting_id)
|
||||
.c_str());
|
||||
|
||||
write_xml_attribute(
|
||||
fp, "default_path",
|
||||
fp, XML_INTERCONNECT_ATTRIBUTE_DEFAULT_PATH,
|
||||
bitstream_setting.default_path(bitstream_interc_setting_id).c_str());
|
||||
|
||||
fp << "/>"
|
||||
|
@ -221,7 +222,7 @@ void write_xml_bitstream_setting(
|
|||
|
||||
/* Write the root node <openfpga_bitstream_setting>
|
||||
*/
|
||||
fp << "<openfpga_bitstream_setting>"
|
||||
fp << "<" << XML_BITSTREAM_SETTING_ROOT_NAME << ">"
|
||||
<< "\n";
|
||||
|
||||
/* Write pb_type -related settings */
|
||||
|
@ -246,6 +247,6 @@ void write_xml_bitstream_setting(
|
|||
}
|
||||
|
||||
/* Write the root node <openfpga_bitstream_setting> */
|
||||
fp << "</openfpga_bitstream_setting>"
|
||||
fp << "</" << XML_BITSTREAM_SETTING_ROOT_NAME << ">"
|
||||
<< "\n";
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue