From: Matthijs Kooijman Date: Mon, 22 Jun 2009 13:14:09 +0000 (+0200) Subject: Generate the VHDLId of an entity in a single place. X-Git-Url: https://git.stderr.nl/gitweb?a=commitdiff_plain;h=2a78027bc1bd5f837b1f638cc1a347c52f5e6ba5;p=matthijs%2Fmaster-project%2Fc%CE%BBash.git Generate the VHDLId of an entity in a single place. Additionally, make the SignatureMap indexed by CoreBndr instead of String. This was previously not possible, because the builtin function also needed to be in the signature map. This is no longer the case. --- diff --git a/VHDL.hs b/VHDL.hs index ab7ee22..3c641a0 100644 --- a/VHDL.hs +++ b/VHDL.hs @@ -114,13 +114,14 @@ createEntity (fname, expr) = do -- There must be a let at top level let (CoreSyn.Let binds (CoreSyn.Var res)) = letexpr res' <- mkMap res - let ent_decl' = createEntityAST fname args' res' + let vhdl_id = mkVHDLBasicId $ bndrToString fname + let ent_decl' = createEntityAST vhdl_id args' res' let AST.EntityDec entity_id _ = ent_decl' let signature = Entity entity_id args' res' - modA vsSignatures (Map.insert (bndrToString fname) signature) + modA vsSignatures (Map.insert fname signature) return ent_decl' where - mkMap :: + mkMap :: --[(SignalId, SignalInfo)] CoreSyn.CoreBndr -> VHDLState VHDLSignalMapElement @@ -144,16 +145,15 @@ createEntity (fname, expr) = do -- | Create the VHDL AST for an entity createEntityAST :: - CoreSyn.CoreBndr -- | The name of the function + AST.VHDLId -- | The name of the function -> [VHDLSignalMapElement] -- | The entity's arguments -> VHDLSignalMapElement -- | The entity's result -> AST.EntityDec -- | The entity with the ent_decl filled in as well -createEntityAST name args res = +createEntityAST vhdl_id args res = AST.EntityDec vhdl_id ports where -- Create a basic Id, since VHDL doesn't grok filenames with extended Ids. - vhdl_id = mkVHDLBasicId $ bndrToString name ports = Maybe.catMaybes $ map (mkIfaceSigDec AST.In) args ++ [mkIfaceSigDec AST.Out res] @@ -187,11 +187,11 @@ createArchitecture :: -> VHDLState AST.ArchBody -- ^ The architecture for this function createArchitecture (fname, expr) = do - --signaturemap <- getA vsSignatures - --let signature = Maybe.fromMaybe - -- (error $ "Generating architecture for function " ++ (prettyShow hsfunc) ++ "without signature? This should not happen!") - -- (Map.lookup hsfunc signaturemap) - let entity_id = mkVHDLBasicId $ bndrToString fname + signaturemap <- getA vsSignatures + let signature = Maybe.fromMaybe + (error $ "Generating architecture for function " ++ (pprString fname) ++ "without signature? This should not happen!") + (Map.lookup fname signaturemap) + let entity_id = ent_id signature -- Strip off lambda's, these will be arguments let (args, letexpr) = CoreSyn.collectBinders expr -- There must be a let at top level @@ -305,7 +305,7 @@ mkConcSm (bndr, app@(CoreSyn.App _ _))= do let signature = Maybe.fromMaybe (error $ "Using function '" ++ (bndrToString f) ++ "' without signature? This should not happen!") - (Map.lookup (bndrToString f) signatures) + (Map.lookup f signatures) entity_id = ent_id signature label = bndrToString bndr -- Add a clk port if we have state diff --git a/VHDLTypes.hs b/VHDLTypes.hs index 95e9ce0..6f6625b 100644 --- a/VHDLTypes.hs +++ b/VHDLTypes.hs @@ -52,7 +52,7 @@ type ElemTypeMap = Map.Map OrdType (AST.VHDLId, AST.TypeDef) type TypeFunMap = Map.Map OrdType [AST.SubProgBody] -- A map of a Haskell function to a hardware signature -type SignatureMap = Map.Map String Entity +type SignatureMap = Map.Map CoreSyn.CoreBndr Entity -- A map of a builtin function to VHDL function builder type NameTable = Map.Map String (Int, [AST.Expr] -> AST.Expr )