return ComplexExprEmitter(*this).Visit(const_cast<Expr*>(E));
}
+/// EmitComplexExprIntoAddr - Emit the computation of the specified expression
+/// of complex type, storing into the specified Value*.
+void CodeGenFunction::EmitComplexExprIntoAddr(const Expr *E,
+ llvm::Value *DestAddr) {
+ assert(E && E->getType()->isComplexType() &&
+ "Invalid complex expression to emit");
+ ComplexExprEmitter Emitter(*this);
+ ComplexPairTy Val = Emitter.Visit(const_cast<Expr*>(E));
+ Emitter.EmitStoreOfComplex(Val, DestAddr, false);
+}
// Expression Emission
//===--------------------------------------------------------------------===//
+/// EmitAnyExpr - Emit an expression of any type: scalar, complex, aggregate,
+/// returning an rvalue corresponding to it. If NeedResult is false, the
+/// result of the expression doesn't need to be generated into memory.
+RValue CodeGenFunction::EmitAnyExpr(const Expr *E, bool NeedResult) {
+ if (!hasAggregateLLVMType(E->getType()))
+ return EmitExpr(E);
+
+ llvm::Value *DestMem = 0;
+ if (NeedResult)
+ DestMem = CreateTempAlloca(ConvertType(E->getType()));
+
+ if (!E->getType()->isComplexType()) {
+ EmitAggExpr(E, DestMem, false);
+ } else if (NeedResult)
+ EmitComplexExprIntoAddr(E, DestMem);
+ else
+ EmitComplexExpr(E);
+
+ return RValue::getAggregate(DestMem);
+}
+
RValue CodeGenFunction::EmitExpr(const Expr *E) {
assert(E && !hasAggregateLLVMType(E->getType()) &&
"Invalid scalar expression to emit");
for (unsigned i = 0, e = E->getNumArgs(); i != e; ++i) {
QualType ArgTy = E->getArg(i)->getType();
- RValue ArgVal = EmitExpr(E->getArg(i));
+ RValue ArgVal = EmitAnyExpr(E->getArg(i));
// If this argument has prototype information, convert it.
if (ArgTyIt != ArgTyEnd) {
}
}
-
if (ArgVal.isScalar())
Args.push_back(ArgVal.getVal());
else // Pass by-address. FIXME: Set attribute bit on call.
// Must be an expression in a stmt context. Emit the value and ignore the
// result.
if (const Expr *E = dyn_cast<Expr>(S)) {
- if (E->getType()->isComplexType()) {
- EmitComplexExpr(E);
- } else if (hasAggregateLLVMType(E->getType()))
- EmitAggExpr(E, 0, false); // Emit an aggregate, ignoring the result.
- else
- EmitExpr(E);
+ EmitAnyExpr(E, false);
} else {
printf("Unimplemented stmt!\n");
S->dump();
RValue EmitCompoundAssignmentResult(const CompoundAssignOperator *E,
LValue LHSLV, RValue ResV);
+ /// EmitAnyExpr - Emit an expression of any type: scalar, complex, aggregate,
+ /// returning an rvalue corresponding to it. If NeedResult is false, the
+ /// result of the expression doesn't need to be generated into memory.
+ RValue EmitAnyExpr(const Expr *E, bool NeedResult = true);
+
RValue EmitExpr(const Expr *E);
RValue EmitIntegerLiteral(const IntegerLiteral *E);
RValue EmitFloatingLiteral(const FloatingLiteral *E);
void EmitAggExpr(const Expr *E, llvm::Value *DestPtr, bool VolatileDest);
/// EmitComplexExpr - Emit the computation of the specified expression of
- /// complex type, ignoring the result.
+ /// complex type, returning the result.
ComplexPairTy EmitComplexExpr(const Expr *E);
+
+ /// EmitComplexExprIntoAddr - Emit the computation of the specified expression
+ /// of complex type, storing into the specified Value*.
+ void EmitComplexExprIntoAddr(const Expr *E, llvm::Value *DestAddr);
};
} // end namespace CodeGen
} // end namespace clang