diff options
author | Thomas Miedema <thomasmiedema@gmail.com> | 2015-03-03 07:21:32 -0600 |
---|---|---|
committer | Austin Seipp <austin@well-typed.com> | 2015-03-03 07:21:33 -0600 |
commit | 89458eba5721de1b6b3378415f26e110bab8cc0f (patch) | |
tree | 9bdcb564437e6053e1f490cd1892f4df0de9736b /compiler/utils/Outputable.hs | |
parent | 5200bdeb26c5ec98739b14b10fc8907296bceeb9 (diff) | |
download | haskell-89458eba5721de1b6b3378415f26e110bab8cc0f.tar.gz |
Pretty-print # on unboxed literals in core
Summary:
Ticket #10104 dealt with showing the '#'s on types with unboxed fields. This
commit pretty prints the '#'s on unboxed literals in core output.
Test Plan: simplCore/should_compile/T8274
Reviewers: jstolarek, simonpj, austin
Reviewed By: simonpj, austin
Subscribers: simonpj, thomie
Differential Revision: https://phabricator.haskell.org/D678
GHC Trac Issues: #8274
Diffstat (limited to 'compiler/utils/Outputable.hs')
-rw-r--r-- | compiler/utils/Outputable.hs | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/compiler/utils/Outputable.hs b/compiler/utils/Outputable.hs index 488094a498..6c7ae08379 100644 --- a/compiler/utils/Outputable.hs +++ b/compiler/utils/Outputable.hs @@ -47,6 +47,10 @@ module Outputable ( pprInfixVar, pprPrefixVar, pprHsChar, pprHsString, pprHsBytes, + + primFloatSuffix, primDoubleSuffix, + pprPrimChar, pprPrimInt, pprPrimWord, pprPrimInt64, pprPrimWord64, + pprFastFilePath, -- * Controlling the style in which output is printed @@ -808,7 +812,7 @@ pprHsChar c | c > '\x10ffff' = char '\\' <> text (show (fromIntegral (ord c) :: pprHsString :: FastString -> SDoc pprHsString fs = vcat (map text (showMultiLineString (unpackFS fs))) --- | Special combinator for showing string literals. +-- | Special combinator for showing bytestring literals. pprHsBytes :: ByteString -> SDoc pprHsBytes bs = let escaped = concatMap escape $ BS.unpack bs in vcat (map text (showMultiLineString escaped)) <> char '#' @@ -818,6 +822,27 @@ pprHsBytes bs = let escaped = concatMap escape $ BS.unpack bs then [c] else '\\' : show w +-- Postfix modifiers for unboxed literals. +-- See Note [Printing of literals in Core] in `basicTypes/Literal.hs`. +primCharSuffix, primFloatSuffix, primIntSuffix :: SDoc +primDoubleSuffix, primWordSuffix, primInt64Suffix, primWord64Suffix :: SDoc +primCharSuffix = char '#' +primFloatSuffix = char '#' +primIntSuffix = char '#' +primDoubleSuffix = text "##" +primWordSuffix = text "##" +primInt64Suffix = text "L#" +primWord64Suffix = text "L##" + +-- | Special combinator for showing unboxed literals. +pprPrimChar :: Char -> SDoc +pprPrimInt, pprPrimWord, pprPrimInt64, pprPrimWord64 :: Integer -> SDoc +pprPrimChar c = pprHsChar c <> primCharSuffix +pprPrimInt i = integer i <> primIntSuffix +pprPrimWord w = integer w <> primWordSuffix +pprPrimInt64 i = integer i <> primInt64Suffix +pprPrimWord64 w = integer w <> primWord64Suffix + --------------------- -- Put a name in parens if it's an operator pprPrefixVar :: Bool -> SDoc -> SDoc |