|
2 | 2 | // |
3 | 3 | // This source file is part of the Swift.org open source project |
4 | 4 | // |
5 | | -// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors |
| 5 | +// Copyright (c) 2014 - 2022 Apple Inc. and the Swift project authors |
6 | 6 | // Licensed under Apache License v2.0 with Runtime Library Exception |
7 | 7 | // |
8 | 8 | // See https://swift.org/LICENSE.txt for license information |
@@ -1796,6 +1796,33 @@ static ValueDecl *getIntToFPWithOverflowOperation(ASTContext &Context, |
1796 | 1796 | return getBuiltinFunction(Id, { InTy }, OutTy); |
1797 | 1797 | } |
1798 | 1798 |
|
| 1799 | +static ValueDecl *getBitWidthOperation( |
| 1800 | + ASTContext &ctx, |
| 1801 | + Identifier id, |
| 1802 | + Type valueTy |
| 1803 | +) { |
| 1804 | + if (!valueTy->getAs<BuiltinIntegerLiteralType>()) return nullptr; |
| 1805 | + return getBuiltinFunction(ctx, id, _thin, _parameters(valueTy), _word); |
| 1806 | +} |
| 1807 | + |
| 1808 | +static ValueDecl *getIsNegativeOperation( |
| 1809 | + ASTContext &ctx, |
| 1810 | + Identifier id, |
| 1811 | + Type valueTy |
| 1812 | +) { |
| 1813 | + if (!valueTy->getAs<BuiltinIntegerLiteralType>()) return nullptr; |
| 1814 | + return getBuiltinFunction(ctx, id, _thin, _parameters(valueTy), _int(1)); |
| 1815 | +} |
| 1816 | + |
| 1817 | +static ValueDecl *getWordAtIndexOperation( |
| 1818 | + ASTContext &ctx, |
| 1819 | + Identifier id, |
| 1820 | + Type valueTy |
| 1821 | +) { |
| 1822 | + if (!valueTy->getAs<BuiltinIntegerLiteralType>()) return nullptr; |
| 1823 | + return getBuiltinFunction(ctx, id, _thin, _parameters(valueTy, _word), _word); |
| 1824 | +} |
| 1825 | + |
1799 | 1826 | static ValueDecl *getUnreachableOperation(ASTContext &Context, |
1800 | 1827 | Identifier Id) { |
1801 | 1828 | auto NeverTy = Context.getNeverType(); |
@@ -2781,6 +2808,18 @@ ValueDecl *swift::getBuiltinValueDecl(ASTContext &Context, Identifier Id) { |
2781 | 2808 | if (Types.size() != 2) return nullptr; |
2782 | 2809 | return getIntToFPWithOverflowOperation(Context, Id, Types[0], Types[1]); |
2783 | 2810 |
|
| 2811 | + case BuiltinValueKind::BitWidth: |
| 2812 | + if (Types.size() != 1) return nullptr; |
| 2813 | + return getBitWidthOperation(Context, Id, Types[0]); |
| 2814 | + |
| 2815 | + case BuiltinValueKind::IsNegative: |
| 2816 | + if (Types.size() != 1) return nullptr; |
| 2817 | + return getIsNegativeOperation(Context, Id, Types[0]); |
| 2818 | + |
| 2819 | + case BuiltinValueKind::WordAtIndex: |
| 2820 | + if (Types.size() != 1) return nullptr; |
| 2821 | + return getWordAtIndexOperation(Context, Id, Types[0]); |
| 2822 | + |
2784 | 2823 | case BuiltinValueKind::GetObjCTypeEncoding: |
2785 | 2824 | return getGetObjCTypeEncodingOperation(Context, Id); |
2786 | 2825 |
|
|
0 commit comments