X-Git-Url: https://git.stderr.nl/gitweb?a=blobdiff_plain;f=c%CE%BBash%2FCLasH%2FVHDL%2FTestbench.hs;h=235dda60c863b38f1a8616cbe71390c7bd07da50;hb=e90120ffb6999ad931a06fd6c0a3b071408d5945;hp=3f77b78aeb0c93b87cab4706b9fdbe881cb921af;hpb=a8bd9c0833fcf1212f5843b9db6c754cd1086353;p=matthijs%2Fmaster-project%2Fc%CE%BBash.git diff --git "a/c\316\273ash/CLasH/VHDL/Testbench.hs" "b/c\316\273ash/CLasH/VHDL/Testbench.hs" index 3f77b78..235dda6 100644 --- "a/c\316\273ash/CLasH/VHDL/Testbench.hs" +++ "b/c\316\273ash/CLasH/VHDL/Testbench.hs" @@ -1,4 +1,3 @@ --- -- Functions to create a VHDL testbench from a list of test input. -- module CLasH.VHDL.Testbench where @@ -15,6 +14,7 @@ import qualified Language.VHDL.AST as AST -- GHC API import CoreSyn +import qualified HscTypes import qualified Var import qualified TysWiredIn @@ -31,17 +31,18 @@ import CLasH.Utils createTestbench :: Maybe Int -- ^ Number of cycles to simulate + -> [HscTypes.CoreModule] -- ^ Compiled modules -> CoreSyn.CoreExpr -- ^ Input stimuli -> CoreSyn.CoreBndr -- ^ Top Entity -> TranslatorSession CoreBndr -- ^ The id of the generated archictecture -createTestbench mCycles stimuli top = do - let stimuli' = reduceCoreListToHsList stimuli +createTestbench mCycles cores stimuli top = do + stimuli' <- reduceCoreListToHsList cores stimuli -- Create a binder for the testbench. We use the unit type (), since the -- testbench has no outputs and no inputs. bndr <- mkInternalVar "testbench" TysWiredIn.unitTy let entity = createTestbenchEntity bndr modA tsEntities (Map.insert bndr entity) - arch <- createTestbenchArch mCycles stimuli' top + arch <- createTestbenchArch mCycles stimuli' top entity modA tsArchitectures (Map.insert bndr arch) return bndr @@ -60,9 +61,10 @@ createTestbenchArch :: Maybe Int -- ^ Number of cycles to simulate -> [CoreSyn.CoreExpr] -- ^ Imput stimuli -> CoreSyn.CoreBndr -- ^ Top Entity + -> Entity -- ^ The signature to create an architecture for -> TranslatorSession (Architecture, [CoreSyn.CoreBndr]) -- ^ The architecture and any other entities used. -createTestbenchArch mCycles stimuli top = do +createTestbenchArch mCycles stimuli top testent= do signature <- getEntity top let entId = ent_id signature iIface = ent_args signature @@ -74,7 +76,7 @@ createTestbenchArch mCycles stimuli top = do [AST.SigDec clockId std_logicTM (Just $ AST.PrimLit "'0'"), AST.SigDec resetId std_logicTM (Just $ AST.PrimLit "'0'")] let oDecs = AST.SigDec (fst oIface) (snd oIface) Nothing - let portmaps = mkAssocElems (map idToVHDLExpr iIds) (AST.NSimple oId) signature + portmaps <- mkAssocElems (map idToVHDLExpr iIds) (AST.NSimple oId) signature let mIns = mkComponentInst "totest" entId portmaps (stimuliAssigns, stimuliDecs, cycles, used) <- createStimuliAssigns mCycles stimuli (head iIds) let finalAssigns = (AST.CSSASm (AST.NSimple resetId AST.:<==: @@ -85,7 +87,7 @@ createTestbenchArch mCycles stimuli top = do let outputProc = createOutputProc [oId] let arch = AST.ArchBody (AST.unsafeVHDLBasicId "test") - (AST.NSimple $ AST.unsafeIdAppend entId "_tb") + (AST.NSimple $ ent_id testent) (map AST.BDISD (finalIDecs ++ stimuliDecs ++ [oDecs])) (mIns : ( (AST.CSPSm clkProc) : (AST.CSPSm outputProc) : finalAssigns ) ) @@ -95,10 +97,10 @@ createStimuliAssigns :: Maybe Int -- ^ Number of cycles to simulate -> [CoreSyn.CoreExpr] -- ^ Input stimuli -> AST.VHDLId -- ^ Input signal - -> TranslatorSession ( [AST.ConcSm] -- ^ Resulting statemetns - , [AST.SigDec] -- ^ Needed signals - , Int -- ^ The number of cycles to simulate - , [CoreSyn.CoreBndr]) -- ^ Any entities used + -> TranslatorSession ( [AST.ConcSm] + , [AST.SigDec] + , Int + , [CoreSyn.CoreBndr]) -- ^ (Resulting statements, Needed signals, The number of cycles to simulate, Any entities used) createStimuliAssigns mCycles [] _ = return ([], [], Maybe.maybe 0 id mCycles, []) createStimuliAssigns mCycles stimuli signal = do @@ -116,9 +118,9 @@ createStimuliAssigns mCycles stimuli signal = do createStimulans :: CoreSyn.CoreExpr -- ^ The stimulans -> Int -- ^ The cycle for this stimulans - -> TranslatorSession ( AST.ConcSm -- ^ The statement - , Var.Var -- ^ the variable it assigns to (assumed to be available!) - , [CoreSyn.CoreBndr]) -- ^ Any entities used by this stimulans + -> TranslatorSession ( AST.ConcSm + , Var.Var + , [CoreSyn.CoreBndr]) -- ^ (The statement, the variable it assigns to (assumed to be available!), Any entities used by this stimulans) createStimulans expr cycl = do -- There must be a let at top level