Internals: Generalize V3Config to be able to set any module pragma. No functional change intended. (#2451)

This commit is contained in:
Yutetsu TAKATSUKASA 2020-07-02 20:54:37 +09:00 committed by GitHub
parent 9d1a39a5e4
commit cc50126ad3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 8 deletions

View File

@ -158,19 +158,19 @@ typedef V3ConfigWildcardResolver<V3ConfigFTask> V3ConfigFTaskResolver;
class V3ConfigModule { class V3ConfigModule {
typedef vl_unordered_set<string> StringSet; typedef vl_unordered_set<string> StringSet;
typedef std::set<AstPragmaType> PragmaSet;
V3ConfigFTaskResolver m_tasks; // Functions/tasks in module V3ConfigFTaskResolver m_tasks; // Functions/tasks in module
V3ConfigVarResolver m_vars; // Variables in module V3ConfigVarResolver m_vars; // Variables in module
StringSet m_coverageOffBlocks; // List of block names for coverage_off StringSet m_coverageOffBlocks; // List of block names for coverage_off
PragmaSet m_modPragmas; // List of Pragmas for modules
bool m_inline; // Whether to force the inline bool m_inline; // Whether to force the inline
bool m_inlineValue; // The inline value (on/off) bool m_inlineValue; // The inline value (on/off)
bool m_public; // Public module
public: public:
V3ConfigModule() V3ConfigModule()
: m_inline(false) : m_inline(false)
, m_inlineValue(false) , m_inlineValue(false) {}
, m_public(false) {}
void update(const V3ConfigModule& m) { void update(const V3ConfigModule& m) {
m_tasks.update(m.m_tasks); m_tasks.update(m.m_tasks);
@ -183,7 +183,10 @@ public:
m_inline = m.m_inline; m_inline = m.m_inline;
m_inlineValue = m.m_inlineValue; m_inlineValue = m.m_inlineValue;
} }
if (!m_public) m_public = m.m_public; for (PragmaSet::const_iterator it = m.m_modPragmas.begin(); it != m.m_modPragmas.end();
++it) {
m_modPragmas.insert(*it);
}
} }
V3ConfigFTaskResolver& ftasks() { return m_tasks; } V3ConfigFTaskResolver& ftasks() { return m_tasks; }
@ -194,7 +197,7 @@ public:
m_inline = true; m_inline = true;
m_inlineValue = set; m_inlineValue = set;
} }
void setPublic(bool set) { m_public = set; } void addModulePragma(AstPragmaType pragma) { m_modPragmas.insert(pragma); }
void apply(AstNodeModule* modp) { void apply(AstNodeModule* modp) {
if (m_inline) { if (m_inline) {
@ -203,8 +206,8 @@ public:
AstNode* nodep = new AstPragma(modp->fileline(), type); AstNode* nodep = new AstPragma(modp->fileline(), type);
modp->addStmtp(nodep); modp->addStmtp(nodep);
} }
if (m_public) { for (PragmaSet::const_iterator it = m_modPragmas.begin(); it != m_modPragmas.end(); ++it) {
AstNode* nodep = new AstPragma(modp->fileline(), AstPragmaType::PUBLIC_MODULE); AstNode* nodep = new AstPragma(modp->fileline(), *it);
modp->addStmtp(nodep); modp->addStmtp(nodep);
} }
} }
@ -408,6 +411,10 @@ void V3Config::addIgnore(V3ErrorCode code, bool on, const string& filename, int
} }
} }
void V3Config::addModulePragma(const string& module, AstPragmaType pragma) {
V3ConfigResolver::s().modules().at(module).addModulePragma(pragma);
}
void V3Config::addInline(FileLine* fl, const string& module, const string& ftask, bool on) { void V3Config::addInline(FileLine* fl, const string& module, const string& ftask, bool on) {
if (ftask.empty()) { if (ftask.empty()) {
V3ConfigResolver::s().modules().at(module).setInline(on); V3ConfigResolver::s().modules().at(module).setInline(on);
@ -439,7 +446,8 @@ void V3Config::addVarAttr(FileLine* fl, const string& module, const string& ftas
} else if (attr == AstAttrType::VAR_PUBLIC) { } else if (attr == AstAttrType::VAR_PUBLIC) {
if (ftask.empty()) { if (ftask.empty()) {
// public module, this is the only exception from var here // public module, this is the only exception from var here
V3ConfigResolver::s().modules().at(module).setPublic(true); V3ConfigResolver::s().modules().at(module).addModulePragma(
AstPragmaType::PUBLIC_MODULE);
} else { } else {
V3ConfigResolver::s().modules().at(module).ftasks().at(ftask).setPublic(true); V3ConfigResolver::s().modules().at(module).ftasks().at(ftask).setPublic(true);
} }

View File

@ -34,6 +34,7 @@ public:
static void addCoverageBlockOff(const string& module, const string& blockname); static void addCoverageBlockOff(const string& module, const string& blockname);
static void addIgnore(V3ErrorCode code, bool on, const string& filename, int min, int max); static void addIgnore(V3ErrorCode code, bool on, const string& filename, int min, int max);
static void addWaiver(V3ErrorCode code, const string& filename, const string& message); static void addWaiver(V3ErrorCode code, const string& filename, const string& message);
static void addModulePragma(const string& module, AstPragmaType pragma);
static void addInline(FileLine* fl, const string& module, const string& ftask, bool on); static void addInline(FileLine* fl, const string& module, const string& ftask, bool on);
static void addVarAttr(FileLine* fl, const string& module, const string& ftask, static void addVarAttr(FileLine* fl, const string& module, const string& ftask,
const string& signal, AstAttrType type, AstSenTree* nodep); const string& signal, AstAttrType type, AstSenTree* nodep);