Begin IR building
authorLuke Lau <luke_lau@icloud.com>
Sun, 10 Mar 2019 01:36:05 +0000 (01:36 +0000)
committerLuke Lau <luke_lau@icloud.com>
Wed, 17 Apr 2019 22:38:30 +0000 (23:38 +0100)
Main.hs [new file with mode: 0644]

diff --git a/Main.hs b/Main.hs
new file mode 100644 (file)
index 0000000..7a26601
--- /dev/null
+++ b/Main.hs
@@ -0,0 +1,28 @@
+{-# LANGUAGE OverloadedStrings #-}
+
+module Main where
+
+import qualified AST
+import qualified Data.Text.Lazy.IO as Text
+import LLVM.IRBuilder
+import LLVM.AST.Constant
+import LLVM.AST.Float
+import LLVM.AST.Operand
+import LLVM.AST.Type
+import LLVM.Pretty
+
+main :: IO ()
+main = do
+  ast <- read <$> getContents
+  let mdl = buildModule "main" $
+        function "expr" [] float $ \_ -> do
+          build ast
+          return ()
+  Text.putStrLn (ppllvm mdl)
+
+build :: AST.Expr -> IRBuilderT ModuleBuilder Operand
+build (AST.Num a) = pure $ ConstantOperand (Float (Single a))
+build (AST.Add a b) = do
+  va <- build a
+  vb <- build b
+  fadd va vb