re-org basically complete for now
This commit is contained in:
parent
f2ef23d02e
commit
f1a59a13fe
|
@ -63,25 +63,6 @@ pInteger = do
|
||||||
Nothing -> value
|
Nothing -> value
|
||||||
|
|
||||||
-- strings
|
-- strings
|
||||||
-- comments
|
|
||||||
-- file
|
|
||||||
-- Autoindex statements
|
|
||||||
-- Module
|
|
||||||
-- Attribute statements
|
|
||||||
-- Signal Specifications
|
|
||||||
-- Connections
|
|
||||||
-- Wires
|
|
||||||
-- Memories
|
|
||||||
-- Cells
|
|
||||||
-- Processes
|
|
||||||
-- Switches
|
|
||||||
-- Syncs
|
|
||||||
|
|
||||||
pWireId :: Parser WireId
|
|
||||||
pWireId = WireId <$> pId
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
pString :: Parser String
|
pString :: Parser String
|
||||||
pString =
|
pString =
|
||||||
between delimiter delimiter parseString
|
between delimiter delimiter parseString
|
||||||
|
@ -89,49 +70,48 @@ pString =
|
||||||
delimiter = char '"'
|
delimiter = char '"'
|
||||||
parseString = many (pEscapedChar <|> noneOf "\\\"")
|
parseString = many (pEscapedChar <|> noneOf "\\\"")
|
||||||
|
|
||||||
pConstant :: Parser Constant
|
-- comments
|
||||||
pConstant =
|
-- file
|
||||||
try (ConstantValue <$> pValue)
|
|
||||||
<|> (ConstantInteger <$> pInteger)
|
|
||||||
<|> (ConstantString <$> pString)
|
|
||||||
|
|
||||||
|
-- Autoindex statements
|
||||||
pAutoIdxStmt :: Parser AutoIdxStmt
|
pAutoIdxStmt :: Parser AutoIdxStmt
|
||||||
pAutoIdxStmt = AutoIdxStmt <$> (string "autoidx" *> pWs *> pInteger <* pEol)
|
pAutoIdxStmt = AutoIdxStmt <$> (string "autoidx" *> pWs *> pInteger <* pEol)
|
||||||
|
|
||||||
|
-- Module
|
||||||
pModuleStmt :: Parser Id
|
pModuleStmt :: Parser Id
|
||||||
pModuleStmt = string "module" *> pWs *> pId <* pEol
|
pModuleStmt = string "module" *> pWs *> pId <* pEol
|
||||||
|
|
||||||
pModuleEndStmt :: Parser ()
|
|
||||||
pModuleEndStmt = void (string "end")
|
|
||||||
|
|
||||||
pParamStmt :: Parser ParamStmt
|
pParamStmt :: Parser ParamStmt
|
||||||
pParamStmt = ParamStmt
|
pParamStmt = ParamStmt
|
||||||
<$> (string "parameter" *> pWs *> pId)
|
<$> (string "parameter" *> pWs *> pId)
|
||||||
<*> optionMaybe (pWs *> pConstant)
|
<*> optionMaybe (pWs *> pConstant)
|
||||||
<* pEol
|
<* pEol
|
||||||
|
|
||||||
|
pConstant :: Parser Constant
|
||||||
|
pConstant =
|
||||||
|
try (ConstantValue <$> pValue)
|
||||||
|
<|> (ConstantInteger <$> pInteger)
|
||||||
|
<|> (ConstantString <$> pString)
|
||||||
|
|
||||||
|
pModuleEndStmt :: Parser ()
|
||||||
|
pModuleEndStmt = void (string "end")
|
||||||
|
|
||||||
|
-- Attribute statements
|
||||||
pAttrStmt :: Parser AttrStmt
|
pAttrStmt :: Parser AttrStmt
|
||||||
pAttrStmt = AttrStmt
|
pAttrStmt = AttrStmt
|
||||||
<$> (string "attribute" *> pWs *> pId)
|
<$> (string "attribute" *> pWs *> pId)
|
||||||
<*> (pWs *> pConstant)
|
<*> (pWs *> pConstant)
|
||||||
<* pEol
|
<* pEol
|
||||||
|
|
||||||
pCellStmt :: Parser CellStmt
|
-- Signal Specifications
|
||||||
pCellStmt = do
|
pSigSpec :: Parser SigSpec
|
||||||
_ <- string "cell"
|
pSigSpec = do
|
||||||
_ <- pWs
|
baseSigSpec <- (SigSpecConstant <$> pConstant)
|
||||||
cellId <- CellId <$> pId
|
<|>
|
||||||
_ <- pWs
|
(SigSpecWireId <$> pWireId)
|
||||||
cellType <- CellType <$> pId
|
<|>
|
||||||
_ <- pEol
|
pSigSpecConcat
|
||||||
return $ CellStmt cellId cellType
|
applySlices baseSigSpec
|
||||||
|
|
||||||
-- Parse a single slice
|
|
||||||
pSlice :: Parser Slice
|
|
||||||
pSlice =
|
|
||||||
Slice
|
|
||||||
<$> (char '[' *> pMaybeWs *> pInteger <* pMaybeWs)
|
|
||||||
<*> (optionMaybe (char ':' *> pInteger) <* pMaybeWs <* char ']')
|
|
||||||
|
|
||||||
pSigSpecConcat :: Parser SigSpec
|
pSigSpecConcat :: Parser SigSpec
|
||||||
pSigSpecConcat = do
|
pSigSpecConcat = do
|
||||||
|
@ -147,33 +127,25 @@ applySlices base = do
|
||||||
Nothing -> return base
|
Nothing -> return base
|
||||||
Just slice -> applySlices (SigSpecSlice base slice)
|
Just slice -> applySlices (SigSpecSlice base slice)
|
||||||
|
|
||||||
pSingleSigSpec :: Parser SigSpec
|
pSlice :: Parser Slice
|
||||||
pSingleSigSpec = do
|
pSlice =
|
||||||
baseSigSpec <- (SigSpecConstant <$> pConstant)
|
Slice
|
||||||
<|>
|
<$> (char '[' *> pMaybeWs *> pInteger <* pMaybeWs)
|
||||||
(SigSpecWireId <$> pWireId)
|
<*> (optionMaybe (char ':' *> pInteger) <* pMaybeWs <* char ']')
|
||||||
applySlices baseSigSpec
|
|
||||||
|
|
||||||
pSigSpec :: Parser SigSpec
|
|
||||||
pSigSpec =
|
|
||||||
try pSigSpecConcat -- Check for concatenation first
|
|
||||||
<|> pSingleSigSpec -- Otherwise parse a single sigspec
|
|
||||||
|
|
||||||
|
-- Connections
|
||||||
pConnStmt :: Parser ConnStmt
|
pConnStmt :: Parser ConnStmt
|
||||||
pConnStmt = ConnStmt
|
pConnStmt = ConnStmt
|
||||||
<$> (string "connect" *> pWs *> pSigSpec)
|
<$> (string "connect" *> pWs *> pSigSpec)
|
||||||
<*> (pWs *> pSigSpec)
|
<*> (pWs *> pSigSpec)
|
||||||
<* pEol
|
<* pEol
|
||||||
|
|
||||||
pWireOption :: Parser WireOption
|
-- Wires
|
||||||
pWireOption =
|
pWire :: Parser Wire
|
||||||
try (WireOptionWidth <$> (string "width" *> pWs *> pInteger)) <|>
|
pWire = do
|
||||||
try (WireOptionOffset <$> (string "offset" *> pWs *> pInteger)) <|>
|
attrs <- many pAttrStmt
|
||||||
try (WireOptionInput <$> (string "input" *> pWs *> pInteger)) <|>
|
wireStmt <- pWireStmt
|
||||||
try (WireOptionOutput <$> (string "output" *> pWs *> pInteger)) <|>
|
return $ Wire wireStmt attrs
|
||||||
try (WireOptionInout <$> (string "inout" *> pWs *> pInteger)) <|>
|
|
||||||
(string "upto" *> return WireOptionUpto) <|>
|
|
||||||
(string "signed" *> return WireOptionSigned)
|
|
||||||
|
|
||||||
pWireStmt :: Parser WireStmt
|
pWireStmt :: Parser WireStmt
|
||||||
pWireStmt =
|
pWireStmt =
|
||||||
|
@ -185,17 +157,25 @@ pWireStmt =
|
||||||
<*> many pWireOption
|
<*> many pWireOption
|
||||||
<* pEol
|
<* pEol
|
||||||
|
|
||||||
pWire :: Parser Wire
|
pWireId :: Parser WireId
|
||||||
pWire = do
|
pWireId = WireId <$> pId
|
||||||
attrs <- many pAttrStmt
|
|
||||||
wireStmt <- pWireStmt
|
|
||||||
return $ Wire wireStmt attrs
|
|
||||||
|
|
||||||
pMemoryOption :: Parser MemoryOption
|
pWireOption :: Parser WireOption
|
||||||
pMemoryOption =
|
pWireOption =
|
||||||
try (MemoryOptionWidth <$> (string "width" *> pWs *> pInteger)) <|>
|
try (WireOptionWidth <$> (string "width" *> pWs *> pInteger)) <|>
|
||||||
try (MemoryOptionSize <$> (string "size" *> pWs *> pInteger)) <|>
|
try (WireOptionOffset <$> (string "offset" *> pWs *> pInteger)) <|>
|
||||||
try (MemoryOptionOffset <$> (string "offset" *> pWs *> pInteger))
|
try (WireOptionInput <$> (string "input" *> pWs *> pInteger)) <|>
|
||||||
|
try (WireOptionOutput <$> (string "output" *> pWs *> pInteger)) <|>
|
||||||
|
try (WireOptionInout <$> (string "inout" *> pWs *> pInteger)) <|>
|
||||||
|
(string "upto" *> return WireOptionUpto) <|>
|
||||||
|
(string "signed" *> return WireOptionSigned)
|
||||||
|
|
||||||
|
-- Memories
|
||||||
|
pMemory :: Parser Memory
|
||||||
|
pMemory = do
|
||||||
|
attrs <- many pAttrStmt
|
||||||
|
memoryStmt <- pMemoryStmt
|
||||||
|
return $ Memory memoryStmt attrs
|
||||||
|
|
||||||
pMemoryStmt :: Parser MemoryStmt
|
pMemoryStmt :: Parser MemoryStmt
|
||||||
pMemoryStmt =
|
pMemoryStmt =
|
||||||
|
@ -207,19 +187,29 @@ pMemoryStmt =
|
||||||
<*> many pMemoryOption
|
<*> many pMemoryOption
|
||||||
<* pEol
|
<* pEol
|
||||||
|
|
||||||
pMemory :: Parser Memory
|
pMemoryOption :: Parser MemoryOption
|
||||||
pMemory = do
|
pMemoryOption =
|
||||||
attrs <- many pAttrStmt
|
try (MemoryOptionWidth <$> (string "width" *> pWs *> pInteger)) <|>
|
||||||
memoryStmt <- pMemoryStmt
|
try (MemoryOptionSize <$> (string "size" *> pWs *> pInteger)) <|>
|
||||||
return $ Memory memoryStmt attrs
|
try (MemoryOptionOffset <$> (string "offset" *> pWs *> pInteger))
|
||||||
|
|
||||||
|
-- Cells
|
||||||
|
pCellStmt :: Parser CellStmt
|
||||||
|
pCellStmt = do
|
||||||
|
_ <- string "cell"
|
||||||
|
_ <- pWs
|
||||||
|
cellId <- CellId <$> pId
|
||||||
|
_ <- pWs
|
||||||
|
cellType <- CellType <$> pId
|
||||||
|
_ <- pEol
|
||||||
|
return $ CellStmt cellId cellType
|
||||||
|
|
||||||
|
-- Processes
|
||||||
|
-- Switches
|
||||||
|
-- Syncs
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
-- <cell> ::= <attr-stmt>* <cell-stmt> <cell-body-stmt>* <cell-end-stmt>
|
|
||||||
-- <cell-stmt> ::= cell <cell-type> <cell-id> <eol>
|
|
||||||
-- <cell-id> ::= <id>
|
|
||||||
-- <cell-type> ::= <id>
|
|
||||||
-- <cell-body-stmt> ::= parameter (signed | real)? <id> <constant> <eol>
|
|
||||||
-- | connect <id> <sigspec> <eol>
|
|
||||||
-- <cell-end-stmt> ::= end <eol>
|
|
||||||
|
|
||||||
-- would correspond to `123456789[0:9][0:8]`
|
-- would correspond to `123456789[0:9][0:8]`
|
||||||
exampleSigSpecSlice =
|
exampleSigSpecSlice =
|
||||||
|
|
Loading…
Reference in a new issue