]> granicus.if.org Git - clang/commitdiff
implement codegen for real/imag. TODO: imag of non-complex.
authorChris Lattner <sabre@nondot.org>
Fri, 24 Aug 2007 21:20:17 +0000 (21:20 +0000)
committerChris Lattner <sabre@nondot.org>
Fri, 24 Aug 2007 21:20:17 +0000 (21:20 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@41376 91177308-0d34-0410-b5e6-96231b3b80d8

CodeGen/CGExprScalar.cpp
test/CodeGen/complex.c

index bdaf1795de45c340ee040a7b98ac8575ae2f2b3d..c10e5106d84b66969e7692d4b1a87e84ffc84d9a 100644 (file)
@@ -147,7 +147,8 @@ public:
   }
   Value *EmitSizeAlignOf(QualType TypeToSize, QualType RetType,
                                bool isSizeOf);
-  // FIXME: Real,Imag.
+  Value *VisitUnaryReal     (const UnaryOperator *E);
+  Value *VisitUnaryImag     (const UnaryOperator *E);
   Value *VisitUnaryExtension(const UnaryOperator *E) {
     return Visit(E->getSubExpr());
   }
@@ -363,7 +364,7 @@ Value *ScalarExprEmitter::VisitUnaryLNot(const UnaryOperator *E) {
 /// EmitSizeAlignOf - Return the size or alignment of the 'TypeToSize' type as
 /// an integer (RetType).
 Value *ScalarExprEmitter::EmitSizeAlignOf(QualType TypeToSize, 
-                                                QualType RetType,bool isSizeOf){
+                                          QualType RetType,bool isSizeOf){
   /// FIXME: This doesn't handle VLAs yet!
   std::pair<uint64_t, unsigned> Info =
     CGF.getContext().getTypeInfo(TypeToSize, SourceLocation());
@@ -377,6 +378,22 @@ Value *ScalarExprEmitter::EmitSizeAlignOf(QualType TypeToSize,
   return llvm::ConstantInt::get(llvm::APInt(ResultWidth, Val));
 }
 
+Value *ScalarExprEmitter::VisitUnaryReal(const UnaryOperator *E) {
+  Expr *Op = E->getSubExpr();
+  if (Op->getType()->isComplexType())
+    return CGF.EmitComplexExpr(Op).first;
+  return Visit(Op);
+}
+Value *ScalarExprEmitter::VisitUnaryImag(const UnaryOperator *E) {
+  Expr *Op = E->getSubExpr();
+  if (Op->getType()->isComplexType())
+    return CGF.EmitComplexExpr(Op).second;
+
+  // FIXME: does this evaluate the subexpr??
+  return 0;  // FIXME:  Return zero of the right int/fp type.
+}
+
+
 //===----------------------------------------------------------------------===//
 //                           Binary Operators
 //===----------------------------------------------------------------------===//
index 3b5437c184a735487260750a0f978260e7938344..8a496ea425b0d37f056aeb1fb73a98bc293195d3 100644 (file)
@@ -26,4 +26,6 @@ void test3() {
   g1 = g1 - g2;
   g1 = g1 * g2;
   g1 = +-~g1;
+
+  double Gr = __real g1;
 }