void APNumericStorage::setIntValue(ASTContext &C, const APInt &Val) { if (hasAllocation()) C.Deallocate(pVal); BitWidth = Val.getBitWidth(); unsigned NumWords = Val.getNumWords(); const uint64_t* Words = Val.getRawData(); if (NumWords > 1) { pVal = new (C) uint64_t[NumWords]; std::copy(Words, Words + NumWords, pVal); } else if (NumWords == 1) VAL = Words[0]; else VAL = 0; }
SymbolicValue SymbolicValue::getInteger(const APInt &value, ASTContext &astContext) { // In the common case, we can form an inline representation. unsigned numWords = value.getNumWords(); if (numWords == 1) return getInteger(value.getRawData()[0], value.getBitWidth()); // Copy the integers from the APInt into the bump pointer. auto *words = astContext.Allocate<uint64_t>(numWords).data(); std::uninitialized_copy(value.getRawData(), value.getRawData() + numWords, words); SymbolicValue result; result.representationKind = RK_Integer; result.value.integer = words; result.auxInfo.integerBitwidth = value.getBitWidth(); return result; }
/** Converts v to mpz_class. Assumes that v is signed */ inline mpz_class toMpz (const APInt &v) { // Based on: // https://llvm.org/svn/llvm-project/polly/trunk/lib/Support/GICHelper.cpp // return v.getSExtValue (); APInt abs; abs = v.isNegative () ? v.abs () : v; const uint64_t *rawdata = abs.getRawData (); unsigned numWords = abs.getNumWords (); // TODO: Check if this is true for all platforms. mpz_class res; mpz_import(res.get_mpz_t (), numWords, 1, sizeof (uint64_t), 0, 0, rawdata); return v.isNegative () ? mpz_class(-res) : res; }
void LLVM_General_GetConstantFloatWords(LLVMValueRef v, uint64_t *bits) { APInt a = unwrap<ConstantFP>(v)->getValueAPF().bitcastToAPInt(); for(unsigned i=0; i != a.getNumWords(); ++i) bits[i] = a.getRawData()[i]; }