Merge branch 'master' of git://github.com/christiaanb/clash
authorMatthijs Kooijman <matthijs@stdin.nl>
Tue, 8 Jun 2010 13:48:06 +0000 (15:48 +0200)
committerMatthijs Kooijman <matthijs@stdin.nl>
Tue, 8 Jun 2010 13:48:06 +0000 (15:48 +0200)
* 'master' of git://github.com/christiaanb/clash:
  Do not be overzealous with inlining results of polymorphic functions
  Do not function extract functions that still have free type variables
  Add setup file
  Fix cabal file to reflect temp bug fixes
  Temporarily disable "inlinenonrepresult" transformation, and apply eta-expansion transformation to all expressions
  Rename cλash dir to clash so it behaves well within the ghc build tree
  update cabal file to upload to hackage
  Remove defunct makeVHDLStrings function, messes with haddock
  Update reducer to use new integer types
  Reflect moving TFVec and TFP Integers into clash in sourcefiles related to builtin types
  Update package dependencies
  Move TFVec and TFP integers (Signed, Unsiged and Index) into clash

clash/CLasH/Normalize.hs
clash/CLasH/Utils/GhcTools.hs

index a70829ade05370f51d66c9dbe0575e8e124ef97c..11212f943df0678a4b9cef09fb52657ba06bc2dd 100644 (file)
@@ -410,15 +410,14 @@ funextract c expr = return expr
 -- Make sure the scrutinee of a case expression is a local variable
 -- reference.
 scrutsimpl :: Transform
--- Don't touch scrutinees that are already simple
-scrutsimpl c expr@(Case (Var _) _ _ _) = return expr
--- Replace all other cases with a let that binds the scrutinee and a new
+-- Replace a case expression with a let that binds the scrutinee and a new
 -- simple scrutinee, but only when the scrutinee is representable (to prevent
 -- loops with inlinenonrep, though I don't think a non-representable scrutinee
--- will be supported anyway...) 
+-- will be supported anyway...) and is not a local variable already.
 scrutsimpl c expr@(Case scrut b ty alts) = do
   repr <- isRepr scrut
-  if repr
+  local_var <- Trans.lift $ is_local_var scrut
+  if repr && not local_var
     then do
       id <- Trans.lift $ mkBinderFor scrut "scrut"
       change $ Let (NonRec id scrut) (Case (Var id) b ty alts)
@@ -821,6 +820,10 @@ inlinenonrepresult context expr | not (is_applicable expr) && not (has_free_tyva
 -- Leave all other expressions unchanged
 inlinenonrepresult c expr = return expr
 
+----------------------------------------------------------------
+-- Type-class transformations
+----------------------------------------------------------------
+
 --------------------------------
 -- ClassOp resolution
 --------------------------------
index f1fe6ba61b2547d494f5709f5bb10f375e4f5d62..022a997eca180bf5040ca7eb349efbf6a0f9fcc4 100644 (file)
@@ -19,6 +19,7 @@ import qualified Name
 import qualified Serialized
 import qualified Var
 import qualified Outputable
+import Outputable(($+$), (<+>), nest, empty, text, vcat)
 import qualified Class
 
 -- Local Imports
@@ -27,6 +28,11 @@ import CLasH.Translator.TranslatorTypes
 import CLasH.Translator.Annotations
 import CLasH.Utils
 
+-- How far to indent the values after a Foo: header
+align = 20
+-- How far to indent all lines after the first
+indent = 5
+
 listBindings :: FilePath -> [FilePath] -> IO ()
 listBindings libdir filenames = do
   (cores,_,_) <- loadModules libdir filenames Nothing
@@ -37,27 +43,28 @@ listBindings libdir filenames = do
   mapM listClass classes
   return ()
 
+-- Slightly different version of hang, that always uses vcat instead of
+-- sep, so the first line of d2 preserves its nesting.
+hang' d1 n d2 = vcat [d1, nest n d2]
+
 listBinding :: (CoreSyn.CoreBndr, CoreSyn.CoreExpr) -> IO ()
-listBinding (b, e) = do
-  putStr "\nBinder: "
-  putStr $ show b ++ "[" ++ show (Var.varUnique b) ++ "]"
-  putStr "\nType of Binder: \n"
-  putStr $ Outputable.showSDoc $ Outputable.ppr $ Var.varType b
-  putStr "\n\nExpression: \n"
-  putStr $ prettyShow e
-  putStr "\n\n"
-  putStr $ Outputable.showSDoc $ Outputable.ppr e
-  putStr "\n\nType of Expression: \n"
-  putStr $ Outputable.showSDoc $ Outputable.ppr $ CoreUtils.exprType e
-  putStr "\n\n"
+listBinding (b, e) = putStr $ Outputable.showSDoc $
+  (text "Binder:") <+> (text $ show b ++ "[" ++ show (Var.varUnique b) ++ "]")
+  $+$ nest indent (
+    hang' (text "Type of Binder:") align (Outputable.ppr $ Var.varType b)
+    $+$ hang' (text "Expression:") align (text $ prettyShow e)
+    $+$ nest align (Outputable.ppr e)
+    $+$ hang' (text "Type of Expression:") align (Outputable.ppr $ CoreUtils.exprType e)
+  )
+  $+$ (text "\n") -- Add an empty line
 
 listClass :: Class.Class -> IO ()
-listClass c = do
-  putStr "\nClass: "
-  putStr $ show (Class.className c)
-  putStr "\nSelectors: "
-  putStr $ show (Class.classSelIds c)
-  putStr "\n"
+listClass c = putStr $ Outputable.showSDoc $
+  (text "Class:") <+> (text $ show (Class.className c))
+  $+$ nest indent (
+    hang' (text "Selectors:") align (text $ show (Class.classSelIds c))
+  )
+  $+$ (text "\n") -- Add an empty line
   
 -- | Show the core structure of the given binds in the given file.
 listBind :: FilePath -> [FilePath] -> String -> IO ()