1 {-# LANGUAGE OverloadedStrings #-}
5 import Control.Monad.IO.Class
6 import qualified Data.Text.Lazy.IO as Text
7 import LLVM.AST.Constant
9 import LLVM.AST.Operand
10 import LLVM.AST.Type as Type
14 import Text.Read (readMaybe)
16 main = buildModuleT "main" repl
18 repl :: ModuleBuilderT IO ()
20 liftIO $ hPutStr stderr "ready> "
21 ast <- liftIO $ readMaybe <$> getLine
23 Nothing -> liftIO $ hPutStrLn stderr "Couldn't parse"
26 mostRecentDef >>= liftIO . Text.hPutStrLn stderr . ppll
30 buildAST :: AST -> ModuleBuilder Operand
31 buildAST (TopLevelExpr x) = function "__anon_expr" [] Type.double $
32 const $ buildExpr x >>= ret
34 buildExpr :: Expr -> IRBuilderT ModuleBuilder Operand
35 buildExpr (Num x) = pure $ ConstantOperand (Float (Double x))