Add division
parent
08e684206e
commit
b89be8de8c
|
@ -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)
|
||||
|
|
|
@ -27,8 +27,8 @@ term = Lit <$> intParser
|
|||
|
||||
table :: [[Operator Parser Expr]]
|
||||
table =
|
||||
[ [ binaryOp "*" Mul
|
||||
-- binaryOp "/" Div
|
||||
[ [ binaryOp "*" Mul,
|
||||
binaryOp "/" Div
|
||||
],
|
||||
[ binaryOp "+" Add,
|
||||
binaryOp "-" Sub
|
||||
|
|
|
@ -5,7 +5,7 @@ data Expr
|
|||
| Add Expr Expr
|
||||
| Sub Expr Expr
|
||||
| Mul Expr Expr
|
||||
| Div Expr Expr
|
||||
deriving
|
||||
( -- | Div Expr Expr
|
||||
Show
|
||||
( Show
|
||||
)
|
Reference in New Issue