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
8 import qualified HscTypes
11 type FuncMap = [(HsFunction,
14 data VHDLSession = VHDLSession {
15 coreMod :: HscTypes.CoreModule, -- The current module
16 nameCount :: Int, -- A counter that can be used to generate unique names
17 funcs :: FuncMap -- A map from HsFunction to FlatFunction, HWFunction, VHDL Entity and Architecture
20 -- Add the function to the session
21 addFunc :: HsFunction -> FlatFunction -> VHDLState ()
22 addFunc hsfunc flatfunc = do
23 fs <- State.gets funcs -- Get the funcs element from the session
24 State.modify (\x -> x {funcs = (hsfunc, flatfunc) : fs }) -- Prepend name and f
26 getModule :: VHDLState HscTypes.CoreModule
27 getModule = State.gets coreMod -- Get the coreMod element from the session
29 type VHDLState = State.State VHDLSession
31 -- Makes the given name unique by appending a unique number.
32 -- This does not do any checking against existing names, so it only guarantees
33 -- uniqueness with other names generated by uniqueName.
34 uniqueName :: String -> VHDLState String
36 count <- State.gets nameCount -- Get the funcs element from the session
37 State.modify (\s -> s {nameCount = count + 1})
38 return $ name ++ "_" ++ (show count)