summaryrefslogtreecommitdiff
path: root/compiler/utils/Outputable.hs
diff options
context:
space:
mode:
authorAndrew Martin <andrew.thaddeus@gmail.com>2018-03-19 12:01:17 -0400
committerBen Gamari <ben@smart-cactus.org>2018-03-19 12:05:11 -0400
commita00b88b9a27736c9c41f1921fcb6b7759ad8425e (patch)
tree88526dc7b20c55460a820043e1c0659e7455f34a /compiler/utils/Outputable.hs
parentbbcea13af845d41a9d51a932476eb841ba182ea5 (diff)
downloadhaskell-a00b88b9a27736c9c41f1921fcb6b7759ad8425e.tar.gz
Implement -dword-hex-literals
Provide flag for showing showing Word# and Word64# as hexadecimal when dumping GHC core. The only affects Word, not Int, and it prefixes the hexadecimal with enough zeroes to make the total character count a power of two. For example: - 0x0C0C instead of 0xC0C - 0x00BA00BA instead of 0xBA00BA This also affects the presentation of Word# and Word64# in GHC's error messages. It is not expected that the flag will be used for this, but it is a side-effect worth noting. Test Plan: none Reviewers: bgamari, simonpj Reviewed By: simonpj Subscribers: simonpj, mpickering, rwbarton, thomie, carter, andrewthad GHC Trac Issues: #14872 Differential Revision: https://phabricator.haskell.org/D4465
Diffstat (limited to 'compiler/utils/Outputable.hs')
-rw-r--r--compiler/utils/Outputable.hs15
1 files changed, 11 insertions, 4 deletions
diff --git a/compiler/utils/Outputable.hs b/compiler/utils/Outputable.hs
index 793b8fb139..2b03555bab 100644
--- a/compiler/utils/Outputable.hs
+++ b/compiler/utils/Outputable.hs
@@ -22,7 +22,7 @@ module Outputable (
empty, isEmpty, nest,
char,
text, ftext, ptext, ztext,
- int, intWithCommas, integer, float, double, rational, doublePrec,
+ int, intWithCommas, integer, word, float, double, rational, doublePrec,
parens, cparen, brackets, braces, quotes, quote,
doubleQuotes, angleBrackets, paBrackets,
semi, comma, colon, dcolon, space, equals, dot, vbar,
@@ -91,7 +91,8 @@ import GhcPrelude
import {-# SOURCE #-} DynFlags( DynFlags, hasPprDebug, hasNoDebugOutput,
targetPlatform, pprUserLength, pprCols,
useUnicode, useUnicodeSyntax,
- shouldUseColor, unsafeGlobalDynFlags )
+ shouldUseColor, unsafeGlobalDynFlags,
+ shouldUseHexWordLiterals )
import {-# SOURCE #-} Module( UnitId, Module, ModuleName, moduleName )
import {-# SOURCE #-} OccName( OccName )
@@ -555,6 +556,7 @@ ptext :: LitString -> SDoc
ztext :: FastZString -> SDoc
int :: Int -> SDoc
integer :: Integer -> SDoc
+word :: Integer -> SDoc
float :: Float -> SDoc
double :: Double -> SDoc
rational :: Rational -> SDoc
@@ -573,6 +575,11 @@ integer n = docToSDoc $ Pretty.integer n
float n = docToSDoc $ Pretty.float n
double n = docToSDoc $ Pretty.double n
rational n = docToSDoc $ Pretty.rational n
+word n = sdocWithDynFlags $ \dflags ->
+ -- See Note [Print Hexadecimal Literals] in Pretty.hs
+ if shouldUseHexWordLiterals dflags
+ then docToSDoc $ Pretty.hex n
+ else docToSDoc $ Pretty.integer n
-- | @doublePrec p n@ shows a floating point number @n@ with @p@
-- digits of precision after the decimal point.
@@ -969,9 +976,9 @@ pprPrimChar :: Char -> SDoc
pprPrimInt, pprPrimWord, pprPrimInt64, pprPrimWord64 :: Integer -> SDoc
pprPrimChar c = pprHsChar c <> primCharSuffix
pprPrimInt i = integer i <> primIntSuffix
-pprPrimWord w = integer w <> primWordSuffix
+pprPrimWord w = word w <> primWordSuffix
pprPrimInt64 i = integer i <> primInt64Suffix
-pprPrimWord64 w = integer w <> primWord64Suffix
+pprPrimWord64 w = word w <> primWord64Suffix
---------------------
-- Put a name in parens if it's an operator