1{- 2 SockeyeParserAST.hs: AST for the Sockeye parser 3 4 Part of Sockeye 5 6 Copyright (c) 2018, 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 SockeyeParserAST 17 ( module SockeyeParserAST 18 , module SockeyeSymbolTable 19 , module SockeyeAST 20 ) where 21 22import Data.Map (Map) 23 24import SockeyeASTMeta 25 26import SockeyeSymbolTable 27 ( NodeType(NodeType) 28 , nodeTypeMeta, originDomain, originType, targetDomain, targetType 29 , Domain(Memory, Interrupt, Power, Clock) 30 , EdgeType(TypeLiteral, TypeName) 31 , edgeTypeMeta, typeLiteral, typeRef 32 , AddressType(AddressType) 33 , ArraySize(ArraySize) 34 ) 35 36import SockeyeAST 37 ( UnqualifiedRef(UnqualifiedRef) 38 , refMeta, refName, refIndex 39 , NodeReference(InternalNodeRef, InputPortRef) 40 , nodeRefMeta, instRef, nodeRef 41 , ArrayIndex(ArrayIndex) 42 , Address(Address) 43 , AddressBlock(AddressBlock) 44 , WildcardSet(ExplicitSet, Wildcard) 45 , NaturalSet(NaturalSet) 46 , NaturalRange(SingletonRange, LimitRange, BitsRange) 47 , natRangeMeta, base, limit, bits 48 , NaturalExpr(Addition, Subtraction, Multiplication, Slice, Concat, Variable, Literal) 49 , natExprMeta, natExprOp1, natExprOp2, bitRange, varName, natural 50 , PropertyExpr(And, Or, Not, Property, True, False) 51 , propExprMeta, propExprOp1, propExprOp2, property 52 ) 53 54data Sockeye = Sockeye 55 { entryPoint :: FilePath 56 , files :: Map FilePath SockeyeFile 57 } 58 deriving (Show) 59 60data SockeyeFile = SockeyeFile 61 { sockeyeFileMeta :: ASTMeta 62 , imports :: [Import] 63 , modules :: [Module] 64 , types :: [NamedType] 65 } 66 deriving (Show) 67 68instance MetaAST SockeyeFile where 69 meta = sockeyeFileMeta 70 71data Import = Import 72 { importMeta :: ASTMeta 73 , importFile :: !FilePath 74 , explImports :: Maybe [ImportAlias] 75 } 76 deriving (Show) 77 78instance MetaAST Import where 79 meta = importMeta 80 81data ImportAlias = ImportAlias 82 { importAliasMeta :: ASTMeta 83 , originalName :: !String 84 , importAlias :: !String 85 } 86 deriving (Show) 87 88instance MetaAST ImportAlias where 89 meta = importAliasMeta 90 91data Module = Module 92 { moduleMeta :: ASTMeta 93 , moduleExtern:: Bool 94 , moduleName :: !String 95 , parameters :: [ModuleParameter] 96 , constants :: [NamedConstant] 97 , instDecls :: [InstanceDeclaration] 98 , nodeDecls :: [NodeDeclaration] 99 , definitions :: [Definition] 100 } 101 deriving (Show) 102 103instance MetaAST Module where 104 meta = moduleMeta 105 106data ModuleParameter = ModuleParameter 107 { paramMeta :: ASTMeta 108 , paramName :: !String 109 , paramRange :: NaturalSet 110 } 111 deriving (Show) 112 113instance MetaAST ModuleParameter where 114 meta = paramMeta 115 116data InstanceDeclaration = InstanceDeclaration 117 { instDeclMeta :: ASTMeta 118 , instName :: !String 119 , instModName :: !String 120 , instArrSize :: Maybe ArraySize 121 } 122 deriving (Show) 123 124instance MetaAST InstanceDeclaration where 125 meta = instDeclMeta 126 127data NodeDeclaration = NodeDeclaration 128 { nodeDeclMeta :: ASTMeta 129 , nodeKind :: !NodeKind 130 , nodeType :: NodeType 131 , nodeName :: !String 132 , nodeArrSize :: Maybe ArraySize 133 } 134 deriving (Show) 135 136instance MetaAST NodeDeclaration where 137 meta = nodeDeclMeta 138 139data NodeKind 140 = InputPort 141 | OutputPort 142 | InternalNode 143 deriving (Eq, Show) 144 145data Definition 146 = Accepts 147 { defMeta :: ASTMeta 148 , node :: UnqualifiedRef 149 , accepts :: [AddressBlock] 150 } 151 | Maps 152 { defMeta :: ASTMeta 153 , node :: UnqualifiedRef 154 , maps :: [MapSpec] 155 } 156 | Converts 157 { defMeta :: ASTMeta 158 , node :: UnqualifiedRef 159 , converts :: [ConvertSpec] 160 } 161 | Overlays 162 { defMeta :: ASTMeta 163 , node :: UnqualifiedRef 164 , overlays :: NodeReference 165 } 166 | BlockOverlays 167 { defMeta :: ASTMeta 168 , node :: UnqualifiedRef 169 , overlays :: NodeReference 170 , blocksizes :: [Integer] 171 } 172 | Instantiates 173 { defMeta :: ASTMeta 174 , inst :: UnqualifiedRef 175 , instModule :: !String 176 , arguments :: [NaturalExpr] 177 } 178 | Binds 179 { defMeta :: ASTMeta 180 , inst :: UnqualifiedRef 181 , binds :: [PortBinding] 182 } 183 | Forall 184 { defMeta :: ASTMeta 185 , boundVarName :: !String 186 , varRange :: NaturalSet 187 , quantifierBody :: [Definition] 188 } 189 deriving (Show) 190 191instance MetaAST Definition where 192 meta = defMeta 193 194data MapSpec = MapSpec 195 { mapSpecMeta :: ASTMeta 196 , mapAddr :: AddressBlock 197 , mapTargets :: [MapTarget] 198 } 199 deriving (Show) 200 201instance MetaAST MapSpec where 202 meta = mapSpecMeta 203 204data MapTarget = MapTarget 205 { mapTargetMeta :: ASTMeta 206 , targetNode :: NodeReference 207 , targetAddr :: AddressBlock 208 } 209 deriving (Show) 210 211instance MetaAST MapTarget where 212 meta = mapTargetMeta 213 214type ConvertSpec = MapSpec 215 216data PortBinding = PortBinding 217 { portBindMeta :: ASTMeta 218 , boundPort :: UnqualifiedRef 219 , boundNode :: NodeReference 220 } 221 deriving (Show) 222 223instance MetaAST PortBinding where 224 meta = portBindMeta 225 226data NamedType = NamedType 227 { namedTypeMeta :: ASTMeta 228 , typeName :: !String 229 , namedType :: AddressType 230 } 231 deriving (Show) 232 233instance MetaAST NamedType where 234 meta = namedTypeMeta 235 236data NamedConstant = NamedConstant 237 { namedConstMeta :: ASTMeta 238 , constName :: !String 239 , namedConst :: !Integer 240 } 241 deriving (Show) 242 243instance MetaAST NamedConstant where 244 meta = namedConstMeta 245