[commit: ghc] master: Remove some uses of the WORDS_BIGENDIAN CPP symbol (b44db6f)

Ian Lynagh <[email protected]>
Newsgroups gmane.comp.lang.haskell.cvs.ghc
Message-ID <[email protected]>
Repository : ssh://darcs.haskell.org//srv/darcs/ghc

On branch  : master

http://hackage.haskell.org/trac/ghc/changeset/b44db6f1fac8e5c166104d6158eeaccbe9eb223d

>---------------------------------------------------------------

commit b44db6f1fac8e5c166104d6158eeaccbe9eb223d
Author: Ian Lynagh <[email protected]>
Date:   Tue Sep 18 17:43:15 2012 +0100

    Remove some uses of the WORDS_BIGENDIAN CPP symbol

>---------------------------------------------------------------

 compiler/cmm/CmmUtils.hs      |   12 +++++-------
 compiler/cmm/PprC.hs          |   12 +++++-------
 includes/mkDerivedConstants.c |   29 +++++++++++++++++++++++++++++
 3 files changed, 39 insertions(+), 14 deletions(-)

diff --git a/compiler/cmm/CmmUtils.hs b/compiler/cmm/CmmUtils.hs
index e4d1c9e..8cbe463 100644
--- a/compiler/cmm/CmmUtils.hs
+++ b/compiler/cmm/CmmUtils.hs
@@ -165,13 +165,11 @@ packHalfWordsCLit :: DynFlags -> StgHalfWord -> StgHalfWord -> CmmLit
 -- ToDo: consider using half-word lits instead
 --       but be careful: that's vulnerable when reversed
 packHalfWordsCLit dflags lower_half_word upper_half_word
-#ifdef WORDS_BIGENDIAN
-   = mkWordCLit dflags ((fromIntegral lower_half_word `shiftL` hALF_WORD_SIZE_IN_BITS)
-                 .|. fromIntegral upper_half_word)
-#else
-   = mkWordCLit dflags ((fromIntegral lower_half_word)
-                 .|. (fromIntegral upper_half_word `shiftL` hALF_WORD_SIZE_IN_BITS))
-#endif
+   = if wORDS_BIGENDIAN dflags
+     then mkWordCLit dflags ((l `shiftL` hALF_WORD_SIZE_IN_BITS) .|. u)
+     else mkWordCLit dflags (l .|. (u `shiftL` hALF_WORD_SIZE_IN_BITS))
+    where l = fromIntegral lower_half_word
+          u = fromIntegral upper_half_word
 
 ---------------------------------------------------
 --
diff --git a/compiler/cmm/PprC.hs b/compiler/cmm/PprC.hs
index bb2f189..1a3eb0d 100644
--- a/compiler/cmm/PprC.hs
+++ b/compiler/cmm/PprC.hs
@@ -492,13 +492,11 @@ pprStatics dflags (CmmStaticLit (CmmFloat f W64) : rest)
   = map pprLit1 (doubleToWords dflags f) ++ pprStatics dflags rest
 pprStatics dflags (CmmStaticLit (CmmInt i W64) : rest)
   | wordWidth dflags == W32
-#ifdef WORDS_BIGENDIAN
-  = pprStatics dflags (CmmStaticLit (CmmInt q W32) :
-                       CmmStaticLit (CmmInt r W32) : rest)
-#else
-  = pprStatics dflags (CmmStaticLit (CmmInt r W32) :
-                       CmmStaticLit (CmmInt q W32) : rest)
-#endif
+  = if wORDS_BIGENDIAN dflags
+    then pprStatics dflags (CmmStaticLit (CmmInt q W32) :
+                            CmmStaticLit (CmmInt r W32) : rest)
+    else pprStatics dflags (CmmStaticLit (CmmInt r W32) :
+                            CmmStaticLit (CmmInt q W32) : rest)
   where r = i .&. 0xffffffff
         q = i `shiftR` 32
 pprStatics dflags (CmmStaticLit (CmmInt _ w) : _)
diff --git a/includes/mkDerivedConstants.c b/includes/mkDerivedConstants.c
index 558d709..c732332 100644
--- a/includes/mkDerivedConstants.c
+++ b/includes/mkDerivedConstants.c
@@ -293,6 +293,27 @@ enum Mode { Gen_Haskell_Type, Gen_Haskell_Value, Gen_Haskell_Wrappers, Gen_Haske
 
 #define FUN_OFFSET(sym) (OFFSET(Capability,f.sym) - OFFSET(Capability,r))
 
+void constantBool(char *haskellName, int val) {
+    switch (mode) {
+    case Gen_Haskell_Type:
+        printf("    , pc_%s :: Bool\n", haskellName);
+        break;
+    case Gen_Haskell_Value:
+        printf("    , pc_%s = %s\n", haskellName, val ? "True" : "False");
+        break;
+    case Gen_Haskell_Wrappers:
+        printf("%s :: DynFlags -> Bool\n", haskellName);
+        printf("%s dflags = pc_%s (sPlatformConstants (settings dflags))\n",
+               haskellName, haskellName);
+        break;
+    case Gen_Haskell_Exports:
+        printf("    %s,\n", haskellName);
+        break;
+    case Gen_Header:
+        break;
+    }
+}
+
 void constantIntC(char *cName, char *haskellName, intptr_t val) {
     /* If the value is larger than 2^28 or smaller than -2^28, then fail.
        This test is a bit conservative, but if any constants are roughly
@@ -700,6 +721,14 @@ main(int argc, char *argv[])
     // Amount of pointer bits used for semi-tagging constructor closures
     constantInt("tAG_BITS", TAG_BITS);
 
+    constantBool("wORDS_BIGENDIAN",
+#ifdef WORDS_BIGENDIAN
+                                    1
+#else
+                                    0
+#endif
+                                         );
+
     switch (mode) {
     case Gen_Haskell_Type:
         printf("  } deriving (Read, Show)\n");
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.