Skip to content

Commit 52be5fd

Browse files
committed
Clock Modeling: Added expect_only_children() and expect_only_attributes() to ensure we reject invalid/unrecognized tags or attributes
1 parent c58e5e8 commit 52be5fd

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

libs/libarchfpga/src/read_xml_arch_file.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3327,12 +3327,16 @@ static void ProcessClockMetalLayers(
33273327
std::unordered_map<std::string, t_metal_layer>& metal_layers,
33283328
pugiutil::loc_data& loc_data)
33293329
{
3330+
std::vector<std::string> expected_attributes = {"name", "Rmetal", "Cmetal"};
3331+
33303332
pugi::xml_node metal_layers_parent = get_single_child(parent, "metal_layers", loc_data);
33313333
int num_metal_layers = count_children(metal_layers_parent, "metal_layer", loc_data);
33323334

33333335
pugi::xml_node curr_layer = get_first_child(metal_layers_parent, "metal_layer", loc_data);
33343336
for(int i = 0; i < num_metal_layers; i++) {
33353337

3338+
expect_only_attributes(curr_layer, expected_attributes, loc_data);
3339+
33363340
// Get metal layer values: name, r_metal, and c_metal
33373341
std::string name (get_attribute(curr_layer, "name", loc_data).value());
33383342
t_metal_layer metal_layer;
@@ -3359,6 +3363,11 @@ static void ProcessClockNetworks(
33593363
const int num_switches,
33603364
pugiutil::loc_data& loc_data)
33613365
{
3366+
std::vector<std::string> expected_spine_attributes =
3367+
{"name", "num_inst", "metal_layer", "starty", "endy", "x", "repeatx", "repeaty"};
3368+
std::vector<std::string> expected_rib_attributes =
3369+
{"name", "num_inst", "metal_layer", "startx", "endx", "y", "repeatx", "repeaty"};
3370+
33623371
int num_clock_networks = count_children(parent, "clock_network", loc_data);
33633372
pugi::xml_node curr_network = get_first_child(parent, "clock_network", loc_data);
33643373
for(int i = 0; i < num_clock_networks; i++) {
@@ -3373,6 +3382,9 @@ static void ProcessClockNetworks(
33733382
// Parse spine
33743383
curr_type = get_single_child(curr_network, "spine", loc_data, OPTIONAL);
33753384
if(curr_type) {
3385+
3386+
expect_only_attributes(curr_network, expected_spine_attributes, loc_data);
3387+
33763388
is_supported_clock_type = true;
33773389
clock_network.type = e_clock_type::SPINE;
33783390

@@ -3396,6 +3408,9 @@ static void ProcessClockNetworks(
33963408
// Parse rib
33973409
curr_type = get_single_child(curr_network, "rib", loc_data, OPTIONAL);
33983410
if(curr_type) {
3411+
3412+
expect_only_attributes(curr_network, expected_spine_attributes, loc_data);
3413+
33993414
is_supported_clock_type = true;
34003415
clock_network.type = e_clock_type::RIB;
34013416

@@ -3436,6 +3451,15 @@ static void ProcessClockSwitchPoints(
34363451
const int num_switches,
34373452
pugiutil::loc_data& loc_data)
34383453
{
3454+
std::vector<std::string> expected_spine_drive_attributes =
3455+
{"name", "type", "yoffset", "switch_name"};
3456+
std::vector<std::string> expected_rib_drive_attributes =
3457+
{"name", "type", "xoffset", "switch_name"};
3458+
std::vector<std::string> expected_spine_tap_attributes =
3459+
{"name", "type", "yoffset", "yincr"};
3460+
std::vector<std::string> expected_rib_tap_attributes =
3461+
{"name", "type", "xoffset", "xincr"};
3462+
34393463
int num_clock_switches = count_children(parent, "switch_point", loc_data);
34403464
pugi::xml_node curr_switch = get_first_child(parent, "switch_point", loc_data);
34413465

@@ -3452,9 +3476,11 @@ static void ProcessClockSwitchPoints(
34523476
std::string name (get_attribute(curr_switch, "name", loc_data).value());
34533477
const char* offset;
34543478
if (clock_network.type == e_clock_type::SPINE) {
3479+
expect_only_attributes(curr_switch, expected_spine_drive_attributes, loc_data);
34553480
offset = get_attribute(curr_switch, "yoffset", loc_data).value();
34563481
} else {
34573482
VTR_ASSERT(clock_network.type == e_clock_type::RIB);
3483+
expect_only_attributes(curr_switch, expected_rib_drive_attributes, loc_data);
34583484
offset = get_attribute(curr_switch, "xoffset", loc_data).value();
34593485
}
34603486

@@ -3483,10 +3509,12 @@ static void ProcessClockSwitchPoints(
34833509
const char* offset;
34843510
const char* increment;
34853511
if (clock_network.type == e_clock_type::SPINE) {
3512+
expect_only_attributes(curr_switch, expected_spine_tap_attributes, loc_data);
34863513
offset = get_attribute(curr_switch, "yoffset", loc_data).value();
34873514
increment = get_attribute(curr_switch, "yincr", loc_data).value();
34883515
} else {
34893516
VTR_ASSERT(clock_network.type == e_clock_type::RIB);
3517+
expect_only_attributes(curr_switch, expected_rib_tap_attributes, loc_data);
34903518
offset = get_attribute(curr_switch, "xoffset", loc_data).value();
34913519
increment = get_attribute(curr_switch, "xincr", loc_data).value();
34923520
}
@@ -3514,12 +3542,18 @@ static void ProcessClockRouting(
35143542
const int num_switches,
35153543
pugiutil::loc_data& loc_data)
35163544
{
3545+
std::vector<std::string> expected_attributes =
3546+
{"from", "to", "switch", "fc_val", "locationx", "locationy"};
3547+
35173548
pugi::xml_node clock_routing_parent = get_single_child(parent, "clock_routing", loc_data);
35183549
int num_routing_connections = count_children(clock_routing_parent, "tap", loc_data);
35193550

35203551
pugi::xml_node curr_connection =
35213552
get_first_child(clock_routing_parent, "tap", loc_data);
35223553
for(int i = 0; i < num_routing_connections; i++) {
3554+
3555+
expect_only_attributes(curr_connection, expected_attributes, loc_data);
3556+
35233557
t_clock_connection_arch clock_connection;
35243558

35253559
const char* from = get_attribute(curr_connection, "from", loc_data).value();

0 commit comments

Comments
 (0)