| ... | ... | @@ -19,6 +19,7 @@ const Zir = @import("../Zir.zig"); |
| 19 | 19 | const Liveness = @import("../Liveness.zig"); |
| 20 | 20 | |
| 21 | 21 | const Mutability = enum { Const, Mut }; |
| 22 | const BigIntConst = std.math.big.int.Const; |
| 22 | 23 | |
| 23 | 24 | pub const CValue = union(enum) { |
| 24 | 25 | none: void, |
| ... | ... | @@ -226,8 +227,7 @@ pub const DeclGen = struct { |
| 226 | 227 | try dg.renderDeclName(decl, writer); |
| 227 | 228 | } |
| 228 | 229 | |
| 229 | | /// Assumes that int_val is an int greater than maxInt(u64) and has > 64 and <= 128 bits. |
| 230 | | fn renderBigInt( |
| 230 | fn renderInt128( |
| 231 | 231 | writer: anytype, |
| 232 | 232 | int_val: anytype, |
| 233 | 233 | ) error{ OutOfMemory, AnalysisFail }!void { |
| ... | ... | @@ -256,6 +256,23 @@ pub const DeclGen = struct { |
| 256 | 256 | return writer.writeByte(')'); |
| 257 | 257 | } |
| 258 | 258 | |
| 259 | fn renderBigIntConst( |
| 260 | dg: *DeclGen, |
| 261 | writer: anytype, |
| 262 | val: BigIntConst, |
| 263 | signed: bool, |
| 264 | ) error{ OutOfMemory, AnalysisFail }!void { |
| 265 | if (signed) { |
| 266 | try renderInt128(writer, val.to(i128) catch { |
| 267 | return dg.fail("TODO implement integer constants larger than 128 bits", .{}); |
| 268 | }); |
| 269 | } else { |
| 270 | try renderInt128(writer, val.to(u128) catch { |
| 271 | return dg.fail("TODO implement integer constants larger than 128 bits", .{}); |
| 272 | }); |
| 273 | } |
| 274 | } |
| 275 | |
| 259 | 276 | fn renderValue( |
| 260 | 277 | dg: *DeclGen, |
| 261 | 278 | writer: anytype, |
| ... | ... | @@ -274,7 +291,7 @@ pub const DeclGen = struct { |
| 274 | 291 | 16 => return writer.writeAll("0xaaaau"), |
| 275 | 292 | 32 => return writer.writeAll("0xaaaaaaaau"), |
| 276 | 293 | 64 => return writer.writeAll("0xaaaaaaaaaaaaaaaau"), |
| 277 | | 128 => return renderBigInt(writer, @as(u128, 0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa)), |
| 294 | 128 => return renderInt128(writer, @as(u128, 0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa)), |
| 278 | 295 | else => unreachable, |
| 279 | 296 | } |
| 280 | 297 | }, |
| ... | ... | @@ -296,12 +313,8 @@ pub const DeclGen = struct { |
| 296 | 313 | } |
| 297 | 314 | switch (ty.zigTypeTag()) { |
| 298 | 315 | .Int => switch (val.tag()) { |
| 299 | | .int_big_positive => try renderBigInt(writer, val.castTag(.int_big_positive).?.asBigInt().to(u128) catch { |
| 300 | | return dg.fail("TODO implement integer constants larger than 128 bits", .{}); |
| 301 | | }), |
| 302 | | .int_big_negative => try renderBigInt(writer, val.castTag(.int_big_negative).?.asBigInt().to(i128) catch { |
| 303 | | return dg.fail("TODO implement integer constants larger than 128 bits", .{}); |
| 304 | | }), |
| 316 | .int_big_positive => try dg.renderBigIntConst(writer, val.castTag(.int_big_positive).?.asBigInt(), ty.isSignedInt()), |
| 317 | .int_big_negative => try dg.renderBigIntConst(writer, val.castTag(.int_big_negative).?.asBigInt(), true), |
| 305 | 318 | else => { |
| 306 | 319 | if (ty.isSignedInt()) |
| 307 | 320 | return writer.print("{d}", .{val.toSignedInt()}); |