- rule_name = occNameFS (primOpOcc op)
- rule_name_case = rule_name `appendFS` FSLIT("->case")
-
- -- A useful shorthand
- one_rule rule_fn = [BuiltinRule { ru_name = rule_name,
- ru_fn = op_name,
- ru_try = rule_fn }]
- case_rule rule_fn = [BuiltinRule { ru_name = rule_name_case,
- ru_fn = op_name,
- ru_try = rule_fn }]
-
- -- ToDo: something for integer-shift ops?
- -- NotOp
-
- primop_rule TagToEnumOp = one_rule tagToEnumRule
- primop_rule DataToTagOp = one_rule dataToTagRule
-
- -- Int operations
- primop_rule IntAddOp = one_rule (twoLits (intOp2 (+)))
- primop_rule IntSubOp = one_rule (twoLits (intOp2 (-)))
- primop_rule IntMulOp = one_rule (twoLits (intOp2 (*)))
- primop_rule IntQuotOp = one_rule (twoLits (intOp2Z quot))
- primop_rule IntRemOp = one_rule (twoLits (intOp2Z rem))
- primop_rule IntNegOp = one_rule (oneLit negOp)
-
- -- Word operations
-#if __GLASGOW_HASKELL__ >= 500
- primop_rule WordAddOp = one_rule (twoLits (wordOp2 (+)))
- primop_rule WordSubOp = one_rule (twoLits (wordOp2 (-)))
- primop_rule WordMulOp = one_rule (twoLits (wordOp2 (*)))
-#endif
- primop_rule WordQuotOp = one_rule (twoLits (wordOp2Z quot))
- primop_rule WordRemOp = one_rule (twoLits (wordOp2Z rem))
-#if __GLASGOW_HASKELL__ >= 407
- primop_rule AndOp = one_rule (twoLits (wordBitOp2 (.&.)))
- primop_rule OrOp = one_rule (twoLits (wordBitOp2 (.|.)))
- primop_rule XorOp = one_rule (twoLits (wordBitOp2 xor))
-#endif
-
- -- coercions
- primop_rule Word2IntOp = one_rule (oneLit (litCoerce word2IntLit))
- primop_rule Int2WordOp = one_rule (oneLit (litCoerce int2WordLit))
- primop_rule Narrow8IntOp = one_rule (oneLit (litCoerce narrow8IntLit))
- primop_rule Narrow16IntOp = one_rule (oneLit (litCoerce narrow16IntLit))
- primop_rule Narrow32IntOp = one_rule (oneLit (litCoerce narrow32IntLit))
- primop_rule Narrow8WordOp = one_rule (oneLit (litCoerce narrow8WordLit))
- primop_rule Narrow16WordOp = one_rule (oneLit (litCoerce narrow16WordLit))
- primop_rule Narrow32WordOp = one_rule (oneLit (litCoerce narrow32WordLit))
- primop_rule OrdOp = one_rule (oneLit (litCoerce char2IntLit))
- primop_rule ChrOp = one_rule (oneLit (litCoerce int2CharLit))
- primop_rule Float2IntOp = one_rule (oneLit (litCoerce float2IntLit))
- primop_rule Int2FloatOp = one_rule (oneLit (litCoerce int2FloatLit))
- primop_rule Double2IntOp = one_rule (oneLit (litCoerce double2IntLit))
- primop_rule Int2DoubleOp = one_rule (oneLit (litCoerce int2DoubleLit))
- -- SUP: Not sure what the standard says about precision in the following 2 cases
- primop_rule Float2DoubleOp = one_rule (oneLit (litCoerce float2DoubleLit))
- primop_rule Double2FloatOp = one_rule (oneLit (litCoerce double2FloatLit))
-
- -- Float
- primop_rule FloatAddOp = one_rule (twoLits (floatOp2 (+)))
- primop_rule FloatSubOp = one_rule (twoLits (floatOp2 (-)))
- primop_rule FloatMulOp = one_rule (twoLits (floatOp2 (*)))
- primop_rule FloatDivOp = one_rule (twoLits (floatOp2Z (/)))
- primop_rule FloatNegOp = one_rule (oneLit negOp)
-
- -- Double
- primop_rule DoubleAddOp = one_rule (twoLits (doubleOp2 (+)))
- primop_rule DoubleSubOp = one_rule (twoLits (doubleOp2 (-)))
- primop_rule DoubleMulOp = one_rule (twoLits (doubleOp2 (*)))
- primop_rule DoubleDivOp = one_rule (twoLits (doubleOp2Z (/)))
- primop_rule DoubleNegOp = one_rule (oneLit negOp)
-
- -- Relational operators
- primop_rule IntEqOp = one_rule (relop (==)) ++ case_rule (litEq True)
- primop_rule IntNeOp = one_rule (relop (/=)) ++ case_rule (litEq False)
- primop_rule CharEqOp = one_rule (relop (==)) ++ case_rule (litEq True)
- primop_rule CharNeOp = one_rule (relop (/=)) ++ case_rule (litEq False)
-
- primop_rule IntGtOp = one_rule (relop (>))
- primop_rule IntGeOp = one_rule (relop (>=))
- primop_rule IntLeOp = one_rule (relop (<=))
- primop_rule IntLtOp = one_rule (relop (<))
-
- primop_rule CharGtOp = one_rule (relop (>))
- primop_rule CharGeOp = one_rule (relop (>=))
- primop_rule CharLeOp = one_rule (relop (<=))
- primop_rule CharLtOp = one_rule (relop (<))
-
- primop_rule FloatGtOp = one_rule (relop (>))
- primop_rule FloatGeOp = one_rule (relop (>=))
- primop_rule FloatLeOp = one_rule (relop (<=))
- primop_rule FloatLtOp = one_rule (relop (<))
- primop_rule FloatEqOp = one_rule (relop (==))
- primop_rule FloatNeOp = one_rule (relop (/=))
-
- primop_rule DoubleGtOp = one_rule (relop (>))
- primop_rule DoubleGeOp = one_rule (relop (>=))
- primop_rule DoubleLeOp = one_rule (relop (<=))
- primop_rule DoubleLtOp = one_rule (relop (<))
- primop_rule DoubleEqOp = one_rule (relop (==))
- primop_rule DoubleNeOp = one_rule (relop (/=))
-
- primop_rule WordGtOp = one_rule (relop (>))
- primop_rule WordGeOp = one_rule (relop (>=))
- primop_rule WordLeOp = one_rule (relop (<=))
- primop_rule WordLtOp = one_rule (relop (<))
- primop_rule WordEqOp = one_rule (relop (==))
- primop_rule WordNeOp = one_rule (relop (/=))
-
- primop_rule other = []
-
-
- relop cmp = twoLits (cmpOp (\ord -> ord `cmp` EQ))
- -- Cunning. cmpOp compares the values to give an Ordering.
- -- It applies its argument to that ordering value to turn
- -- the ordering into a boolean value. (`cmp` EQ) is just the job.
+ -- A useful shorthand
+ one_lit = oneLit op_name
+ two_lits = twoLits op_name
+ relop cmp = two_lits (cmpOp (\ord -> ord `cmp` EQ))
+ -- Cunning. cmpOp compares the values to give an Ordering.
+ -- It applies its argument to that ordering value to turn
+ -- the ordering into a boolean value. (`cmp` EQ) is just the job.
+
+ -- ToDo: something for integer-shift ops?
+ -- NotOp
+
+ primop_rule TagToEnumOp = mkBasicRule op_name 2 tagToEnumRule
+ primop_rule DataToTagOp = mkBasicRule op_name 2 dataToTagRule
+
+ -- Int operations
+ primop_rule IntAddOp = two_lits (intOp2 (+))
+ primop_rule IntSubOp = two_lits (intOp2 (-))
+ primop_rule IntMulOp = two_lits (intOp2 (*))
+ primop_rule IntQuotOp = two_lits (intOp2Z quot)
+ primop_rule IntRemOp = two_lits (intOp2Z rem)
+ primop_rule IntNegOp = one_lit negOp
+ primop_rule ISllOp = two_lits (intShiftOp2 Bits.shiftL)
+ primop_rule ISraOp = two_lits (intShiftOp2 Bits.shiftR)
+ primop_rule ISrlOp = two_lits (intShiftOp2 shiftRightLogical)
+
+ -- Word operations
+ primop_rule WordAddOp = two_lits (wordOp2 (+))
+ primop_rule WordSubOp = two_lits (wordOp2 (-))
+ primop_rule WordMulOp = two_lits (wordOp2 (*))
+ primop_rule WordQuotOp = two_lits (wordOp2Z quot)
+ primop_rule WordRemOp = two_lits (wordOp2Z rem)
+ primop_rule AndOp = two_lits (wordBitOp2 (.&.))
+ primop_rule OrOp = two_lits (wordBitOp2 (.|.))
+ primop_rule XorOp = two_lits (wordBitOp2 xor)
+ primop_rule SllOp = two_lits (wordShiftOp2 Bits.shiftL)
+ primop_rule SrlOp = two_lits (wordShiftOp2 shiftRightLogical)
+
+ -- coercions
+ primop_rule Word2IntOp = one_lit (litCoerce word2IntLit)
+ primop_rule Int2WordOp = one_lit (litCoerce int2WordLit)
+ primop_rule Narrow8IntOp = one_lit (litCoerce narrow8IntLit)
+ primop_rule Narrow16IntOp = one_lit (litCoerce narrow16IntLit)
+ primop_rule Narrow32IntOp = one_lit (litCoerce narrow32IntLit)
+ primop_rule Narrow8WordOp = one_lit (litCoerce narrow8WordLit)
+ primop_rule Narrow16WordOp = one_lit (litCoerce narrow16WordLit)
+ primop_rule Narrow32WordOp = one_lit (litCoerce narrow32WordLit)
+ primop_rule OrdOp = one_lit (litCoerce char2IntLit)
+ primop_rule ChrOp = one_lit (predLitCoerce litFitsInChar int2CharLit)
+ primop_rule Float2IntOp = one_lit (litCoerce float2IntLit)
+ primop_rule Int2FloatOp = one_lit (litCoerce int2FloatLit)
+ primop_rule Double2IntOp = one_lit (litCoerce double2IntLit)
+ primop_rule Int2DoubleOp = one_lit (litCoerce int2DoubleLit)
+ -- SUP: Not sure what the standard says about precision in the following 2 cases
+ primop_rule Float2DoubleOp = one_lit (litCoerce float2DoubleLit)
+ primop_rule Double2FloatOp = one_lit (litCoerce double2FloatLit)
+
+ -- Float
+ primop_rule FloatAddOp = two_lits (floatOp2 (+))
+ primop_rule FloatSubOp = two_lits (floatOp2 (-))
+ primop_rule FloatMulOp = two_lits (floatOp2 (*))
+ primop_rule FloatDivOp = two_lits (floatOp2Z (/))
+ primop_rule FloatNegOp = one_lit negOp
+
+ -- Double
+ primop_rule DoubleAddOp = two_lits (doubleOp2 (+))
+ primop_rule DoubleSubOp = two_lits (doubleOp2 (-))
+ primop_rule DoubleMulOp = two_lits (doubleOp2 (*))
+ primop_rule DoubleDivOp = two_lits (doubleOp2Z (/))
+ primop_rule DoubleNegOp = one_lit negOp
+
+ -- Relational operators
+ primop_rule IntEqOp = relop (==) ++ litEq op_name True
+ primop_rule IntNeOp = relop (/=) ++ litEq op_name False
+ primop_rule CharEqOp = relop (==) ++ litEq op_name True
+ primop_rule CharNeOp = relop (/=) ++ litEq op_name False
+
+ primop_rule IntGtOp = relop (>) ++ boundsCmp op_name Gt
+ primop_rule IntGeOp = relop (>=) ++ boundsCmp op_name Ge
+ primop_rule IntLeOp = relop (<=) ++ boundsCmp op_name Le
+ primop_rule IntLtOp = relop (<) ++ boundsCmp op_name Lt
+
+ primop_rule CharGtOp = relop (>) ++ boundsCmp op_name Gt
+ primop_rule CharGeOp = relop (>=) ++ boundsCmp op_name Ge
+ primop_rule CharLeOp = relop (<=) ++ boundsCmp op_name Le
+ primop_rule CharLtOp = relop (<) ++ boundsCmp op_name Lt
+
+ primop_rule FloatGtOp = relop (>)
+ primop_rule FloatGeOp = relop (>=)
+ primop_rule FloatLeOp = relop (<=)
+ primop_rule FloatLtOp = relop (<)
+ primop_rule FloatEqOp = relop (==)
+ primop_rule FloatNeOp = relop (/=)
+
+ primop_rule DoubleGtOp = relop (>)
+ primop_rule DoubleGeOp = relop (>=)
+ primop_rule DoubleLeOp = relop (<=)
+ primop_rule DoubleLtOp = relop (<)
+ primop_rule DoubleEqOp = relop (==)
+ primop_rule DoubleNeOp = relop (/=)
+
+ primop_rule WordGtOp = relop (>) ++ boundsCmp op_name Gt
+ primop_rule WordGeOp = relop (>=) ++ boundsCmp op_name Ge
+ primop_rule WordLeOp = relop (<=) ++ boundsCmp op_name Le
+ primop_rule WordLtOp = relop (<) ++ boundsCmp op_name Lt
+ primop_rule WordEqOp = relop (==)
+ primop_rule WordNeOp = relop (/=)
+
+ primop_rule _ = []
+
+