diff options
| author | _ov4 <hausemasterstream@gmail.com> | 2026-02-02 09:02:39 +0000 |
|---|---|---|
| committer | _ov4 <hausemasterstream@gmail.com> | 2026-02-02 09:02:39 +0000 |
| commit | 09e128ce98de793d22669255897e4b4816d0e53e (patch) | |
| tree | 7afcbeb1e245641b60cfa68dcf0915e019975d24 /lib/CodeGen/CodeGen.cc | |
| parent | 419420770c4545ea4010047ef2153004d4700eed (diff) | |
Added logical operators
Diffstat (limited to 'lib/CodeGen/CodeGen.cc')
| -rw-r--r-- | lib/CodeGen/CodeGen.cc | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/lib/CodeGen/CodeGen.cc b/lib/CodeGen/CodeGen.cc index da6b005..95e3768 100644 --- a/lib/CodeGen/CodeGen.cc +++ b/lib/CodeGen/CodeGen.cc @@ -105,6 +105,21 @@ Value *CodeGen::emitExpr(ExprAST *Expr) { return Arrays->emitArrayAccess(ArrAcc, *this); } + if (auto *Unary = dynamic_cast<UnaryExprAST*>(Expr)) { + Value *Operand = emitExpr(Unary->getOperand()); + if (!Operand) return nullptr; + + if (Unary->getOp() == tok_not) { + if (Operand->getType()->isIntegerTy(64)) { + Operand = Builder->CreateICmpNE(Operand, ConstantInt::get(*TheContext, APInt(64, 0)), "tobool"); + } else if (Operand->getType()->isDoubleTy()) { + Operand = Builder->CreateFCmpONE(Operand, ConstantFP::get(*TheContext, APFloat(0.0)), "tobool"); + } + + return Builder->CreateNot(Operand, "nottmp"); + } + } + if (auto *Bin = dynamic_cast<BinaryExprAST*>(Expr)) { Value *L = emitExpr(Bin->getLHS()); Value *R = emitExpr(Bin->getRHS()); @@ -385,6 +400,11 @@ void CodeGen::emitStmt(StmtAST *Stmt) { if (AI->getAllocatedType() == Type::getDoubleTy(*TheContext) && Val->getType()->isIntegerTy(64)) { Val = Builder->CreateSIToFP(Val, Type::getDoubleTy(*TheContext)); } + + if (AI->getAllocatedType() == Type::getInt64Ty(*TheContext) && Val->getType()->isIntegerTy(1)) { + Val = Builder->CreateZExt(Val, Type::getInt64Ty(*TheContext)); + } + Builder->CreateStore(Val, Alloca); } } |
