RTLIL parser presumably finished except for comment parser
This commit is contained in:
parent
851a18f82d
commit
8e0073a1e6
|
@ -70,4 +70,9 @@ $ rtlil-parse
|
|||
I have yet to evaluate the implications of how this affects
|
||||
multi-clock domain circuits and their associated primitives such
|
||||
as asynchronous FIFOs, but I plan to make sure simulation of such
|
||||
circuits is possible and correct.
|
||||
circuits is possible and correct.
|
||||
|
||||
# Lessons Learned
|
||||
- Should have written parser to be token based where after consuming
|
||||
and capturing token, we consume and discard all following whitespaces
|
||||
as well as comments...
|
1
TODO.md
1
TODO.md
|
@ -42,6 +42,7 @@
|
|||
- [x] Remove all instances of `_ <-`
|
||||
- [ ] Module
|
||||
- [ ] Remove weird GHC imports
|
||||
- [x] Are the `try` statements in `pWireOption` correctly constructed?
|
||||
- [ ] Consider the very weird case where the process body has nothing,
|
||||
thus, `pEolAndAdvanceToNextNonWs` may never get invoked in any of
|
||||
the sub-parsers encapsulated in `pProcessBody`. Do we need to
|
||||
|
|
|
@ -5,11 +5,15 @@ module RTLILParser.AST (
|
|||
-- Values
|
||||
Value(..),
|
||||
|
||||
-- File
|
||||
File(..),
|
||||
|
||||
-- Autoindex statements
|
||||
AutoIdxStmt(..),
|
||||
|
||||
-- Module
|
||||
ParamStmt(..), Constant(..),
|
||||
Module(..), ModuleStmt(..), ModuleBody(..),
|
||||
ModuleBodyVariant(..), ParamStmt(..), Constant(..),
|
||||
|
||||
-- Attribute statements
|
||||
AttrStmt(..),
|
||||
|
@ -68,20 +72,26 @@ data Value = Value
|
|||
-- strings
|
||||
-- comments
|
||||
-- file
|
||||
data File = File AutoIdxStmt [Module] deriving (Show)
|
||||
|
||||
-- Autoindex statements
|
||||
data AutoIdxStmt = AutoIdxStmt Int deriving (Show)
|
||||
|
||||
-- Module
|
||||
data ParamStmt = ParamStmt
|
||||
{ paramId :: Id
|
||||
, paramConstant :: Maybe Constant
|
||||
}
|
||||
deriving (Show)
|
||||
data Constant = ConstantValue Value
|
||||
| ConstantInteger Int
|
||||
| ConstantString String
|
||||
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
|
||||
deriving (Show)
|
||||
data ParamStmt = ParamStmt Id (Maybe Constant) deriving (Show)
|
||||
data Constant = ConstantValue Value
|
||||
| ConstantInteger Int
|
||||
| ConstantString String
|
||||
deriving (Show)
|
||||
|
||||
-- Attribute statements
|
||||
data AttrStmt = AttrStmt Id Constant deriving (Show)
|
||||
|
|
|
@ -11,11 +11,15 @@ import RTLILParser.AST (
|
|||
-- Values
|
||||
Value(..),
|
||||
|
||||
-- File
|
||||
File(..),
|
||||
|
||||
-- Autoindex statements
|
||||
AutoIdxStmt(..),
|
||||
|
||||
-- Module
|
||||
ParamStmt(..), Constant(..),
|
||||
Module(..), ModuleStmt(..), ModuleBody(..),
|
||||
ModuleBodyVariant(..), ParamStmt(..), Constant(..),
|
||||
|
||||
-- Attribute statements
|
||||
AttrStmt(..),
|
||||
|
@ -106,6 +110,10 @@ pString =
|
|||
|
||||
-- comments
|
||||
-- file
|
||||
pFile :: Parser File
|
||||
pFile = File
|
||||
<$> pAutoIdxStmt
|
||||
<*> many pModule
|
||||
|
||||
-- Autoindex statements
|
||||
pAutoIdxStmt :: Parser AutoIdxStmt
|
||||
|
@ -114,9 +122,37 @@ pAutoIdxStmt = AutoIdxStmt
|
|||
pInteger <* pEolAndAdvanceToNextNonWs)
|
||||
|
||||
-- Module
|
||||
pModuleStmt :: Parser Id
|
||||
pModuleStmt = string "module" *> pWs *> pId <*
|
||||
pEolAndAdvanceToNextNonWs
|
||||
pModule :: Parser Module
|
||||
pModule = do
|
||||
attrs <- many pAttrStmt
|
||||
moduleStmt <- pModuleStmt
|
||||
moduleBody <- pModuleBody
|
||||
pModuleEndStmt
|
||||
return $ Module moduleStmt attrs moduleBody
|
||||
|
||||
pModuleStmt :: Parser ModuleStmt
|
||||
pModuleStmt = ModuleStmt
|
||||
<$> (string "module" *> pWs *>
|
||||
pId <* pEolAndAdvanceToNextNonWs)
|
||||
|
||||
pModuleBody :: Parser ModuleBody
|
||||
pModuleBody = ModuleBody
|
||||
<$> many pModuleBodyVariant
|
||||
|
||||
pModuleBodyVariant :: Parser ModuleBodyVariant
|
||||
pModuleBodyVariant =
|
||||
-- `pWire`, `pMemory`, `pCell`, `pProcess` all
|
||||
-- start by parsing attribute statements, so we
|
||||
-- need backtracking since we can't determin which
|
||||
-- parser will succeed based on the first character
|
||||
-- we encounter alone. `pParamStmt` technically doesn't
|
||||
-- need to be prefixed by `try`, so that is a stylistic
|
||||
-- choice.
|
||||
try (ModuleBodyParamStmt <$> pParamStmt) <|>
|
||||
try (ModuleBodyWire <$> pWire ) <|>
|
||||
try (ModuleBodyMemory <$> pMemory ) <|>
|
||||
try (ModuleBodyCell <$> pCell ) <|>
|
||||
(ModuleBodyProcess <$> pProcess )
|
||||
|
||||
pParamStmt :: Parser ParamStmt
|
||||
pParamStmt = ParamStmt
|
||||
|
@ -126,9 +162,9 @@ pParamStmt = ParamStmt
|
|||
|
||||
pConstant :: Parser Constant
|
||||
pConstant =
|
||||
try (ConstantValue <$> pValue)
|
||||
<|> (ConstantInteger <$> pInteger)
|
||||
<|> (ConstantString <$> pString)
|
||||
try (ConstantValue <$> pValue )
|
||||
<|> (ConstantInteger <$> pInteger)
|
||||
<|> (ConstantString <$> pString )
|
||||
|
||||
pModuleEndStmt :: Parser ()
|
||||
pModuleEndStmt = void (string "end")
|
||||
|
|
Loading…
Reference in a new issue