Fix big character literal printing in External Core
[ghc-hetmet.git] / compiler / coreSyn / MkExternalCore.lhs
index 1dc3b7e..3e8a989 100644 (file)
@@ -25,12 +25,15 @@ import Name
 import NameSet
 import UniqSet
 import Outputable
+import Encoding
 import ForeignCall
 import DynFlags
 import StaticFlags
 import IO
 import FastString
 
+import Data.Char
+
 emitExternalCore :: DynFlags -> NameSet -> CgGuts -> IO ()
 emitExternalCore dflags exports cg_guts
  | opt_EmitExternalCore 
@@ -159,7 +162,12 @@ make_alt a@(DEFAULT,_ ,_) = pprPanic ("MkExternalCore: make_alt: DEFAULT "
 make_lit :: Literal -> C.Lit
 make_lit l = 
   case l of
-    MachChar i -> C.Lchar i t
+    -- Note that we need to check whether the character is "big".
+    -- External Core only allows character literals up to '\xff'.
+    MachChar i | i <= chr 0xff -> C.Lchar i t
+    -- For a character bigger than 0xff, we represent it in ext-core
+    -- as an int lit with a char type.
+    MachChar i             -> C.Lint (fromIntegral $ ord i) t 
     MachStr s -> C.Lstring (unpackFS s) t
     MachNullAddr -> C.Lint 0 t
     MachInt i -> C.Lint i t
@@ -219,13 +227,16 @@ make_var_id = make_id True
 -- *do* want to keep the package name (we don't want baseZCGHCziBase,
 -- because that would just be ugly.)
 -- SIGH.
+-- We encode the package name as well.
 make_mid :: Module -> C.Id
 -- Super ugly code, but I can't find anything else that does quite what I
 -- want (encodes the hierarchical module name without encoding the colon
 -- that separates the package name from it.)
-make_mid m = (packageIdString (modulePackageId m)) ++
-             ":" ++
-             showSDoc (pprCode CStyle (pprModuleName (moduleName m)))
+make_mid m = showSDoc $
+              (text $ zEncodeString $ packageIdString $ modulePackageId m)
+              <> text ":"
+              <> (pprEncoded $ pprModuleName $ moduleName m)
+     where pprEncoded = pprCode CStyle
                
 make_qid :: Bool -> Name -> C.Qual C.Id
 make_qid is_var n = (mname,make_id is_var n)