I seem to have implemented the Cell parser
This commit is contained in:
parent
f1a59a13fe
commit
97217ee5bf
|
@ -1,12 +1,13 @@
|
||||||
module RTLILParser.AST(
|
module RTLILParser.AST(
|
||||||
AutoIdxStmt(..) ,ParamStmt(..) ,AutogenId(..)
|
AutoIdxStmt(..) ,ParamStmt(..) ,AutogenId(..)
|
||||||
,Constant(..) ,CellStmt(..) ,PublicId(..)
|
,Constant(..) ,CellStmt(..) ,PublicId(..)
|
||||||
,AttrStmt(..) ,Value(..) ,Id(..)
|
,AttrStmt(..) ,Value(..) ,Id(..)
|
||||||
,CellId(..) ,CellType(..) ,WireId(..)
|
,CellId(..) ,CellType(..) ,WireId(..)
|
||||||
,SigSpec(..) ,Slice(..) ,ConnStmt(..)
|
,SigSpec(..) ,Slice(..) ,ConnStmt(..)
|
||||||
,WireOption(..) ,WireStmt(..) ,Wire(..)
|
,WireOption(..) ,WireStmt(..) ,Wire(..)
|
||||||
,MemoryOption(..) ,MemoryStmt(..) ,Memory(..)
|
,MemoryOption(..) ,MemoryStmt(..) ,Memory(..)
|
||||||
,MemoryID(..)
|
,MemoryID(..) ,CellBodyStmt(..) ,ParameterSign(..)
|
||||||
|
,Cell(..)
|
||||||
) where
|
) where
|
||||||
import Text.Read (Lexeme(Ident))
|
import Text.Read (Lexeme(Ident))
|
||||||
import Data.Functor.Contravariant (Contravariant)
|
import Data.Functor.Contravariant (Contravariant)
|
||||||
|
@ -84,9 +85,18 @@ data MemoryOption = MemoryOptionWidth Int
|
||||||
deriving (Show)
|
deriving (Show)
|
||||||
|
|
||||||
-- Cells
|
-- Cells
|
||||||
|
data Cell = Cell CellStmt [AttrStmt] [CellBodyStmt]
|
||||||
|
deriving (Show)
|
||||||
data CellStmt = CellStmt CellId CellType deriving (Show)
|
data CellStmt = CellStmt CellId CellType deriving (Show)
|
||||||
data CellId = CellId Id deriving (Show)
|
data CellId = CellId Id deriving (Show)
|
||||||
data CellType = CellType Id deriving (Show)
|
data CellType = CellType Id deriving (Show)
|
||||||
|
data ParameterSign = Signed | Real deriving (Show)
|
||||||
|
data CellBodyStmt = CellBodyParameter
|
||||||
|
(Maybe ParameterSign)
|
||||||
|
Id
|
||||||
|
Constant
|
||||||
|
| CellConnect Id SigSpec
|
||||||
|
deriving (Show)
|
||||||
|
|
||||||
-- Processes
|
-- Processes
|
||||||
-- Switches
|
-- Switches
|
||||||
|
|
|
@ -4,14 +4,15 @@ import Control.Monad (void)
|
||||||
import Text.Parsec
|
import Text.Parsec
|
||||||
import Text.Parsec.String (Parser)
|
import Text.Parsec.String (Parser)
|
||||||
import RTLILParser.AST(
|
import RTLILParser.AST(
|
||||||
AutoIdxStmt(..) ,ParamStmt(..) ,AutogenId(..)
|
AutoIdxStmt(..) ,ParamStmt(..) ,AutogenId(..)
|
||||||
,Constant(..) ,CellStmt(..) ,PublicId(..)
|
,Constant(..) ,CellStmt(..) ,PublicId(..)
|
||||||
,AttrStmt(..) ,Value(..) ,Id(..)
|
,AttrStmt(..) ,Value(..) ,Id(..)
|
||||||
,CellId(..) ,CellType(..) ,WireId(..)
|
,CellId(..) ,CellType(..) ,WireId(..)
|
||||||
,SigSpec(..) ,Slice(..) ,ConnStmt(..)
|
,SigSpec(..) ,Slice(..) ,ConnStmt(..)
|
||||||
,WireOption(..) ,WireStmt(..) ,Wire(..)
|
,WireOption(..) ,WireStmt(..) ,Wire(..)
|
||||||
,MemoryOption(..) ,MemoryStmt(..) ,Memory(..)
|
,MemoryOption(..) ,MemoryStmt(..) ,Memory(..)
|
||||||
,MemoryID(..)
|
,MemoryID(..) ,CellBodyStmt(..) ,ParameterSign(..)
|
||||||
|
,Cell(..)
|
||||||
)
|
)
|
||||||
import Util(binaryStringToInt)
|
import Util(binaryStringToInt)
|
||||||
import RTLILParser.Primitives(
|
import RTLILParser.Primitives(
|
||||||
|
@ -83,8 +84,8 @@ pModuleStmt = string "module" *> pWs *> pId <* pEol
|
||||||
|
|
||||||
pParamStmt :: Parser ParamStmt
|
pParamStmt :: Parser ParamStmt
|
||||||
pParamStmt = ParamStmt
|
pParamStmt = ParamStmt
|
||||||
<$> (string "parameter" *> pWs *> pId)
|
<$> (string "parameter" *> pWs *> pId <* pWs)
|
||||||
<*> optionMaybe (pWs *> pConstant)
|
<*> optionMaybe pConstant
|
||||||
<* pEol
|
<* pEol
|
||||||
|
|
||||||
pConstant :: Parser Constant
|
pConstant :: Parser Constant
|
||||||
|
@ -194,16 +195,46 @@ pMemoryOption =
|
||||||
try (MemoryOptionOffset <$> (string "offset" *> pWs *> pInteger))
|
try (MemoryOptionOffset <$> (string "offset" *> pWs *> pInteger))
|
||||||
|
|
||||||
-- Cells
|
-- Cells
|
||||||
|
pCell :: Parser Cell
|
||||||
|
pCell = do
|
||||||
|
attrStmts <- many pAttrStmt
|
||||||
|
cellStmt <- pCellStmt
|
||||||
|
cellBodyStmts <- many pCellBodyStmt
|
||||||
|
return $ Cell cellStmt attrStmts cellBodyStmts
|
||||||
|
|
||||||
pCellStmt :: Parser CellStmt
|
pCellStmt :: Parser CellStmt
|
||||||
pCellStmt = do
|
pCellStmt = do
|
||||||
_ <- string "cell"
|
_ <- string "cell"
|
||||||
_ <- pWs
|
_ <- pWs
|
||||||
cellId <- CellId <$> pId
|
|
||||||
_ <- pWs
|
|
||||||
cellType <- CellType <$> pId
|
cellType <- CellType <$> pId
|
||||||
|
_ <- pWs
|
||||||
|
cellId <- CellId <$> pId
|
||||||
_ <- pEol
|
_ <- pEol
|
||||||
return $ CellStmt cellId cellType
|
return $ CellStmt cellId cellType
|
||||||
|
|
||||||
|
pCellBodyStmt :: Parser CellBodyStmt
|
||||||
|
pCellBodyStmt = pCellBodyParameter <|> pCellBodyConnect
|
||||||
|
|
||||||
|
pParameterSign :: Parser ParameterSign
|
||||||
|
pParameterSign =
|
||||||
|
(Signed <$ string "signed") <|>
|
||||||
|
(Real <$ string "real")
|
||||||
|
|
||||||
|
pCellBodyParameter :: Parser CellBodyStmt
|
||||||
|
pCellBodyParameter = do
|
||||||
|
_ <- string "parameter" <* pWs
|
||||||
|
sign <- optionMaybe pParameterSign <* pMaybeWs
|
||||||
|
id <- pId
|
||||||
|
const <- pConstant <* pEol
|
||||||
|
return $ CellBodyParameter sign id const
|
||||||
|
|
||||||
|
pCellBodyConnect :: Parser CellBodyStmt
|
||||||
|
pCellBodyConnect = do
|
||||||
|
_ <- string "connect" <* pWs
|
||||||
|
id <- pId <* pWs
|
||||||
|
sigSpec <- pSigSpec <* pEol
|
||||||
|
return $ CellConnect id sigSpec
|
||||||
|
|
||||||
-- Processes
|
-- Processes
|
||||||
-- Switches
|
-- Switches
|
||||||
-- Syncs
|
-- Syncs
|
||||||
|
|
Loading…
Reference in a new issue