From 405d6ecc55c79af1ae4d3042096a95c9dca9c92f Mon Sep 17 00:00:00 2001 From: Yehowshua Immanuel Date: Sun, 8 Dec 2024 23:42:03 -0500 Subject: [PATCH] I believe I've finished the sync parser --- TODO.md | 4 +++- src/RTLILParser/AST.hs | 2 +- src/RTLILParser/Parser.hs | 26 +++++++++++++++++++++++++- 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/TODO.md b/TODO.md index 0b2d70f..cfded04 100644 --- a/TODO.md +++ b/TODO.md @@ -25,9 +25,11 @@ - [ ] may want to also derive equality statements - [x] replace both `pEol *> pMaybeWs` and `pEol <* pMaybeWs` with `pEolAndAdvanceToNextNonWs` + - [ ] Check inline sequencing of whitespace parsers in do blocks. + Terminating instances of `pWs` should be preceeded by `<*` # Parser Development - - [ ] Sync + - [x] Sync - [ ] Process - [ ] Module diff --git a/src/RTLILParser/AST.hs b/src/RTLILParser/AST.hs index 15e1eb9..2e4d10b 100644 --- a/src/RTLILParser/AST.hs +++ b/src/RTLILParser/AST.hs @@ -154,7 +154,7 @@ data CaseBody = CaseBody [CaseBodyVariants] deriving (Show) -- Syncs data Sync = Sync SyncStmt [UpdateStmt] deriving (Show) -data SyncStmt = SigSpecPredicated SyncType SigSpec +data SyncStmt = SigSpecPredicated SigSpec SyncType | Global | Init | Always diff --git a/src/RTLILParser/Parser.hs b/src/RTLILParser/Parser.hs index 549bafe..77ccbf5 100644 --- a/src/RTLILParser/Parser.hs +++ b/src/RTLILParser/Parser.hs @@ -330,6 +330,31 @@ pSwitchEndStmt :: Parser () pSwitchEndStmt = void (string "end" *> pEolAndAdvanceToNextNonWs) -- Syncs +pSync :: Parser Sync +pSync = Sync + <$> pSyncStmt + <*> many pUpdateStmt + +pSyncStmt :: Parser SyncStmt +pSyncStmt = pKeywordSync *> + pSigSpecPredicatedSyncStmt <|> + pNonSigSpecPredicatedSyncStmt + where pKeywordSync = string "sync" *> pWs + +pSigSpecPredicatedSyncStmt :: Parser SyncStmt +pSigSpecPredicatedSyncStmt = do + syncType <- pSyncType <* pWs + sigSpec <- pSigSpec <* pEolAndAdvanceToNextNonWs + return $ SigSpecPredicated sigSpec syncType + +pNonSigSpecPredicatedSyncStmt :: Parser SyncStmt +pNonSigSpecPredicatedSyncStmt = + keyword <* pEolAndAdvanceToNextNonWs + where keyword = + (Global <$ string "global" ) <|> + (Init <$ string "init" ) <|> + (Always <$ string "always" ) + pSyncType :: Parser SyncType pSyncType = (Low <$ string "low" ) <|> @@ -343,7 +368,6 @@ pUpdateStmt = UpdateStmt <$> (string "update" *> pWs *> pDestSigSpec) <*> (pWs *> pSrcSigSpec <* pEolAndAdvanceToNextNonWs) - -- would correspond to `123456789[0:9][0:8]` exampleSigSpecSlice = SigSpecSlice