@@ -32,14 +32,14 @@ class Generator {
32
32
Generator (raw_ostream &output) : output(output) {}
33
33
34
34
// / Returns whether successfully emitted attribute/type parsers.
35
- void emitParse (StringRef kind, Record &x);
35
+ void emitParse (StringRef kind, const Record &x);
36
36
37
37
// / Returns whether successfully emitted attribute/type printers.
38
38
void emitPrint (StringRef kind, StringRef type,
39
- ArrayRef<std::pair<int64_t , Record *>> vec);
39
+ ArrayRef<std::pair<int64_t , const Record *>> vec);
40
40
41
41
// / Emits parse dispatch table.
42
- void emitParseDispatch (StringRef kind, ArrayRef<Record *> vec);
42
+ void emitParseDispatch (StringRef kind, ArrayRef<const Record *> vec);
43
43
44
44
// / Emits print dispatch table.
45
45
void emitPrintDispatch (StringRef kind, ArrayRef<std::string> vec);
@@ -51,8 +51,9 @@ class Generator {
51
51
StringRef failure, mlir::raw_indented_ostream &ios);
52
52
53
53
// / Emits print instructions.
54
- void emitPrintHelper (Record *memberRec, StringRef kind, StringRef parent,
55
- StringRef name, mlir::raw_indented_ostream &ios);
54
+ void emitPrintHelper (const Record *memberRec, StringRef kind,
55
+ StringRef parent, StringRef name,
56
+ mlir::raw_indented_ostream &ios);
56
57
57
58
raw_ostream &output;
58
59
};
@@ -75,7 +76,7 @@ static std::string capitalize(StringRef str) {
75
76
}
76
77
77
78
// / Return the C++ type for the given record.
78
- static std::string getCType (Record *def) {
79
+ static std::string getCType (const Record *def) {
79
80
std::string format = " {0}" ;
80
81
if (def->isSubClassOf (" Array" )) {
81
82
def = def->getValueAsDef (" elemT" );
@@ -92,7 +93,8 @@ static std::string getCType(Record *def) {
92
93
return formatv (format.c_str (), cType.str ());
93
94
}
94
95
95
- void Generator::emitParseDispatch (StringRef kind, ArrayRef<Record *> vec) {
96
+ void Generator::emitParseDispatch (StringRef kind,
97
+ ArrayRef<const Record *> vec) {
96
98
mlir::raw_indented_ostream os (output);
97
99
char const *head =
98
100
R"( static {0} read{0}(MLIRContext* context, DialectBytecodeReader &reader))" ;
@@ -126,7 +128,7 @@ void Generator::emitParseDispatch(StringRef kind, ArrayRef<Record *> vec) {
126
128
os << " return " << capitalize (kind) << " ();\n " ;
127
129
}
128
130
129
- void Generator::emitParse (StringRef kind, Record &x) {
131
+ void Generator::emitParse (StringRef kind, const Record &x) {
130
132
if (x.getNameInitAsString () == " ReservedOrDead" )
131
133
return ;
132
134
@@ -293,7 +295,7 @@ void Generator::emitParseHelper(StringRef kind, StringRef returnType,
293
295
}
294
296
295
297
void Generator::emitPrint (StringRef kind, StringRef type,
296
- ArrayRef<std::pair<int64_t , Record *>> vec) {
298
+ ArrayRef<std::pair<int64_t , const Record *>> vec) {
297
299
if (type == " ReservedOrDead" )
298
300
return ;
299
301
@@ -304,7 +306,7 @@ void Generator::emitPrint(StringRef kind, StringRef type,
304
306
auto funScope = os.scope (" {\n " , " }\n\n " );
305
307
306
308
// Check that predicates specified if multiple bytecode instances.
307
- for (llvm::Record *rec : make_second_range (vec)) {
309
+ for (const llvm::Record *rec : make_second_range (vec)) {
308
310
StringRef pred = rec->getValueAsString (" printerPredicate" );
309
311
if (vec.size () > 1 && pred.empty ()) {
310
312
for (auto [index , rec] : vec) {
@@ -344,7 +346,7 @@ void Generator::emitPrint(StringRef kind, StringRef type,
344
346
}
345
347
}
346
348
347
- void Generator::emitPrintHelper (Record *memberRec, StringRef kind,
349
+ void Generator::emitPrintHelper (const Record *memberRec, StringRef kind,
348
350
StringRef parent, StringRef name,
349
351
mlir::raw_indented_ostream &ios) {
350
352
std::string getter;
@@ -423,7 +425,7 @@ void Generator::emitPrintDispatch(StringRef kind, ArrayRef<std::string> vec) {
423
425
namespace {
424
426
// / Container of Attribute or Type for Dialect.
425
427
struct AttrOrType {
426
- std::vector<Record *> attr, type;
428
+ std::vector<const Record *> attr, type;
427
429
};
428
430
} // namespace
429
431
@@ -435,14 +437,14 @@ static bool emitBCRW(const RecordKeeper &records, raw_ostream &os) {
435
437
it->getValueAsString (" dialect" ) != selectedBcDialect)
436
438
continue ;
437
439
dialectAttrOrType[it->getValueAsString (" dialect" )].attr =
438
- it->getValueAsListOfDefs (" elems" );
440
+ it->getValueAsListOfConstDefs (" elems" );
439
441
}
440
442
for (const Record *it : records.getAllDerivedDefinitions (" DialectTypes" )) {
441
443
if (!selectedBcDialect.empty () &&
442
444
it->getValueAsString (" dialect" ) != selectedBcDialect)
443
445
continue ;
444
446
dialectAttrOrType[it->getValueAsString (" dialect" )].type =
445
- it->getValueAsListOfDefs (" elems" );
447
+ it->getValueAsListOfConstDefs (" elems" );
446
448
}
447
449
448
450
if (dialectAttrOrType.size () != 1 )
@@ -452,15 +454,16 @@ static bool emitBCRW(const RecordKeeper &records, raw_ostream &os) {
452
454
auto it = dialectAttrOrType.front ();
453
455
Generator gen (os);
454
456
455
- SmallVector<std::vector<Record *> *, 2 > vecs;
457
+ SmallVector<std::vector<const Record *> *, 2 > vecs;
456
458
SmallVector<std::string, 2 > kinds;
457
459
vecs.push_back (&it.second .attr );
458
460
kinds.push_back (" attribute" );
459
461
vecs.push_back (&it.second .type );
460
462
kinds.push_back (" type" );
461
463
for (auto [vec, kind] : zip (vecs, kinds)) {
462
464
// Handle Attribute/Type emission.
463
- std::map<std::string, std::vector<std::pair<int64_t , Record *>>> perType;
465
+ std::map<std::string, std::vector<std::pair<int64_t , const Record *>>>
466
+ perType;
464
467
for (auto kt : llvm::enumerate (*vec))
465
468
perType[getCType (kt.value ())].emplace_back (kt.index (), kt.value ());
466
469
for (const auto &jt : perType) {
0 commit comments