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
passes
- [ ] are recursive slices inclusive?
- [ ] what are the semantics of connection `<conn-stmt>`? Where is
`<conn-stmt>` employed?
- [ ] what are the semantics of connection `<conn-stmt>`?
- [ ] Validate that `123456789[0:9][0:8]` is valid RTLIL
- [ ] add validation section to README
- [ ] just support Cell memV2

View file

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

View file

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

View file

@ -6,6 +6,7 @@ module RTLILParser.Primitives(
,pOctal
,pEscapedChar
,advanceToNextToken
,advanceToFirstToken
) where
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 can be be inline, but must still end at the end of the line
pComment :: Parser String
pComment = do
char '#'
comment <- many (noneOf "\r\n")
pEol
return comment
pComment = p <?> name where
name = "Comment"
p =
do
char '#'
comment <- many (noneOf "\r\n")
pEol
return comment
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))