Add a new module "Flatten".
[matthijs/master-project/cλash.git] / Flatten.hs
1 module Flatten where
2 import Translator (HsValueMap)
3
4
5 data FlatFunction = FlatFunction {
6   args   :: [SignalDefMap],
7   res    :: SignalUseMap,
8   --sigs   :: [SignalDef],
9   apps   :: [App],
10   conds  :: [CondDef]
11 } deriving (Show, Eq)
12     
13 type SignalUseMap = HsValueMap SignalUse
14 type SignalDefMap = HsValueMap SignalDef
15
16 data SignalUse = SignalUse {
17   sigUseId :: Int
18 } deriving (Show, Eq)
19
20 data SignalDef = SignalDef {
21   sigDefId :: Int
22 } deriving (Show, Eq)
23
24 data App = App {
25   appFunc :: HsFunction,
26   appArgs :: [SignalUseMap],
27   appRes  :: SignalDefMap
28 } deriving (Show, Eq)
29
30 data CondDef = CondDef {
31   cond    :: SignalUse,
32   high    :: SignalUse,
33   low     :: SignalUse,
34   condRes :: SignalDef
35 } deriving (Show, Eq)
36
37 -- | How is a given (single) value in a function's type (ie, argument or
38 -- return value) used?
39 data HsValueUse = 
40   Port           -- ^ Use it as a port (input or output)
41   | State Int    -- ^ Use it as state (input or output). The int is used to
42                  --   match input state to output state.
43   | HighOrder {  -- ^ Use it as a high order function input
44     hoName :: String,  -- ^ Which function is passed in?
45     hoArgs :: [HsUseMap]   -- ^ Which arguments are already applied? This
46                          -- ^ map should only contain Port and other
47                          --   HighOrder values. 
48   }
49   deriving (Show, Eq)
50
51 type HsUseMap = HsValueMap HsValueUse
52
53 data HsFunction = HsFunction {
54   hsFuncName :: String,
55   hsFuncArgs :: [HsUseMap],
56   hsFuncRes  :: HsUseMap
57 } deriving (Show, Eq)
58
59 type BindMap = [(
60   String,              -- ^ The bind name
61   Either               -- ^ The bind value which is either
62     SignalUse          -- ^ a signal
63     (
64       HsValueUse,      -- ^ or a HighOrder function
65       [SignalUse]      -- ^ With these signals already applied to it
66     )
67   )]
68 -- vim: set ts=8 sw=2 sts=2 expandtab: