2 -- Simple module providing some types used by Translator. These are in a
3 -- separate module to prevent circular dependencies in Pretty for example.
5 module TranslatorTypes where
7 import qualified Control.Monad.State as State
10 type FuncMap = [(HsFunction,
13 data VHDLSession = VHDLSession {
14 nameCount :: Int, -- A counter that can be used to generate unique names
15 funcs :: FuncMap -- A map from HsFunction to FlatFunction, HWFunction, VHDL Entity and Architecture
18 -- Add the function to the session
19 addFunc :: HsFunction -> FlatFunction -> VHDLState ()
20 addFunc hsfunc flatfunc = do
21 fs <- State.gets funcs -- Get the funcs element from the session
22 State.modify (\x -> x {funcs = (hsfunc, flatfunc) : fs }) -- Prepend name and f
24 type VHDLState = State.State VHDLSession
26 -- Makes the given name unique by appending a unique number.
27 -- This does not do any checking against existing names, so it only guarantees
28 -- uniqueness with other names generated by uniqueName.
29 uniqueName :: String -> VHDLState String
31 count <- State.gets nameCount -- Get the funcs element from the session
32 State.modify (\s -> s {nameCount = count + 1})
33 return $ name ++ "_" ++ (show count)