From: Matthijs Kooijman Date: Sun, 21 Jun 2009 16:39:20 +0000 (+0200) Subject: Split off the VHDL type generating code. X-Git-Url: https://git.stderr.nl/gitweb?a=commitdiff_plain;h=387569c4f69c310fc8832a29dfa50652ce504f7d;p=matthijs%2Fmaster-project%2Fc%CE%BBash.git Split off the VHDL type generating code. Previously, the vhdl_ty function did builtin type lookups, cached custom types and creating new custom types. Now, the latter is moved into the new function create_vhdl_ty. --- diff --git a/VHDL.hs b/VHDL.hs index 8eb130f..a0b4c84 100644 --- a/VHDL.hs +++ b/VHDL.hs @@ -436,19 +436,26 @@ vhdl_ty ty = do Just t -> return t -- No type yet, try to construct it Nothing -> do - let new_ty = do - -- Use the Maybe Monad for failing when one of these fails - (tycon, args) <- Type.splitTyConApp_maybe ty - let name = Name.getOccString (TyCon.tyConName tycon) - case name of - "TFVec" -> Just $ mk_vector_ty (tfvec_len ty) ty - "SizedWord" -> Just $ mk_vector_ty (sized_word_len ty) ty - otherwise -> Nothing - -- Return new_ty when a new type was successfully created - Maybe.fromMaybe + new_ty <- (construct_vhdl_ty ty) + return $ Maybe.fromMaybe (error $ "Unsupported Haskell type: " ++ (showSDoc $ ppr ty)) new_ty +-- Construct a new VHDL type for the given Haskell type. +construct_vhdl_ty :: Type.Type -> VHDLState (Maybe AST.TypeMark) +construct_vhdl_ty ty = do + case Type.splitTyConApp_maybe ty of + Just (tycon, args) -> do + let name = Name.getOccString (TyCon.tyConName tycon) + case name of + "TFVec" -> do + res <- mk_vector_ty (tfvec_len ty) ty + return $ Just res + "SizedWord" -> do + res <- mk_vector_ty (sized_word_len ty) ty + return $ Just res + otherwise -> return Nothing + -- | Create a VHDL vector type mk_vector_ty :: Int -- ^ The length of the vector