sv2v.hs 978 Bytes
Newer Older
1
{- sv2v
Zachary Snow committed
2 3 4 5
 - Author: Zachary Snow <zach@zachjs.com>
 -
 - conversion entry point
 -}
6 7 8 9

import System.IO
import System.Exit

10
import Data.List (elemIndex)
11
import Job (readJob, files, exclude, incdir, define, siloed)
12
import Convert (convert)
13
import Language.SystemVerilog.Parser (parseFiles)
14

15 16 17 18 19 20
splitDefine :: String -> (String, String)
splitDefine str =
    case elemIndex '=' str of
        Nothing -> (str, "")
        Just idx -> (take idx str, drop (idx + 1) str)

21 22
main :: IO ()
main = do
23
    job <- readJob
24
    -- parse the input files
25
    let defines = map splitDefine $ define job
26 27 28 29 30 31 32 33 34 35 36
    result <- parseFiles (incdir job) defines (siloed job) (files job)
    case result of
        Left msg -> do
            hPutStr stderr $ msg ++ "\n"
            exitFailure
        Right asts -> do
            -- convert the files
            let asts' = convert (exclude job) asts
            -- print the converted files out
            hPrint stdout $ concat asts'
            exitSuccess