mirror of
https://github.com/verilator/verilator.git
synced 2026-10-06 10:03:44 +02:00
Fix format of signed enums (#8338)
This commit is contained in:
+2
-1
@@ -47,6 +47,7 @@ public:
|
||||
COMPLEX = VL_VFORMATATTR_COMPLEX,
|
||||
DOUBLE = VL_VFORMATATTR_DOUBLE,
|
||||
ENUM = VL_VFORMATATTR_ENUM,
|
||||
ENUM_SIGNED = VL_VFORMATATTR_ENUM_SIGNED,
|
||||
SCOPE = VL_VFORMATATTR_SCOPE,
|
||||
STRING = VL_VFORMATATTR_STRING,
|
||||
TIMEUNIT = VL_VFORMATATTR_TIMEUNIT
|
||||
@@ -63,7 +64,7 @@ public:
|
||||
char ascii() const { return m_e; }
|
||||
bool isComplex() const { return m_e == COMPLEX; }
|
||||
bool isDouble() const { return m_e == DOUBLE; }
|
||||
bool isEnum() const { return m_e == ENUM; }
|
||||
bool isEnum() const { return m_e == ENUM || m_e == ENUM_SIGNED; }
|
||||
bool isSigned() const { return m_e == SIGNED; }
|
||||
bool isString() const { return m_e == STRING; }
|
||||
bool isUnsigned() const { return m_e == UNSIGNED; }
|
||||
|
||||
+14
-7
@@ -6768,7 +6768,9 @@ class WidthVisitor final : public VNVisitor {
|
||||
argp = newp;
|
||||
} else if (nodep->exprFormat()) {
|
||||
if (AstEnumDType* const enumDtp = formatEnumDType(argp)) {
|
||||
nodep->addExprsp(new AstSFormatArg{argp->fileline(), VFormatAttr::ENUM, argp});
|
||||
const VFormatAttr attr
|
||||
= enumDtp->isSigned() ? VFormatAttr::ENUM_SIGNED : VFormatAttr::ENUM;
|
||||
nodep->addExprsp(new AstSFormatArg{argp->fileline(), attr, argp});
|
||||
AstNodeExpr* const namep
|
||||
= enumSelect(argp->cloneTreePure(false), enumDtp, VAttrType::ENUM_NAME);
|
||||
nodep->addExprsp(
|
||||
@@ -8796,12 +8798,17 @@ class WidthVisitor final : public VNVisitor {
|
||||
}
|
||||
if (widthSet && width == 0) fallbackFormat = "'h%0h";
|
||||
}
|
||||
AstNodeExpr* const newp = new AstCond{
|
||||
subargp->fileline(), enumTestValid(subargp, enumDtp),
|
||||
enumSelect(subargp->cloneTreePure(false), enumDtp,
|
||||
VAttrType::ENUM_NAME),
|
||||
new AstSFormatF{subargp->fileline(), fallbackFormat, true,
|
||||
subargp->cloneTreePure(false)}};
|
||||
AstNodeExpr* fallbackp = subargp->cloneTreePure(false);
|
||||
if (enumDtp->isSigned()) {
|
||||
fallbackp = new AstSFormatArg{subargp->fileline(),
|
||||
VFormatAttr::SIGNED, fallbackp};
|
||||
}
|
||||
AstNodeExpr* const newp
|
||||
= new AstCond{subargp->fileline(), enumTestValid(subargp, enumDtp),
|
||||
enumSelect(subargp->cloneTreePure(false), enumDtp,
|
||||
VAttrType::ENUM_NAME),
|
||||
new AstSFormatF{subargp->fileline(), fallbackFormat,
|
||||
true, fallbackp}};
|
||||
subargp->replaceWith(new AstSFormatArg{subargp->fileline(),
|
||||
VFormatAttr::COMPLEX, newp});
|
||||
VL_DO_DANGLING(pushDeletep(subargp), subargp);
|
||||
|
||||
Reference in New Issue
Block a user