2023-09-24 04:15:11 +00:00
|
|
|
{-# LANGUAGE ImportQualifiedPost #-}
|
|
|
|
{-# LANGUAGE OverloadedStrings #-}
|
|
|
|
|
2023-09-08 03:57:12 +00:00
|
|
|
module Main (main) where
|
|
|
|
|
2023-09-29 07:02:34 +00:00
|
|
|
-- import Compiler.ExeGen
|
|
|
|
import Compiler.LLVMGen
|
2023-09-29 10:17:12 +00:00
|
|
|
import Data.ByteString.Char8 qualified as B
|
2023-09-24 04:15:11 +00:00
|
|
|
import Data.Text.Lazy.IO qualified as T
|
|
|
|
import Parser.Expr
|
2023-09-08 04:04:01 +00:00
|
|
|
import System.Environment
|
2023-09-29 10:17:12 +00:00
|
|
|
import System.Process
|
2023-09-24 04:15:11 +00:00
|
|
|
import Types.Expr
|
2023-09-07 22:24:45 +00:00
|
|
|
|
2023-09-08 05:53:11 +00:00
|
|
|
getRight :: ParseResult -> Expr
|
|
|
|
getRight (Right r) = r
|
|
|
|
|
2023-09-24 04:15:11 +00:00
|
|
|
main :: IO ()
|
2023-09-08 03:57:12 +00:00
|
|
|
main = do
|
2023-09-08 06:31:07 +00:00
|
|
|
fileName <- fmap head getArgs
|
|
|
|
contents <- readFile fileName
|
2023-09-29 07:26:49 +00:00
|
|
|
T.putStrLn "- Parsing file..."
|
2023-09-29 04:42:59 +00:00
|
|
|
let parsed = getRight (parseExpr contents)
|
2023-09-29 07:26:49 +00:00
|
|
|
T.putStrLn "- Generating LLVM to './a.out.ll'..."
|
2023-09-29 10:17:12 +00:00
|
|
|
llvmGen parsed >>= B.writeFile "a.out.ll"
|
|
|
|
T.putStrLn "- Compiling to executable './a.out'..."
|
|
|
|
callCommand "clang a.out.ll"
|
2023-09-29 07:26:49 +00:00
|
|
|
T.putStrLn "- Done."
|