aboutsummaryrefslogtreecommitdiff
path: root/src/Module.zig
diff options
context:
space:
mode:
authormlugg <mlugg@mlugg.co.uk>2023-05-09 17:06:10 +0100
committerAndrew Kelley <andrew@ziglang.org>2023-06-10 20:42:30 -0700
commit466328d1ca29f3f6dd142f74dda13b26687e71e0 (patch)
tree40d1310c7ae5dc98fce899884cfdaa2b310728b2 /src/Module.zig
parent5881a2d63771b070107bdc2325aa1bc455b2d926 (diff)
downloadzig-466328d1ca29f3f6dd142f74dda13b26687e71e0.tar.gz
zig-466328d1ca29f3f6dd142f74dda13b26687e71e0.zip
InternPool: transition float values
Diffstat (limited to 'src/Module.zig')
-rw-r--r--src/Module.zig18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/Module.zig b/src/Module.zig
index 6bcd148e67..b32904e165 100644
--- a/src/Module.zig
+++ b/src/Module.zig
@@ -6940,6 +6940,24 @@ pub fn unionValue(mod: *Module, union_ty: Type, tag: Value, val: Value) Allocato
return i.toValue();
}
+/// This function casts the float representation down to the representation of the type, potentially
+/// losing data if the representation wasn't correct.
+pub fn floatValue(mod: *Module, ty: Type, x: anytype) Allocator.Error!Value {
+ const storage: InternPool.Key.Float.Storage = switch (ty.floatBits(mod.getTarget())) {
+ 16 => .{ .f16 = @floatCast(f16, x) },
+ 32 => .{ .f32 = @floatCast(f32, x) },
+ 64 => .{ .f64 = @floatCast(f64, x) },
+ 80 => .{ .f80 = @floatCast(f80, x) },
+ 128 => .{ .f128 = @floatCast(f128, x) },
+ else => unreachable,
+ };
+ const i = try intern(mod, .{ .float = .{
+ .ty = ty.ip_index,
+ .storage = storage,
+ } });
+ return i.toValue();
+}
+
pub fn smallestUnsignedInt(mod: *Module, max: u64) Allocator.Error!Type {
return intType(mod, .unsigned, Type.smallestUnsignedBits(max));
}