[flang] Enhance getTypeAsString for RecordType

Add support for RecordType in getTypeAsString

Depends on D153461

Reviewed By: razvanlupusoru, jeanPerier

Differential Revision: https://reviews.llvm.org/D153467
This commit is contained in:
Valentin Clement 2023-06-23 09:49:22 -07:00
parent f9fd0062b6
commit 8015ea6a6d
No known key found for this signature in database
GPG Key ID: 086D54783C928776
2 changed files with 10 additions and 2 deletions

View File

@ -482,7 +482,8 @@ int getTypeCode(mlir::Type ty, const fir::KindMapping &kindMap) {
std::string getTypeAsString(mlir::Type ty, const fir::KindMapping &kindMap,
llvm::StringRef prefix) {
std::stringstream name;
std::string buf;
llvm::raw_string_ostream name{buf};
name << prefix.str();
if (!prefix.empty())
name << "_";
@ -535,8 +536,10 @@ std::string getTypeAsString(mlir::Type ty, const fir::KindMapping &kindMap,
} else if (auto boxTy = mlir::dyn_cast_or_null<fir::BoxType>(ty)) {
name << "box_";
ty = boxTy.getEleTy();
} else if (auto recTy = mlir::dyn_cast_or_null<fir::RecordType>(ty)) {
name << "rec_" << recTy.getName();
break;
} else {
// TODO: add support for RecordType
llvm::report_fatal_error("unsupported type");
}
}

View File

@ -299,4 +299,9 @@ TEST_F(FIRTypesTest, getTypeAsString) {
EXPECT_EQ("class_none",
fir::getTypeAsString(
fir::ClassType::get(mlir::NoneType::get(&context)), *kindMap));
auto derivedTy = fir::RecordType::get(&context, "derived");
llvm::SmallVector<std::pair<std::string, mlir::Type>> components;
components.emplace_back("p1", mlir::IntegerType::get(&context, 64));
derivedTy.finalize({}, components);
EXPECT_EQ("rec_derived", fir::getTypeAsString(derivedTy, *kindMap));
}