diff options
Diffstat (limited to 'src/parsing.h')
-rw-r--r-- | src/parsing.h | 54 |
1 files changed, 36 insertions, 18 deletions
diff --git a/src/parsing.h b/src/parsing.h index 8432b41f2..9b2cb490b 100644 --- a/src/parsing.h +++ b/src/parsing.h @@ -143,16 +143,19 @@ parseConst(cashew::IString s, Type type, MixedArena& allocator) { if (modifier) { std::istringstream istr(modifier); istr >> std::hex >> pattern; - if (istr.fail()) + if (istr.fail()) { throw ParseException("invalid f32 format"); + } pattern |= 0x7f800000U; } else { pattern = 0x7fc00000U; } - if (negative) + if (negative) { pattern |= 0x80000000U; - if (!std::isnan(bit_cast<float>(pattern))) + } + if (!std::isnan(bit_cast<float>(pattern))) { pattern |= 1U; + } ret->value = Literal(pattern).castToF32(); break; } @@ -161,16 +164,19 @@ parseConst(cashew::IString s, Type type, MixedArena& allocator) { if (modifier) { std::istringstream istr(modifier); istr >> std::hex >> pattern; - if (istr.fail()) + if (istr.fail()) { throw ParseException("invalid f64 format"); + } pattern |= 0x7ff0000000000000ULL; } else { pattern = 0x7ff8000000000000UL; } - if (negative) + if (negative) { pattern |= 0x8000000000000000ULL; - if (!std::isnan(bit_cast<double>(pattern))) + } + if (!std::isnan(bit_cast<double>(pattern))) { pattern |= 1ULL; + } ret->value = Literal(pattern).castToF64(); break; } @@ -200,20 +206,23 @@ parseConst(cashew::IString s, Type type, MixedArena& allocator) { if ((str[0] == '0' && str[1] == 'x') || (str[0] == '-' && str[1] == '0' && str[2] == 'x')) { bool negative = str[0] == '-'; - if (negative) + if (negative) { str++; + } std::istringstream istr(str); uint32_t temp; istr >> std::hex >> temp; - if (istr.fail()) + if (istr.fail()) { throw ParseException("invalid i32 format"); + } ret->value = Literal(negative ? -temp : temp); } else { std::istringstream istr(str[0] == '-' ? str + 1 : str); uint32_t temp; istr >> temp; - if (istr.fail()) + if (istr.fail()) { throw ParseException("invalid i32 format"); + } ret->value = Literal(str[0] == '-' ? -temp : temp); } break; @@ -222,20 +231,23 @@ parseConst(cashew::IString s, Type type, MixedArena& allocator) { if ((str[0] == '0' && str[1] == 'x') || (str[0] == '-' && str[1] == '0' && str[2] == 'x')) { bool negative = str[0] == '-'; - if (negative) + if (negative) { str++; + } std::istringstream istr(str); uint64_t temp; istr >> std::hex >> temp; - if (istr.fail()) + if (istr.fail()) { throw ParseException("invalid i64 format"); + } ret->value = Literal(negative ? -temp : temp); } else { std::istringstream istr(str[0] == '-' ? str + 1 : str); uint64_t temp; istr >> temp; - if (istr.fail()) + if (istr.fail()) { throw ParseException("invalid i64 format"); + } ret->value = Literal(str[0] == '-' ? -temp : temp); } break; @@ -275,13 +287,15 @@ struct UniqueNameMapper { Index otherIndex = 0; Name getPrefixedName(Name prefix) { - if (reverseLabelMapping.find(prefix) == reverseLabelMapping.end()) + if (reverseLabelMapping.find(prefix) == reverseLabelMapping.end()) { return prefix; + } // make sure to return a unique name not already on the stack while (1) { Name ret = Name(prefix.str + std::to_string(otherIndex++)); - if (reverseLabelMapping.find(ret) == reverseLabelMapping.end()) + if (reverseLabelMapping.find(ret) == reverseLabelMapping.end()) { return ret; + } } } @@ -331,21 +345,25 @@ struct UniqueNameMapper { static void doPreVisitControlFlow(Walker* self, Expression** currp) { auto* curr = *currp; if (auto* block = curr->dynCast<Block>()) { - if (block->name.is()) + if (block->name.is()) { block->name = self->mapper.pushLabelName(block->name); + } } else if (auto* loop = curr->dynCast<Loop>()) { - if (loop->name.is()) + if (loop->name.is()) { loop->name = self->mapper.pushLabelName(loop->name); + } } } static void doPostVisitControlFlow(Walker* self, Expression** currp) { auto* curr = *currp; if (auto* block = curr->dynCast<Block>()) { - if (block->name.is()) + if (block->name.is()) { self->mapper.popLabelName(block->name); + } } else if (auto* loop = curr->dynCast<Loop>()) { - if (loop->name.is()) + if (loop->name.is()) { self->mapper.popLabelName(loop->name); + } } } |