mirror of
https://github.com/verilator/verilator.git
synced 2026-10-06 10:03:44 +02:00
Emit parameter values as 'static constexpr' instead of enum
All parameters that are required in the output are now emitted as 'static constexpr, except for string or array of strings parameters, which are still emitted as 'static const' (required as std::string is not a literal type, so cannot be constexpr). This simplifies handling of parameters and supports 'real' parameters.
This commit is contained in:
+19
-23
@@ -202,35 +202,31 @@ class EmitCImp final : EmitCFunc {
|
||||
}
|
||||
}
|
||||
void emitParamDefns(const AstNodeModule* modp) {
|
||||
const string modName = prefixNameProtect(modp);
|
||||
bool first = true;
|
||||
for (const AstNode* nodep = modp->stmtsp(); nodep; nodep = nodep->nextp()) {
|
||||
if (const AstVar* const varp = VN_CAST_CONST(nodep, Var)) {
|
||||
if (varp->isParam() && (varp->isUsedParam() || varp->isSigPublic())) {
|
||||
UASSERT_OBJ(varp->valuep(), nodep, "No init for a param?");
|
||||
// These should be static const values, however older MSVC++ did't
|
||||
// support them; should be ok now under C++11, need to refactor.
|
||||
if (varp->isWide()) { // Unsupported for output
|
||||
} else if (varp->isString()) {
|
||||
puts("const std::string ");
|
||||
puts(prefixNameProtect(modp) + "::" + protect("var_" + varp->name())
|
||||
+ "(");
|
||||
iterateAndNextNull(varp->valuep());
|
||||
puts(");\n");
|
||||
} else if (!VN_IS(varp->valuep(), Const)) { // Unsupported for output
|
||||
// putsDecoration("// enum ..... "+varp->nameProtect()
|
||||
// +"not simple value, see variable above instead");
|
||||
} else if (VN_IS(varp->dtypep(), BasicDType)
|
||||
&& VN_CAST(varp->dtypep(), BasicDType)
|
||||
->isOpaque()) { // Can't put out e.g. doubles
|
||||
} else {
|
||||
puts(varp->isQuad() ? "const QData " : "const IData ");
|
||||
puts(prefixNameProtect(modp) + "::" + protect("var_" + varp->name())
|
||||
+ "(");
|
||||
iterateAndNextNull(varp->valuep());
|
||||
puts(");\n");
|
||||
if (varp->isParam()) {
|
||||
if (first) {
|
||||
puts("\n");
|
||||
putsDecoration("// Parameter definitions for " + modName + "\n");
|
||||
first = false;
|
||||
}
|
||||
UASSERT_OBJ(varp->valuep(), nodep, "No init for a param?");
|
||||
// Only C++ LiteralTypes can be constexpr
|
||||
const bool canBeConstexpr = varp->dtypep()->isLiteralType();
|
||||
puts(canBeConstexpr ? "constexpr " : "const ");
|
||||
const string scopedName = modName + "::" + varp->nameProtect();
|
||||
puts(varp->dtypep()->cType(scopedName, false, false));
|
||||
if (!canBeConstexpr) {
|
||||
puts(" = ");
|
||||
emitConstInit(varp->valuep());
|
||||
}
|
||||
puts(";\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!first) puts("\n");
|
||||
}
|
||||
void emitCtorImp(const AstNodeModule* modp) {
|
||||
const string modName = prefixNameProtect(modp);
|
||||
|
||||
Reference in New Issue
Block a user