[flang-commits] [flang] 8015ea6 - [flang] Enhance getTypeAsString for RecordType
Valentin Clement via flang-commits
flang-commits at lists.llvm.org
Fri Jun 23 09:51:11 PDT 2023
Author: Valentin Clement
Date: 2023-06-23T09:51:05-07:00
New Revision: 8015ea6a6dd960494be8e0cbca33bf7783ca8af4
URL: https://github.com/llvm/llvm-project/commit/8015ea6a6dd960494be8e0cbca33bf7783ca8af4
DIFF: https://github.com/llvm/llvm-project/commit/8015ea6a6dd960494be8e0cbca33bf7783ca8af4.diff
LOG: [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
Added:
Modified:
flang/lib/Optimizer/Dialect/FIRType.cpp
flang/unittests/Optimizer/FIRTypesTest.cpp
Removed:
################################################################################
diff --git a/flang/lib/Optimizer/Dialect/FIRType.cpp b/flang/lib/Optimizer/Dialect/FIRType.cpp
index 7fb3c56321cd7..60d35b2c818e3 100644
--- a/flang/lib/Optimizer/Dialect/FIRType.cpp
+++ b/flang/lib/Optimizer/Dialect/FIRType.cpp
@@ -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");
}
}
diff --git a/flang/unittests/Optimizer/FIRTypesTest.cpp b/flang/unittests/Optimizer/FIRTypesTest.cpp
index a006eeffd8f70..819f50a21ab6f 100644
--- a/flang/unittests/Optimizer/FIRTypesTest.cpp
+++ b/flang/unittests/Optimizer/FIRTypesTest.cpp
@@ -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));
}
More information about the flang-commits
mailing list