[cfe-dev] codegen binaryOperator constant exprs
Nuno Lopes
nunoplopes at sapo.pt
Tue Jan 29 08:17:07 PST 2008
Hi,
Below is a patch to add support to codegen for a few binary operators in
constant exprs.
I'm not sure about SDiv and SRem. I dunno if the operations should be signed
or not, but I leave that to someone more enlighten in the subject than me :)
Nuno
Index: CodeGen/CGExprConstant.cpp
===================================================================
--- CodeGen/CGExprConstant.cpp (revision 46515)
+++ CodeGen/CGExprConstant.cpp (working copy)
@@ -246,11 +246,31 @@
}
// Binary operators
- llvm::Constant *VisitBinOr(const BinaryOperator *E) {
+ llvm::Constant *VisitBinaryOperator(const BinaryOperator *E) {
llvm::Constant *LHS = Visit(E->getLHS());
llvm::Constant *RHS = Visit(E->getRHS());
-
- return llvm::ConstantExpr::getOr(LHS, RHS);
+
+ switch (E->getOpcode()) {
+ default:
+ CGM.WarnUnsupported(E, "binary operator");
+ return 0;
+ case BinaryOperator::And:
+ return llvm::ConstantExpr::getAnd(LHS, RHS);
+ case BinaryOperator::Or:
+ return llvm::ConstantExpr::getOr(LHS, RHS);
+ case BinaryOperator::Xor:
+ return llvm::ConstantExpr::getXor(LHS, RHS);
+ case BinaryOperator::Add:
+ return llvm::ConstantExpr::getAdd(LHS, RHS);
+ case BinaryOperator::Sub:
+ return llvm::ConstantExpr::getSub(LHS, RHS);
+ case BinaryOperator::Mul:
+ return llvm::ConstantExpr::getMul(LHS, RHS);
+ case BinaryOperator::Div:
+ return llvm::ConstantExpr::getSDiv(LHS, RHS);
+ case BinaryOperator::Rem:
+ return llvm::ConstantExpr::getSRem(LHS, RHS);
+ }
}
// Utility methods
More information about the cfe-dev
mailing list