Skip to content

Commit c66655b

Browse files
committed
Address review comments:
- Remove struct prefix - Remove underscores
1 parent a9dc867 commit c66655b

File tree

5 files changed

+31
-34
lines changed

5 files changed

+31
-34
lines changed

example/ExampleDialect.td

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,6 @@ def StructBackedType : DialectType<ExampleDialect, "struct.backed"> {
369369
}];
370370
let typeArguments = (args AttrI32:$field0, AttrI32:$field1, AttrI32:$field2);
371371
let representation = (repr_struct (IntegerType 41));
372-
let structPrefix = "sb_";
373372

374373
let defaultGetterHasExplicitContextArgument = 1;
375374
}

include/llvm-dialects/Dialect/Dialect.td

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,6 @@ class DialectType<Dialect dialect_, string mnemonic_> : Type, Predicate {
239239
/// discriminant; the discriminant should be a type that cannot naturally
240240
/// appear elsewhere, e.g. (repr_struct (IntegerType 41))
241241
dag representation = (repr_targetext);
242-
string structPrefix = "";
243242
}
244243

245244
def and;

include/llvm-dialects/TableGen/DialectType.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ class DialectType : public BaseCppPredicate {
7878

7979
bool m_structBacked = false;
8080
unsigned m_structSentinelBitWidth;
81-
std::string m_structPrefix;
8281
};
8382

8483
} // namespace llvm_dialects

lib/TableGen/DialectType.cpp

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,6 @@ bool DialectType::init(raw_ostream &errs, GenDialectsContext &context,
6060
->getValue();
6161
}
6262
}
63-
if (auto *p = record->getValue("structPrefix"))
64-
m_structPrefix = record->getValueAsString("structPrefix").str();
65-
else
66-
m_structPrefix =
67-
(m_dialectRec->getValueAsString("name").str() + "." + m_mnemonic + ".");
6863

6964
for (unsigned argIdx = 0; argIdx < m_arguments.size(); ++argIdx)
7065
m_canDerive.push_back(true);
@@ -269,6 +264,10 @@ void DialectType::emitDefinition(raw_ostream &out, GenDialect *dialect) const {
269264
fmt.addSubst("types", symbols.chooseName("types"));
270265
fmt.addSubst("ints", symbols.chooseName("ints"));
271266
fmt.addSubst("_errs", symbols.chooseName("errs"));
267+
fmt.addSubst("os", symbols.chooseName("os"));
268+
fmt.addSubst("name", symbols.chooseName("name"));
269+
fmt.addSubst("fields", symbols.chooseName("fields"));
270+
fmt.addSubst("st", symbols.chooseName("st"));
272271

273272
if (m_structBacked) {
274273
out << tgfmt("$_type* $_type::get(", &fmt);
@@ -297,29 +296,30 @@ void DialectType::emitDefinition(raw_ostream &out, GenDialect *dialect) const {
297296
}
298297
}
299298

300-
out << " std::string __name; ::llvm::raw_string_ostream __os(__name);\n";
301-
out << tgfmt(" __os << \"$0\";\n", &fmt, m_structPrefix);
299+
out << tgfmt(
300+
" std::string $name; ::llvm::raw_string_ostream $os($name);\n", &fmt);
301+
out << tgfmt(" $os << \"$0\";\n", &fmt, m_mnemonic);
302302
for (const auto &getterArg : getterArgs)
303-
out << " __os << (uint64_t)" << getterArg.name << " << '.';\n";
303+
out << tgfmt(" $os << '.' << (uint64_t)$0;\n", &fmt, getterArg.name);
304304

305-
out << tgfmt(" ::std::vector<::llvm::Type*> __fields;\n", &fmt);
305+
out << tgfmt(" ::std::vector<::llvm::Type*> $fields;\n", &fmt);
306306
out << tgfmt(
307-
" __fields.push_back(::llvm::IntegerType::get($_context, $0));\n",
308-
&fmt, Twine(m_structSentinelBitWidth));
307+
" $fields.push_back(::llvm::IntegerType::get($_context, $0));\n", &fmt,
308+
Twine(m_structSentinelBitWidth));
309309

310310
for (const auto &getterArg : getterArgs) {
311311
out << tgfmt(R"(
312312
if ($0 == 0)
313-
__fields.push_back(::llvm::StructType::get($_context));
313+
$fields.push_back(::llvm::StructType::get($_context));
314314
else
315-
__fields.push_back(::llvm::IntegerType::get($_context, $0));
315+
$fields.push_back(::llvm::IntegerType::get($_context, $0));
316316
)",
317317
&fmt, getterArg.name);
318318
}
319-
out << tgfmt(" auto *__st = ::llvm::StructType::create($_context, "
320-
"__fields, __os.str(), /*isPacked=*/false);\n",
319+
out << tgfmt(" auto *$st = ::llvm::StructType::create($_context, "
320+
"$fields, $os.str(), /*isPacked=*/false);\n",
321321
&fmt);
322-
out << tgfmt(" return static_cast<$_type *>(__st);\n}\n\n", &fmt);
322+
out << tgfmt(" return static_cast<$_type *>($st);\n}\n\n", &fmt);
323323

324324
out << tgfmt(R"(
325325
bool $_type::classof(const ::llvm::Type *t) {

test/example/generated/ExampleDialect.cpp.inc

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -262,30 +262,30 @@ StructBackedType* StructBackedType::get(::llvm::LLVMContext & ctx, uint32_t fiel
262262

263263

264264

265-
std::string __name; ::llvm::raw_string_ostream __os(__name);
266-
__os << "sb_";
267-
__os << (uint64_t)field0 << '.';
268-
__os << (uint64_t)field1 << '.';
269-
__os << (uint64_t)field2 << '.';
270-
::std::vector<::llvm::Type*> __fields;
271-
__fields.push_back(::llvm::IntegerType::get(ctx, 41));
265+
std::string name; ::llvm::raw_string_ostream os(name);
266+
os << "struct.backed";
267+
os << '.' << (uint64_t)field0;
268+
os << '.' << (uint64_t)field1;
269+
os << '.' << (uint64_t)field2;
270+
::std::vector<::llvm::Type*> fields;
271+
fields.push_back(::llvm::IntegerType::get(ctx, 41));
272272

273273
if (field0 == 0)
274-
__fields.push_back(::llvm::StructType::get(ctx));
274+
fields.push_back(::llvm::StructType::get(ctx));
275275
else
276-
__fields.push_back(::llvm::IntegerType::get(ctx, field0));
276+
fields.push_back(::llvm::IntegerType::get(ctx, field0));
277277

278278
if (field1 == 0)
279-
__fields.push_back(::llvm::StructType::get(ctx));
279+
fields.push_back(::llvm::StructType::get(ctx));
280280
else
281-
__fields.push_back(::llvm::IntegerType::get(ctx, field1));
281+
fields.push_back(::llvm::IntegerType::get(ctx, field1));
282282

283283
if (field2 == 0)
284-
__fields.push_back(::llvm::StructType::get(ctx));
284+
fields.push_back(::llvm::StructType::get(ctx));
285285
else
286-
__fields.push_back(::llvm::IntegerType::get(ctx, field2));
287-
auto *__st = ::llvm::StructType::create(ctx, __fields, __os.str(), /*isPacked=*/false);
288-
return static_cast<StructBackedType *>(__st);
286+
fields.push_back(::llvm::IntegerType::get(ctx, field2));
287+
auto *st = ::llvm::StructType::create(ctx, fields, os.str(), /*isPacked=*/false);
288+
return static_cast<StructBackedType *>(st);
289289
}
290290

291291

0 commit comments

Comments
 (0)