Skip to content

Commit d0695fc

Browse files
committed
[SILGen] Factor out logic to create version literals. NFC.
Factor out a helper to create version literals for llvm::VersionTuple components.
1 parent c6ee1b3 commit d0695fc

File tree

1 file changed

+21
-8
lines changed

1 file changed

+21
-8
lines changed

lib/SILGen/SILGenDecl.cpp

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1194,25 +1194,38 @@ void SILGenFunction::visitVarDecl(VarDecl *D) {
11941194
// We handle emitting the variable storage when we see the pattern binding.
11951195
}
11961196

1197-
/// Emit a check that returns 1 if the running OS version is in
1198-
/// the specified version range and 0 otherwise. The returned SILValue
1199-
/// (which has type Builtin.Int1) represents the result of this check.
1200-
SILValue SILGenFunction::emitOSVersionRangeCheck(SILLocation loc,
1201-
const VersionRange &range) {
1202-
// Emit constants for the checked version range.
1203-
llvm::VersionTuple Vers = range.getLowerEndpoint();
1197+
/// Emit literals for the major, minor, and subminor components of the version
1198+
/// and return a tuple of SILValues for them.
1199+
static std::tuple<SILValue, SILValue, SILValue>
1200+
emitVersionLiterals(SILLocation loc, SILGenBuilder &B, ASTContext &ctx,
1201+
llvm::VersionTuple Vers) {
12041202
unsigned major = Vers.getMajor();
12051203
unsigned minor =
12061204
(Vers.getMinor().hasValue() ? Vers.getMinor().getValue() : 0);
12071205
unsigned subminor =
12081206
(Vers.getSubminor().hasValue() ? Vers.getSubminor().getValue() : 0);
12091207

1210-
SILType wordType = SILType::getBuiltinWordType(getASTContext());
1208+
SILType wordType = SILType::getBuiltinWordType(ctx);
12111209

12121210
SILValue majorValue = B.createIntegerLiteral(loc, wordType, major);
12131211
SILValue minorValue = B.createIntegerLiteral(loc, wordType, minor);
12141212
SILValue subminorValue = B.createIntegerLiteral(loc, wordType, subminor);
12151213

1214+
return std::make_tuple(majorValue, minorValue, subminorValue);
1215+
}
1216+
1217+
/// Emit a check that returns 1 if the running OS version is in
1218+
/// the specified version range and 0 otherwise. The returned SILValue
1219+
/// (which has type Builtin.Int1) represents the result of this check.
1220+
SILValue SILGenFunction::emitOSVersionRangeCheck(SILLocation loc,
1221+
const VersionRange &range) {
1222+
// Emit constants for the checked version range.
1223+
SILValue majorValue;
1224+
SILValue minorValue;
1225+
SILValue subminorValue;
1226+
std::tie(majorValue, minorValue, subminorValue) =
1227+
emitVersionLiterals(loc, B, getASTContext(), range.getLowerEndpoint());
1228+
12161229
// Emit call to _stdlib_isOSVersionAtLeast(major, minor, patch)
12171230
FuncDecl *versionQueryDecl =
12181231
getASTContext().getIsOSVersionAtLeastDecl();

0 commit comments

Comments
 (0)