Merge branch 'cλash' of http://git.stderr.nl/matthijs/projects/master-project
authorChristiaan Baaij <christiaan.baaij@gmail.com>
Mon, 22 Jun 2009 11:39:00 +0000 (13:39 +0200)
committerChristiaan Baaij <christiaan.baaij@gmail.com>
Mon, 22 Jun 2009 11:39:00 +0000 (13:39 +0200)
* 'cλash' of http://git.stderr.nl/matthijs/projects/master-project:
  Check parameter counts in mkConcSm instead of the actual generate functions.
  Make the hw functions builtin operators instead of components.
  Fix typo.

Generate.hs
GlobalNameTable.hs
VHDL.hs

index 2beacb8d5616e7c9014f3fef35a6644d02773a49..23e4a2c7195c6b37cfb8980e174a795c436989cb 100644 (file)
@@ -3,6 +3,15 @@ module Generate where
 import qualified ForSyDe.Backend.VHDL.AST as AST
 import Constants
 
+-- | Generate a binary operator application. The first argument should be a
+-- constructor from the AST.Expr type, e.g. AST.And.
+genExprOp2 :: (AST.Expr -> AST.Expr -> AST.Expr) -> [AST.Expr] -> AST.Expr
+genExprOp2 op [arg1, arg2] = op arg1 arg2
+
+-- | Generate a unary operator application
+genExprOp1 :: (AST.Expr -> AST.Expr) -> [AST.Expr] -> AST.Expr
+genExprOp1 op [arg] = op arg
+
 -- | Generate a function call from the Function Name and a list of expressions
 --   (its arguments)
 genExprFCall :: AST.VHDLId -> [AST.Expr] -> AST.Expr
@@ -10,16 +19,6 @@ genExprFCall fName args =
    AST.PrimFCall $ AST.FCall (AST.NSimple fName)  $
              map (\exp -> Nothing AST.:=>: AST.ADExpr exp) args
 
--- | List version of genExprFCall1
-genExprFCall1L :: AST.VHDLId -> [AST.Expr] -> AST.Expr
-genExprFCall1L fName [arg] = genExprFCall fName [arg]
-genExprFCall1L _ _ = error "Generate.genExprFCall1L incorrect length"
-
--- | List version of genExprFCall2
-genExprFCall2L :: AST.VHDLId -> [AST.Expr] -> AST.Expr
-genExprFCall2L fName [arg1, arg2] = genExprFCall fName [arg1,arg2]
-genExprFCall2L _ _ = error "Generate.genExprFCall2L incorrect length"
-
 genUnconsVectorFuns :: AST.TypeMark -- ^ type of the vector elements
                     -> AST.TypeMark -- ^ type of the vector
                     -> [AST.SubProgBody]
@@ -154,4 +153,4 @@ genUnconsVectorFuns elemTM vectorTM  =
                                (AST.PrimName (AST.NAttribute $ 
                                   AST.AttribName (AST.NSimple vecPar) lengthId Nothing) 
                                                              AST.:-: AST.PrimLit "1"))
-    dropRet =  AST.ReturnSm (Just $ AST.PrimName $ AST.NSimple resId)
\ No newline at end of file
+    dropRet =  AST.ReturnSm (Just $ AST.PrimName $ AST.NSimple resId)
index c860dcb437e5732c50968168d770bc10aca075ef..756c6113c932e978e29a7bccd52d84669250e0e0 100644 (file)
@@ -17,6 +17,10 @@ mkGlobalNameTable = Map.fromList
 
 globalNameTable :: NameTable
 globalNameTable = mkGlobalNameTable
-  [ ("!"    , (2, genExprFCall2L exId                           ) )
-  , ("head"           , (1, genExprFCall1L headId                         ) )
-  ]
\ No newline at end of file
+  [ ("!"              , (2, genExprFCall exId                             ) )
+  , ("head"           , (1, genExprFCall headId                           ) )
+  , ("hwxor"          , (2, genExprOp2 AST.Xor                            ) )
+  , ("hwand"          , (2, genExprOp2 AST.And                            ) )
+  , ("hwor"           , (2, genExprOp2 AST.And                            ) )
+  , ("hwnot"          , (1, genExprOp1 AST.Not                            ) )
+  ]
diff --git a/VHDL.hs b/VHDL.hs
index 76a2552e98c7805ccd74b333b5795ba603b1e1cd..0f60fcb7a65d15bc23414488e4f0135a5d3c5207 100644 (file)
--- a/VHDL.hs
+++ b/VHDL.hs
@@ -280,20 +280,23 @@ mkConcSm (bndr, app@(CoreSyn.App _ _))= do
           let sel_name = mkSelectedName bndr label in
           mkUncondAssign (Right sel_name) (varToVHDLExpr arg)
     IdInfo.VanillaGlobal -> do
-      -- It's a global value imported from elsewhere. These can be builting
+      -- It's a global value imported from elsewhere. These can be builtin
       -- functions.
       funSignatures <- getA vsNameTable
       case (Map.lookup (bndrToString f) funSignatures) of
-        Just funSignature ->
-          let
-            sigs = map (bndrToString.varBndr) args
-            sigsNames = map (\signal -> (AST.PrimName (AST.NSimple (mkVHDLExtId signal)))) sigs
-            func = (snd funSignature) sigsNames
-            src_wform = AST.Wform [AST.WformElem func Nothing]
-            dst_name = AST.NSimple (mkVHDLExtId (bndrToString bndr))
-            assign = dst_name AST.:<==: (AST.ConWforms [] src_wform Nothing)
-          in
-            return $ AST.CSSASm assign
+        Just (arg_count, builder) ->
+          if length args == arg_count then
+            let
+              sigs = map (bndrToString.varBndr) args
+              sigsNames = map (\signal -> (AST.PrimName (AST.NSimple (mkVHDLExtId signal)))) sigs
+              func = builder sigsNames
+              src_wform = AST.Wform [AST.WformElem func Nothing]
+              dst_name = AST.NSimple (mkVHDLExtId (bndrToString bndr))
+              assign = dst_name AST.:<==: (AST.ConWforms [] src_wform Nothing)
+            in
+              return $ AST.CSSASm assign
+          else
+            error $ "VHDL.mkConcSm Incorrect number of arguments to builtin function: " ++ pprString f ++ " Args: " ++ pprString args
         Nothing -> error $ "Using function from another module that is not a known builtin: " ++ pprString f
     IdInfo.NotGlobalId -> do
       signatures <- getA vsSignatures