2019-03-18 10:00:23 +01:00
|
|
|
{- sv2v
|
|
|
|
|
- Author: Zachary Snow <zach@zachjs.com>
|
|
|
|
|
-}
|
2019-02-08 06:19:39 +01:00
|
|
|
module Language.SystemVerilog.Parser
|
2019-08-06 04:00:04 +02:00
|
|
|
( parseFiles
|
2019-04-04 02:24:09 +02:00
|
|
|
) where
|
2019-02-08 05:49:12 +01:00
|
|
|
|
2019-08-06 04:00:04 +02:00
|
|
|
import qualified Data.Map.Strict as Map
|
2019-04-04 02:24:09 +02:00
|
|
|
import Language.SystemVerilog.AST (AST)
|
2019-08-06 04:00:04 +02:00
|
|
|
import Language.SystemVerilog.Parser.Lex (lexFile, Env)
|
2019-04-04 02:24:09 +02:00
|
|
|
import Language.SystemVerilog.Parser.Parse (parse)
|
2019-02-08 05:49:12 +01:00
|
|
|
|
2019-08-06 04:00:04 +02:00
|
|
|
-- parses a compilation unit given include search paths and predefined macros
|
|
|
|
|
parseFiles :: [FilePath] -> [(String, String)] -> [FilePath] -> IO [AST]
|
|
|
|
|
parseFiles includePaths defines paths = do
|
|
|
|
|
let env = Map.map (\a -> (a, [])) $ Map.fromList defines
|
|
|
|
|
parseFiles' includePaths env paths
|
|
|
|
|
|
|
|
|
|
-- parses a compilation unit given include search paths and predefined macros
|
|
|
|
|
parseFiles' :: [FilePath] -> Env -> [FilePath] -> IO [AST]
|
|
|
|
|
parseFiles' _ _ [] = return []
|
|
|
|
|
parseFiles' includePaths env (path : paths) = do
|
|
|
|
|
(ast, env') <- parseFile' includePaths env path
|
|
|
|
|
asts <- parseFiles' includePaths env' paths
|
|
|
|
|
return $ ast : asts
|
|
|
|
|
|
2019-04-04 02:24:09 +02:00
|
|
|
-- parses a file given include search paths, a table of predefined macros, and
|
|
|
|
|
-- the file path
|
2019-08-06 04:00:04 +02:00
|
|
|
parseFile' :: [String] -> Env -> FilePath -> IO (AST, Env)
|
|
|
|
|
parseFile' includePaths env path = do
|
|
|
|
|
(tokens, env') <- lexFile includePaths env path
|
|
|
|
|
let ast = parse tokens
|
|
|
|
|
return (ast, env')
|