some progress but still need to test against corpus
This commit is contained in:
parent
7f8168720d
commit
bcd5d32290
17
README.md
17
README.md
|
@ -49,3 +49,20 @@ $ rtlil-parse test/corpus/xprop_dffe_1nnd_wrapped_xprop.il -o parsed1.ast
|
||||||
|
|
||||||
# TODO
|
# TODO
|
||||||
- [ ] automated CICD on gitea on personal servers
|
- [ ] automated CICD on gitea on personal servers
|
||||||
|
- [ ] update to have support for four state logic by converting 'X' and 'Z' to zero
|
||||||
|
|
||||||
|
# Limitations
|
||||||
|
- Does not support propagating non-two state logic, that is, no
|
||||||
|
support for X or Z values. Default behavior is to reject such
|
||||||
|
input although future iterations may support initializing X and
|
||||||
|
Z to 0.
|
||||||
|
- All cycles in circuit graphs must have at one D Flip-Flop on the
|
||||||
|
cycle path. This requirement necesarily pre-cludes simulation of
|
||||||
|
circuits such as NAND level-resolution SRAMs. The main reason for
|
||||||
|
this restriction is to avoid having to handle metastability in
|
||||||
|
simulation.
|
||||||
|
|
||||||
|
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.
|
|
@ -4,7 +4,7 @@ import System.Environment (getArgs)
|
||||||
import System.IO
|
import System.IO
|
||||||
import Control.Exception (catch, IOException)
|
import Control.Exception (catch, IOException)
|
||||||
|
|
||||||
import qualified Haskellator
|
import Haskellator
|
||||||
|
|
||||||
main :: IO ()
|
main :: IO ()
|
||||||
main = do
|
main = do
|
||||||
|
@ -19,6 +19,7 @@ main = do
|
||||||
putStrLn "File Contents:"
|
putStrLn "File Contents:"
|
||||||
putStrLn contents
|
putStrLn contents
|
||||||
[] -> putStrLn "cabal run Haskellator -- <file-path>"
|
[] -> putStrLn "cabal run Haskellator -- <file-path>"
|
||||||
|
putStrLn $ show Haskellator.val
|
||||||
|
|
||||||
-- Handle potential file reading errors
|
-- Handle potential file reading errors
|
||||||
handleReadError :: IOException -> IO String
|
handleReadError :: IOException -> IO String
|
||||||
|
|
|
@ -55,7 +55,9 @@ common warnings
|
||||||
ghc-options: -Wall
|
ghc-options: -Wall
|
||||||
|
|
||||||
library
|
library
|
||||||
exposed-modules: Haskellator
|
exposed-modules:
|
||||||
|
Haskellator,
|
||||||
|
RtlilAstTypes
|
||||||
other-modules:
|
other-modules:
|
||||||
hs-source-dirs: src
|
hs-source-dirs: src
|
||||||
build-depends:
|
build-depends:
|
||||||
|
|
|
@ -1,33 +1,70 @@
|
||||||
-- this parser largely references:
|
-- this parser largely references:
|
||||||
-- https://github.com/YosysHQ/yosys/blob/111b747d2797238eadf541879848492a9d34909a/docs/source/yosys_internals/formats/rtlil_text.rst
|
-- https://github.com/YosysHQ/yosys/blob/111b747d2797238eadf541879848492a9d34909a/docs/source/yosys_internals/formats/rtlil_text.rst
|
||||||
module Haskellator(a) where
|
module Haskellator(a, val) where
|
||||||
|
|
||||||
|
import Data.Char (digitToInt)
|
||||||
|
import Data.List (foldl')
|
||||||
|
|
||||||
|
import Control.Monad (void)
|
||||||
import Text.Parsec
|
import Text.Parsec
|
||||||
import Text.Parsec.String (Parser)
|
import Text.Parsec.String (Parser)
|
||||||
|
import RtlilAstTypes(
|
||||||
|
PublicId(..),
|
||||||
|
AutogenId(..),
|
||||||
|
AutoIdxStmt(..),
|
||||||
|
Value(..)
|
||||||
|
)
|
||||||
|
|
||||||
|
binaryStringToInt :: String -> Int
|
||||||
|
binaryStringToInt = foldl' (\acc x -> acc * 2 + digitToInt x) 0
|
||||||
|
|
||||||
-- https://github.com/YosysHQ/yosys/blob/111b747d2797238eadf541879848492a9d34909a/frontends/rtlil/rtlil_lexer.l#L88C1-L88C17
|
-- https://github.com/YosysHQ/yosys/blob/111b747d2797238eadf541879848492a9d34909a/frontends/rtlil/rtlil_lexer.l#L88C1-L88C17
|
||||||
nonws :: Parser Char
|
nonws :: Parser Char
|
||||||
nonws = noneOf " \t\r\n"
|
nonws = noneOf " \t\r\n"
|
||||||
|
|
||||||
pPublicId :: Parser String
|
pWs :: Parser String
|
||||||
pPublicId = char '\\' *> many1 nonws
|
pWs = many1 (oneOf " \t")
|
||||||
|
|
||||||
pAutogenId :: Parser String
|
pEol :: Parser String
|
||||||
pAutogenId = char '$' *> many1 nonws
|
pEol = many1 (oneOf "\r\n")
|
||||||
|
|
||||||
|
pPublicId :: Parser PublicId
|
||||||
|
pPublicId = PublicId <$> (char '\\' *> many1 nonws)
|
||||||
|
|
||||||
|
pAutogenId :: Parser AutogenId
|
||||||
|
pAutogenId = AutogenId <$> (char '$' *> many1 nonws)
|
||||||
|
|
||||||
decimalDigit :: Parser Char
|
decimalDigit :: Parser Char
|
||||||
decimalDigit = oneOf "0123456789"
|
decimalDigit = oneOf "0123456789"
|
||||||
|
|
||||||
|
-- update in the future to support 4 state logic
|
||||||
|
-- by converting x and z to 0 and warning about it.
|
||||||
binaryDigit :: Parser Char
|
binaryDigit :: Parser Char
|
||||||
binaryDigit = oneOf "01xzm-"
|
binaryDigit = oneOf "01"
|
||||||
|
|
||||||
|
pValue :: Parser Value
|
||||||
|
pValue = Value <$> pInteger
|
||||||
|
<*> (binaryStringToInt <$> many1 binaryDigit)
|
||||||
|
|
||||||
-- an integer can be positive or negative
|
|
||||||
pInteger :: Parser Int
|
pInteger :: Parser Int
|
||||||
pInteger = read <$> (pNegInt <|> pPosInt)
|
pInteger = do
|
||||||
where
|
sign <- optionMaybe (char '-')
|
||||||
pIntAtom = many1 decimalDigit
|
digits <- many1 digit
|
||||||
pNegInt = char '-' *> pIntAtom
|
let value = read digits
|
||||||
pPosInt = pIntAtom
|
return $ case sign of
|
||||||
|
Just _ -> -value
|
||||||
|
Nothing -> value
|
||||||
|
|
||||||
|
pAutogenIdx :: Parser AutoIdxStmt
|
||||||
|
pAutogenIdx = AutoIdxStmt <$> (string "autoidx" *> pWs *> pInteger <* pEol)
|
||||||
|
|
||||||
|
pModuleEndStmt :: Parser ()
|
||||||
|
pModuleEndStmt = void (string "end")
|
||||||
|
|
||||||
|
-- pModuleEndStmt :: Parser String
|
||||||
|
-- pModuleEndStmt = string "end" <* pEol
|
||||||
|
|
||||||
|
val = parse pInteger "pInteger" "721"
|
||||||
|
|
||||||
a :: Int
|
a :: Int
|
||||||
a = 3
|
a = 3
|
19
src/RtlilAstTypes.hs
Normal file
19
src/RtlilAstTypes.hs
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
module RtlilAstTypes(
|
||||||
|
PublicId(..),
|
||||||
|
AutogenId(..),
|
||||||
|
AutoIdxStmt(..),
|
||||||
|
Value(..)
|
||||||
|
) where
|
||||||
|
|
||||||
|
data PublicId = PublicId String deriving (Show)
|
||||||
|
data AutogenId = AutogenId String deriving (Show)
|
||||||
|
data AutoIdxStmt = AutoIdxStmt Int deriving (Show)
|
||||||
|
data Value = Value
|
||||||
|
{ width :: Int
|
||||||
|
, value :: Int
|
||||||
|
}
|
||||||
|
deriving (Show)
|
||||||
|
data Constant = ConstantValue Value
|
||||||
|
| ConstantInteger Int
|
||||||
|
| ConstantString String
|
||||||
|
deriving (Show)
|
Loading…
Reference in a new issue