[add primitive optimizations dealing with conversion operators
John Meacham <john@repetae.net>**20070531050142] hunk ./C/FromGrin2.hs 200
-        (Op.BitsArch Op.BitsInt) -> "unsigned"
hunk ./C/FromGrin2.hs 204
-        (Op.BitsArch Op.BitsInt) -> "int"
hunk ./C/Op.hs 58
-    | Not
hunk ./C/Op.hs 149
-data ArchBits = BitsInt | BitsMax | BitsPtr
+data ArchBits = BitsMax | BitsPtr
hunk ./C/Op.hs 176
-readTy "bits<int>" = return $ TyBits (BitsArch BitsInt) HintNone
hunk ./C/Op.hs 187
-bits_int = TyBits (BitsArch BitsInt) HintNone
hunk ./C/Op.hs 209
-    show BitsInt = "int"
hunk ./C/Op.hs 256
+    f FEq  = True
+    f FNEq = True
+    f FOrdered = True
hunk ./C/Op.hs 261
+commuteBinOp :: BinOp -> Maybe BinOp
+commuteBinOp x | isCommutable x = return x
+commuteBinOp Lt = return Gte
+commuteBinOp Gt = return Lte
+commuteBinOp Lte = return Gt
+commuteBinOp Gte = return Lt
+commuteBinOp ULt = return UGte
+commuteBinOp UGt = return ULte
+commuteBinOp ULte = return UGt
+commuteBinOp UGte = return ULt
+commuteBinOp FLt = return FGte
+commuteBinOp FGt = return FLte
+commuteBinOp FLte = return FGt
+commuteBinOp FGte = return FLt
+commuteBinOp _ = Nothing
+
hunk ./C/Op.hs 339
+    isEagerSafe (ConvOp o _) = isEagerSafe o
hunk ./E/PrimOpt.hs 16
+import C.OpEval
hunk ./E/PrimOpt.hs 53
-intt = rawType "int"
hunk ./E/PrimOpt.hs 54
-rawMap = Map.fromList [ (rawType w,toAtom t) | (_,_,_,w,t) <- allCTypes]
-typ_float = toAtom "float"
hunk ./E/PrimOpt.hs 55
+cextra Op {} [] = ""
+cextra Op {} xs = '.':map f xs where
+    f ELit {} = 'c'
+    f _ = 'e'
+cextra _ _ = ""
+
+primConv cop t1 t2 e rt = EPrim (APrim (Op (Op.ConvOp cop t1) t2) mempty) [e] rt
hunk ./E/PrimOpt.hs 63
-iTrue = (ELit (LitInt 1 intt))
-iFalse = (ELit (LitInt 0 intt))
-isIntegral t = Map.lookup t rawMap /= Just typ_float
+primOpt' dataTable  e@(EPrim (APrim s _) xs t) = do
+    let --primopt (Op (Op.BinOp bop _ _) _) [e1,e2] rt = binOp bop e1 e2
+        primopt (Op (Op.ConvOp cop t1) t2) [ELit (LitInt n t)] rt = return $ ELit (LitInt (convNumber cop t1 t2 n) rt)
+        primopt (Op (Op.ConvOp cop t1) t2) [e1] rt = case convOp cop t1 t2 of
+            Nothing | getType e1 == rt -> return e1
+            Just cop' | cop' /= cop -> return $ primConv cop' t1 t2 e1 rt
+            _ -> fail "could not apply conversion optimization"
+        primopt _ _ _ = fail "No Primitive optimization to apply"
+    case primopt s xs t of
+        Just n -> do
+            mtick (toAtom $ "E.PrimOpt." ++ braces (pprint s) ++ cextra s xs )
+            primOpt' dataTable  n
+        Nothing -> return e
+primOpt' _ e = return e
+
+--instance Expression t E where
+--    toBool True = ELit lTruezh
+--    toBool False = ELit lFalse
+--    createBinOp bop e1 e2 =
+--                (EPrim (APrim Op { primCOp = Op.BinOp cop (stringToOpTy ta) (stringToOpTy tb), primRetTy = (stringToOpTy tr) } mempty) [pa, pb] str) t
hunk ./E/PrimOpt.hs 84
-primOpt' _  x = return x
hunk ./E/PrimOpt.hs 86
-cextra Operator {} [] = ""
-cextra Operator {} xs = '.':map f xs where
-    f ELit {} = 'c'
-    f _ = 'e'
-cextra _ _ = ""