@@ -1658,7 +1658,7 @@ class SILGenApply : public Lowering::ExprVisitor<SILGenApply> {
1658
1658
} // end anonymous namespace
1659
1659
1660
1660
// TODO: move onto SGF directly and reuse in SILGenDistributed and other places
1661
- static PreparedArguments emitStringLiteral (SILGenFunction &SGF, Expr * E,
1661
+ static PreparedArguments emitStringLiteralArgs (SILGenFunction &SGF, SILLocation E,
1662
1662
StringRef Str, SGFContext C,
1663
1663
StringLiteralExpr::Encoding encoding) {
1664
1664
uint64_t Length;
@@ -1695,7 +1695,6 @@ static PreparedArguments emitStringLiteral(SILGenFunction &SGF, Expr *E,
1695
1695
auto Int1Ty = SILType::getBuiltinIntegerType (1 , SGF.getASTContext ());
1696
1696
auto *isASCIIInst = SGF.B .createIntegerLiteral (E, Int1Ty, isASCII);
1697
1697
1698
-
1699
1698
ManagedValue EltsArray[] = {
1700
1699
ManagedValue::forUnmanaged (string),
1701
1700
ManagedValue::forUnmanaged (lengthInst),
@@ -1840,7 +1839,7 @@ static bool hasUnownedInnerPointerResult(CanSILFunctionType fnType) {
1840
1839
static inline PreparedArguments
1841
1840
buildBuiltinLiteralArgs (SILGenFunction &SGF, SGFContext C,
1842
1841
StringLiteralExpr *stringLiteral) {
1843
- return emitStringLiteral (SGF, stringLiteral, stringLiteral->getValue (), C,
1842
+ return emitStringLiteralArgs (SGF, stringLiteral, stringLiteral->getValue (), C,
1844
1843
stringLiteral->getEncoding ());
1845
1844
}
1846
1845
@@ -1902,7 +1901,7 @@ buildBuiltinLiteralArgs(SILGenFunction &SGF, SGFContext C,
1902
1901
RegexLiteralExpr *expr) {
1903
1902
auto &ctx = SGF.getASTContext ();
1904
1903
// %0 = string_literal <regex text>
1905
- auto strLiteralArgs = emitStringLiteral (SGF, expr, expr->getRegexText (), C,
1904
+ auto strLiteralArgs = emitStringLiteralArgs (SGF, expr, expr->getRegexText (), C,
1906
1905
StringLiteralExpr::Encoding::UTF8);
1907
1906
// %1 = function_ref String.init(
1908
1907
// _builtinStringLiteral:utf8CodeUnitCount:isASCII:)
@@ -1949,20 +1948,20 @@ buildBuiltinLiteralArgs(SILGenFunction &SGF, SGFContext C,
1949
1948
case MagicIdentifierLiteralExpr::FileIDSpelledAsFile:
1950
1949
case MagicIdentifierLiteralExpr::FileID: {
1951
1950
std::string value = loc.isValid () ? SGF.getMagicFileIDString (loc) : " " ;
1952
- return emitStringLiteral (SGF, magicLiteral, value, C,
1951
+ return emitStringLiteralArgs (SGF, magicLiteral, value, C,
1953
1952
magicLiteral->getStringEncoding ());
1954
1953
}
1955
1954
1956
1955
case MagicIdentifierLiteralExpr::FilePathSpelledAsFile:
1957
1956
case MagicIdentifierLiteralExpr::FilePath: {
1958
1957
StringRef value = loc.isValid () ? SGF.getMagicFilePathString (loc) : " " ;
1959
- return emitStringLiteral (SGF, magicLiteral, value, C,
1958
+ return emitStringLiteralArgs (SGF, magicLiteral, value, C,
1960
1959
magicLiteral->getStringEncoding ());
1961
1960
}
1962
1961
1963
1962
case MagicIdentifierLiteralExpr::Function: {
1964
1963
StringRef value = loc.isValid () ? SGF.getMagicFunctionString () : " " ;
1965
- return emitStringLiteral (SGF, magicLiteral, value, C,
1964
+ return emitStringLiteralArgs (SGF, magicLiteral, value, C,
1966
1965
magicLiteral->getStringEncoding ());
1967
1966
}
1968
1967
@@ -2012,6 +2011,24 @@ static inline PreparedArguments buildBuiltinLiteralArgs(SILGenFunction &SGF,
2012
2011
}
2013
2012
}
2014
2013
2014
+ ManagedValue SILGenFunction::emitStringLiteral (SILLocation loc,
2015
+ StringRef text,
2016
+ StringLiteralExpr::Encoding encoding,
2017
+ SGFContext ctx) {
2018
+ auto &C = getASTContext ();
2019
+
2020
+ // === Prepare the arguments
2021
+ auto args = emitStringLiteralArgs (*this , loc, text, ctx, encoding);
2022
+
2023
+ // === Find the constructor
2024
+ auto strInitDecl = C.getStringBuiltinInitDecl (C.getStringDecl ());
2025
+
2026
+ RValue r = emitApplyAllocatingInitializer (loc, strInitDecl, std::move (args),
2027
+ /* overriddenSelfType*/ Type (), ctx);
2028
+
2029
+ return std::move (r).getScalarValue ();
2030
+ }
2031
+
2015
2032
// ===----------------------------------------------------------------------===//
2016
2033
// Argument Emission
2017
2034
// ===----------------------------------------------------------------------===//
0 commit comments