From: Christiaan Baaij Date: Fri, 26 Jun 2009 12:28:34 +0000 (+0200) Subject: Added support for instances of tfp integer, but poorly... X-Git-Url: https://git.stderr.nl/gitweb?a=commitdiff_plain;h=c154f599b83d1a91e99993666139e01f10033d5c;p=matthijs%2Fmaster-project%2Fc%CE%BBash.git Added support for instances of tfp integer, but poorly... They are always used as 'structural' parameters for functions and as such should not be turned in to ports when these arguments are applied. --- diff --git a/Adders.hs b/Adders.hs index d64331f..408e6b8 100644 --- a/Adders.hs +++ b/Adders.hs @@ -174,8 +174,8 @@ highordtest = \x -> xand a b = hwand a b -functiontest :: TFVec D4 Bit -> Bit -> Bit -functiontest = \v s -> let r = foldl xand s v in r +functiontest :: TFVec D4 Bit -> TFVec D2 Bit +functiontest = \v -> let r = select d0 d1 d2 v in r xhwnot x = hwnot x diff --git a/Generate.hs b/Generate.hs index f55aa3d..0a9e9b5 100644 --- a/Generate.hs +++ b/Generate.hs @@ -490,8 +490,8 @@ genUnconsVectorFuns elemTM vectorTM = -- return res copyExpr = AST.ReturnSm (Just $ AST.PrimName $ AST.NSimple resId) selSpec = AST.Function (mkVHDLExtId selId) [AST.IfaceVarDec fPar naturalTM, - AST.IfaceVarDec nPar naturalTM, AST.IfaceVarDec sPar naturalTM, + AST.IfaceVarDec nPar naturalTM, AST.IfaceVarDec vecPar vectorTM ] vectorTM -- variable res : fsvec_x (0 to n-1); selVar = diff --git a/VHDLTools.hs b/VHDLTools.hs index 1268116..96a8ae5 100644 --- a/VHDLTools.hs +++ b/VHDLTools.hs @@ -8,6 +8,7 @@ import qualified Control.Monad as Monad import qualified Control.Arrow as Arrow import qualified Data.Monoid as Monoid import Data.Accessor +import Debug.Trace -- ForSyDe import qualified ForSyDe.Backend.VHDL.AST as AST @@ -126,7 +127,20 @@ varToVHDLExpr var = -- This is a dataconstructor. -- Not a datacon, just another signal. Perhaps we should check for -- local/global here as well? - Nothing -> AST.PrimName $ AST.NSimple $ varToVHDLId var + -- Sadly so.. tfp decimals are types, not data constructors, but instances + -- should still be translated to integer literals. It is probebly not the + -- best solution to translate them here. + -- FIXME: Find a better solution for translating instances of tfp integers + Nothing -> + let + ty = Var.varType var + res = case Type.splitTyConApp_maybe ty of + Just (tycon, args) -> + case Name.getOccString (TyCon.tyConName tycon) of + "Dec" -> AST.PrimLit $ (show (eval_tfp_int ty)) + otherwise -> AST.PrimName $ AST.NSimple $ varToVHDLId var + in + res -- Turn a VHDLName into an AST expression vhdlNameToVHDLExpr = AST.PrimName @@ -243,7 +257,8 @@ mkIndexedName name index = AST.NIndexed (AST.IndexedName name [index]) builtin_types = Map.fromList [ ("Bit", std_logicTM), - ("Bool", booleanTM) -- TysWiredIn.boolTy + ("Bool", booleanTM), -- TysWiredIn.boolTy + ("Dec", integerTM) ] -- Translate a Haskell type to a VHDL type, generating a new type if needed.