xand a b = hwand a b
-functiontest :: TFVec D4 Bit -> TFVec D8 Bit
-functiontest = \v -> let r = v ++ $(vectorTH ([High,Low,High,Low] :: [Bit])) in r
+functiontest :: TFVec D4 (TFVec D3 Bit) -> (TFVec D12 Bit, TFVec D3 Bit)
+functiontest = \v -> let r = (concat v, head v) in r
xhwnot x = hwnot x
-- | Get the length of a FSVec type
tfvec_len :: Type.Type -> Int
-tfvec_len ty =
- eval_tfp_int len
+tfvec_len ty = eval_tfp_int (tfvec_len_ty ty)
+
+tfvec_len_ty :: Type.Type -> Type.Type
+tfvec_len_ty ty = len
where
args = case Type.splitTyConApp_maybe ty of
Just (tycon, args) -> args
- Nothing -> error $ "\nCoreTools.tfvec_len: Not a vector type: " ++ (pprString ty)
+ Nothing -> error $ "\nCoreTools.tfvec_len_ty: Not a vector type: " ++ (pprString ty)
[len, el_ty] = args
-- | Get the element type of a TFVec type
elem_htype_either <- mkHType el_ty
case elem_htype_either of
-- Could create element type
- Right elem_htype ->
- return $ Right $ VecType (tfvec_len ty) elem_htype
+ Right elem_htype -> do
+ len <- vec_len ty
+ return $ Right $ VecType len elem_htype
-- Could not create element type
Left err -> return $ Left $
"VHDLTools.mkHType: Can not construct vectortype for elementtype: " ++ pprString el_ty ++ "\n"
return $ case ty_either of
Left _ -> False
Right _ -> True
+
+vec_len :: Type.Type -> TypeSession Int
+vec_len ty = do
+ veclens <- getA vsTfpInts
+ let len_ty = tfvec_len_ty ty
+ let existing_len = Map.lookup (OrdType len_ty) veclens
+ case existing_len of
+ Just len -> return len
+ Nothing -> do
+ let new_len = tfvec_len ty
+ modA vsTfpInts (Map.insert (OrdType len_ty) (new_len))
+ return new_len
\ No newline at end of file
-- A map of a Haskell function to a hardware signature
type SignatureMap = Map.Map CoreSyn.CoreBndr Entity
+type TfpIntMap = Map.Map OrdType Int
+
data TypeState = TypeState {
-- | A map of Core type -> VHDL Type
vsTypes_ :: TypeMap,
-- | A list of type declarations
vsTypeDecls_ :: [AST.PackageDecItem],
-- | A map of vector Core type -> VHDL type function
- vsTypeFuns_ :: TypeFunMap
+ vsTypeFuns_ :: TypeFunMap,
+ vsTfpInts_ :: TfpIntMap
}
-- Derive accessors
$( Data.Accessor.Template.deriveAccessors ''TypeState )
-- Define an empty TypeState
-emptyTypeState = TypeState Map.empty [] Map.empty
+emptyTypeState = TypeState Map.empty [] Map.empty Map.empty
-- Define a session
type TypeSession = State.State TypeState