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
12 -- | A map from a HsFunction identifier to various stuff we collect about a
13 -- function along the way.
14 type FuncMap = [(HsFunction, FuncData)]
15 -- | Some stuff we collect about a function along the way.
16 type FuncData = (FlatFunction)
18 data VHDLSession = VHDLSession {
19 coreMod :: HscTypes.CoreModule, -- The current module
20 nameCount :: Int, -- A counter that can be used to generate unique names
21 funcs :: FuncMap -- A map from HsFunction to FlatFunction, HWFunction, VHDL Entity and Architecture
24 -- | Add the function to the session
25 addFunc :: HsFunction -> FlatFunction -> VHDLState ()
26 addFunc hsfunc flatfunc = do
27 fs <- State.gets funcs -- Get the funcs element from the session
28 State.modify (\x -> x {funcs = (hsfunc, flatfunc) : fs }) -- Prepend name and f
30 -- | Find the given function in the current session
31 getFunc :: HsFunction -> VHDLState (Maybe FuncData)
33 fs <- State.gets funcs -- Get the funcs element from the session
34 return $ lookup hsfunc fs
36 getModule :: VHDLState HscTypes.CoreModule
37 getModule = State.gets coreMod -- Get the coreMod element from the session
39 type VHDLState = State.State VHDLSession
41 -- Makes the given name unique by appending a unique number.
42 -- This does not do any checking against existing names, so it only guarantees
43 -- uniqueness with other names generated by uniqueName.
44 uniqueName :: String -> VHDLState String
46 count <- State.gets nameCount -- Get the funcs element from the session
47 State.modify (\s -> s {nameCount = count + 1})
48 return $ name ++ "_" ++ (show count)
50 -- vim: set ts=8 sw=2 sts=2 expandtab: