From: wolfgang Date: Wed, 10 Nov 2004 01:56:01 +0000 (+0000) Subject: [project @ 2004-11-10 01:56:00 by wolfgang] X-Git-Tag: Initial_conversion_from_CVS_complete~1462 X-Git-Url: http://git.megacz.com/?p=ghc-hetmet.git;a=commitdiff_plain;h=db35b90546b47fcd7193a83531d65ef38f1706f5 [project @ 2004-11-10 01:56:00 by wolfgang] Fix pretty-printing of integer constants on 64-bit platforms. If sizeof(int) == 4 on a 64-bit platform, we have to add an 'L' suffix to integer constants. --- diff --git a/ghc/compiler/cmm/PprC.hs b/ghc/compiler/cmm/PprC.hs index 421b557..a21ee6d 100644 --- a/ghc/compiler/cmm/PprC.hs +++ b/ghc/compiler/cmm/PprC.hs @@ -270,11 +270,11 @@ pprSwitch e maybe_ids caseify (ix:ixs, ident) = vcat (map do_fallthrough ixs) $$ final_branch ix where do_fallthrough ix = - hsep [ ptext SLIT("case") , pprHexVal ix <> colon , + hsep [ ptext SLIT("case") , pprHexVal ix wordRep <> colon , ptext SLIT("/* fall through */") ] final_branch ix = - hsep [ ptext SLIT("case") , pprHexVal ix <> colon , + hsep [ ptext SLIT("case") , pprHexVal ix wordRep <> colon , ptext SLIT("goto") , (pprBlockId ident) <> semi ] -- --------------------------------------------------------------------- @@ -362,13 +362,7 @@ pprMachOpApp mop args pprLit :: CmmLit -> SDoc pprLit lit = case lit of - CmmInt i I64 | machRepByteWidth I32 == wORD_SIZE - -> pprHexVal i <> ptext SLIT("LL") - -- Append an 'LL' suffix to 64-bit integers on a 32-bit - -- platform. This might not be strictly necessary (the - -- type will always be apparent from the context), but - -- it avoids some warnings from gcc. - CmmInt i _rep -> pprHexVal i + CmmInt i rep -> pprHexVal i rep CmmFloat f rep -> parens (machRepCType rep) <> (rational f) CmmLabel clbl -> mkW_ <> pprCLabel clbl CmmLabelOff clbl i -> mkW_ <> pprCLabel clbl <> char '+' <> int i @@ -979,12 +973,19 @@ commafy :: [SDoc] -> SDoc commafy xs = hsep $ punctuate comma xs -- Print in C hex format: 0x13fa -pprHexVal :: Integer -> SDoc -pprHexVal 0 = ptext SLIT("0x0") -pprHexVal w - | w < 0 = parens (char '-' <> ptext SLIT("0x") <> go (-w)) - | otherwise = ptext SLIT("0x") <> go w +pprHexVal :: Integer -> MachRep -> SDoc +pprHexVal 0 _ = ptext SLIT("0x0") +pprHexVal w rep + | w < 0 = parens (char '-' <> ptext SLIT("0x") <> go (-w) <> repsuffix rep) + | otherwise = ptext SLIT("0x") <> go w <> repsuffix rep where + -- type suffix for literals: + -- on 32-bit platforms, add "LL" to 64-bit literals + repsuffix I64 | wORD_SIZE == 4 = ptext SLIT("LL") + -- on 64-bit platforms with 32-bit int, add "L" to 64-bit literals + repsuffix I64 | cINT_SIZE == 4 = ptext SLIT("L") + repsuffix _ = empty + go 0 = empty go w' = go q <> dig where diff --git a/ghc/compiler/main/Constants.lhs b/ghc/compiler/main/Constants.lhs index 091a7de..ac6bddc 100644 --- a/ghc/compiler/main/Constants.lhs +++ b/ghc/compiler/main/Constants.lhs @@ -125,6 +125,12 @@ wORD_SIZE = (SIZEOF_HSWORD :: Int) wORD_SIZE_IN_BITS = wORD_SIZE * 8 :: Int \end{code} +Size of a C int, in bytes. May be smaller than wORD_SIZE. + +\begin{code} +cINT_SIZE = (SIZEOF_INT :: Int) +\end{code} + Size of a storage manager block (in bytes). \begin{code}