1{-
2    SockeyeSymbolTable.hs: Symbol Table for Sockeye
3
4    Part of Sockeye
5
6    Copyright (c) 2017, ETH Zurich.
7
8    All rights reserved.
9
10    This file is distributed under the terms in the attached LICENSE file.
11    If you do not find this file, copies can be found by writing to:
12    ETH Zurich D-INFK, CAB F.78, Universitaetstrasse 6, CH-8092 Zurich,
13    Attn: Systems Group.
14-}
15
16module SockeyeSymbolTable
17    ( module SockeyeSymbolTable
18    , module SockeyeAST
19    ) where
20
21import Data.Set (Set)
22import Data.Map (Map)
23
24import SockeyeASTMeta
25
26import SockeyeAST
27    ( NaturalSet(NaturalSet)
28    , NaturalRange(SingletonRange, LimitRange, BitsRange)
29    , natRangeMeta, base, limit, bits
30    , NaturalExpr(Addition, Subtraction, Multiplication, Slice, Concat, Variable, Literal)
31    , natExprMeta, natExprOp1, natExprOp2, bitRange, varName, natural
32    )
33
34data Sockeye = Sockeye
35    { entryPoint :: FilePath
36    , files      :: Map FilePath SockeyeFile
37    }
38    deriving (Show)
39
40data SockeyeFile = SockeyeFile
41    { sockeyeFileMeta :: ASTMeta 
42    , modules         :: Map String Module
43    , types           :: Map String NamedType
44    }
45    deriving (Show)
46
47instance MetaAST SockeyeFile where
48    meta = sockeyeFileMeta
49
50data Module
51    = Module
52        { moduleMeta     :: ASTMeta
53        , parameters     :: Map String ModuleParameter
54        , parameterOrder :: [String]
55        , constants      :: Map String NamedConstant
56        , inputPorts     :: Set String
57        , outputPorts    :: Map String Node
58        , instances      :: Map String Instance
59        , nodes          :: Map String Node
60        }
61    | ImportedModule
62        { moduleMeta  :: ASTMeta
63        , moduleFile  :: !FilePath
64        , origModName :: !String
65        }
66    deriving (Show)
67
68instance MetaAST Module where
69    meta = moduleMeta
70
71data ModuleParameter = ModuleParameter
72    { paramMeta  :: ASTMeta
73    , paramRange :: NaturalSet
74    }
75    deriving (Show)
76
77instance MetaAST ModuleParameter where
78    meta = paramMeta
79
80data Instance = Instance
81    { instMeta    :: ASTMeta
82    , instModule  :: !String
83    , instArrSize :: Maybe ArraySize
84    }
85    deriving (Show)
86
87instance MetaAST Instance where
88    meta = instMeta
89
90data Node = Node
91    { nodeMeta    :: ASTMeta
92    , nodeType    :: NodeType
93    , nodeArrSize :: Maybe ArraySize
94    }
95    deriving (Show)
96
97instance MetaAST Node where
98    meta = nodeMeta
99
100data NodeType = NodeType
101    { nodeTypeMeta :: ASTMeta
102    , originDomain :: !Domain
103    , originType   :: EdgeType
104    , targetDomain :: !Domain
105    , targetType   :: Maybe EdgeType
106    }
107    deriving (Show)
108
109instance MetaAST NodeType where
110    meta = nodeTypeMeta
111
112data Domain
113    = Memory
114    | Interrupt
115    | Power
116    | Clock
117    deriving (Eq, Show)
118
119data EdgeType
120    = TypeLiteral
121        { edgeTypeMeta :: ASTMeta
122        , typeLiteral  :: AddressType
123        }
124    | TypeName
125        { edgeTypeMeta :: ASTMeta
126        , typeRef      :: !String
127        }
128    deriving (Show)
129
130instance MetaAST EdgeType where
131    meta = edgeTypeMeta
132
133data NamedType
134    = NamedType
135        { namedTypeMeta :: ASTMeta
136        , namedType     :: AddressType
137        }
138    | ImportedType
139        { namedTypeMeta :: ASTMeta
140        , typeFile      :: !FilePath
141        , origTypeName  :: !String
142        }
143    deriving (Show)
144
145instance MetaAST NamedType where
146    meta = namedTypeMeta
147
148data NamedConstant = NamedConstant
149    { namedConstMeta :: ASTMeta
150    , namedConst     :: !Integer
151    }
152    deriving (Show)
153
154instance MetaAST NamedConstant where
155    meta = namedConstMeta
156
157data ArraySize = ArraySize ASTMeta [NaturalSet]
158    deriving (Show)
159
160instance MetaAST ArraySize where
161    meta (ArraySize m _) = m
162
163data AddressType = AddressType ASTMeta [NaturalSet]
164    deriving (Show)
165
166instance MetaAST AddressType where
167    meta (AddressType m _) = m
168