19#include "mlir/IR/DialectImplementation.h"
20#include "llvm/ADT/STLExtras.h"
21#include "llvm/ADT/StringExtras.h"
22#include "llvm/ADT/StringSet.h"
23#include "llvm/ADT/TypeSwitch.h"
24#include "llvm/Support/ManagedStatic.h"
41 verifyHWModulePortType(function_ref<InFlightDiagnostic()> emitError,
43 Type type)
const override {
45 if (isa<NetType>(type))
47 <<
"sv.net handles are not supported on output ports";
48 if (isa<VarType>(type))
50 <<
"sv.var handles are not supported on output ports";
57void SVDialect::initialize() {
63 addInterfaces<SVHandleModulePortTypeInterface>();
66#define GET_ATTRDEF_CLASSES
67#include "circt/Dialect/SV/SVDialect.cpp.inc"
77 auto set = std::make_unique<StringSet<>>();
79#include "ReservedWords.def"
97 llvm::StringMap<size_t> &nextGeneratedNameIDs,
98 bool caseInsensitiveKeywords) {
104 if (!
reservedWords->contains(caseInsensitiveKeywords ? origName.lower()
106 auto itAndInserted = nextGeneratedNameIDs.insert({origName, 0});
107 if (itAndInserted.second)
108 return itAndInserted.first->getKey();
112 SmallString<16> nameBuffer(origName.begin(), origName.end());
113 nameBuffer.push_back(
'_');
114 auto baseSize = nameBuffer.size();
115 auto &nextGeneratedNameID = nextGeneratedNameIDs[origName];
119 auto suffix = llvm::utostr(nextGeneratedNameID++);
120 nameBuffer.append(suffix.begin(), suffix.end());
124 auto itAndInserted = nextGeneratedNameIDs.insert({nameBuffer, 0});
125 if (itAndInserted.second)
126 return itAndInserted.first->getKey();
129 nameBuffer.resize(baseSize);
134 return llvm::isAlpha(ch) || ch ==
'_';
145 llvm::StringMap<size_t> &nextGeneratedNameIDs,
146 bool caseInsensitiveKeywords) {
151 caseInsensitiveKeywords);
157 caseInsensitiveKeywords);
160 SmallString<16> tmpName;
164 for (
char ch : name) {
167 else if (ch ==
' ' || ch ==
'.')
170 tmpName += llvm::utohexstr((
unsigned char)ch);
176 caseInsensitiveKeywords);
186 if (name.front() ==
'\\') {
190 for (
auto ch : name.drop_front()) {
191 bool isValidChar = llvm::isPrint(ch) && !llvm::isSpace(ch);
198 for (
char ch : name) {
204 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.
HWModulePortTypeInterface(mlir::Dialect *dialect)