re-org, work towards switch and process support
This commit is contained in:
parent
97217ee5bf
commit
6de594c621
|
@ -1,14 +1,43 @@
|
||||||
module RTLILParser.AST(
|
module RTLILParser.AST (
|
||||||
AutoIdxStmt(..) ,ParamStmt(..) ,AutogenId(..)
|
-- Identifiers
|
||||||
,Constant(..) ,CellStmt(..) ,PublicId(..)
|
Id(..), PublicId(..), AutogenId(..),
|
||||||
,AttrStmt(..) ,Value(..) ,Id(..)
|
|
||||||
,CellId(..) ,CellType(..) ,WireId(..)
|
-- Values
|
||||||
,SigSpec(..) ,Slice(..) ,ConnStmt(..)
|
Value(..),
|
||||||
,WireOption(..) ,WireStmt(..) ,Wire(..)
|
|
||||||
,MemoryOption(..) ,MemoryStmt(..) ,Memory(..)
|
-- Autoindex statements
|
||||||
,MemoryID(..) ,CellBodyStmt(..) ,ParameterSign(..)
|
AutoIdxStmt(..),
|
||||||
,Cell(..)
|
|
||||||
) where
|
-- Module
|
||||||
|
ParamStmt(..), Constant(..),
|
||||||
|
|
||||||
|
-- Attribute statements
|
||||||
|
AttrStmt(..),
|
||||||
|
|
||||||
|
-- Signal Specifications
|
||||||
|
SigSpec(..), Slice(..),
|
||||||
|
|
||||||
|
-- Connections
|
||||||
|
ConnStmt(..),
|
||||||
|
|
||||||
|
-- Wires
|
||||||
|
Wire(..), WireStmt(..), WireId(..), WireOption(..),
|
||||||
|
|
||||||
|
-- Memories
|
||||||
|
Memory(..), MemoryStmt(..), MemoryID(..), MemoryOption(..),
|
||||||
|
|
||||||
|
-- Cells
|
||||||
|
Cell(..), CellStmt(..), CellId(..), CellType(..), ParameterSign(..),
|
||||||
|
CellBodyStmt(..),
|
||||||
|
|
||||||
|
-- Processes
|
||||||
|
DestSigSpec(..), SrcSigSpec(..), AssignStmt(..),
|
||||||
|
|
||||||
|
-- Switches
|
||||||
|
Switch(..), SwitchStmt(..), Case(..), CaseStmt(..), Compare(..),
|
||||||
|
CaseBodyVariants(..), CaseBody(..)
|
||||||
|
) where
|
||||||
|
|
||||||
import Text.Read (Lexeme(Ident))
|
import Text.Read (Lexeme(Ident))
|
||||||
import Data.Functor.Contravariant (Contravariant)
|
import Data.Functor.Contravariant (Contravariant)
|
||||||
import GHC.RTS.Flags (DoCostCentres(CostCentresAll))
|
import GHC.RTS.Flags (DoCostCentres(CostCentresAll))
|
||||||
|
@ -99,5 +128,23 @@ data CellBodyStmt = CellBodyParameter
|
||||||
deriving (Show)
|
deriving (Show)
|
||||||
|
|
||||||
-- Processes
|
-- Processes
|
||||||
|
data DestSigSpec = DestSigSpec SigSpec deriving (Show)
|
||||||
|
data SrcSigSpec = SrcSigSpec SigSpec deriving (Show)
|
||||||
|
data AssignStmt = AssignStmt DestSigSpec SrcSigSpec
|
||||||
|
deriving (Show)
|
||||||
|
|
||||||
-- Switches
|
-- Switches
|
||||||
|
data Switch = Switch SwitchStmt [AttrStmt] [Case]
|
||||||
|
deriving (Show)
|
||||||
|
data SwitchStmt = SwitchStmt SigSpec [AttrStmt] deriving (Show)
|
||||||
|
data Case = Case CaseStmt [AttrStmt] [AssignStmt] CaseBody
|
||||||
|
deriving (Show)
|
||||||
|
data CaseStmt = CaseStmt (Maybe Compare)
|
||||||
|
deriving (Show)
|
||||||
|
data Compare = Compare SigSpec [SigSpec]
|
||||||
|
deriving (Show)
|
||||||
|
data CaseBodyVariants = CaseBodySwitchVariant Switch
|
||||||
|
| CaseBodyAssignVariant AssignStmt
|
||||||
|
deriving (Show)
|
||||||
|
data CaseBody = CaseBody [CaseBodyVariants] deriving (Show)
|
||||||
-- Syncs
|
-- Syncs
|
|
@ -3,18 +3,46 @@ module RTLILParser.Parser(a, val) where
|
||||||
import Control.Monad (void)
|
import Control.Monad (void)
|
||||||
import Text.Parsec
|
import Text.Parsec
|
||||||
import Text.Parsec.String (Parser)
|
import Text.Parsec.String (Parser)
|
||||||
import RTLILParser.AST(
|
|
||||||
AutoIdxStmt(..) ,ParamStmt(..) ,AutogenId(..)
|
|
||||||
,Constant(..) ,CellStmt(..) ,PublicId(..)
|
|
||||||
,AttrStmt(..) ,Value(..) ,Id(..)
|
|
||||||
,CellId(..) ,CellType(..) ,WireId(..)
|
|
||||||
,SigSpec(..) ,Slice(..) ,ConnStmt(..)
|
|
||||||
,WireOption(..) ,WireStmt(..) ,Wire(..)
|
|
||||||
,MemoryOption(..) ,MemoryStmt(..) ,Memory(..)
|
|
||||||
,MemoryID(..) ,CellBodyStmt(..) ,ParameterSign(..)
|
|
||||||
,Cell(..)
|
|
||||||
)
|
|
||||||
import Util(binaryStringToInt)
|
import Util(binaryStringToInt)
|
||||||
|
import RTLILParser.AST (
|
||||||
|
-- Identifiers
|
||||||
|
Id(..), PublicId(..), AutogenId(..),
|
||||||
|
|
||||||
|
-- Values
|
||||||
|
Value(..),
|
||||||
|
|
||||||
|
-- Autoindex statements
|
||||||
|
AutoIdxStmt(..),
|
||||||
|
|
||||||
|
-- Module
|
||||||
|
ParamStmt(..), Constant(..),
|
||||||
|
|
||||||
|
-- Attribute statements
|
||||||
|
AttrStmt(..),
|
||||||
|
|
||||||
|
-- Signal Specifications
|
||||||
|
SigSpec(..), Slice(..),
|
||||||
|
|
||||||
|
-- Connections
|
||||||
|
ConnStmt(..),
|
||||||
|
|
||||||
|
-- Wires
|
||||||
|
Wire(..), WireStmt(..), WireId(..), WireOption(..),
|
||||||
|
|
||||||
|
-- Memories
|
||||||
|
Memory(..), MemoryStmt(..), MemoryID(..), MemoryOption(..),
|
||||||
|
|
||||||
|
-- Cells
|
||||||
|
Cell(..), CellStmt(..), CellId(..), CellType(..), ParameterSign(..),
|
||||||
|
CellBodyStmt(..),
|
||||||
|
|
||||||
|
-- Processes
|
||||||
|
DestSigSpec(..), SrcSigSpec(..), AssignStmt(..),
|
||||||
|
|
||||||
|
-- Switches
|
||||||
|
Switch(..), SwitchStmt(..), Case(..), CaseStmt(..), Compare(..),
|
||||||
|
CaseBodyVariants(..), CaseBody(..)
|
||||||
|
)
|
||||||
import RTLILParser.Primitives(
|
import RTLILParser.Primitives(
|
||||||
pWs
|
pWs
|
||||||
,pNonWs
|
,pNonWs
|
||||||
|
@ -131,7 +159,7 @@ applySlices base = do
|
||||||
pSlice :: Parser Slice
|
pSlice :: Parser Slice
|
||||||
pSlice =
|
pSlice =
|
||||||
Slice
|
Slice
|
||||||
<$> (char '[' *> pMaybeWs *> pInteger <* pMaybeWs)
|
<$> (pMaybeWs *> char '[' *> pMaybeWs *> pInteger <* pMaybeWs)
|
||||||
<*> (optionMaybe (char ':' *> pInteger) <* pMaybeWs <* char ']')
|
<*> (optionMaybe (char ':' *> pInteger) <* pMaybeWs <* char ']')
|
||||||
|
|
||||||
-- Connections
|
-- Connections
|
||||||
|
@ -233,10 +261,29 @@ pCellBodyConnect = do
|
||||||
_ <- string "connect" <* pWs
|
_ <- string "connect" <* pWs
|
||||||
id <- pId <* pWs
|
id <- pId <* pWs
|
||||||
sigSpec <- pSigSpec <* pEol
|
sigSpec <- pSigSpec <* pEol
|
||||||
return $ CellConnect id sigSpec
|
return $ CellConnect id sigSpec
|
||||||
|
|
||||||
-- Processes
|
-- Processes
|
||||||
|
pDestSigSpec :: Parser DestSigSpec
|
||||||
|
pDestSigSpec = DestSigSpec <$> pSigSpec
|
||||||
|
|
||||||
|
pSrcSigSpec :: Parser SrcSigSpec
|
||||||
|
pSrcSigSpec = SrcSigSpec <$> pSigSpec
|
||||||
|
|
||||||
|
pAssignStmt :: Parser AssignStmt
|
||||||
|
pAssignStmt = AssignStmt
|
||||||
|
<$> (string "assign" *> pWs *> pDestSigSpec)
|
||||||
|
<*> (pWs *> pSrcSigSpec <* pEol)
|
||||||
|
|
||||||
-- Switches
|
-- Switches
|
||||||
|
pCaseStmt :: Parser CaseStmt
|
||||||
|
pCaseStmt = CaseStmt
|
||||||
|
<$> (string "case" *> pWs *> optionMaybe pCompare <* pEol)
|
||||||
|
|
||||||
|
pCompare :: Parser Compare
|
||||||
|
pCompare = Compare
|
||||||
|
<$> pSigSpec
|
||||||
|
<*> many (char ',' *> pMaybeWs *> pSigSpec)
|
||||||
-- Syncs
|
-- Syncs
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue