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
|
I have yet to evaluate the implications of how this affects
|
||||||
multi-clock domain circuits and their associated primitives such
|
multi-clock domain circuits and their associated primitives such
|
||||||
as asynchronous FIFOs, but I plan to make sure simulation of 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 `_ <-`
|
- [x] Remove all instances of `_ <-`
|
||||||
- [ ] Module
|
- [ ] Module
|
||||||
- [ ] Remove weird GHC imports
|
- [ ] Remove weird GHC imports
|
||||||
|
- [x] Are the `try` statements in `pWireOption` correctly constructed?
|
||||||
- [ ] Consider the very weird case where the process body has nothing,
|
- [ ] Consider the very weird case where the process body has nothing,
|
||||||
thus, `pEolAndAdvanceToNextNonWs` may never get invoked in any of
|
thus, `pEolAndAdvanceToNextNonWs` may never get invoked in any of
|
||||||
the sub-parsers encapsulated in `pProcessBody`. Do we need to
|
the sub-parsers encapsulated in `pProcessBody`. Do we need to
|
||||||
|
|
|
@ -5,11 +5,15 @@ module RTLILParser.AST (
|
||||||
-- Values
|
-- Values
|
||||||
Value(..),
|
Value(..),
|
||||||
|
|
||||||
|
-- File
|
||||||
|
File(..),
|
||||||
|
|
||||||
-- Autoindex statements
|
-- Autoindex statements
|
||||||
AutoIdxStmt(..),
|
AutoIdxStmt(..),
|
||||||
|
|
||||||
-- Module
|
-- Module
|
||||||
ParamStmt(..), Constant(..),
|
Module(..), ModuleStmt(..), ModuleBody(..),
|
||||||
|
ModuleBodyVariant(..), ParamStmt(..), Constant(..),
|
||||||
|
|
||||||
-- Attribute statements
|
-- Attribute statements
|
||||||
AttrStmt(..),
|
AttrStmt(..),
|
||||||
|
@ -68,20 +72,26 @@ data Value = Value
|
||||||
-- strings
|
-- strings
|
||||||
-- comments
|
-- comments
|
||||||
-- file
|
-- file
|
||||||
|
data File = File AutoIdxStmt [Module] deriving (Show)
|
||||||
|
|
||||||
-- Autoindex statements
|
-- Autoindex statements
|
||||||
data AutoIdxStmt = AutoIdxStmt Int deriving (Show)
|
data AutoIdxStmt = AutoIdxStmt Int deriving (Show)
|
||||||
|
|
||||||
-- Module
|
-- Module
|
||||||
data ParamStmt = ParamStmt
|
data Module = Module ModuleStmt [AttrStmt] ModuleBody deriving (Show)
|
||||||
{ paramId :: Id
|
data ModuleStmt = ModuleStmt Id deriving (Show)
|
||||||
, paramConstant :: Maybe Constant
|
data ModuleBody = ModuleBody [ModuleBodyVariant] deriving (Show)
|
||||||
}
|
data ModuleBodyVariant = ModuleBodyParamStmt ParamStmt
|
||||||
deriving (Show)
|
| ModuleBodyWire Wire
|
||||||
data Constant = ConstantValue Value
|
| ModuleBodyMemory Memory
|
||||||
| ConstantInteger Int
|
| ModuleBodyCell Cell
|
||||||
| ConstantString String
|
| ModuleBodyProcess Process
|
||||||
deriving (Show)
|
deriving (Show)
|
||||||
|
data ParamStmt = ParamStmt Id (Maybe Constant) deriving (Show)
|
||||||
|
data Constant = ConstantValue Value
|
||||||
|
| ConstantInteger Int
|
||||||
|
| ConstantString String
|
||||||
|
deriving (Show)
|
||||||
|
|
||||||
-- Attribute statements
|
-- Attribute statements
|
||||||
data AttrStmt = AttrStmt Id Constant deriving (Show)
|
data AttrStmt = AttrStmt Id Constant deriving (Show)
|
||||||
|
|
|
@ -11,11 +11,15 @@ import RTLILParser.AST (
|
||||||
-- Values
|
-- Values
|
||||||
Value(..),
|
Value(..),
|
||||||
|
|
||||||
|
-- File
|
||||||
|
File(..),
|
||||||
|
|
||||||
-- Autoindex statements
|
-- Autoindex statements
|
||||||
AutoIdxStmt(..),
|
AutoIdxStmt(..),
|
||||||
|
|
||||||
-- Module
|
-- Module
|
||||||
ParamStmt(..), Constant(..),
|
Module(..), ModuleStmt(..), ModuleBody(..),
|
||||||
|
ModuleBodyVariant(..), ParamStmt(..), Constant(..),
|
||||||
|
|
||||||
-- Attribute statements
|
-- Attribute statements
|
||||||
AttrStmt(..),
|
AttrStmt(..),
|
||||||
|
@ -106,6 +110,10 @@ pString =
|
||||||
|
|
||||||
-- comments
|
-- comments
|
||||||
-- file
|
-- file
|
||||||
|
pFile :: Parser File
|
||||||
|
pFile = File
|
||||||
|
<$> pAutoIdxStmt
|
||||||
|
<*> many pModule
|
||||||
|
|
||||||
-- Autoindex statements
|
-- Autoindex statements
|
||||||
pAutoIdxStmt :: Parser AutoIdxStmt
|
pAutoIdxStmt :: Parser AutoIdxStmt
|
||||||
|
@ -114,9 +122,37 @@ pAutoIdxStmt = AutoIdxStmt
|
||||||
pInteger <* pEolAndAdvanceToNextNonWs)
|
pInteger <* pEolAndAdvanceToNextNonWs)
|
||||||
|
|
||||||
-- Module
|
-- Module
|
||||||
pModuleStmt :: Parser Id
|
pModule :: Parser Module
|
||||||
pModuleStmt = string "module" *> pWs *> pId <*
|
pModule = do
|
||||||
pEolAndAdvanceToNextNonWs
|
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 :: Parser ParamStmt
|
||||||
pParamStmt = ParamStmt
|
pParamStmt = ParamStmt
|
||||||
|
@ -126,9 +162,9 @@ pParamStmt = ParamStmt
|
||||||
|
|
||||||
pConstant :: Parser Constant
|
pConstant :: Parser Constant
|
||||||
pConstant =
|
pConstant =
|
||||||
try (ConstantValue <$> pValue)
|
try (ConstantValue <$> pValue )
|
||||||
<|> (ConstantInteger <$> pInteger)
|
<|> (ConstantInteger <$> pInteger)
|
||||||
<|> (ConstantString <$> pString)
|
<|> (ConstantString <$> pString )
|
||||||
|
|
||||||
pModuleEndStmt :: Parser ()
|
pModuleEndStmt :: Parser ()
|
||||||
pModuleEndStmt = void (string "end")
|
pModuleEndStmt = void (string "end")
|
||||||
|
|
Loading…
Reference in a new issue