This repository has been archived on 2024-04-05. You can view files and clone it, but cannot push or open issues/pull-requests.
really-bad-compiler-in-haskell/main/Main.hs

29 lines
745 B
Haskell
Raw Normal View History

{-# LANGUAGE ImportQualifiedPost #-}
{-# LANGUAGE OverloadedStrings #-}
2023-09-08 03:57:12 +00:00
module Main (main) where
-- import Compiler.ExeGen
import Compiler.LLVMGen
2023-09-29 10:17:12 +00:00
import Data.ByteString.Char8 qualified as B
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
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
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..."
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."