prettifying Cmm: print MachOps as identifiers by replacing ' ' with '_'
[ghc-hetmet.git] / compiler / cmm / PprCmm.hs
index 6321410..cb2adf7 100644 (file)
@@ -292,6 +292,8 @@ infixMachOp1 (MO_U_Lt   _) = Just (char '<')
 infixMachOp1 _             = Nothing
 
 -- %left '-' '+'
+pprExpr7 (CmmMachOp (MO_Add rep1) [x, CmmLit (CmmInt i rep2)]) | i < 0
+   = pprExpr7 (CmmMachOp (MO_Sub rep1) [x, CmmLit (CmmInt (negate i) rep2)])
 pprExpr7 (CmmMachOp op [x,y]) | Just doc <- infixMachOp7 op
    = pprExpr7 x <+> doc <+> pprExpr8 y
 pprExpr7 e = pprExpr8 e
@@ -337,7 +339,10 @@ genMachOp mop args
    || isJust (infixMachOp7 mop)
    || isJust (infixMachOp8 mop)         = parens (pprExpr (CmmMachOp mop args))
 
-   | otherwise = char '%' <> pprMachOp mop <> parens (commafy (map pprExpr args))
+   | otherwise = char '%' <> ppr_op <> parens (commafy (map pprExpr args))
+        where ppr_op = text (map (\c -> if c == ' ' then '_' else c)
+                                 (show mop))
+                -- replace spaces in (show mop) with underscores,
 
 --
 -- Unsigned ops on the word size of the machine get nice symbols.