xand a b = hwand a b
-functiontest :: SizedWord D8 -> RangedWord D255
-functiontest = \a -> let r = fromSizedWord a in r
+functiontest :: SizedInt D8 -> SizedInt D8
+functiontest = \a -> let r = a + (1 :: SizedInt D8) in r
xhwnot x = hwnot x
-- | Get the width of a SizedWord type
sized_word_len :: Type.Type -> Int
-sized_word_len ty =
- eval_tfp_int len
- where
- (tycon, args) = Type.splitTyConApp ty
- [len] = args
+sized_word_len ty = eval_tfp_int (sized_word_len_ty ty)
+
+sized_word_len_ty :: Type.Type -> Type.Type
+sized_word_len_ty ty = len
+ where
+ args = case Type.splitTyConApp_maybe ty of
+ Just (tycon, args) -> args
+ Nothing -> error $ "\nCoreTools.sized_word_len_ty: Not a sized word type: " ++ (pprString ty)
+ [len] = args
+
+-- | Get the width of a SizedInt type
+sized_int_len :: Type.Type -> Int
+sized_int_len ty = eval_tfp_int (sized_int_len_ty ty)
+
+sized_int_len_ty :: Type.Type -> Type.Type
+sized_int_len_ty ty = len
+ where
+ args = case Type.splitTyConApp_maybe ty of
+ Just (tycon, args) -> args
+ Nothing -> error $ "\nCoreTools.sized_int_len_ty: Not a sized int type: " ++ (pprString ty)
+ [len] = args
-- | Get the upperbound of a RangedWord type
ranged_word_bound :: Type.Type -> Int
-ranged_word_bound ty =
- eval_tfp_int len
+ranged_word_bound ty = eval_tfp_int (ranged_word_bound_ty ty)
+
+ranged_word_bound_ty :: Type.Type -> Type.Type
+ranged_word_bound_ty ty = len
where
- (tycon, args) = Type.splitTyConApp ty
+ args = case Type.splitTyConApp_maybe ty of
+ Just (tycon, args) -> args
+ Nothing -> error $ "\nCoreTools.ranged_word_bound_ty: Not a sized word type: " ++ (pprString ty)
[len] = args
-- | Evaluate a core Type representing type level int from the TypeLevel
-module Pretty (prettyShow, pprString) where
+module Pretty (prettyShow, pprString, pprStringDebug) where
import qualified Data.Map as Map
import qualified Module
import qualified HscTypes
import Text.PrettyPrint.HughesPJClass
-import Outputable ( showSDoc, ppr, Outputable, OutputableBndr)
+import Outputable ( showSDoc, showSDocDebug, ppr, Outputable, OutputableBndr)
import qualified ForSyDe.Backend.Ppr
import qualified ForSyDe.Backend.VHDL.Ppr
-- Convenience method for turning an Outputable into a string
pprString :: (Outputable x) => x -> String
pprString = showSDoc . ppr
+
+pprStringDebug :: (Outputable x) => x -> String
+pprStringDebug = showSDocDebug . ppr
import qualified HscTypes
import HscTypes ( cm_binds, cm_types )
import MonadUtils ( liftIO )
-import Outputable ( showSDoc, ppr )
+import Outputable ( showSDoc, ppr, showSDocDebug )
import GHC.Paths ( libdir )
import DynFlags ( defaultDynFlags )
import qualified UniqSupply
mapM (writeVHDL dir) vhdl
return ()
+listBindings :: String -> IO [()]
+listBindings filename = do
+ core <- loadModule filename
+ let binds = CoreSyn.flattenBinds $ cm_binds core
+ mapM (listBinding) binds
+
+listBinding :: (CoreBndr, CoreExpr) -> IO ()
+listBinding (b, e) = do
+ putStr "\nBinder: "
+ putStr $ show b
+ putStr "\nExpression: \n"
+ putStr $ prettyShow e
+ putStr "\n\n"
+ putStr $ showSDoc $ ppr e
+ putStr "\n\n"
+ putStr $ showSDoc $ ppr $ CoreUtils.exprType e
+ putStr "\n\n"
+
-- | Show the core structure of the given binds in the given file.
listBind :: String -> String -> IO ()
listBind filename name = do
import qualified OccName
import qualified Var
import qualified Id
+import qualified IdInfo
import qualified TyCon
import qualified Type
import qualified DataCon
in
res
+
-- Turn a VHDLName into an AST expression
vhdlNameToVHDLExpr = AST.PrimName
case name of
"TFVec" -> mk_vector_ty ty
"SizedWord" -> mk_unsigned_ty ty
+ "SizedInt" -> mk_signed_ty ty
"RangedWord" -> mk_natural_ty 0 (ranged_word_bound ty)
-- Create a custom type from this tycon
otherwise -> mk_tycon_ty tycon args
return (Right (ty_id, Right ty_def))
mk_unsigned_ty ::
- Type.Type -- ^ Haskell type of the signed integer
+ Type.Type -- ^ Haskell type of the unsigned integer
-> TypeSession (Either String (AST.TypeMark, Either AST.TypeDef AST.SubtypeIn))
mk_unsigned_ty ty = do
let size = sized_word_len ty
let ty_id = mkVHDLExtId $ "unsigned_" ++ show (size - 1)
let range = AST.ConstraintIndex $ AST.IndexConstraint [AST.ToRange (AST.PrimLit "0") (AST.PrimLit $ show (size - 1))]
+ let ty_def = AST.SubtypeIn unsignedTM (Just range)
+ return (Right (ty_id, Right ty_def))
+
+mk_signed_ty ::
+ Type.Type -- ^ Haskell type of the signed integer
+ -> TypeSession (Either String (AST.TypeMark, Either AST.TypeDef AST.SubtypeIn))
+mk_signed_ty ty = do
+ let size = sized_word_len ty
+ let ty_id = mkVHDLExtId $ "signed_" ++ show (size - 1)
+ let range = AST.ConstraintIndex $ AST.IndexConstraint [AST.ToRange (AST.PrimLit "0") (AST.PrimLit $ show (size - 1))]
let ty_def = AST.SubtypeIn signedTM (Just range)
return (Right (ty_id, Right ty_def))
case elem_htype_either of
-- Could create element type
Right elem_htype -> do
- len <- vec_len ty
+ len <- tfp_to_int (tfvec_len_ty 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"
++ err
- "SizedWord" -> return $ Right $ StdType $ OrdType ty
- "RangedWord" -> return $ Right $ StdType $ OrdType ty
+ "SizedWord" -> do
+ len <- tfp_to_int (sized_word_len_ty ty)
+ return $ Right $ SizedWType len
+ "SizedInt" -> do
+ len <- tfp_to_int (sized_word_len_ty ty)
+ return $ Right $ SizedIType len
+ "RangedWord" -> do
+ bound <- tfp_to_int (ranged_word_bound_ty ty)
+ return $ Right $ RangedWType bound
otherwise -> do
mkTyConHType tycon args
Nothing -> return $ Right $ StdType $ OrdType ty
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
+tfp_to_int :: Type.Type -> TypeSession Int
+tfp_to_int ty = do
+ lens <- getA vsTfpInts
+ let existing_len = Map.lookup (OrdType ty) lens
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))
+ let new_len = eval_tfp_int ty
+ modA vsTfpInts (Map.insert (OrdType ty) (new_len))
return new_len
\ No newline at end of file
data HType = StdType OrdType |
ADTType String [HType] |
VecType Int HType |
+ SizedWType Int |
+ RangedWType Int |
+ SizedIType Int |
BuiltinType String
deriving (Eq, Ord)