Skip to content

Commit eb862aa

Browse files
authored
Merge pull request #23 from bryantam/wala-feature/FloatLiterals
added check for float and double using if-statements
2 parents 88c30e7 + 859aff2 commit eb862aa

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

lib/WALASupport/InstrKindInfoGetter.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -233,22 +233,29 @@ jobject InstrKindInfoGetter::handleFloatLiteralInst() {
233233
FloatLiteralInst* castInst = cast<FloatLiteralInst>(instr);
234234
APFloat value = castInst->getValue();
235235

236-
if (value.isFinite()) {
236+
if (&value.getSemantics() == &APFloat::IEEEsingle()) {
237+
// To Float
238+
node = (*wala)->makeConstant(value.convertToFloat());
239+
}
240+
else if (&value.getSemantics() == &APFloat::IEEEdouble()) {
241+
// To Double
242+
node = (*wala)->makeConstant(value.convertToDouble());
243+
}
244+
else if (value.isFinite()) {
237245
// To BigDecimal
238246
SmallVector<char, 128> buf;
239247
value.toString(buf);
240248
jobject bigDecimal = (*wala).makeBigDecimal(buf.data(), buf.size());
241249
node = (*wala)->makeConstant(bigDecimal);
242-
nodeMap->insert(std::make_pair(castInst, node));
243250
}
244251
else {
245252
// Infinity or NaN, convert to double
246253
// as BigDecimal constructor cannot accept strings of these
247254
bool APFLosesInfo;
248255
value.convert(APFloat::IEEEdouble(), APFloat::rmNearestTiesToEven, &APFLosesInfo);
249256
node = (*wala)->makeConstant(value.convertToDouble());
250-
nodeMap->insert(std::make_pair(castInst, node));
251257
}
258+
nodeMap->insert(std::make_pair(castInst, node));
252259
return node;
253260
}
254261

0 commit comments

Comments
 (0)