Skip to content

Commit

Permalink
style: pre-commit fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
pre-commit-ci[bot] committed Nov 13, 2024
1 parent 5890207 commit eab24e7
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 42 deletions.
6 changes: 3 additions & 3 deletions tools/reflect/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
# ~~~

add_library(
slang_reflect_obj_lib OBJECT src/SvStruct.cpp src/SvType.cpp src/SvEnum.cpp
src/SvTypeReflector.cpp src/SvLocalParam.cpp
src/SvUnion.cpp)
slang_reflect_obj_lib OBJECT
src/SvStruct.cpp src/SvType.cpp src/SvEnum.cpp src/SvTypeReflector.cpp
src/SvLocalParam.cpp src/SvUnion.cpp)

target_include_directories(slang_reflect_obj_lib PUBLIC include ../../include)
target_link_libraries(slang_reflect_obj_lib PUBLIC slang::slang)
Expand Down
3 changes: 1 addition & 2 deletions tools/reflect/include/SvEnum.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@

class SvEnum final : public SvGeneric {
public:
explicit SvEnum(const slang::ast::TypeAliasType& type) :
SvGeneric(Kind::Enum), type(type) {}
explicit SvEnum(const slang::ast::TypeAliasType& type) : SvGeneric(Kind::Enum), type(type) {}

void toCpp(HppFile& hppFile, std::string_view, const SvAliases&, bool) const override;

Expand Down
1 change: 0 additions & 1 deletion tools/reflect/include/SvGeneric.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#pragma once

#include "CppEmitter.h"

#include <unordered_map>

using SvAliases = std::unordered_map<std::string_view, std::string_view>;
Expand Down
3 changes: 1 addition & 2 deletions tools/reflect/include/SvUnion.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@

class SvUnion final : public SvGeneric {
public:
explicit SvUnion(const slang::ast::TypeAliasType& type) :
SvGeneric(Kind::Union), type(type) {}
explicit SvUnion(const slang::ast::TypeAliasType& type) : SvGeneric(Kind::Union), type(type) {}

void toCpp(HppFile& hppFile, std::string_view, const SvAliases&, bool noSystemC) const override;

Expand Down
57 changes: 23 additions & 34 deletions tools/reflect/src/SvStruct.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ void SvStruct::toCpp(HppFile& hppFile, const std::string_view _namespace, const
//** MEMBERS DECLARATION **//
for (const auto& [name, type] : members) {
if (type.isStructEnumOrUnion() && _namespace != type._namespace) {
hppFile.addWithIndent(fmt::format("{}::{} {};\n", type._namespace,
type.toString(), name));
hppFile.addWithIndent(
fmt::format("{}::{} {};\n", type._namespace, type.toString(), name));
hppFile.addIncludeHeader(type._namespace);
}
else {
Expand All @@ -59,10 +59,8 @@ void SvStruct::toCpp(HppFile& hppFile, const std::string_view _namespace, const
//** GENERATE START AND WIDTH OF EACH SIGNAL **//
size_t startBit = 0;
for (const auto& [name, type] : members) {
hppFile.addWithIndent(
fmt::format("static constexpr size_t {}_s = {};\n", name, startBit));
hppFile.addWithIndent(
fmt::format("static constexpr size_t {}_w = {};\n", name, type.size));
hppFile.addWithIndent(fmt::format("static constexpr size_t {}_s = {};\n", name, startBit));
hppFile.addWithIndent(fmt::format("static constexpr size_t {}_w = {};\n", name, type.size));
startBit += type.size;
}
hppFile.addWithIndent(fmt::format("static constexpr size_t _size = {};\n", structSize));
Expand All @@ -89,14 +87,14 @@ void SvStruct::toCpp(HppFile& hppFile, const std::string_view _namespace, const
values.emplace_back(
fmt::format("__data.range({0}_s + {0}_w - 1, {0}_s)", name));
else
values.emplace_back(fmt::format(
"__data.range({0}_s + {0}_w - 1, {0}_s).to_uint64()", name));
values.emplace_back(
fmt::format("__data.range({0}_s + {0}_w - 1, {0}_s).to_uint64()", name));
}
}
else {
for (const auto& [name, type] : members)
values.emplace_back(fmt::format("(__data >> {0}_s) & (~0ULL >> (64 - {1}))",
name, type.size));
values.emplace_back(
fmt::format("(__data >> {0}_s) & (~0ULL >> (64 - {1}))", name, type.size));
}

for (auto i = 0; i < members.size(); i++) {
Expand All @@ -105,12 +103,11 @@ void SvStruct::toCpp(HppFile& hppFile, const std::string_view _namespace, const

if (type.isStructEnumOrUnion())
if (_namespace != type._namespace)
hppFile.addWithIndent(fmt::format("{} = {}::{}({});\n", name,
type._namespace,
hppFile.addWithIndent(fmt::format("{} = {}::{}({});\n", name, type._namespace,
type.toString(), value));
else
hppFile.addWithIndent(fmt::format("{} = {}({});\n", name,
type.toString(), value));
hppFile.addWithIndent(
fmt::format("{} = {}({});\n", name, type.toString(), value));
else
hppFile.addWithIndent(fmt::format("{} = {};\n", name, value));
}
Expand All @@ -133,17 +130,15 @@ void SvStruct::toCpp(HppFile& hppFile, const std::string_view _namespace, const
if (type.size == 1)
value = fmt::format("__data.get_bit({0}_s)", name);
else
value = fmt::format("__data.range({0}_s + {0}_w - 1, {0}_s).to_uint64()",
name);
value = fmt::format("__data.range({0}_s + {0}_w - 1, {0}_s).to_uint64()", name);

if (type.isStructEnumOrUnion())
if (_namespace != type._namespace)
hppFile.addWithIndent(fmt::format("{} = {}::{}({});\n", name,
type._namespace,
hppFile.addWithIndent(fmt::format("{} = {}::{}({});\n", name, type._namespace,
type.toString(), value));
else
hppFile.addWithIndent(fmt::format("{} = {}({});\n", name,
type.toString(), value));
hppFile.addWithIndent(
fmt::format("{} = {}({});\n", name, type.toString(), value));
else
hppFile.addWithIndent(fmt::format("{} = {};\n", name, value));
}
Expand All @@ -162,8 +157,7 @@ void SvStruct::toCpp(HppFile& hppFile, const std::string_view _namespace, const
hppFile.addWithIndent(fmt::format("ret.set_bit({0}_s, {0});\n", name));
}
else {
hppFile.addWithIndent(
fmt::format("ret.range({0}_s + {0}_w - 1, {0}_s) = ", name));
hppFile.addWithIndent(fmt::format("ret.range({0}_s + {0}_w - 1, {0}_s) = ", name));
if (type.isStructEnumOrUnion() && type.size > 64)
hppFile.add(fmt::format("sc_bv<{}>({});\n", type.size, name));
else
Expand Down Expand Up @@ -195,8 +189,7 @@ void SvStruct::toCpp(HppFile& hppFile, const std::string_view _namespace, const
hppFile.addWithIndent(fmt::format("ret.set_bit({0}_s, {0});\n", name));
}
else {
hppFile.addWithIndent(
fmt::format("ret.range({0}_s + {0}_w - 1, {0}_s) = ", name));
hppFile.addWithIndent(fmt::format("ret.range({0}_s + {0}_w - 1, {0}_s) = ", name));
if (type.isStructEnumOrUnion() && type.size > 64)
hppFile.add(fmt::format("sc_bv<{}>({});\n", type.size, name));
else
Expand Down Expand Up @@ -243,8 +236,7 @@ void SvStruct::toCpp(HppFile& hppFile, const std::string_view _namespace, const
for (const auto& [name, type] : members) {
if (type.isStructEnumOrUnion() && _namespace != type._namespace) {
hppFile.addWithIndent(fmt::format("static {}::{} get_{} (const {}& __data) {{\n",
type._namespace, type.toString(),
name, cppTypeStr));
type._namespace, type.toString(), name, cppTypeStr));
}
else {
hppFile.addWithIndent(fmt::format("static {} get_{} (const {}& __data) {{\n",
Expand All @@ -258,21 +250,18 @@ void SvStruct::toCpp(HppFile& hppFile, const std::string_view _namespace, const
else if (type.size > 64)
value = fmt::format("__data.range({0}_s + {0}_w - 1, {0}_s)", name);
else
value = fmt::format("__data.range({0}_s + {0}_w - 1, {0}_s).to_uint64()",
name);
value = fmt::format("__data.range({0}_s + {0}_w - 1, {0}_s).to_uint64()", name);
}
else {
value = fmt::format("(__data >> {0}_s) & (~0ULL >> (64 - {1}))", name,
type.size);
value = fmt::format("(__data >> {0}_s) & (~0ULL >> (64 - {1}))", name, type.size);
}

if (type.isStructEnumOrUnion())
if (_namespace != type._namespace)
hppFile.addWithIndent(fmt::format("return {}::{}({});\n", type._namespace,
type.toString(), value));
else
hppFile.addWithIndent(
fmt::format("return {}({});\n", type.toString(), value));
fmt::format("return {}::{}({});\n", type._namespace, type.toString(), value));
else
hppFile.addWithIndent(fmt::format("return {}({});\n", type.toString(), value));
else
hppFile.addWithIndent(fmt::format("return {};\n", value));

Expand Down

0 comments on commit eab24e7

Please sign in to comment.