From: Christiaan Baaij Date: Wed, 24 Jun 2009 10:35:50 +0000 (+0200) Subject: Merge branch 'cλash' of http://git.stderr.nl/matthijs/projects/master-project X-Git-Url: https://git.stderr.nl/gitweb?a=commitdiff_plain;h=4d96e10ba2805470597642cf4c2ba797eda1b1f9;hp=6fffdcf32a54a6372442d22a87537ee9733073ad;p=matthijs%2Fmaster-project%2Fc%CE%BBash.git Merge branch 'cλash' of git.stderr.nl/matthijs/projects/master-project * 'cλash' of http://git.stderr.nl/matthijs/projects/master-project: Put the Builders in the VHDLSession. Remove the globalNameTable from the VHDLState. Swap the VHDLState and VHDLSession type names. --- diff --git a/Generate.hs b/Generate.hs index 75bea24..8065363 100644 --- a/Generate.hs +++ b/Generate.hs @@ -48,10 +48,10 @@ genMapCall entity [arg, res] = return $ genSm genScheme = AST.ForGn nPar range -- Get the entity name and port names entity_id = ent_id entity - argport = map (Monad.liftM fst) (ent_args entity) + argports = map (Monad.liftM fst) (ent_args entity) resport = (Monad.liftM fst) (ent_res entity) -- Assign the ports - inport = mkAssocElemIndexed (head argport) (varToString arg) nPar + inport = mkAssocElemIndexed (argports!!0) (varToString arg) nPar outport = mkAssocElemIndexed resport (varToString res) nPar clk_port = mkAssocElem (Just $ mkVHDLExtId "clk") "clk" portassigns = Maybe.catMaybes [inport,outport,clk_port] @@ -60,6 +60,34 @@ genMapCall entity [arg, res] = return $ genSm compins = mkComponentInst mapLabel entity_id portassigns -- Return the generate functions genSm = AST.GenerateSm label genScheme [] [compins] + +genZipWithCall :: + Entity + -> [CoreSyn.CoreBndr] + -> AST.GenerateSm +genZipWithCall entity [arg1, arg2, res] = genSm + where + -- Setup the generate scheme + len = (tfvec_len . Var.varType) res + label = mkVHDLExtId ("zipWithVector" ++ (varToString res)) + nPar = AST.unsafeVHDLBasicId "n" + range = AST.ToRange (AST.PrimLit "0") (AST.PrimLit $ show (len-1)) + genScheme = AST.ForGn nPar range + -- Get the entity name and port names + entity_id = ent_id entity + argports = map (Monad.liftM fst) (ent_args entity) + resport = (Monad.liftM fst) (ent_res entity) + -- Assign the ports + inport1 = mkAssocElemIndexed (argports!!0) (varToString arg1) nPar + inport2 = mkAssocElemIndexed (argports!!1) (varToString arg2) nPar + outport = mkAssocElemIndexed resport (varToString res) nPar + clk_port = mkAssocElem (Just $ mkVHDLExtId "clk") "clk" + portassigns = Maybe.catMaybes [inport1,inport2,outport,clk_port] + -- Generate the portmap + mapLabel = "zipWith" ++ (AST.fromVHDLId entity_id) + compins = mkComponentInst mapLabel entity_id portassigns + -- Return the generate functions + genSm = AST.GenerateSm label genScheme [] [compins] genUnconsVectorFuns :: AST.TypeMark -- ^ type of the vector elements -> AST.TypeMark -- ^ type of the vector @@ -74,7 +102,7 @@ genUnconsVectorFuns elemTM vectorTM = , AST.SubProgBody takeSpec [AST.SPVD takeVar] [takeExpr, takeRet] , AST.SubProgBody dropSpec [AST.SPVD dropVar] [dropExpr, dropRet] , AST.SubProgBody plusgtSpec [AST.SPVD plusgtVar] [plusgtExpr, plusgtRet] - , AST.SubProgBody emptySpec [AST.SPVD emptyVar] [emptyExpr] + , AST.SubProgBody emptySpec [AST.SPCD emptyVar] [emptyExpr] , AST.SubProgBody singletonSpec [AST.SPVD singletonVar] [singletonRet] , AST.SubProgBody copySpec [AST.SPVD copyVar] [copyExpr] ] @@ -217,12 +245,9 @@ genUnconsVectorFuns elemTM vectorTM = plusgtRet = AST.ReturnSm (Just $ AST.PrimName $ AST.NSimple resId) emptySpec = AST.Function emptyId [] vectorTM emptyVar = - AST.VarDec resId - (AST.SubtypeIn vectorTM - (Just $ AST.ConstraintIndex $ AST.IndexConstraint - [AST.ToRange (AST.PrimLit "0") - (AST.PrimLit "-1")])) - Nothing + AST.ConstDec resId + (AST.SubtypeIn vectorTM Nothing) + (Just $ AST.PrimLit "\"\"") emptyExpr = AST.ReturnSm (Just $ AST.PrimName (AST.NSimple resId)) singletonSpec = AST.Function singletonId [AST.IfaceVarDec aPar elemTM ] vectorTM diff --git a/GlobalNameTable.hs b/GlobalNameTable.hs index 45eed89..aa74628 100644 --- a/GlobalNameTable.hs +++ b/GlobalNameTable.hs @@ -27,6 +27,7 @@ globalNameTable = mkGlobalNameTable , ("drop" , (2, Left $ genExprFCall dropId ) ) , ("+>" , (2, Left $ genExprFCall plusgtId ) ) , ("map" , (2, Right $ genMapCall ) ) + , ("zipWith" , (3, Right $ genZipWithCall ) ) , ("empty" , (0, Left $ genExprFCall emptyId ) ) , ("singleton" , (1, Left $ genExprFCall singletonId ) ) , ("copy" , (2, Left $ genExprFCall copyId ) )