@@ -102,6 +102,13 @@ public enum BuiltinFunction: Hashable {
102102
103103 case ptrtoint( BuiltinType )
104104
105+ /// Truncates/extends from the given C integer type to the given built-in integer type.
106+ case fromcint( cIntType: BuiltinCNumericType , targetType: BuiltinType )
107+
108+ /// Truncates/extends from the given Hylo integer type to the given C type.
109+ case tocint(
110+ hyloIntegerType: BuiltinType , targetCType: BuiltinCNumericType , sourceTypeSigned: Bool )
111+
105112 case fadd( MathFlags , BuiltinType )
106113
107114 case fsub( MathFlags , BuiltinType )
@@ -371,7 +378,6 @@ public enum BuiltinFunction: Hashable {
371378
372379 case atomic_singlethreadfence_seqcst
373380
374-
375381 /// A set of customizations to the behavior of floating point operations.
376382 ///
377383 /// The meaning of each customization is given by the LLVM option of the same name.
@@ -481,6 +487,10 @@ extension BuiltinFunction {
481487 return . init( ^t, to: . builtin( . ptr) )
482488 case . ptrtoint( let t) :
483489 return . init( . builtin( . ptr) , to: ^t)
490+ case . fromcint( let cIntType, let targetType) :
491+ return . init( . builtin( . cNumeric( cIntType) ) , to: . builtin( targetType) )
492+ case . tocint( let hyloIntegerType, let targetCType, _) :
493+ return . init( . builtin( hyloIntegerType) , to: . builtin( . cNumeric( targetCType) ) )
484494 case . fadd( _, let t) :
485495 return . init( ^t, ^t, to: ^t)
486496 case . fsub( _, let t) :
@@ -818,6 +828,11 @@ extension BuiltinFunction: CustomStringConvertible {
818828 return " inttoptr_ \( t) "
819829 case . ptrtoint( let t) :
820830 return " ptrtoint_ \( t) "
831+ case . fromcint( let cIntType, let targetType) :
832+ return " fromcint_ \( cIntType) _ \( targetType) "
833+ case . tocint( let hyloIntegerType, let targtCIntType, let isSigned) :
834+ let signed = isSigned ? " s " : " u "
835+ return " tocint_ \( signed) _ \( hyloIntegerType) _ \( targtCIntType) "
821836 case . fadd( let f, let t) :
822837 return f. isEmpty ? " fadd_ \( t) " : " fadd_ \( f) _ \( t) "
823838 case . fsub( let f, let t) :
@@ -1109,7 +1124,6 @@ extension BuiltinFunction.MathFlags: CustomStringConvertible {
11091124
11101125}
11111126
1112-
11131127// MARK: Parsing
11141128
11151129extension BuiltinFunction {
@@ -1243,6 +1257,36 @@ extension BuiltinFunction {
12431257 guard let t = builtinType ( & tokens) else { return nil }
12441258 self = . ptrtoint( t)
12451259
1260+ case " fromcint " :
1261+ guard
1262+ let fromCType = builtinType ( & tokens) ,
1263+ case . cNumeric( let cIntType) = fromCType,
1264+ cIntType. isInteger
1265+ else { return nil }
1266+
1267+ guard let targetIntType = builtinType ( & tokens) , targetIntType. isInteger
1268+ else { return nil }
1269+
1270+ self = . fromcint( cIntType: cIntType, targetType: targetIntType)
1271+
1272+ case " tocint " :
1273+ guard let isSized = tokens. popFirst ( ) ,
1274+ isSized == " u " || isSized == " s "
1275+ else { return nil }
1276+
1277+ guard
1278+ let fromType = builtinType ( & tokens) ,
1279+ fromType. isInteger
1280+ else { return nil }
1281+
1282+ guard let targetType = builtinType ( & tokens) ,
1283+ case . cNumeric( let cIntType) = targetType,
1284+ cIntType. isInteger
1285+ else { return nil }
1286+
1287+ self = . tocint(
1288+ hyloIntegerType: fromType, targetCType: cIntType, sourceTypeSigned: isSized == " s " )
1289+
12461290 case " fadd " :
12471291 guard let ( p, t) = floatingPointArithmeticTail ( & tokens) else { return nil }
12481292 self = . fadd( p, t)
0 commit comments