Skip to content

Commit

Permalink
[core] code format
Browse files Browse the repository at this point in the history
  • Loading branch information
tangxifan committed Nov 27, 2024
1 parent 637dd08 commit 7108524
Show file tree
Hide file tree
Showing 13 changed files with 148 additions and 96 deletions.
15 changes: 7 additions & 8 deletions libs/libarchopenfpga/src/bitstream_setting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ BitstreamSetting::clock_routing_settings() const {
clock_routing_setting_ids_.end());
}


BitstreamSetting::bitstream_interconnect_setting_range
BitstreamSetting::interconnect_settings() const {
return vtr::make_range(interconnect_setting_ids_.begin(),
Expand Down Expand Up @@ -135,15 +134,15 @@ std::string BitstreamSetting::default_mode_bits_to_string(

std::string BitstreamSetting::clock_routing_network(
const BitstreamClockRoutingSettingId& clock_routing_setting_id) const {
VTR_ASSERT(true ==
valid_bitstream_clock_routing_setting_id(clock_routing_setting_id));
VTR_ASSERT(
true == valid_bitstream_clock_routing_setting_id(clock_routing_setting_id));
return clock_routing_network_names_[clock_routing_setting_id];
}

BasicPort BitstreamSetting::clock_routing_pin(
const BitstreamClockRoutingSettingId& clock_routing_setting_id) const {
VTR_ASSERT(true ==
valid_bitstream_clock_routing_setting_id(clock_routing_setting_id));
VTR_ASSERT(
true == valid_bitstream_clock_routing_setting_id(clock_routing_setting_id));
return clock_routing_pins_[clock_routing_setting_id];
}

Expand Down Expand Up @@ -245,8 +244,7 @@ BitstreamSetting::add_bitstream_default_mode_setting(

BitstreamClockRoutingSettingId
BitstreamSetting::add_bitstream_clock_routing_setting(
const std::string& ntwk_name,
const BasicPort& pin) {
const std::string& ntwk_name, const BasicPort& pin) {
BitstreamClockRoutingSettingId clock_routing_setting_id =
BitstreamClockRoutingSettingId(clock_routing_setting_ids_.size());
clock_routing_setting_ids_.push_back(clock_routing_setting_id);
Expand Down Expand Up @@ -326,7 +324,8 @@ bool BitstreamSetting::valid_bitstream_default_mode_setting_id(

bool BitstreamSetting::valid_bitstream_clock_routing_setting_id(
const BitstreamClockRoutingSettingId& clock_routing_setting_id) const {
return (size_t(clock_routing_setting_id) < clock_routing_setting_ids_.size()) &&
return (size_t(clock_routing_setting_id) <
clock_routing_setting_ids_.size()) &&
(clock_routing_setting_id ==
clock_routing_setting_ids_[clock_routing_setting_id]);
}
Expand Down
8 changes: 3 additions & 5 deletions libs/libarchopenfpga/src/bitstream_setting.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
#include <vector>

#include "bitstream_setting_fwd.h"
#include "openfpga_port.h"
#include "vtr_geometry.h"
#include "vtr_vector.h"
#include "openfpga_port.h"

/* namespace openfpga begins */
namespace openfpga {
Expand Down Expand Up @@ -167,8 +167,7 @@ class BitstreamSetting {

/* Clock routing settings */
BitstreamClockRoutingSettingId add_bitstream_clock_routing_setting(
const std::string& ntwk_name,
const BasicPort& pin);
const std::string& ntwk_name, const BasicPort& pin);

/* Interconnect settings */
BitstreamInterconnectSettingId add_bitstream_interconnect_setting(
Expand Down Expand Up @@ -234,8 +233,7 @@ class BitstreamSetting {
clock_routing_setting_ids_;
vtr::vector<BitstreamClockRoutingSettingId, std::string>
clock_routing_network_names_;
vtr::vector<BitstreamClockRoutingSettingId, BasicPort>
clock_routing_pins_;
vtr::vector<BitstreamClockRoutingSettingId, BasicPort> clock_routing_pins_;

/* Interconnect-related settings:
* - Name of interconnect under a given pb_type
Expand Down
14 changes: 10 additions & 4 deletions libs/libarchopenfpga/src/bitstream_setting_xml_constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@

/* Constants required by XML parser */

constexpr const char* XML_BITSTREAM_SETTING_ROOT_NAME = "openfpga_bitstream_setting";
constexpr const char* XML_BITSTREAM_SETTING_ROOT_NAME =
"openfpga_bitstream_setting";
/* Pb-type XML syntax */
constexpr const char* XML_PB_TYPE_NODE_NAME = "pb_type";
constexpr const char* XML_PB_TYPE_ATTRIBUTE_NAME = "name";
constexpr const char* XML_PB_TYPE_ATTRIBUTE_SOURCE = "source";
constexpr const char* XML_PB_TYPE_ATTRIBUTE_CONTENT = "content";
constexpr const char* XML_PB_TYPE_ATTRIBUTE_IS_MODE_SELECT_BITSTREAM = "is_mode_select_bitstream";
constexpr const char* XML_PB_TYPE_ATTRIBUTE_BITSTREAM_OFFSET = "bitstream_offset";
constexpr const char* XML_PB_TYPE_ATTRIBUTE_IS_MODE_SELECT_BITSTREAM =
"is_mode_select_bitstream";
constexpr const char* XML_PB_TYPE_ATTRIBUTE_BITSTREAM_OFFSET =
"bitstream_offset";

/* Default mode bits XML syntax */
constexpr const char* XML_DEFAULT_MODE_BITS_NODE_NAME = "default_mode_bits";
Expand Down Expand Up @@ -42,6 +45,9 @@ constexpr const char* XML_OVERWRITE_BITSTREAM_ATTRIBUTE_PATH = "path";
constexpr const char* XML_OVERWRITE_BITSTREAM_ATTRIBUTE_VALUE = "value";

/* Sanity check constants */
constexpr const char* XML_VALID_NODE_NAMES[] = {XML_BITSTREAM_SETTING_ROOT_NAME, XML_DEFAULT_MODE_BITS_NODE_NAME, XML_INTERCONNECT_NODE_NAME, XML_CLOCK_ROUTING_NODE_NAME, XML_NON_FABRIC_NODE_NAME, XML_OVERWRITE_BITSTREAM_NODE_NAME};
constexpr const char* XML_VALID_NODE_NAMES[] = {
XML_BITSTREAM_SETTING_ROOT_NAME, XML_DEFAULT_MODE_BITS_NODE_NAME,
XML_INTERCONNECT_NODE_NAME, XML_CLOCK_ROUTING_NODE_NAME,
XML_NON_FABRIC_NODE_NAME, XML_OVERWRITE_BITSTREAM_NODE_NAME};

#endif
89 changes: 58 additions & 31 deletions libs/libarchopenfpga/src/read_xml_bitstream_setting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@

/* Headers from libarchfpga */
#include "arch_error.h"
#include "bitstream_setting_xml_constants.h"
#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
Expand All @@ -30,11 +30,14 @@ 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, XML_PB_TYPE_ATTRIBUTE_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, XML_PB_TYPE_ATTRIBUTE_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, XML_PB_TYPE_ATTRIBUTE_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);
Expand All @@ -47,15 +50,16 @@ 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, XML_PB_TYPE_ATTRIBUTE_IS_MODE_SELECT_BITSTREAM, loc_data,
pugiutil::ReqOpt::OPTIONAL)
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, XML_PB_TYPE_ATTRIBUTE_BITSTREAM_OFFSET, loc_data,
pugiutil::ReqOpt::OPTIONAL)
.as_int(0);
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);
}

Expand All @@ -67,12 +71,15 @@ 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, XML_DEFAULT_MODE_BITS_ATTRIBUTE_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, XML_DEFAULT_MODE_BITS_ATTRIBUTE_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);

Expand All @@ -90,21 +97,28 @@ static void read_xml_bitstream_clock_routing_setting(
pugi::xml_node& xml_clk_routing, const pugiutil::loc_data& loc_data,
openfpga::BitstreamSetting& bitstream_setting) {
const std::string& ntwk_attr =
get_attribute(xml_clk_routing, XML_CLOCK_ROUTING_ATTRIBUTE_NETWORK, loc_data).as_string();
get_attribute(xml_clk_routing, XML_CLOCK_ROUTING_ATTRIBUTE_NETWORK,
loc_data)
.as_string();

const std::string& pin_attr =
get_attribute(xml_clk_routing, XML_CLOCK_ROUTING_ATTRIBUTE_PIN, loc_data).as_string();
get_attribute(xml_clk_routing, XML_CLOCK_ROUTING_ATTRIBUTE_PIN, loc_data)
.as_string();
/* Parse the port and apply sanity checks */
openfpga::PortParser port_parser(pin_attr);
openfpga::BasicPort pin = port_parser.port();
if (!pin.is_valid()) {
archfpga_throw(loc_data.filename_c_str(), loc_data.line(xml_clk_routing),
"Invalid pin '%s' which should be valid port. For example, clk[1:1]\n", pin_attr.c_str());
archfpga_throw(
loc_data.filename_c_str(), loc_data.line(xml_clk_routing),
"Invalid pin '%s' which should be valid port. For example, clk[1:1]\n",
pin_attr.c_str());
}
if (1 != pin.get_width()) {
archfpga_throw(loc_data.filename_c_str(), loc_data.line(xml_clk_routing),
"Invalid pin '%s' with a width of '%lu'. Only allow pin definition with width of 1. For example, clk[2:2]\n", pin_attr.c_str(), pin.get_width());
}
"Invalid pin '%s' with a width of '%lu'. Only allow pin "
"definition with width of 1. For example, clk[2:2]\n",
pin_attr.c_str(), pin.get_width());
}

/* Add to bitstream setting */
bitstream_setting.add_bitstream_clock_routing_setting(ntwk_attr, pin);
Expand All @@ -117,9 +131,12 @@ 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, XML_INTERCONNECT_ATTRIBUTE_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, XML_INTERCONNECT_ATTRIBUTE_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);
Expand All @@ -138,19 +155,24 @@ 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, XML_NON_FABRIC_ATTRIBUTE_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, XML_NON_FABRIC_ATTRIBUTE_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(XML_NON_FABRIC_PB_NODE_NAME)) {
bad_tag(xml_child, loc_data, xml_non_fabric, {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, XML_NON_FABRIC_PB_ATTRIBUTE_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, XML_NON_FABRIC_PB_ATTRIBUTE_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);
}
Expand All @@ -165,12 +187,15 @@ static void read_xml_overwrite_bitstream_setting(
// Loopthrough bit
for (pugi::xml_node xml_bit : xml_overwrite_bitstream.children()) {
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});
bad_tag(xml_bit, loc_data, xml_overwrite_bitstream,
{XML_OVERWRITE_BITSTREAM_ATTRIBUTE_BIT});
}
const std::string& path_attr =
get_attribute(xml_bit, XML_OVERWRITE_BITSTREAM_ATTRIBUTE_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, XML_OVERWRITE_BITSTREAM_ATTRIBUTE_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]");
Expand All @@ -191,7 +216,7 @@ openfpga::BitstreamSetting read_xml_bitstream_setting(
* each child should be named after <pb_type>
*/
for (pugi::xml_node xml_child : Node.children()) {
bool valid_node = false;
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;
Expand All @@ -209,20 +234,22 @@ openfpga::BitstreamSetting read_xml_bitstream_setting(
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(XML_DEFAULT_MODE_BITS_NODE_NAME)) {
} 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(XML_CLOCK_ROUTING_NODE_NAME)) {
read_xml_bitstream_clock_routing_setting(xml_child, loc_data,
bitstream_setting);
bitstream_setting);
} 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(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(XML_OVERWRITE_BITSTREAM_NODE_NAME));
VTR_ASSERT_SAFE(xml_child.name() ==
std::string(XML_OVERWRITE_BITSTREAM_NODE_NAME));
read_xml_overwrite_bitstream_setting(xml_child, loc_data,
bitstream_setting);
}
Expand Down
17 changes: 9 additions & 8 deletions libs/libarchopenfpga/src/write_xml_bitstream_setting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
#include "vtr_log.h"

/* Headers from readarchopenfpga library */
#include "bitstream_setting_xml_constants.h"
#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
Expand Down Expand Up @@ -198,14 +198,15 @@ static void write_xml_bitstream_clock_routing_setting(
<< "<" << XML_CLOCK_ROUTING_NODE_NAME;

/* Generate the full hierarchy name of the pb_type */
write_xml_attribute(fp, XML_CLOCK_ROUTING_ATTRIBUTE_NETWORK,
bitstream_setting.clock_routing_network(bitstream_clock_routing_setting_id)
.c_str());
write_xml_attribute(
fp, XML_CLOCK_ROUTING_ATTRIBUTE_NETWORK,
bitstream_setting.clock_routing_network(bitstream_clock_routing_setting_id)
.c_str());

write_xml_attribute(
fp, XML_CLOCK_ROUTING_ATTRIBUTE_PIN,
bitstream_setting
.clock_routing_pin(bitstream_clock_routing_setting_id).to_verilog_string()
bitstream_setting.clock_routing_pin(bitstream_clock_routing_setting_id)
.to_verilog_string()
.c_str());
fp << "/>"
<< "\n";
Expand Down Expand Up @@ -269,8 +270,8 @@ void write_xml_bitstream_setting(
/* Write clock_routing -related settings */
for (const auto& bitstream_clock_routing_setting_id :
bitstream_setting.clock_routing_settings()) {
write_xml_bitstream_clock_routing_setting(fp, fname, bitstream_setting,
bitstream_clock_routing_setting_id);
write_xml_bitstream_clock_routing_setting(
fp, fname, bitstream_setting, bitstream_clock_routing_setting_id);
}

/* Write interconnect -related settings */
Expand Down
2 changes: 1 addition & 1 deletion libs/libopenfpgacapnproto/gen/unique_blocks_uxsdcxx.capnp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# Input file: /home/xifan/github/OpenFPGA/libs/libopenfpgacapnproto/gen/unique_blocks.xsd
# md5sum of input file: 1db9d740309076fa51f61413bae1e072

@0x9cb54e2c8c367c87;
@0xc5bb4dab7879b418;
using Cxx = import "/capnp/c++.capnp";
$Cxx.namespace("ucap");

Expand Down
Loading

0 comments on commit 7108524

Please sign in to comment.