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

_______________________________________________
cfe-dev mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev

Reply via email to