Merge branch 'cλash' of http://git.stderr.nl/matthijs/projects/master-project
authorChristiaan Baaij <christiaan.baaij@gmail.com>
Mon, 29 Jun 2009 13:06:34 +0000 (15:06 +0200)
committerChristiaan Baaij <christiaan.baaij@gmail.com>
Mon, 29 Jun 2009 13:06:34 +0000 (15:06 +0200)
* 'cλash' of http://git.stderr.nl/matthijs/projects/master-project:
  Make genMap support mapping applications.
  Allow arguments to builtins to be applications.

1  2 
Generate.hs

diff --combined Generate.hs
index 3e3a21d1fa356b8c20a403de4e90283a2600c37f,3c5705ac9531bbe696bdf28107e111b2a0cb7f46..e6a5d45503c6879b1b4df8e6136754074f92d9c9
@@@ -84,9 -84,11 +84,11 @@@ genFCall' (Right name) _ _ = error $ "C
  
  -- | Generate a generate statement for the builtin function "map"
  genMap :: BuiltinBuilder
- genMap = genVarArgs genMap'
- genMap' :: (Either CoreSyn.CoreBndr AST.VHDLName) -> CoreSyn.CoreBndr -> [Var.Var] -> VHDLSession [AST.ConcSm]
- genMap' (Left res) f [mapped_f, arg] =
+ genMap (Left res) f [Left mapped_f, Left (Var arg)] =
+   -- mapped_f must be a CoreExpr (since we can't represent functions as VHDL
+   -- expressions). arg must be a CoreExpr (and should be a CoreSyn.Var), since
+   -- we must index it (which we couldn't if it was a VHDL Expr, since only
+   -- VHDLNames can be indexed).
    let
      -- Setup the generate scheme
      len         = (tfvec_len . Var.varType) res
      resname     = mkIndexedName (varToVHDLName res) n_expr
      argexpr     = vhdlNameToVHDLExpr $ mkIndexedName (varToVHDLName arg) n_expr
    in do
-     app_concsms <- genApplication (Right resname) mapped_f [Right argexpr]
+     let (CoreSyn.Var real_f, already_mapped_args) = CoreSyn.collectArgs mapped_f
+     let valargs = get_val_args (Var.varType real_f) already_mapped_args
+     app_concsms <- genApplication (Right resname) real_f (map Left valargs ++ [Right argexpr])
      -- Return the generate statement
      return [AST.CSGSm $ AST.GenerateSm label genScheme [] app_concsms]
  
@@@ -374,7 -378,6 +378,7 @@@ genUnconsVectorFuns elemTM vectorTM  
    , (selId, AST.SubProgBody selSpec  [AST.SPVD selVar] [selFor, selRet])
    , (ltplusId, AST.SubProgBody ltplusSpec [AST.SPVD ltplusVar] [ltplusExpr, ltplusRet]  )  
    , (plusplusId, AST.SubProgBody plusplusSpec [AST.SPVD plusplusVar] [plusplusExpr, plusplusRet])
 +  , (lengthTId, AST.SubProgBody lengthTSpec [] [lengthTExpr])
    ]
    where 
      ixPar   = AST.unsafeVHDLBasicId "ix"
                       ((AST.PrimName $ AST.NSimple vec1Par) AST.:&: 
                        (AST.PrimName $ AST.NSimple vec2Par))
      plusplusRet = AST.ReturnSm (Just $ AST.PrimName $ AST.NSimple resId)
 +    lengthTSpec = AST.Function (mkVHDLExtId lengthTId) [AST.IfaceVarDec vecPar vectorTM] naturalTM
 +    lengthTExpr = AST.ReturnSm (Just $ AST.PrimName (AST.NAttribute $ 
 +                                AST.AttribName (AST.NSimple vecPar) (mkVHDLBasicId lengthId) Nothing))
  
  -----------------------------------------------------------------------------
  -- A table of builtin functions
@@@ -641,7 -641,6 +645,7 @@@ globalNameTable = Map.fromLis
    , (emptyId          , (0, genFCall                ) )
    , (singletonId      , (1, genFCall                ) )
    , (copyId           , (2, genFCall                ) )
 +  , (lengthTId        , (1, genFCall                ) )
    , (hwxorId          , (2, genOperator2 AST.Xor    ) )
    , (hwandId          , (2, genOperator2 AST.And    ) )
    , (hworId           , (2, genOperator2 AST.Or     ) )