diff --git a/README.md b/README.md index 62bcd62..1b2b8dc 100644 --- a/README.md +++ b/README.md @@ -48,4 +48,21 @@ $ rtlil-parse test/corpus/xprop_dffe_1nnd_wrapped_xprop.il -o parsed1.ast ``` # TODO - - [ ] automated CICD on gitea on personal servers \ No newline at end of file + - [ ] 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. \ No newline at end of file diff --git a/app/Main.hs b/app/Main.hs index 8553897..0f7ddaa 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -4,7 +4,7 @@ import System.Environment (getArgs) import System.IO import Control.Exception (catch, IOException) -import qualified Haskellator +import Haskellator main :: IO () main = do @@ -19,6 +19,7 @@ main = do putStrLn "File Contents:" putStrLn contents [] -> putStrLn "cabal run Haskellator -- " + putStrLn $ show Haskellator.val -- Handle potential file reading errors handleReadError :: IOException -> IO String diff --git a/haskellator.cabal b/haskellator.cabal index 7bfee47..1cad66d 100644 --- a/haskellator.cabal +++ b/haskellator.cabal @@ -55,7 +55,9 @@ common warnings ghc-options: -Wall library - exposed-modules: Haskellator + exposed-modules: + Haskellator, + RtlilAstTypes other-modules: hs-source-dirs: src build-depends: diff --git a/src/Haskellator.hs b/src/Haskellator.hs index b2cac52..e280220 100644 --- a/src/Haskellator.hs +++ b/src/Haskellator.hs @@ -1,33 +1,70 @@ -- this parser largely references: -- 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.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 nonws :: Parser Char nonws = noneOf " \t\r\n" -pPublicId :: Parser String -pPublicId = char '\\' *> many1 nonws +pWs :: Parser String +pWs = many1 (oneOf " \t") -pAutogenId :: Parser String -pAutogenId = char '$' *> many1 nonws +pEol :: Parser String +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 = 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 = 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 = read <$> (pNegInt <|> pPosInt) - where - pIntAtom = many1 decimalDigit - pNegInt = char '-' *> pIntAtom - pPosInt = pIntAtom +pInteger = do + sign <- optionMaybe (char '-') + digits <- many1 digit + let value = read digits + 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 = 3 \ No newline at end of file diff --git a/src/RtlilAstTypes.hs b/src/RtlilAstTypes.hs new file mode 100644 index 0000000..d8e39c1 --- /dev/null +++ b/src/RtlilAstTypes.hs @@ -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)