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; } }
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; } }
APValue::APValue(const APValue &RHS) : Kind(Uninitialized) { switch (RHS.getKind()) { case Uninitialized: break; case Int: MakeInt(); setInt(RHS.getInt()); break; case Float: MakeFloat(); setFloat(RHS.getFloat()); break; case Vector: MakeVector(); setVector(((const Vec *)(const char *)RHS.Data.buffer)->Elts, RHS.getVectorLength()); break; case ComplexInt: MakeComplexInt(); setComplexInt(RHS.getComplexIntReal(), RHS.getComplexIntImag()); break; case ComplexFloat: MakeComplexFloat(); setComplexFloat(RHS.getComplexFloatReal(), RHS.getComplexFloatImag()); break; case LValue: MakeLValue(); if (RHS.hasLValuePath()) setLValue(RHS.getLValueBase(), RHS.getLValueOffset(), RHS.getLValuePath(), RHS.isLValueOnePastTheEnd(), RHS.isNullPointer()); else setLValue(RHS.getLValueBase(), RHS.getLValueOffset(), NoLValuePath(), RHS.isNullPointer()); break; case Array: MakeArray(RHS.getArrayInitializedElts(), RHS.getArraySize()); for (unsigned I = 0, N = RHS.getArrayInitializedElts(); I != N; ++I) getArrayInitializedElt(I) = RHS.getArrayInitializedElt(I); if (RHS.hasArrayFiller()) getArrayFiller() = RHS.getArrayFiller(); break; case Struct: MakeStruct(RHS.getStructNumBases(), RHS.getStructNumFields()); for (unsigned I = 0, N = RHS.getStructNumBases(); I != N; ++I) getStructBase(I) = RHS.getStructBase(I); for (unsigned I = 0, N = RHS.getStructNumFields(); I != N; ++I) getStructField(I) = RHS.getStructField(I); break; case Union: MakeUnion(); setUnion(RHS.getUnionField(), RHS.getUnionValue()); break; case MemberPointer: MakeMemberPointer(RHS.getMemberPointerDecl(), RHS.isMemberPointerToDerivedMember(), RHS.getMemberPointerPath()); break; case AddrLabelDiff: MakeAddrLabelDiff(); setAddrLabelDiff(RHS.getAddrLabelDiffLHS(), RHS.getAddrLabelDiffRHS()); break; } }