@@ -67,7 +67,7 @@ extension Constant where Repr == Unsigned {
6767 ///
6868 /// - parameter type: The type to cast towards.
6969 ///
70- /// - returns: A const value representing this value cast to the given
70+ /// - returns: A const value representing this value cast to the given
7171 /// floating type.
7272 public func cast( to type: FloatType ) -> Constant < Floating > {
7373 let val = self . asLLVM ( )
@@ -99,7 +99,7 @@ extension Constant where Repr == Signed {
9999 ///
100100 /// - parameter type: The type to cast towards.
101101 ///
102- /// - returns: A const value representing this value cast to the given
102+ /// - returns: A const value representing this value cast to the given
103103 /// floating type.
104104 public func cast( to type: FloatType ) -> Constant < Floating > {
105105 let val = self . asLLVM ( )
@@ -131,7 +131,7 @@ extension Constant where Repr == Floating {
131131 ///
132132 /// - parameter type: The type to cast towards.
133133 ///
134- /// - returns: A const value representing this value cast to the given
134+ /// - returns: A const value representing this value cast to the given
135135 /// floating type.
136136 public func cast( to type: FloatType ) -> Constant < Floating > {
137137 let val = self . asLLVM ( )
@@ -350,7 +350,7 @@ extension Constant {
350350 return Constant < Signed > ( llvm: LLVMConstSub ( lhs. llvm, rhs. llvm) )
351351 }
352352 }
353-
353+
354354 /// Creates a constant sub operation to subtract two homogenous constants.
355355 ///
356356 /// - parameter lhs: The first value (the minuend).
@@ -508,7 +508,7 @@ extension Constant {
508508 /// - parameter lhs: The first value (the dividend).
509509 /// - parameter rhs: The second value (the divisor).
510510 ///
511- /// - returns: A constant value representing the quotient of the first and
511+ /// - returns: A constant value representing the quotient of the first and
512512 /// second operands.
513513 public static func divide( _ lhs: Constant < Unsigned > , _ rhs: Constant < Unsigned > ) -> Constant < Unsigned > {
514514 return Constant < Unsigned > ( llvm: LLVMConstUDiv ( lhs. llvm, rhs. llvm) )
@@ -520,7 +520,7 @@ extension Constant {
520520 /// - parameter lhs: The first value (the dividend).
521521 /// - parameter rhs: The second value (the divisor).
522522 ///
523- /// - returns: A constant value representing the quotient of the first and
523+ /// - returns: A constant value representing the quotient of the first and
524524 /// second operands.
525525 public static func divide( _ lhs: Constant < Signed > , _ rhs: Constant < Signed > ) -> Constant < Signed > {
526526 return Constant < Signed > ( llvm: LLVMConstSDiv ( lhs. llvm, rhs. llvm) )
@@ -532,7 +532,7 @@ extension Constant {
532532 /// - parameter lhs: The first value (the dividend).
533533 /// - parameter rhs: The second value (the divisor).
534534 ///
535- /// - returns: A constant value representing the quotient of the first and
535+ /// - returns: A constant value representing the quotient of the first and
536536 /// second operands.
537537 public static func divide( _ lhs: Constant < Floating > , _ rhs: Constant < Floating > ) -> Constant < Floating > {
538538 return Constant < Floating > ( llvm: LLVMConstFDiv ( lhs. llvm, rhs. llvm) )
@@ -546,9 +546,9 @@ extension Constant where Repr == Unsigned {
546546 ///
547547 /// - parameter rhs: The second value (the divisor).
548548 ///
549- /// - returns: A constant value representing the quotient of the first and
549+ /// - returns: A constant value representing the quotient of the first and
550550 /// second operands.
551- public func dividing( _ rhs: Constant ) -> Constant {
551+ public func dividing( by rhs: Constant ) -> Constant {
552552 return Constant . divide ( self , rhs)
553553 }
554554}
@@ -560,9 +560,9 @@ extension Constant where Repr == Signed {
560560 ///
561561 /// - parameter rhs: The second value (the divisor).
562562 ///
563- /// - returns: A constant value representing the quotient of the first and
563+ /// - returns: A constant value representing the quotient of the first and
564564 /// second operands.
565- public func dividing( _ rhs: Constant ) -> Constant {
565+ public func dividing( by rhs: Constant ) -> Constant {
566566 return Constant . divide ( self , rhs)
567567 }
568568}
@@ -574,9 +574,9 @@ extension Constant where Repr == Floating {
574574 ///
575575 /// - parameter rhs: The second value (the divisor).
576576 ///
577- /// - returns: A constant value representing the quotient of the first and
577+ /// - returns: A constant value representing the quotient of the first and
578578 /// second operands.
579- public func dividing( _ rhs: Constant ) -> Constant {
579+ public func dividing( by rhs: Constant ) -> Constant {
580580 return Constant . divide ( self , rhs)
581581 }
582582}
@@ -585,7 +585,7 @@ extension Constant where Repr == Floating {
585585
586586extension Constant {
587587
588- /// A constant remainder operation that provides the remainder after divison
588+ /// A constant remainder operation that provides the remainder after divison
589589 /// of the first value by the second value.
590590 ///
591591 /// - parameter lhs: The first value (the dividend).
@@ -597,7 +597,7 @@ extension Constant {
597597 return Constant < Unsigned > ( llvm: LLVMConstURem ( lhs. llvm, rhs. llvm) )
598598 }
599599
600- /// A constant remainder operation that provides the remainder after divison
600+ /// A constant remainder operation that provides the remainder after divison
601601 /// of the first value by the second value.
602602 ///
603603 /// - parameter lhs: The first value (the dividend).
@@ -673,7 +673,7 @@ extension Constant {
673673 /// - parameter lhs: The first value to compare.
674674 /// - parameter rhs: The second value to compare.
675675 ///
676- /// - returns: A constant integral value (i1) representing the result of the
676+ /// - returns: A constant integral value (i1) representing the result of the
677677 /// comparision of the given operands.
678678 public static func equals< T: NumericalConstantRepresentation > ( _ lhs: Constant < T > , _ rhs: Constant < T > ) -> Constant < Signed > {
679679
@@ -803,7 +803,7 @@ extension Constant {
803803 /// - parameter rhs: The second operand.
804804 /// - parameter name: The name for the newly inserted instruction.
805805 ///
806- /// - returns: A constant value representing the logical OR of the values of
806+ /// - returns: A constant value representing the logical OR of the values of
807807 /// the two given operands.
808808 public static func or< T: IntegralConstantRepresentation > ( _ lhs: Constant < T > , _ rhs: Constant < T > ) -> Constant < T > {
809809 return Constant < T > ( llvm: LLVMConstOr ( lhs. llvm, rhs. llvm) )
@@ -833,6 +833,18 @@ extension Constant {
833833 return Constant < T > ( llvm: LLVMConstShl ( lhs. llvm, rhs. llvm) )
834834 }
835835
836+ /// A constant right-shift of the first value by the second amount.
837+ ///
838+ /// - parameter lhs: The first operand.
839+ /// - parameter rhs: The second operand.
840+ /// - parameter arithmetic: Should the shift be arithmetic or logical (defaults to true)
841+ ///
842+ /// - returns: A constant value representing the value of the first operand
843+ /// shifted left by the number of bits specified in the second operand.
844+ public static func rightShift< T: IntegralConstantRepresentation > ( _ lhs: Constant < T > , _ rhs: Constant < T > , arithmetic: Bool = true ) -> Constant < T > {
845+ return Constant < T > ( llvm: arithmetic ? LLVMConstAShr ( lhs. llvm, rhs. llvm) : LLVMConstLShr ( lhs. llvm, rhs. llvm) )
846+ }
847+
836848
837849 // MARK: Conditional Operations
838850
@@ -861,3 +873,167 @@ extension Constant where Repr == Struct {
861873 }
862874 }
863875}
876+
877+
878+ // MARK: Swift Operators
879+
880+ extension Constant where Repr == Floating {
881+
882+ public static func + ( lhs: Constant , rhs: Constant ) -> Constant {
883+ return lhs. adding ( rhs)
884+ }
885+
886+ public static func - ( lhs: Constant , rhs: Constant ) -> Constant {
887+ return lhs. subtracting ( rhs)
888+ }
889+
890+ public static func * ( lhs: Constant , rhs: Constant ) -> Constant {
891+ return lhs. multiplying ( rhs)
892+ }
893+
894+ public static func / ( lhs: Constant , rhs: Constant ) -> Constant {
895+ return lhs. dividing ( by: rhs)
896+ }
897+
898+ public static func % ( lhs: Constant , rhs: Constant ) -> Constant {
899+ return lhs. remainder ( rhs)
900+ }
901+
902+ public static func == ( lhs: Constant , rhs: Constant ) -> Constant < Signed > {
903+ return Constant . equals ( lhs, rhs)
904+ }
905+
906+ public static func < ( lhs: Constant , rhs: Constant ) -> Constant < Signed > {
907+ return Constant . lessThan ( lhs, rhs)
908+ }
909+
910+ public static func > ( lhs: Constant , rhs: Constant ) -> Constant < Signed > {
911+ return Constant . greaterThan ( lhs, rhs)
912+ }
913+
914+ public static func <= ( lhs: Constant , rhs: Constant ) -> Constant < Signed > {
915+ return Constant . lessThanOrEqual ( lhs, rhs)
916+ }
917+
918+ public static func >= ( lhs: Constant , rhs: Constant ) -> Constant < Signed > {
919+ return Constant . greaterThanOrEqual ( lhs, rhs)
920+ }
921+ }
922+
923+ extension Constant where Repr == Signed {
924+
925+ public static func + ( lhs: Constant , rhs: Constant ) -> Constant {
926+ return lhs. adding ( rhs)
927+ }
928+
929+ public static func - ( lhs: Constant , rhs: Constant ) -> Constant {
930+ return lhs. subtracting ( rhs)
931+ }
932+
933+ public static func * ( lhs: Constant , rhs: Constant ) -> Constant {
934+ return lhs. multiplying ( rhs)
935+ }
936+
937+ public static func / ( lhs: Constant , rhs: Constant ) -> Constant {
938+ return lhs. dividing ( by: rhs)
939+ }
940+
941+ public static func % ( lhs: Constant , rhs: Constant ) -> Constant {
942+ return lhs. remainder ( rhs)
943+ }
944+
945+ public static func == ( lhs: Constant , rhs: Constant ) -> Constant {
946+ return Constant . equals ( lhs, rhs)
947+ }
948+
949+ public static func < ( lhs: Constant , rhs: Constant ) -> Constant {
950+ return Constant . lessThan ( lhs, rhs)
951+ }
952+
953+ public static func > ( lhs: Constant , rhs: Constant ) -> Constant {
954+ return Constant . greaterThan ( lhs, rhs)
955+ }
956+
957+ public static func <= ( lhs: Constant , rhs: Constant ) -> Constant {
958+ return Constant . lessThanOrEqual ( lhs, rhs)
959+ }
960+
961+ public static func >= ( lhs: Constant , rhs: Constant ) -> Constant {
962+ return Constant . greaterThanOrEqual ( lhs, rhs)
963+ }
964+
965+ public static func |( lhs: Constant , rhs: Constant ) -> Constant {
966+ return Constant . or ( lhs, rhs)
967+ }
968+
969+ public static func & ( lhs: Constant , rhs: Constant ) -> Constant {
970+ return Constant . and ( lhs, rhs)
971+ }
972+
973+ public static func <<( lhs: Constant , rhs: Constant ) -> Constant {
974+ return Constant . leftShift ( lhs, rhs)
975+ }
976+
977+ public static func >>( lhs: Constant , rhs: Constant ) -> Constant {
978+ return Constant . rightShift ( lhs, rhs)
979+ }
980+ }
981+
982+ extension Constant where Repr == Unsigned {
983+
984+ public static func + ( lhs: Constant , rhs: Constant ) -> Constant {
985+ return lhs. adding ( rhs)
986+ }
987+
988+ public static func - ( lhs: Constant , rhs: Constant ) -> Constant {
989+ return lhs. subtracting ( rhs)
990+ }
991+
992+ public static func * ( lhs: Constant , rhs: Constant ) -> Constant {
993+ return lhs. multiplying ( rhs)
994+ }
995+
996+ public static func / ( lhs: Constant , rhs: Constant ) -> Constant {
997+ return lhs. dividing ( by: rhs)
998+ }
999+
1000+ public static func % ( lhs: Constant , rhs: Constant ) -> Constant {
1001+ return lhs. remainder ( rhs)
1002+ }
1003+
1004+ public static func == ( lhs: Constant , rhs: Constant ) -> Constant < Signed > {
1005+ return Constant . equals ( lhs, rhs)
1006+ }
1007+
1008+ public static func < ( lhs: Constant , rhs: Constant ) -> Constant < Signed > {
1009+ return Constant . lessThan ( lhs, rhs)
1010+ }
1011+
1012+ public static func > ( lhs: Constant , rhs: Constant ) -> Constant < Signed > {
1013+ return Constant . greaterThan ( lhs, rhs)
1014+ }
1015+
1016+ public static func <= ( lhs: Constant , rhs: Constant ) -> Constant < Signed > {
1017+ return Constant . lessThanOrEqual ( lhs, rhs)
1018+ }
1019+
1020+ public static func >= ( lhs: Constant , rhs: Constant ) -> Constant < Signed > {
1021+ return Constant . greaterThanOrEqual ( lhs, rhs)
1022+ }
1023+
1024+ public static func |( lhs: Constant , rhs: Constant ) -> Constant {
1025+ return Constant . or ( lhs, rhs)
1026+ }
1027+
1028+ public static func & ( lhs: Constant , rhs: Constant ) -> Constant {
1029+ return Constant . and ( lhs, rhs)
1030+ }
1031+
1032+ public static func <<( lhs: Constant , rhs: Constant ) -> Constant {
1033+ return Constant . leftShift ( lhs, rhs)
1034+ }
1035+
1036+ public static func >>( lhs: Constant , rhs: Constant ) -> Constant {
1037+ return Constant . rightShift ( lhs, rhs)
1038+ }
1039+ }
0 commit comments