Skip to content

Commit 4e96b4b

Browse files
committed
[lib][rr_graph] check schema id if capnp is enabled
1 parent a413b42 commit 4e96b4b

File tree

3 files changed

+19
-11
lines changed

3 files changed

+19
-11
lines changed

libs/librrgraph/src/io/rr_graph_reader.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
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>
1816
#include "rr_graph_reader.h"
1917

2018
#include "rr_graph_uxsdcxx_serializer.h"
@@ -28,6 +26,7 @@
2826
#include "pugixml_util.hpp"
2927

3028
#ifdef VTR_ENABLE_CAPNPROTO
29+
# include <capnp/schema.h>
3130
# include "rr_graph_uxsdcxx_capnp.h"
3231
# include "mmap_file.h"
3332
#endif
@@ -87,9 +86,12 @@ void load_rr_file(RRGraphBuilder* rr_graph_builder,
8786
rr_graph_builder->set_tileable(true);
8887
}
8988

89+
unsigned long schema_file_id = 0;
90+
#ifdef VTR_ENABLE_CAPNPROTO
9091
::capnp::Schema schema = ::capnp::Schema::from<ucap::RrGraph>();
91-
unsigned long schema_file_id = schema.getProto().getScopeId();
92+
schema_file_id = schema.getProto().getScopeId();
9293
VTR_LOG("Schema file ID: 0x%016lx\n", schema_file_id);
94+
#endif
9395

9496
RrGraphSerializer reader(
9597
graph_type,

libs/librrgraph/src/io/rr_graph_uxsdcxx_serializer.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1730,10 +1730,14 @@ class RrGraphSerializer final : public uxsd::RrGraphBase<RrGraphContextTypes> {
17301730
* </xs:complexType>
17311731
*/
17321732
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);
1733+
// Only check if the schema file ID is not 0. If it is 0, it means capnproto is not enabled.
1734+
// Thus, we cannot check the schema file ID mismatch.
1735+
if (schema_file_id_ != 0) {
1736+
if (schema_file_id != schema_file_id_) {
1737+
report_error(
1738+
"Schema file ID mismatch: Expected ID 0x%016lx, but got ID 0x%016lx",
1739+
schema_file_id_, schema_file_id);
1740+
}
17371741
}
17381742
}
17391743
inline void set_rr_graph_tool_comment(const char* tool_comment, void*& /*ctx*/) final {

libs/librrgraph/src/io/rr_graph_writer.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,15 @@
55
* children tags such as timing, location, or some general
66
* details. Each tag has attributes to describe them */
77

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

1210
#include <cstdio>
1311
#include <fstream>
1412
#include <limits>
1513
#include "rr_graph_uxsdcxx_serializer.h"
1614
#include "rr_graph_uxsdcxx.h"
1715
#ifdef VTR_ENABLE_CAPNPROTO
16+
# include <capnp/schema.h>
1817
# include "serdes_utils.h"
1918
# include "rr_graph_uxsdcxx_capnp.h"
2019
#endif
@@ -41,9 +40,12 @@ void write_rr_graph(RRGraphBuilder* rr_graph_builder,
4140
const char* echo_file_name,
4241
bool is_flat) {
4342

43+
unsigned long schema_file_id = 0;
44+
#ifdef VTR_ENABLE_CAPNPROTO
4445
::capnp::Schema schema = ::capnp::Schema::from<ucap::RrGraph>();
45-
unsigned long schema_file_id = schema.getProto().getScopeId();
46+
schema_file_id = schema.getProto().getScopeId();
4647
VTR_LOG("Schema file ID: 0x%016lx\n", schema_file_id);
48+
#endif
4749

4850
RrGraphSerializer reader(
4951
/*graph_type=*/e_graph_type(),

0 commit comments

Comments
 (0)