More complex float evaluator support.

llvm-svn: 59428
This commit is contained in:
Anders Carlsson 2008-11-16 21:51:21 +00:00
parent 807e8c5d63
commit 9ddf7bedf9
1 changed files with 45 additions and 0 deletions

View File

@ -1084,6 +1084,24 @@ public:
return APValue(APFloat(0.0), Result);
}
APValue VisitCastExpr(CastExpr *E) {
Expr* SubExpr = E->getSubExpr();
if (SubExpr->getType()->isRealFloatingType()) {
APFloat Result(0.0);
if (!EvaluateFloat(SubExpr, Result, Info))
return APValue();
return APValue(Result, APFloat(0.0));
}
// FIXME: Handle more casts.
return APValue();
}
APValue VisitBinaryOperator(const BinaryOperator *E);
};
} // end anonymous namespace
@ -1093,6 +1111,33 @@ static bool EvaluateComplexFloat(const Expr *E, APValue &Result, EvalInfo &Info)
return Result.isComplexFloat();
}
APValue ComplexFloatExprEvaluator::VisitBinaryOperator(const BinaryOperator *E)
{
APValue Result, RHS;
if (!EvaluateComplexFloat(E->getLHS(), Result, Info))
return APValue();
if (!EvaluateComplexFloat(E->getRHS(), RHS, Info))
return APValue();
switch (E->getOpcode()) {
default: return APValue();
case BinaryOperator::Add:
Result.getComplexFloatReal().add(RHS.getComplexFloatReal(),
APFloat::rmNearestTiesToEven);
Result.getComplexFloatImag().add(RHS.getComplexFloatImag(),
APFloat::rmNearestTiesToEven);
case BinaryOperator::Sub:
Result.getComplexFloatReal().subtract(RHS.getComplexFloatReal(),
APFloat::rmNearestTiesToEven);
Result.getComplexFloatImag().subtract(RHS.getComplexFloatImag(),
APFloat::rmNearestTiesToEven);
}
return Result;
}
//===----------------------------------------------------------------------===//
// Top level Expr::Evaluate method.
//===----------------------------------------------------------------------===//