diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2023-05-08 11:51:32 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2023-06-10 20:42:30 -0700 |
| commit | 68b95a39b1fe734b938ec02fa2b16bbb63170f87 (patch) | |
| tree | b86f3f97c04c23ad7e23d910d0fe65d5b06f27b4 /src/Module.zig | |
| parent | fd674d95bee4815783bb282c80ba6af369296706 (diff) | |
| download | zig-68b95a39b1fe734b938ec02fa2b16bbb63170f87.tar.gz zig-68b95a39b1fe734b938ec02fa2b16bbb63170f87.zip | |
InternPool: add ptr-to-int value
Also modify coercion in Sema to be InternPool-aware by calling
getCoerced.
The unnecessary comptime logic in mod.intValue is deleted too
Diffstat (limited to 'src/Module.zig')
| -rw-r--r-- | src/Module.zig | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/src/Module.zig b/src/Module.zig index d06d22402a..a5e61fa4f9 100644 --- a/src/Module.zig +++ b/src/Module.zig @@ -6887,17 +6887,23 @@ pub fn singleConstPtrType(mod: *Module, child_type: Type) Allocator.Error!Type { return ptrType(mod, .{ .elem_type = child_type.ip_index, .is_const = true }); } +pub fn ptrIntValue(mod: *Module, ty: Type, x: u64) Allocator.Error!Value { + assert(ty.zigTypeTag(mod) == .Pointer); + const i = try intern(mod, .{ .ptr = .{ + .ty = ty.ip_index, + .addr = .{ .int = try intern(mod, .{ .int = .{ + .ty = ty.ip_index, + .storage = .{ .u64 = x }, + } }) }, + } }); + return i.toValue(); +} + pub fn intValue(mod: *Module, ty: Type, x: anytype) Allocator.Error!Value { if (std.debug.runtime_safety) { - // TODO: decide if this also works for ABI int types like enums const tag = ty.zigTypeTag(mod); assert(tag == .Int or tag == .ComptimeInt); } - if (@TypeOf(x) == comptime_int) { - if (comptime std.math.cast(u64, x)) |casted| return intValue_u64(mod, ty, casted); - if (comptime std.math.cast(i64, x)) |casted| return intValue_i64(mod, ty, casted); - @compileError("Out-of-range comptime_int passed to Module.intValue"); - } if (std.math.cast(u64, x)) |casted| return intValue_u64(mod, ty, casted); if (std.math.cast(i64, x)) |casted| return intValue_i64(mod, ty, casted); var limbs_buffer: [4]usize = undefined; |
