Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use bigint printer when int attr exceeds uint64 range #12

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion zirgen/compiler/codegen/RustLanguageSyntax.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,16 @@ void RustLanguageSyntax::fallbackEmitLiteral(CodegenEmitter& cg,
mlir::Type ty,
mlir::Attribute value) {
TypeSwitch<Attribute>(value)
.Case<IntegerAttr>([&](auto intAttr) { cg << intAttr.getValue().getZExtValue(); })
.Case<IntegerAttr>([&](auto intAttr) {
auto maybeInt = intAttr.getValue().tryZExtValue();
// Can we represent the value as a uint64, or is it large enough
// to need a more expensive string formatting operation?
if (maybeInt) {
cg << *maybeInt;
} else {
intAttr.getValue().print(*cg.getOutputStream(), /*signed*/ false);
}
})
.Case<StringAttr>([&](auto strAttr) { cg.emitEscapedString(strAttr); })
.Default([&](auto) {
llvm::errs() << "Don't know how to emit type " << ty << " into rust++ with value " << value
Expand Down
Loading