2024-11-17 14:20:29 +00:00
|
|
|
module Main where
|
|
|
|
|
|
|
|
import System.Environment (getArgs)
|
|
|
|
import Control.Exception (catch, IOException)
|
2024-12-06 19:57:32 +00:00
|
|
|
import Text.Show.Pretty (ppShow)
|
2024-11-17 14:20:29 +00:00
|
|
|
|
2024-11-23 00:06:15 +00:00
|
|
|
import Haskellator
|
2024-11-17 14:20:29 +00:00
|
|
|
|
|
|
|
main :: IO ()
|
|
|
|
main = do
|
|
|
|
-- Get the command-line arguments
|
|
|
|
args <- getArgs
|
|
|
|
|
2024-12-11 05:20:19 +00:00
|
|
|
-- Check if the input and output file names are provided
|
2024-11-17 14:20:29 +00:00
|
|
|
case args of
|
2024-12-11 05:20:19 +00:00
|
|
|
(inputFilePath:outputFilePath:_) -> do
|
|
|
|
contents <- catch (readFile inputFilePath) handleReadError
|
|
|
|
let output = ppShow $ Haskellator.runParser contents inputFilePath
|
|
|
|
catch (writeFile outputFilePath output) handleWriteError
|
|
|
|
putStrLn $ "Output written to " ++ outputFilePath
|
|
|
|
_ -> putStrLn "Usage: cabal run rtlil-parse -- <input-file-path> <output-file-path>"
|
2024-11-17 14:20:29 +00:00
|
|
|
|
|
|
|
-- Handle potential file reading errors
|
|
|
|
handleReadError :: IOException -> IO String
|
2024-12-11 05:20:19 +00:00
|
|
|
handleReadError _ = return "Error: Could not read the input file."
|
|
|
|
|
|
|
|
-- Handle potential file writing errors
|
|
|
|
handleWriteError :: IOException -> IO ()
|
|
|
|
handleWriteError _ = putStrLn "Error: Could not write to the output file."
|