18 #include "mlir/IR/DialectImplementation.h"
19 #include "llvm/ADT/STLExtras.h"
20 #include "llvm/ADT/StringExtras.h"
21 #include "llvm/ADT/StringSet.h"
22 #include "llvm/ADT/TypeSwitch.h"
23 #include "llvm/Support/ManagedStatic.h"
25 using namespace circt;
32 void SVDialect::initialize() {
40 #include "circt/Dialect/SV/SV.cpp.inc"
44 #define GET_ATTRDEF_CLASSES
45 #include "circt/Dialect/SV/SVDialect.cpp.inc"
55 auto set = std::make_unique<StringSet<>>();
57 #include "ReservedWords.def"
75 llvm::StringMap<size_t> &nextGeneratedNameIDs,
76 bool caseInsensitiveKeywords) {
82 if (!
reservedWords->contains(caseInsensitiveKeywords ? origName.lower()
84 auto itAndInserted = nextGeneratedNameIDs.insert({origName, 0});
85 if (itAndInserted.second)
86 return itAndInserted.first->getKey();
90 SmallString<16> nameBuffer(origName.begin(), origName.end());
91 nameBuffer.push_back(
'_');
92 auto baseSize = nameBuffer.size();
93 auto &nextGeneratedNameID = nextGeneratedNameIDs[origName];
97 auto suffix = llvm::utostr(nextGeneratedNameID++);
98 nameBuffer.append(suffix.begin(), suffix.end());
102 auto itAndInserted = nextGeneratedNameIDs.insert({nameBuffer, 0});
103 if (itAndInserted.second)
104 return itAndInserted.first->getKey();
107 nameBuffer.resize(baseSize);
112 return llvm::isAlpha(ch) || ch ==
'_';
123 llvm::StringMap<size_t> &nextGeneratedNameIDs,
124 bool caseInsensitiveKeywords) {
129 caseInsensitiveKeywords);
135 caseInsensitiveKeywords);
138 SmallString<16> tmpName;
142 for (
char ch : name) {
145 else if (ch ==
' ' || ch ==
'.')
148 tmpName += llvm::utohexstr((
unsigned char)ch);
154 caseInsensitiveKeywords);
166 for (
char ch : name) {
171 return reservedWords->contains(caseInsensitiveKeywords ? name.lower()
static bool isValidVerilogCharacterFirst(char ch)
static llvm::ManagedStatic< StringSet<>, ReservedWordsCreator > reservedWords
A StringSet that contains all of the reserved names (e.g., Verilog and VHDL keywords) that we need to...
static bool isValidVerilogCharacter(char ch)
llvm::StringRef resolveKeywordConflict(llvm::StringRef origName, llvm::StringMap< size_t > &nextGeneratedNameIDs, bool caseInsensitiveKeywords)
Given string origName, generate a new name if it conflicts with any keyword or any other name in the ...
StringRef legalizeName(llvm::StringRef name, llvm::StringMap< size_t > &nextGeneratedNameIDs, bool caseInsensitiveKeywords)
Legalize the specified name for use in SV output.
bool isNameValid(llvm::StringRef name, bool caseInsensitiveKeywords)
Check if a name is valid for use in SV output by only containing characters allowed in SV identifiers...
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
Return a StringSet that contains all of the reserved names (e.g.