aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorYann Herklotz Grave <git@yannherklotzgrave.com>2019-03-01 12:33:17 +0000
committerYann Herklotz Grave <git@yannherklotzgrave.com>2019-03-01 12:33:46 +0000
commit2e7cb975a93bddf28e97b937e5abc0adb9857514 (patch)
treec10aa423843b5d70b9ac7a5e6cd32cb11c4cb0ac /src
parent0391ac16eb646857f6a7ab1f908b919ba74c60d0 (diff)
downloadverismith-2e7cb975a93bddf28e97b937e5abc0adb9857514.tar.gz
verismith-2e7cb975a93bddf28e97b937e5abc0adb9857514.zip
[Fix #38] Fix parser to correctly identify input and output ports
Diffstat (limited to 'src')
-rw-r--r--src/VeriFuzz/Parser.hs15
1 files changed, 13 insertions, 2 deletions
diff --git a/src/VeriFuzz/Parser.hs b/src/VeriFuzz/Parser.hs
index 596867c..3e5ddb2 100644
--- a/src/VeriFuzz/Parser.hs
+++ b/src/VeriFuzz/Parser.hs
@@ -22,6 +22,7 @@ module VeriFuzz.Parser
)
where
+import Control.Lens
import Data.Functor (($>))
import Data.Functor.Identity (Identity)
import qualified Data.Text as T
@@ -213,14 +214,24 @@ parseModList :: Parser [Identifier]
parseModList = list <|> spaces $> []
where list = aroundList (string "(") (string ")") ident
+filterDecl :: PortDir -> ModItem -> Bool
+filterDecl p (Decl (Just p') _) = p == p'
+filterDecl _ _ = False
+
+modPorts :: PortDir -> [ModItem] -> [Port]
+modPorts p mis = filter (filterDecl p) mis ^.. traverse . declPort
+
parseModDecl :: Parser ModDecl
parseModDecl = do
name <- reserved "module" *> ident
- modL <- fmap defaultPort <$> parseModList
+ _ <- fmap defaultPort <$> parseModList
_ <- symbol ";"
modItem <- lexeme $ option [] . try $ many1 parseModItem
_ <- reserved "endmodule"
- return $ ModDecl name [] modL modItem
+ return $ ModDecl name
+ (modPorts PortOut modItem)
+ (modPorts PortIn modItem)
+ modItem
parseDescription :: Parser Description
parseDescription = Description <$> lexeme parseModDecl