Skip to content

Commit 286b8f9

Browse files
authored
slang-reflect: add namespace to std and SystemC types (#1559)
1 parent 8ab1438 commit 286b8f9

File tree

4 files changed

+24
-22
lines changed

4 files changed

+24
-22
lines changed

tools/reflect/src/SvEnum.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88
void SvEnum::toCpp(HppFile& hppFile, std::string_view, const SvAliases&, bool) const {
99
auto underlyingType = [&] {
1010
if (type.getBitstreamWidth() <= 8)
11-
return "uint8_t"sv;
11+
return "std::uint8_t"sv;
1212
if (type.getBitstreamWidth() <= 16)
13-
return "uint16_t"sv;
13+
return "std::uint16_t"sv;
1414
if (type.getBitstreamWidth() <= 32)
15-
return "uint32_t"sv;
15+
return "std::uint32_t"sv;
1616
if (type.getBitstreamWidth() <= 64)
17-
return "uint64_t"sv;
17+
return "std::uint64_t"sv;
1818
SLANG_THROW(
1919
std::runtime_error("Enum with $bits size bigger than 64 bits are not supported"));
2020
};
@@ -47,7 +47,7 @@ void SvEnum::toCpp(HppFile& hppFile, std::string_view, const SvAliases&, bool) c
4747

4848
//** SIZE **/
4949
hppFile.addWithIndent(
50-
fmt::format("static constexpr size_t _size = {};\n\n", type.getBitstreamWidth()));
50+
fmt::format("static constexpr std::size_t _size = {};\n\n", type.getBitstreamWidth()));
5151

5252
//** LOCAL **//
5353
hppFile.addWithIndent("Type type;\n");
@@ -93,9 +93,9 @@ void SvEnum::toCpp(HppFile& hppFile, std::string_view, const SvAliases&, bool) c
9393
hppFile.addWithIndent("}\n\n");
9494

9595
//** OVERLOAD UINT64_T OPERATOR **//
96-
hppFile.addWithIndent(fmt::format("operator uint64_t() const {{\n"));
96+
hppFile.addWithIndent(fmt::format("operator std::uint64_t() const {{\n"));
9797
hppFile.increaseIndent();
98-
hppFile.addWithIndent(fmt::format("return static_cast<uint64_t>(type);\n", type.name));
98+
hppFile.addWithIndent(fmt::format("return static_cast<std::uint64_t>(type);\n", type.name));
9999
hppFile.decreaseIndent();
100100
hppFile.addWithIndent("}\n\n");
101101

tools/reflect/src/SvStruct.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,13 @@ void SvStruct::toCpp(HppFile& hppFile, const std::string_view _namespace, const
5959
//** GENERATE START AND WIDTH OF EACH SIGNAL **//
6060
size_t startBit = 0;
6161
for (const auto& [name, type] : members) {
62-
hppFile.addWithIndent(fmt::format("static constexpr size_t {}_s = {};\n", name, startBit));
63-
hppFile.addWithIndent(fmt::format("static constexpr size_t {}_w = {};\n", name, type.size));
62+
hppFile.addWithIndent(
63+
fmt::format("static constexpr std::size_t {}_s = {};\n", name, startBit));
64+
hppFile.addWithIndent(
65+
fmt::format("static constexpr std::size_t {}_w = {};\n", name, type.size));
6466
startBit += type.size;
6567
}
66-
hppFile.addWithIndent(fmt::format("static constexpr size_t _size = {};\n", structSize));
68+
hppFile.addWithIndent(fmt::format("static constexpr std::size_t _size = {};\n", structSize));
6769
hppFile.add("\n");
6870

6971
//** GENERATE DEFAULT CONSTRUCTOR **//
@@ -120,8 +122,8 @@ void SvStruct::toCpp(HppFile& hppFile, const std::string_view _namespace, const
120122
// Note: This constructor will be generated only if the other constructor is not already from a
121123
// sc_bv
122124
if (!noSystemC && structSize <= 64) {
123-
hppFile.addWithIndent(
124-
fmt::format("{}(const sc_bv<{}>& __data) {{\n", structName, type.getBitstreamWidth()));
125+
hppFile.addWithIndent(fmt::format("{}(const sc_dt::sc_bv<{}>& __data) {{\n", structName,
126+
type.getBitstreamWidth()));
125127

126128
hppFile.increaseIndent();
127129

@@ -159,7 +161,7 @@ void SvStruct::toCpp(HppFile& hppFile, const std::string_view _namespace, const
159161
else {
160162
hppFile.addWithIndent(fmt::format("ret.range({0}_s + {0}_w - 1, {0}_s) = ", name));
161163
if (type.isStructEnumOrUnion() && type.size > 64)
162-
hppFile.add(fmt::format("sc_bv<{}>({});\n", type.size, name));
164+
hppFile.add(fmt::format("sc_dt::sc_bv<{}>({});\n", type.size, name));
163165
else
164166
hppFile.add(fmt::format("{};\n", name));
165167
}
@@ -183,15 +185,15 @@ void SvStruct::toCpp(HppFile& hppFile, const std::string_view _namespace, const
183185
if (!noSystemC && cppType != CppType::SC_BV) {
184186
hppFile.addWithIndent(fmt::format("operator sc_bv<{}>() const {{\n", structSize));
185187
hppFile.increaseIndent();
186-
hppFile.addWithIndent(fmt::format("auto ret = sc_bv<{}>();\n", structSize));
188+
hppFile.addWithIndent(fmt::format("auto ret = sc_dt::sc_bv<{}>();\n", structSize));
187189
for (const auto& [name, type] : members) {
188190
if (type.cppType == CppType::BOOL) {
189191
hppFile.addWithIndent(fmt::format("ret.set_bit({0}_s, {0});\n", name));
190192
}
191193
else {
192194
hppFile.addWithIndent(fmt::format("ret.range({0}_s + {0}_w - 1, {0}_s) = ", name));
193195
if (type.isStructEnumOrUnion() && type.size > 64)
194-
hppFile.add(fmt::format("sc_bv<{}>({});\n", type.size, name));
196+
hppFile.add(fmt::format("sc_dt::sc_bv<{}>({});\n", type.size, name));
195197
else
196198
hppFile.add(fmt::format("{};\n", name));
197199
}

tools/reflect/src/SvType.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ std::string toString(const Type& cppType) {
4949
// clang-format off
5050
switch (cppType) {
5151
case BOOL: return "bool";
52-
case U32: return "uint32_t";
53-
case U64: return "uint64_t";
54-
case SC_BV: return "sc_bv<{}>";
52+
case U32: return "std::uint32_t";
53+
case U64: return "std::uint64_t";
54+
case SC_BV: return "sc_dt::sc_bv<{}>";
5555
case STRUCT: return "{}";
5656
case ENUM: return "{}";
5757
case UNION: return "{}";

tools/reflect/src/SvUnion.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ void SvUnion::toCpp(HppFile& hppFile, std::string_view _namespace, const SvAlias
2121

2222
const size_t unionSize = type.getBitstreamWidth();
2323
const auto cppType = CppType::fromSize(unionSize);
24-
hppFile.addWithIndent(fmt::format("static constexpr size_t _size = {};\n\n", unionSize));
24+
hppFile.addWithIndent(fmt::format("static constexpr std::size_t _size = {};\n\n", unionSize));
2525

2626
if (cppType == CppType::SC_BV && noSystemC) {
2727
slang::OS::printE(fmt::format("Headers for the union {} can not be generated without "
@@ -70,8 +70,8 @@ void SvUnion::toCpp(HppFile& hppFile, std::string_view _namespace, const SvAlias
7070
// Note: This constructor will be generated only if the other constructor is not already
7171
// from a sc_bv
7272
if (!noSystemC && unionSize <= 64) {
73-
hppFile.addWithIndent(
74-
fmt::format("{}(const sc_bv<{}>& __data) {{\n", unionName, type.getBitstreamWidth()));
73+
hppFile.addWithIndent(fmt::format("{}(const sc_dt::sc_bv<{}>& __data) {{\n", unionName,
74+
type.getBitstreamWidth()));
7575

7676
hppFile.increaseIndent();
7777

@@ -87,7 +87,7 @@ void SvUnion::toCpp(HppFile& hppFile, std::string_view _namespace, const SvAlias
8787
if (cppType == CppType::SC_BV) {
8888
hppFile.addWithIndent(fmt::format("operator {}() const {{\n", cppTypeStr));
8989
hppFile.increaseIndent();
90-
hppFile.addWithIndent(fmt::format("return sc_bv<{}>(union_data);\n", unionSize));
90+
hppFile.addWithIndent(fmt::format("return sc_dt::sc_bv<{}>(union_data);\n", unionSize));
9191
}
9292
else {
9393
hppFile.addWithIndent(fmt::format("operator {}() const {{\n", cppTypeStr));

0 commit comments

Comments
 (0)