Skip to content

Commit

Permalink
Allow constant-folding of arbitrary-precision integer casts
Browse files Browse the repository at this point in the history
  • Loading branch information
vlstill committed Jan 10, 2024
1 parent d7dfee1 commit 76af275
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions frontends/common/constantFolding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -808,6 +808,16 @@ const IR::Node *DoConstantFolding::postorder(IR::Cast *e) {
} else {
return e;
}
} else if (etype->is<IR::Type_InfInt>()) {
if (const auto *constant = expr->to<IR::Constant>()) {
const auto *ctype = constant->type;
if (!ctype->is<IR::Type_Bits>() && !ctype->is<IR::Type_InfInt>()) {
::error(ErrorType::ERR_INVALID, "%1%: Cannot cast %1% to arbitrary presion integer",
ctype);
return e;
}
return new IR::Constant(e->srcInfo, etype, constant->value, constant->base);
}
} else if (etype->is<IR::Type_Boolean>()) {
if (expr->is<IR::BoolLiteral>()) return expr;
if (expr->is<IR::Constant>()) {
Expand Down

0 comments on commit 76af275

Please sign in to comment.