Add division
parent
08e684206e
commit
b89be8de8c
|
@ -27,9 +27,7 @@ getLLVM expr =
|
||||||
printf <- externVarArgs "printf" [ptr] i32
|
printf <- externVarArgs "printf" [ptr] i32
|
||||||
function "main" [] i32 $ \_ -> mdo
|
function "main" [] i32 $ \_ -> mdo
|
||||||
numFormatStr <- globalStringPtr "%d\n" (mkName "str")
|
numFormatStr <- globalStringPtr "%d\n" (mkName "str")
|
||||||
traceShow numFormatStr $ pure ()
|
|
||||||
ourExpression <- exprToLLVM expr
|
ourExpression <- exprToLLVM expr
|
||||||
-- _ <- call (FunctionType i32 [i32])
|
|
||||||
_ <- call (FunctionType i32 [ptr] True) printf [(ConstantOperand numFormatStr, []), (ourExpression, [])]
|
_ <- call (FunctionType i32 [ptr] True) printf [(ConstantOperand numFormatStr, []), (ourExpression, [])]
|
||||||
ret (int32 0)
|
ret (int32 0)
|
||||||
|
|
||||||
|
@ -52,6 +50,10 @@ exprToLLVM (Expr.Mul a b) = mdo
|
||||||
lhs <- exprToLLVM a
|
lhs <- exprToLLVM a
|
||||||
rhs <- exprToLLVM b
|
rhs <- exprToLLVM b
|
||||||
mul lhs rhs
|
mul lhs rhs
|
||||||
|
exprToLLVM (Expr.Div a b) = mdo
|
||||||
|
lhs <- exprToLLVM a
|
||||||
|
rhs <- exprToLLVM b
|
||||||
|
sdiv lhs rhs
|
||||||
|
|
||||||
primToLLVM :: Int -> Operand
|
primToLLVM :: Int -> Operand
|
||||||
primToLLVM i = int32 (fromIntegral i)
|
primToLLVM i = int32 (fromIntegral i)
|
||||||
|
|
|
@ -27,8 +27,8 @@ term = Lit <$> intParser
|
||||||
|
|
||||||
table :: [[Operator Parser Expr]]
|
table :: [[Operator Parser Expr]]
|
||||||
table =
|
table =
|
||||||
[ [ binaryOp "*" Mul
|
[ [ binaryOp "*" Mul,
|
||||||
-- binaryOp "/" Div
|
binaryOp "/" Div
|
||||||
],
|
],
|
||||||
[ binaryOp "+" Add,
|
[ binaryOp "+" Add,
|
||||||
binaryOp "-" Sub
|
binaryOp "-" Sub
|
||||||
|
|
|
@ -5,7 +5,7 @@ data Expr
|
||||||
| Add Expr Expr
|
| Add Expr Expr
|
||||||
| Sub Expr Expr
|
| Sub Expr Expr
|
||||||
| Mul Expr Expr
|
| Mul Expr Expr
|
||||||
|
| Div Expr Expr
|
||||||
deriving
|
deriving
|
||||||
( -- | Div Expr Expr
|
( Show
|
||||||
Show
|
|
||||||
)
|
)
|
Reference in New Issue