1 {-# LANGUAGE OverloadedStrings #-}
3 import AST as K -- K for Kaleidoscope
5 import Control.Monad.IO.Class
6 import qualified Data.Text.Lazy.IO as Text
7 import LLVM.AST.Constant
9 import LLVM.AST.FloatingPointPredicate hiding (False, True)
10 import LLVM.AST.Operand
11 import LLVM.AST.Type as Type
15 import Text.Read (readMaybe)
17 main = buildModuleT "main" repl
19 repl :: ModuleBuilderT IO ()
21 liftIO $ hPutStr stderr "ready> "
22 ast <- liftIO $ readMaybe <$> getLine
24 Nothing -> liftIO $ hPutStrLn stderr "Couldn't parse"
27 mostRecentDef >>= liftIO . Text.hPutStrLn stderr . ppll
31 buildAST :: AST -> ModuleBuilder Operand
32 buildAST (TopLevelExpr x) = function "__anon_expr" [] Type.double $
33 const $ buildExpr x >>= ret
35 buildExpr :: Expr -> IRBuilderT ModuleBuilder Operand
36 buildExpr (Num x) = pure $ ConstantOperand (Float (Double x))
37 buildExpr (BinOp op a b) = do
42 then uitofp tmp Type.double