diff options
Diffstat (limited to 'lib/CodeGen/ArithmeticHandler.cc')
| -rw-r--r-- | lib/CodeGen/ArithmeticHandler.cc | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/lib/CodeGen/ArithmeticHandler.cc b/lib/CodeGen/ArithmeticHandler.cc index 762f0a3..df83513 100644 --- a/lib/CodeGen/ArithmeticHandler.cc +++ b/lib/CodeGen/ArithmeticHandler.cc @@ -1,4 +1,5 @@ #include "cps/ArithmeticHandler.h" +#include "cps/Lexer.h" #include <cstdio> using namespace llvm; @@ -20,7 +21,6 @@ Value *ArithmeticHandler::emitBinaryOp(int Op, Value *LHS, Value *RHS, int Line) return Builder.CreateFDiv(LVal, RVal, "divtmp"); } - // DIV / MOD : Only Integer. if (Op == tok_div || Op == tok_mod) { if (!LIsInt || !RIsInt) { fprintf(stderr, "Error: DIV and MOD operators require INTEGER operands.\n"); @@ -29,6 +29,24 @@ Value *ArithmeticHandler::emitBinaryOp(int Op, Value *LHS, Value *RHS, int Line) if (Op == tok_div) return Builder.CreateSDiv(LHS, RHS, "div_int_tmp"); if (Op == tok_mod) return Builder.CreateSRem(LHS, RHS, "mod_tmp"); } + + if (Op == tok_and || Op == tok_or) { + Value *L = LHS; + Value *R = RHS; + + if (L->getType()->isIntegerTy(64)) + L = Builder.CreateICmpNE(L, ConstantInt::get(Context, APInt(64, 0)), "tobool"); + if (R->getType()->isIntegerTy(64)) + R = Builder.CreateICmpNE(R, ConstantInt::get(Context, APInt(64, 0)), "tobool"); + + if (L->getType()->isDoubleTy()) + L = Builder.CreateFCmpONE(L, ConstantFP::get(Context, APFloat(0.0)), "tobool"); + if (R->getType()->isDoubleTy()) + R = Builder.CreateFCmpONE(R, ConstantFP::get(Context, APFloat(0.0)), "tobool"); + + if (Op == tok_and) return Builder.CreateAnd(L, R, "andtmp"); + if (Op == tok_or) return Builder.CreateOr(L, R, "ortmp"); + } if (LIsDouble || RIsDouble) { Value *LVal = LHS; |
