From: Christiaan Baaij Date: Tue, 14 Jul 2009 08:28:03 +0000 (+0200) Subject: Added resize function X-Git-Url: https://git.stderr.nl/gitweb?a=commitdiff_plain;h=03b96c164e75ab3af5887a4cb498759370a31100;p=matthijs%2Fmaster-project%2Fc%CE%BBash.git Added resize function --- diff --git a/Adders.hs b/Adders.hs index a281ea6..6529642 100644 --- a/Adders.hs +++ b/Adders.hs @@ -181,8 +181,8 @@ xand a b = hwand a b functiontest :: TFVec D3 (TFVec D4 Bit) -> TFVec D12 Bit functiontest = \v -> let r = concat v in r -functiontest2 :: SizedInt D8 -> SizedInt D8 -functiontest2 = \a -> let r = a + 1 in r +functiontest2 :: SizedInt D8 -> SizedInt D7 +functiontest2 = \a -> let r = Data.SizedInt.resize a in r xhwnot x = hwnot x diff --git a/Constants.hs b/Constants.hs index c392521..ad87e0a 100644 --- a/Constants.hs +++ b/Constants.hs @@ -258,6 +258,9 @@ toSignedId = "to_signed" toUnsignedId :: String toUnsignedId = "to_unsigned" +resizeId :: String +resizeId = "resize" + ------------------ -- VHDL type marks ------------------ diff --git a/Generate.hs b/Generate.hs index 4846d58..1af1be3 100644 --- a/Generate.hs +++ b/Generate.hs @@ -134,6 +134,22 @@ genFromSizedWord' (Left res) f args = do map (\exp -> Nothing AST.:=>: AST.ADExpr exp) args genFromSizedWord' (Right name) _ _ = error $ "\nGenerate.genFromSizedWord': Cannot generate builtin function call assigned to a VHDLName: " ++ show name +genResize :: BuiltinBuilder +genResize = genExprArgs $ genExprRes genResize' +genResize' :: Either CoreSyn.CoreBndr AST.VHDLName -> CoreSyn.CoreBndr -> [AST.Expr] -> VHDLSession AST.Expr +genResize' (Left res) f [arg] = do { + ; let { ty = Var.varType res + ; (tycon, args) = Type.splitTyConApp ty + ; name = Name.getOccString (TyCon.tyConName tycon) + } ; + ; len <- case name of + "SizedInt" -> MonadState.lift vsType $ tfp_to_int (sized_int_len_ty ty) + "SizedWord" -> MonadState.lift vsType $ tfp_to_int (sized_word_len_ty ty) + ; return $ AST.PrimFCall $ AST.FCall (AST.NSimple (mkVHDLBasicId resizeId)) + [Nothing AST.:=>: AST.ADExpr arg, Nothing AST.:=>: AST.ADExpr( AST.PrimLit (show len))] + } +genResize' (Right name) _ _ = error $ "\nGenerate.genFromSizedWord': Cannot generate builtin function call assigned to a VHDLName: " ++ show name + -- FIXME: I'm calling genLitArgs which is very specific function, -- which needs to be fixed as well genFromInteger :: BuiltinBuilder @@ -1026,4 +1042,5 @@ globalNameTable = Map.fromList , (minusId , (2, genOperator2 (AST.:-:) ) ) , (fromSizedWordId , (1, genFromSizedWord ) ) , (fromIntegerId , (1, genFromInteger ) ) + , (resizeId , (1, genResize ) ) ] diff --git "a/c\316\273ash.cabal" "b/c\316\273ash.cabal" index b5f497a..4796956 100644 --- "a/c\316\273ash.cabal" +++ "b/c\316\273ash.cabal" @@ -13,7 +13,7 @@ stability: alpha maintainer: christiaan.baaij@gmail.com & matthijs@stdin.nl build-depends: base > 4, syb, ghc, ghc-paths, transformers, haskell98, ForSyDe > 3.0, regex-posix ,data-accessor-template, pretty, - data-accessor, containers, prettyclass, tfp > 0.3.1, + data-accessor, containers, prettyclass, tfp > 0.3.2, tfvec > 0.1.2, QuickCheck, template-haskell, filepath executable: clash