Skip to content

Commit 29581b7

Browse files
committed
comments, as requested by PR
1 parent aae9e19 commit 29581b7

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

mlir/lib/Target/IRDLToCpp/IRDLToCpp.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ constexpr char definitionMacroFlag[] = "GEN_DIALECT_DEF";
3030

3131
namespace {
3232

33+
/// The set of strings that can be generated from a Dialect declaraiton
3334
struct DialectStrings {
3435
std::string dialectName;
3536
std::string dialectCppName;
@@ -41,11 +42,13 @@ struct DialectStrings {
4142
std::string namespacePath;
4243
};
4344

45+
/// The set of strings that can be generated from a Type declaraiton
4446
struct TypeStrings {
4547
StringRef typeName;
4648
std::string typeCppName;
4749
};
4850

51+
/// The set of strings that can be generated from an Operation declaraiton
4952
struct OpStrings {
5053
StringRef opName;
5154
std::string opCppName;
@@ -61,23 +64,27 @@ static std::string joinNameList(llvm::ArrayRef<std::string> names) {
6164
return nameArray;
6265
}
6366

67+
/// Generates the C++ type name for a TypeOp
6468
static std::string typeToCppName(irdl::TypeOp type) {
6569
return llvm::formatv("{0}Type",
6670
convertToCamelFromSnakeCase(type.getSymName(), true));
6771
}
6872

73+
/// Generates the C++ class name for an OperationOp
6974
static std::string opToCppName(irdl::OperationOp op) {
7075
return llvm::formatv("{0}Op",
7176
convertToCamelFromSnakeCase(op.getSymName(), true));
7277
}
7378

79+
/// Generates TypeStrings from a TypeOp
7480
static TypeStrings getStrings(irdl::TypeOp type) {
7581
TypeStrings strings;
7682
strings.typeName = type.getSymName();
7783
strings.typeCppName = typeToCppName(type);
7884
return strings;
7985
}
8086

87+
/// Generates OpStrings from an OperatioOp
8188
static OpStrings getStrings(irdl::OperationOp op) {
8289
auto operandOp = op.getOp<irdl::OperandsOp>();
8390

@@ -104,12 +111,14 @@ static OpStrings getStrings(irdl::OperationOp op) {
104111
return strings;
105112
}
106113

114+
/// Fills a dictionary with values from TypeStrings
107115
static void fillDict(irdl::detail::dictionary &dict,
108116
const TypeStrings &strings) {
109117
dict["TYPE_NAME"] = strings.typeName;
110118
dict["TYPE_CPP_NAME"] = strings.typeCppName;
111119
}
112120

121+
/// Fills a dictionary with values from OpStrings
113122
static void fillDict(irdl::detail::dictionary &dict, const OpStrings &strings) {
114123
const auto operandCount = strings.opOperandNames.size();
115124
const auto resultCount = strings.opResultNames.size();
@@ -124,6 +133,7 @@ static void fillDict(irdl::detail::dictionary &dict, const OpStrings &strings) {
124133
resultCount ? joinNameList(strings.opResultNames) : "{\"\"}";
125134
}
126135

136+
/// Fills a dictionary with values from DialectStrings
127137
static void fillDict(irdl::detail::dictionary &dict,
128138
const DialectStrings &strings) {
129139
dict["DIALECT_NAME"] = strings.dialectName;

mlir/lib/Target/IRDLToCpp/TemplatingUtils.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,15 @@
1818

1919
namespace mlir::irdl::detail {
2020

21+
/// A dictionary stores a mapping of template variables to their assigned
22+
/// variables
2123
using dictionary = llvm::StringMap<llvm::SmallString<8>>;
2224

25+
/// Template Code as used by IRDL-to-Cpp.
26+
///
27+
/// For efficiency, produces a bytecode representation of an input string
28+
/// - LiteralToken: A contiguous stream of characters to be printed
29+
/// - ReplacementToken: A template variable that will be replaced
2330
class Template {
2431
public:
2532
Template(llvm::StringRef str) {
@@ -40,6 +47,8 @@ class Template {
4047
}
4148
}
4249

50+
// Render will apply a dictionary to the Template
51+
// and send it to the specified output stream
4352
void render(llvm::raw_ostream &out, const dictionary &replacements) const {
4453
for (auto instruction : bytecode) {
4554
std::visit(

0 commit comments

Comments
 (0)