nearly repaired parser but need to create switch test case

This commit is contained in:
Yehowshua Immanuel 2024-12-10 14:41:45 -05:00
parent a02ba006de
commit 7fd7c85fff
4 changed files with 43 additions and 25 deletions

View file

@ -6,8 +6,7 @@
- [ ] need canonical form making it easy to run all these validation - [ ] need canonical form making it easy to run all these validation
passes passes
- [ ] are recursive slices inclusive? - [ ] are recursive slices inclusive?
- [ ] what are the semantics of connection `<conn-stmt>`? Where is - [ ] what are the semantics of connection `<conn-stmt>`?
`<conn-stmt>` employed?
- [ ] Validate that `123456789[0:9][0:8]` is valid RTLIL - [ ] Validate that `123456789[0:9][0:8]` is valid RTLIL
- [ ] add validation section to README - [ ] add validation section to README
- [ ] just support Cell memV2 - [ ] just support Cell memV2

View file

@ -72,7 +72,7 @@ data Value = Value
-- strings -- strings
-- comments -- comments
-- file -- file
data File = File AutoIdxStmt [Module] deriving (Show) data File = File (Maybe AutoIdxStmt) [Module] deriving (Show)
-- Autoindex statements -- Autoindex statements
data AutoIdxStmt = AutoIdxStmt Int deriving (Show) data AutoIdxStmt = AutoIdxStmt Int deriving (Show)
@ -81,11 +81,12 @@ data AutoIdxStmt = AutoIdxStmt Int deriving (Show)
data Module = Module ModuleStmt [AttrStmt] ModuleBody deriving (Show) data Module = Module ModuleStmt [AttrStmt] ModuleBody deriving (Show)
data ModuleStmt = ModuleStmt Id deriving (Show) data ModuleStmt = ModuleStmt Id deriving (Show)
data ModuleBody = ModuleBody [ModuleBodyVariant] deriving (Show) data ModuleBody = ModuleBody [ModuleBodyVariant] deriving (Show)
data ModuleBodyVariant = ModuleBodyParamStmt ParamStmt data ModuleBodyVariant = ModuleBodyParamStmt ParamStmt
| ModuleBodyWire Wire | ModuleBodyWire Wire
| ModuleBodyMemory Memory | ModuleBodyMemory Memory
| ModuleBodyCell Cell | ModuleBodyCell Cell
| ModuleBodyProcess Process | ModuleBodyProcess Process
| ModuleBodyConnStmt ConnStmt
deriving (Show) deriving (Show)
data ParamStmt = ParamStmt Id (Maybe Constant) deriving (Show) data ParamStmt = ParamStmt Id (Maybe Constant) deriving (Show)
data Constant = ConstantValue Value data Constant = ConstantValue Value
@ -149,8 +150,7 @@ data Process = Process ProcStmt [AttrStmt] ProcessBody
data ProcStmt = ProcStmt Id deriving (Show) data ProcStmt = ProcStmt Id deriving (Show)
data ProcessBody = ProcessBody data ProcessBody = ProcessBody
[AssignStmt] [AssignStmt]
(Maybe Switch) [Switch]
[AssignStmt]
[Sync] [Sync]
deriving (Show) deriving (Show)
data AssignStmt = AssignStmt DestSigSpec SrcSigSpec data AssignStmt = AssignStmt DestSigSpec SrcSigSpec
@ -171,7 +171,7 @@ data Compare = Compare [SigSpec]
data CaseBodyVariants = CaseBodySwitchVariant Switch data CaseBodyVariants = CaseBodySwitchVariant Switch
| CaseBodyAssignVariant AssignStmt | CaseBodyAssignVariant AssignStmt
deriving (Show) deriving (Show)
data CaseBody = CaseBody [CaseBodyVariants] deriving (Show) data CaseBody = CaseBody [AssignStmt] [Switch] deriving (Show)
-- Syncs -- Syncs
data Sync = Sync SyncStmt [UpdateStmt] deriving (Show) data Sync = Sync SyncStmt [UpdateStmt] deriving (Show)

View file

@ -62,6 +62,7 @@ import RTLILParser.Primitives(
,pOctal ,pOctal
,pEscapedChar ,pEscapedChar
,advanceToNextToken ,advanceToNextToken
,advanceToFirstToken
) )
-- taken from: https://yosyshq.readthedocs.io/projects/yosys/en/0.47/appendix/rtlil_text.html -- taken from: https://yosyshq.readthedocs.io/projects/yosys/en/0.47/appendix/rtlil_text.html
@ -134,7 +135,7 @@ pFile = p <?> name where
name = "File" name = "File"
p = p =
File File
<$> (advanceToNextToken *> pAutoIdxStmt) <$> (advanceToFirstToken *> optionMaybe (try pAutoIdxStmt))
<*> many pModule <*> many pModule
-- Autoindex statements -- Autoindex statements
@ -189,7 +190,8 @@ pModuleBodyVariant = p <?> name where
try (ModuleBodyWire <$> pWire ) <|> try (ModuleBodyWire <$> pWire ) <|>
try (ModuleBodyMemory <$> pMemory ) <|> try (ModuleBodyMemory <$> pMemory ) <|>
try (ModuleBodyCell <$> pCell ) <|> try (ModuleBodyCell <$> pCell ) <|>
try (ModuleBodyProcess <$> pProcess ) try (ModuleBodyProcess <$> pProcess ) <|>
try (ModuleBodyConnStmt <$> pConnStmt )
pParamStmt :: Parser ParamStmt pParamStmt :: Parser ParamStmt
pParamStmt = p <?> name where pParamStmt = p <?> name where
@ -435,11 +437,10 @@ pProcessBody = p <?> name where
-- with the character 'a', we need to be able to rewind failed -- with the character 'a', we need to be able to rewind failed
-- attempts for `pAssignStmt` and `pSwitch` parsers as the first -- attempts for `pAssignStmt` and `pSwitch` parsers as the first
-- character being an 'a' would have been consumed. -- character being an 'a' would have been consumed.
assignStmtsBefore <- many $ try pAssignStmt assignStmts <- many $ try pAssignStmt
switch <- optionMaybe $ try pSwitch switch <- many $ try pSwitch
assignStmtsAfter <- many pAssignStmt -- syncs <- many pSync
syncs <- many pSync return $ ProcessBody [] [] []
return $ ProcessBody assignStmtsBefore switch assignStmtsAfter syncs
pAssignStmt :: Parser AssignStmt pAssignStmt :: Parser AssignStmt
pAssignStmt = p <?> name where pAssignStmt = p <?> name where
@ -507,7 +508,12 @@ pCompare = p <?> name where
<$> pSigSpec `sepBy` (pMaybeWs *> char ',' *> pMaybeWs) <$> pSigSpec `sepBy` (pMaybeWs *> char ',' *> pMaybeWs)
pCaseBody :: Parser CaseBody pCaseBody :: Parser CaseBody
pCaseBody = (CaseBody <$> many pCaseBodyVariant) <?> "CaseBody" pCaseBody = p <?> name where
name = "CaseBody"
p =
CaseBody
<$> many pAssignStmt
<*> many pSwitch
pCaseBodyVariant :: Parser CaseBodyVariants pCaseBodyVariant :: Parser CaseBodyVariants
pCaseBodyVariant = p <?> name where pCaseBodyVariant = p <?> name where

View file

@ -6,6 +6,7 @@ module RTLILParser.Primitives(
,pOctal ,pOctal
,pEscapedChar ,pEscapedChar
,advanceToNextToken ,advanceToNextToken
,advanceToFirstToken
) where ) where
import Control.Monad (void) import Control.Monad (void)
@ -48,11 +49,23 @@ pEol = void (many1 (oneOf "\r\n") <* pMaybeWs)
-- a comment begins with # and ends at the end of the line -- a comment begins with # and ends at the end of the line
-- a comment can be be inline, but must still end at the end of the line -- a comment can be be inline, but must still end at the end of the line
pComment :: Parser String pComment :: Parser String
pComment = do pComment = p <?> name where
char '#' name = "Comment"
comment <- many (noneOf "\r\n") p =
pEol do
return comment char '#'
comment <- many (noneOf "\r\n")
pEol
return comment
advanceToNextToken :: Parser () advanceToNextToken :: Parser ()
advanceToNextToken = void (pMaybeWs *> many1 (void pComment <|> pEol)) advanceToNextToken = p <?> name where
name = "AdvanceToNextToken"
p =
void (pMaybeWs *> many1 (void pComment <|> pEol))
advanceToFirstToken :: Parser ()
advanceToFirstToken = p <?> name where
name = "AdvanceToFirstToken"
p =
void (pMaybeWs *> many (void pComment <|> pEol))