Add division

pull/21/head
Ethan Reece 2023-09-29 05:31:33 -05:00
parent 08e684206e
commit b89be8de8c
Signed by: me
GPG Key ID: D3993665FF92E1C3
3 changed files with 8 additions and 6 deletions

View File

@ -27,9 +27,7 @@ getLLVM expr =
printf <- externVarArgs "printf" [ptr] i32
function "main" [] i32 $ \_ -> mdo
numFormatStr <- globalStringPtr "%d\n" (mkName "str")
traceShow numFormatStr $ pure ()
ourExpression <- exprToLLVM expr
-- _ <- call (FunctionType i32 [i32])
_ <- call (FunctionType i32 [ptr] True) printf [(ConstantOperand numFormatStr, []), (ourExpression, [])]
ret (int32 0)
@ -52,6 +50,10 @@ exprToLLVM (Expr.Mul a b) = mdo
lhs <- exprToLLVM a
rhs <- exprToLLVM b
mul lhs rhs
exprToLLVM (Expr.Div a b) = mdo
lhs <- exprToLLVM a
rhs <- exprToLLVM b
sdiv lhs rhs
primToLLVM :: Int -> Operand
primToLLVM i = int32 (fromIntegral i)

View File

@ -27,8 +27,8 @@ term = Lit <$> intParser
table :: [[Operator Parser Expr]]
table =
[ [ binaryOp "*" Mul
-- binaryOp "/" Div
[ [ binaryOp "*" Mul,
binaryOp "/" Div
],
[ binaryOp "+" Add,
binaryOp "-" Sub

View File

@ -5,7 +5,7 @@ data Expr
| Add Expr Expr
| Sub Expr Expr
| Mul Expr Expr
| Div Expr Expr
deriving
( -- | Div Expr Expr
Show
( Show
)