@@ -201,17 +201,24 @@ void DialectType::emitDeclaration(raw_ostream &out, GenDialect *dialect) const {
201201 out << " static bool classof(const ::llvm::Type *t);\n\n " ;
202202
203203 unsigned fieldIdx = 1 ; // sentinel
204+ auto getCastExpr = [&fmt](const NamedValue &argument,
205+ llvm::StringRef expr) -> std::string {
206+ return tgfmt (cast<Attr>(argument.type )->getFromUnsigned (), &fmt, expr);
207+ };
204208 for (const auto &argument : typeArguments ()) {
205209 std::string camel = convertToCamelFromSnakeCase (argument.name , true );
206210 out << tgfmt (
207- R"( unsigned get$0 () const {
208- ::llvm::Type *elt = getElementType($1 );
211+ R"( $0 get$1 () const {
212+ ::llvm::Type *elt = getElementType($2 );
209213 if (elt->isStructTy())
210- return 0 ;
211- return ::llvm::cast<::llvm::IntegerType>(elt)->getBitWidth() ;
214+ return $3 ;
215+ return $4 ;
212216 }
213217)" ,
214- &fmt, camel, fieldIdx++);
218+ &fmt, argument.type ->getCppType (), camel, fieldIdx++,
219+ getCastExpr (argument, " 0" ),
220+ getCastExpr (argument,
221+ " ::llvm::cast<::llvm::IntegerType>(elt)->getBitWidth()" ));
215222 }
216223
217224 out << " };\n\n " ;
@@ -307,14 +314,17 @@ void DialectType::emitDefinition(raw_ostream &out, GenDialect *dialect) const {
307314 " $fields.push_back(::llvm::IntegerType::get($_context, $0));\n " , &fmt,
308315 Twine (m_structSentinelBitWidth));
309316
310- for (const auto &getterArg : getterArgs) {
317+ for (const auto &[argument, getterArg] :
318+ llvm::zip (typeArguments (), getterArgs)) {
319+ std::string castExpr = tgfmt (cast<Attr>(argument.type )->getToUnsigned (),
320+ &fmt, getterArg.name );
311321 out << tgfmt (R"(
312322 if ($0 == 0)
313323 $fields.push_back(::llvm::StructType::get($_context));
314324 else
315325 $fields.push_back(::llvm::IntegerType::get($_context, $0));
316326)" ,
317- &fmt, getterArg. name );
327+ &fmt, castExpr );
318328 }
319329 out << tgfmt (" auto *$st = ::llvm::StructType::create($_context, "
320330 " $fields, $os.str(), /*isPacked=*/false);\n " ,
0 commit comments