diff --git a/TODO.md b/TODO.md index f07f6d7..51b56fb 100644 --- a/TODO.md +++ b/TODO.md @@ -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 ``? Where is - `` employed? + - [ ] what are the semantics of connection ``? - [ ] Validate that `123456789[0:9][0:8]` is valid RTLIL - [ ] add validation section to README - [ ] just support Cell memV2 diff --git a/src/RTLILParser/AST.hs b/src/RTLILParser/AST.hs index 56d0461..e01191f 100644 --- a/src/RTLILParser/AST.hs +++ b/src/RTLILParser/AST.hs @@ -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) diff --git a/src/RTLILParser/Parser.hs b/src/RTLILParser/Parser.hs index 29de085..43b8a8a 100644 --- a/src/RTLILParser/Parser.hs +++ b/src/RTLILParser/Parser.hs @@ -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 diff --git a/src/RTLILParser/Primitives.hs b/src/RTLILParser/Primitives.hs index 4a6517c..059eefd 100644 --- a/src/RTLILParser/Primitives.hs +++ b/src/RTLILParser/Primitives.hs @@ -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)) \ No newline at end of file +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)) \ No newline at end of file