예제 #1
0
파일: APValue.cpp 프로젝트: avakar/clang
static void WriteShortAPValueToStream(raw_ostream& Out,
                                      const APValue& V) {
  switch (V.getKind()) {
  default: llvm_unreachable("Unknown APValue kind!");
  case APValue::Uninitialized:
    Out << "Uninitialized";
    break;
  case APValue::Int:
    Out << V.getInt();
    break;
  case APValue::Float:
    Out << GetApproxValue(V.getFloat());
    break;
  case APValue::Vector:
    Out << '[';
    WriteShortAPValueToStream(Out, V.getVectorElt(0));
    for (unsigned i = 1; i != V.getVectorLength(); ++i) {
      Out << ", ";
      WriteShortAPValueToStream(Out, V.getVectorElt(i));
    }
    Out << ']';
    break;
  case APValue::ComplexInt:
    Out << V.getComplexIntReal() << "+" << V.getComplexIntImag() << "i";
    break;
  case APValue::ComplexFloat:
    Out << GetApproxValue(V.getComplexFloatReal()) << "+"
        << GetApproxValue(V.getComplexFloatImag()) << "i";
    break;
  case APValue::LValue:
    Out << "LValue: <todo>";
    break;
  }
}
예제 #2
0
void HipaccBoundaryCondition::setConstVal(APValue &val, ASTContext &Ctx) {
  QualType QT = getImage()->getType();

  bool isVecType = QT->isVectorType();
  if (isVecType) {
      QT = QT->getAs<VectorType>()->getElementType();
  }
  const BuiltinType *BT = QT->getAs<BuiltinType>();

  switch (BT->getKind()) {
    case BuiltinType::WChar_S:
    case BuiltinType::WChar_U:
    case BuiltinType::ULongLong:
    case BuiltinType::UInt128:
    case BuiltinType::LongLong:
    case BuiltinType::Int128:
    case BuiltinType::LongDouble:
    case BuiltinType::Void:
    case BuiltinType::Bool:
    default:
      assert(0 && "BuiltinType for Boundary handling constant not supported.");
    case BuiltinType::Char_S:
    case BuiltinType::SChar:
    case BuiltinType::Char_U:
    case BuiltinType::UChar:
      if (isVecType) {
        SmallVector<Expr *, 16> initExprs;

        for (size_t I=0, N=val.getVectorLength(); I!=N; ++I) {
          APValue lane = val.getVectorElt(I);
          initExprs.push_back(new (Ctx)
              CharacterLiteral(lane.getInt().getSExtValue(),
                CharacterLiteral::Ascii, QT, SourceLocation()));
        }

        constExpr = new (Ctx) InitListExpr(Ctx, SourceLocation(),
            llvm::makeArrayRef(initExprs.data(), initExprs.size()),
            SourceLocation());
        constExpr->setType(getImage()->getType());
      } else {
        constExpr = new (Ctx) CharacterLiteral(val.getInt().getSExtValue(),
            CharacterLiteral::Ascii, QT, SourceLocation());
      }
      break;
    case BuiltinType::Char16:
    case BuiltinType::Char32:
    case BuiltinType::Short:
    case BuiltinType::UShort:
    case BuiltinType::Int:
    case BuiltinType::UInt:
    case BuiltinType::Long:
    case BuiltinType::ULong:
      if (isVecType) {
        SmallVector<Expr *, 16> initExprs;

        for (size_t I=0, N=val.getVectorLength(); I!=N; ++I) {
          APValue lane = val.getVectorElt(I);
          initExprs.push_back(new (Ctx) IntegerLiteral(Ctx, lane.getInt(), QT,
                SourceLocation()));
        }

        constExpr = new (Ctx) InitListExpr(Ctx, SourceLocation(),
            llvm::makeArrayRef(initExprs.data(), initExprs.size()),
            SourceLocation());
        constExpr->setType(getImage()->getType());
      } else {
        constExpr = new (Ctx) IntegerLiteral(Ctx, val.getInt(), QT,
            SourceLocation());
      }
      break;
    case BuiltinType::Float:
    case BuiltinType::Double:
      if (isVecType) {
        SmallVector<Expr *, 16> initExprs;

        for (size_t I=0, N=val.getVectorLength(); I!=N; ++I) {
          APValue lane = val.getVectorElt(I);
          initExprs.push_back(FloatingLiteral::Create(Ctx,
                llvm::APFloat(lane.getFloat()), false, QT, SourceLocation()));
        }

        constExpr = new (Ctx) InitListExpr(Ctx, SourceLocation(),
            llvm::makeArrayRef(initExprs.data(), initExprs.size()),
            SourceLocation());
        constExpr->setType(getImage()->getType());
      } else {
        constExpr = FloatingLiteral::Create(Ctx, llvm::APFloat(val.getFloat()),
            false, QT, SourceLocation());
      }
      break;
  }
}