From: Matthijs Kooijman Date: Wed, 21 Jan 2009 10:48:58 +0000 (+0100) Subject: Generate input port names from the argument types. X-Git-Url: https://git.stderr.nl/gitweb?a=commitdiff_plain;h=553b58f58b14a0bbe3421fc7c69c268d071dd4bb;p=matthijs%2Fmaster-project%2Fc%CE%BBash.git Generate input port names from the argument types. This replaces the hardcoded list of input port names which was used for testing before. --- diff --git a/Translator.hs b/Translator.hs index 64cdb51..56cbe5e 100644 --- a/Translator.hs +++ b/Translator.hs @@ -166,14 +166,38 @@ getInstantiations args binds expr = showSDoc $ ppr $ expr getArchitecture (NonRec var expr) = "architecture structural of " ++ name ++ " is\n" ++ "begin\n" - ++ getInstantiations (Args [Tuple [Port "portin0", Port "portin1"]]) [] expr + ++ getInstantiations (Args inportnames) [] expr ++ "end structural\n" where name = (getOccString var) ty = CoreUtils.exprType expr + (fargs, res) = Type.splitFunTys ty + --state = if length fargs == 1 then () else (last fargs) + ports = if length fargs == 1 then fargs else (init fargs) + inportnames = case ports of + [port] -> [getPortNameMapForTy "portin" port] + ps -> getPortNameMapForTys "portin" 0 ps data PortNameMap = Args [PortNameMap] -- Each of the submaps represent an argument to the -- function. Should only occur at top level. | Tuple [PortNameMap] | Port String + +-- Generate a port name map (or multiple for tuple types) in the given direction for +-- each type given. +getPortNameMapForTys :: String -> Int -> [Type] -> [PortNameMap] +getPortNameMapForTys prefix num [] = [] +getPortNameMapForTys prefix num (t:ts) = + (getPortNameMapForTy (prefix ++ show num) t) : getPortNameMapForTys prefix (num + 1) ts + +getPortNameMapForTy :: String -> Type -> PortNameMap +getPortNameMapForTy name ty = + if (TyCon.isTupleTyCon tycon) then + -- Expand tuples we find + Tuple (getPortNameMapForTys name 0 args) + else -- Assume it's a type constructor application, ie simple data type + -- TODO: Add type? + Port name + where + (tycon, args) = Type.splitTyConApp ty