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() {
65#include "circt/Dialect/SV/SV.cpp.inc"
69 addInterfaces<SVHandleModulePortTypeInterface>();
72#define GET_ATTRDEF_CLASSES
73#include "circt/Dialect/SV/SVDialect.cpp.inc"
83 auto set = std::make_unique<StringSet<>>();
85#include "ReservedWords.def"
103 llvm::StringMap<size_t> &nextGeneratedNameIDs,
104 bool caseInsensitiveKeywords) {
110 if (!
reservedWords->contains(caseInsensitiveKeywords ? origName.lower()
112 auto itAndInserted = nextGeneratedNameIDs.insert({origName, 0});
113 if (itAndInserted.second)
114 return itAndInserted.first->getKey();
118 SmallString<16> nameBuffer(origName.begin(), origName.end());
119 nameBuffer.push_back(
'_');
120 auto baseSize = nameBuffer.size();
121 auto &nextGeneratedNameID = nextGeneratedNameIDs[origName];
125 auto suffix = llvm::utostr(nextGeneratedNameID++);
126 nameBuffer.append(suffix.begin(), suffix.end());
130 auto itAndInserted = nextGeneratedNameIDs.insert({nameBuffer, 0});
131 if (itAndInserted.second)
132 return itAndInserted.first->getKey();
135 nameBuffer.resize(baseSize);
140 return llvm::isAlpha(ch) || ch ==
'_';
151 llvm::StringMap<size_t> &nextGeneratedNameIDs,
152 bool caseInsensitiveKeywords) {
157 caseInsensitiveKeywords);
163 caseInsensitiveKeywords);
166 SmallString<16> tmpName;
170 for (
char ch : name) {
173 else if (ch ==
' ' || ch ==
'.')
176 tmpName += llvm::utohexstr((
unsigned char)ch);
182 caseInsensitiveKeywords);
192 if (name.front() ==
'\\') {
196 for (
auto ch : name.drop_front()) {
197 bool isValidChar = llvm::isPrint(ch) && !llvm::isSpace(ch);
204 for (
char ch : name) {
210 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)