[flang] Add lowering for ASCII character constant

Lower character constant of KIND = 1 with the
`createStringLiteral` helper function.

This patch is part of the upstreaming effort from fir-dev branch.

Reviewed By: kiranchandramohan, schweitz

Differential Revision: https://reviews.llvm.org/D118992
This commit is contained in:
Valentin Clement 2022-02-07 12:17:02 +01:00
parent 0c553bff8e
commit 74751f4b0c
No known key found for this signature in database
GPG Key ID: 086D54783C928776
1 changed files with 13 additions and 1 deletions

View File

@ -292,6 +292,16 @@ public:
} }
} }
/// Convert a ascii scalar literal CHARACTER to IR. (specialization)
ExtValue
genAsciiScalarLit(const Fortran::evaluate::Scalar<Fortran::evaluate::Type<
Fortran::common::TypeCategory::Character, 1>> &value,
int64_t len) {
assert(value.size() == static_cast<std::uint64_t>(len) &&
"value.size() doesn't match with len");
return fir::factory::createStringLiteral(builder, getLoc(), value);
}
template <Fortran::common::TypeCategory TC, int KIND> template <Fortran::common::TypeCategory TC, int KIND>
ExtValue ExtValue
genval(const Fortran::evaluate::Constant<Fortran::evaluate::Type<TC, KIND>> genval(const Fortran::evaluate::Constant<Fortran::evaluate::Type<TC, KIND>>
@ -302,7 +312,9 @@ public:
opt = con.GetScalarValue(); opt = con.GetScalarValue();
assert(opt.has_value() && "constant has no value"); assert(opt.has_value() && "constant has no value");
if constexpr (TC == Fortran::common::TypeCategory::Character) { if constexpr (TC == Fortran::common::TypeCategory::Character) {
TODO(getLoc(), "genval char constant"); if constexpr (KIND == 1)
return genAsciiScalarLit(opt.value(), con.LEN());
TODO(getLoc(), "genval for Character with KIND != 1");
} else { } else {
return genScalarLit<TC, KIND>(opt.value()); return genScalarLit<TC, KIND>(opt.value());
} }