re-org basically complete for now

This commit is contained in:
Yehowshua Immanuel 2024-12-06 17:57:38 -05:00
parent f2ef23d02e
commit f1a59a13fe

View file

@ -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,86 +127,96 @@ 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 =
try (WireOptionWidth <$> (string "width" *> pWs *> pInteger)) <|>
try (WireOptionOffset <$> (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)
pWireStmt :: Parser WireStmt
pWireStmt =
WireStmt
<$ string "wire"
<* pWs
<*> (WireId <$> pId)
<* pWs
<*> many pWireOption
<* pEol
pWire :: Parser Wire pWire :: Parser Wire
pWire = do pWire = do
attrs <- many pAttrStmt attrs <- many pAttrStmt
wireStmt <- pWireStmt wireStmt <- pWireStmt
return $ Wire wireStmt attrs return $ Wire wireStmt attrs
pMemoryOption :: Parser MemoryOption pWireStmt :: Parser WireStmt
pMemoryOption = pWireStmt =
try (MemoryOptionWidth <$> (string "width" *> pWs *> pInteger)) <|> WireStmt
try (MemoryOptionSize <$> (string "size" *> pWs *> pInteger)) <|> <$ string "wire"
try (MemoryOptionOffset <$> (string "offset" *> pWs *> pInteger))
pMemoryStmt :: Parser MemoryStmt
pMemoryStmt =
MemoryStmt
<$ string "memory"
<* pWs <* pWs
<*> (MemoryID <$> pId) <*> (WireId <$> pId)
<* pWs <* pWs
<*> many pMemoryOption <*> many pWireOption
<* pEol <* pEol
pWireId :: Parser WireId
pWireId = WireId <$> pId
pWireOption :: Parser WireOption
pWireOption =
try (WireOptionWidth <$> (string "width" *> pWs *> pInteger)) <|>
try (WireOptionOffset <$> (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 :: Parser Memory
pMemory = do pMemory = do
attrs <- many pAttrStmt attrs <- many pAttrStmt
memoryStmt <- pMemoryStmt memoryStmt <- pMemoryStmt
return $ Memory memoryStmt attrs return $ Memory memoryStmt attrs
-- <cell> ::= <attr-stmt>* <cell-stmt> <cell-body-stmt>* <cell-end-stmt> pMemoryStmt :: Parser MemoryStmt
-- <cell-stmt> ::= cell <cell-type> <cell-id> <eol> pMemoryStmt =
-- <cell-id> ::= <id> MemoryStmt
-- <cell-type> ::= <id> <$ string "memory"
-- <cell-body-stmt> ::= parameter (signed | real)? <id> <constant> <eol> <* pWs
-- | connect <id> <sigspec> <eol> <*> (MemoryID <$> pId)
-- <cell-end-stmt> ::= end <eol> <* pWs
<*> many pMemoryOption
<* pEol
pMemoryOption :: Parser MemoryOption
pMemoryOption =
try (MemoryOptionWidth <$> (string "width" *> pWs *> pInteger)) <|>
try (MemoryOptionSize <$> (string "size" *> pWs *> pInteger)) <|>
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
-- would correspond to `123456789[0:9][0:8]` -- would correspond to `123456789[0:9][0:8]`
exampleSigSpecSlice = exampleSigSpecSlice =
SigSpecSlice SigSpecSlice
( (
SigSpecSlice SigSpecSlice
(SigSpecConstant (ConstantInteger 123456789)) (SigSpecConstant (ConstantInteger 123456789))
(Slice 0 $ Just 9) (Slice 0 $ Just 9)
) )
(Slice 0 $ Just 8) (Slice 0 $ Just 8)