module Main where import Control.Monad import Data.Either import System.Environment import System.Exit import Check import Codegen import Parser import PShow fromLeft :: Either a b -> a fromLeft (Left a) = a fromLeft (Right _) = error "Either is not a Left" fromRight :: Either a b -> b fromRight (Right b) = b fromRight (Left _) = error "Either is not a Right" dieShow :: (Show a) => a -> IO () dieShow = die . show main :: IO () main = do args <- getArgs when (length args /= 1) $ die "Pass NL file name as a command-line parameter" let fname = args !! 0 parseResult <- (\file -> parseProgram file fname) <$> readFile fname when (isLeft parseResult) $ dieShow $ fromLeft parseResult let ast = fromRight parseResult putStrLn $ pshow ast checked <- either die return $ checkProgram ast putStrLn "After checking:" putStrLn $ pshow checked llvmMod <- either die return $ codegen checked "Module" fname putStrLn "Module:" print llvmMod