[commit: ghc] master: Rewrite ppLlvmBlock to use standard library "break" (8f0ecc0)

David Terei davidterei at gmail.com
Fri Jun 28 03:56:44 CEST 2013


Repository : http://darcs.haskell.org/ghc.git/

On branch  : master

https://github.com/ghc/ghc/commit/8f0ecc0343b0a1c9fcbdf3224b2d9067dd549659

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

commit 8f0ecc0343b0a1c9fcbdf3224b2d9067dd549659
Author: Peter Wortmann <scpmw at leeds.ac.uk>
Date:   Wed Jun 26 15:44:36 2013 +0100

    Rewrite ppLlvmBlock to use standard library "break"

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

 compiler/llvmGen/Llvm/PpLlvm.hs | 21 ++++++++-------------
 1 file changed, 8 insertions(+), 13 deletions(-)

diff --git a/compiler/llvmGen/Llvm/PpLlvm.hs b/compiler/llvmGen/Llvm/PpLlvm.hs
index d1cb055..87be8f6 100644
--- a/compiler/llvmGen/Llvm/PpLlvm.hs
+++ b/compiler/llvmGen/Llvm/PpLlvm.hs
@@ -186,19 +186,14 @@ ppLlvmBlocks blocks = vcat $ map ppLlvmBlock blocks
 -- | Print out an LLVM block.
 -- It must be part of a function definition.
 ppLlvmBlock :: LlvmBlock -> SDoc
-ppLlvmBlock (LlvmBlock blockId stmts)
-  = go blockId stmts
-  where
-    lbreak acc []              = (Nothing, reverse acc, [])
-    lbreak acc (MkLabel id:xs) = (Just id, reverse acc, xs)
-    lbreak acc (x:xs)          = lbreak (x:acc) xs
-
-    go id code =
-        let (id2, block, rest) = lbreak [] code
-            ppRest = case id2 of
-                         Just id2' -> go id2' rest
-                         Nothing   -> empty
-        in ppLlvmBlockLabel id
+ppLlvmBlock (LlvmBlock blockId stmts) =
+  let isLabel (MkLabel _) = True
+      isLabel _           = False
+      (block, rest)       = break isLabel stmts
+      ppRest = case rest of
+        MkLabel id:xs -> ppLlvmBlock (LlvmBlock id xs)
+        _             -> empty
+  in ppLlvmBlockLabel blockId
            $+$ (vcat $ map ppLlvmStatement block)
            $+$ newLine
            $+$ ppRest





More information about the ghc-commits mailing list