X-Git-Url: https://git.stderr.nl/gitweb?a=blobdiff_plain;f=VHDL.hs;h=a0b4c842185792efdd79dbcd1abd547116347444;hb=387569c4f69c310fc8832a29dfa50652ce504f7d;hp=8eb130fad8e0d11e016e3222e011f55b36977e05;hpb=8a17f35807fb35ee4d2a4c35c75e1cf99066f94d;p=matthijs%2Fmaster-project%2Fc%CE%BBash.git 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