Skip to content

Commit aa358f8

Browse files
committed
[lib][rr_graph] update API calls for rr graph io
1 parent 5a8e572 commit aa358f8

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

libs/librrgraph/src/io/rr_graph_reader.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
* are overwritten by the rr graph file if one is specified. If an optional
1414
* identifier such as capacitance is not specified, it is set to 0 */
1515

16+
17+
#include <capnp/schema.h>
1618
#include "rr_graph_reader.h"
1719

1820
#include "rr_graph_uxsdcxx_serializer.h"
@@ -85,6 +87,10 @@ void load_rr_file(RRGraphBuilder* rr_graph_builder,
8587
rr_graph_builder->set_tileable(true);
8688
}
8789

90+
::capnp::Schema schema = ::capnp::Schema::from<ucap::RrGraph>();
91+
unsigned long schema_file_id = schema.getProto().getScopeId();
92+
VTR_LOG("Schema file ID: 0x%016lx\n", schema_file_id);
93+
8894
RrGraphSerializer reader(
8995
graph_type,
9096
base_cost_type,
@@ -108,6 +114,7 @@ void load_rr_file(RRGraphBuilder* rr_graph_builder,
108114
&rr_graph_builder->rr_node_metadata(),
109115
&rr_graph_builder->rr_edge_metadata(),
110116
&arch->strings,
117+
schema_file_id,
111118
is_flat);
112119

113120
if (vtr::check_file_name_extension(read_rr_graph_name, ".xml")) {

libs/librrgraph/src/io/rr_graph_uxsdcxx_serializer.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,7 @@ class RrGraphSerializer final : public uxsd::RrGraphBase<RrGraphContextTypes> {
294294
MetadataStorage<int>* rr_node_metadata,
295295
MetadataStorage<std::tuple<int, int, short>>* rr_edge_metadata,
296296
vtr::string_internment* strings,
297+
unsigned long schema_file_id,
297298
bool is_flat)
298299
: chan_width_(chan_width)
299300
, rr_nodes_(rr_nodes)
@@ -319,6 +320,7 @@ class RrGraphSerializer final : public uxsd::RrGraphBase<RrGraphContextTypes> {
319320
, strings_(strings)
320321
, empty_(strings_->intern_string(""))
321322
, report_error_(nullptr)
323+
, schema_file_id_(schema_file_id)
322324
, is_flat_(is_flat) {
323325
// Initialize internal data
324326
init_side_map();
@@ -1727,6 +1729,13 @@ class RrGraphSerializer final : public uxsd::RrGraphBase<RrGraphContextTypes> {
17271729
* <xs:attribute name="tool_comment" type="xs:string" />
17281730
* </xs:complexType>
17291731
*/
1732+
inline void set_rr_graph_schema_file_id(unsigned long schema_file_id, void*& /*ctx*/) final {
1733+
if (schema_file_id != schema_file_id_) {
1734+
report_error(
1735+
"Schema file ID mismatch: Expected ID 0x%016lx, but got ID 0x%016lx",
1736+
schema_file_id_, schema_file_id);
1737+
}
1738+
}
17301739
inline void set_rr_graph_tool_comment(const char* tool_comment, void*& /*ctx*/) final {
17311740
std::string correct_string = "Generated from arch file ";
17321741
correct_string += get_arch_file_name();
@@ -1748,6 +1757,10 @@ class RrGraphSerializer final : public uxsd::RrGraphBase<RrGraphContextTypes> {
17481757
}
17491758
}
17501759

1760+
inline unsigned long get_rr_graph_schema_file_id(void*& /*ctx*/) final {
1761+
return schema_file_id_;
1762+
}
1763+
17511764
inline const char* get_rr_graph_tool_comment(void*& /*ctx*/) final {
17521765
temp_string_.assign("Generated from arch file ");
17531766
temp_string_ += get_arch_file_name();
@@ -2181,6 +2194,7 @@ class RrGraphSerializer final : public uxsd::RrGraphBase<RrGraphContextTypes> {
21812194
vtr::string_internment* strings_;
21822195
vtr::interned_string empty_;
21832196
const std::function<void(const char*)>* report_error_;
2197+
unsigned long schema_file_id_;
21842198
bool is_flat_;
21852199

21862200
// Temporary data to check grid block types

libs/librrgraph/src/io/rr_graph_writer.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
* children tags such as timing, location, or some general
66
* details. Each tag has attributes to describe them */
77

8-
#include "rr_graph_writer.h"
8+
9+
#include <capnp/schema.h>
10+
#include "rr_graph_writer.h"
911

1012
#include <cstdio>
1113
#include <fstream>
@@ -39,6 +41,10 @@ void write_rr_graph(RRGraphBuilder* rr_graph_builder,
3941
const char* echo_file_name,
4042
bool is_flat) {
4143

44+
::capnp::Schema schema = ::capnp::Schema::from<ucap::RrGraph>();
45+
unsigned long schema_file_id = schema.getProto().getScopeId();
46+
VTR_LOG("Schema file ID: 0x%016lx\n", schema_file_id);
47+
4248
RrGraphSerializer reader(
4349
/*graph_type=*/e_graph_type(),
4450
/*base_cost_type=*/e_base_cost_type(),
@@ -62,6 +68,7 @@ void write_rr_graph(RRGraphBuilder* rr_graph_builder,
6268
&rr_graph_builder->rr_node_metadata(),
6369
&rr_graph_builder->rr_edge_metadata(),
6470
&arch->strings,
71+
schema_file_id,
6572
is_flat);
6673

6774
if (vtr::check_file_name_extension(file_name, ".xml")) {

0 commit comments

Comments
 (0)