diff --git a/main/Compiler/LLVMGen.hs b/main/Compiler/LLVMGen.hs index 648abee..d36277d 100644 --- a/main/Compiler/LLVMGen.hs +++ b/main/Compiler/LLVMGen.hs @@ -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) diff --git a/main/Parser/Expr.hs b/main/Parser/Expr.hs index 0e5a720..a2f3f4c 100644 --- a/main/Parser/Expr.hs +++ b/main/Parser/Expr.hs @@ -27,8 +27,8 @@ term = Lit <$> intParser table :: [[Operator Parser Expr]] table = - [ [ binaryOp "*" Mul - -- binaryOp "/" Div + [ [ binaryOp "*" Mul, + binaryOp "/" Div ], [ binaryOp "+" Add, binaryOp "-" Sub diff --git a/main/Types/Expr.hs b/main/Types/Expr.hs index 23e75e9..51c8925 100644 --- a/main/Types/Expr.hs +++ b/main/Types/Expr.hs @@ -5,7 +5,7 @@ data Expr | Add Expr Expr | Sub Expr Expr | Mul Expr Expr + | Div Expr Expr deriving - ( -- | Div Expr Expr - Show + ( Show ) \ No newline at end of file