compiler: rename "@XToY" to "@YFromX", zig fmt: rewrite them

Signed-off-by: Eric Joldasov <bratishkaerik@getgoogleoff.me>
This commit is contained in:
Eric Joldasov 2023-06-14 20:27:03 +06:00 committed by Andrew Kelley
parent e6e8cacab9
commit a6c8ee5231
22 changed files with 339 additions and 319 deletions

View file

@ -1396,6 +1396,26 @@ fn renderBuiltinCall(
try ais.writer().writeAll("@max"); try ais.writer().writeAll("@max");
} else if (mem.eql(u8, slice, "@minimum")) { } else if (mem.eql(u8, slice, "@minimum")) {
try ais.writer().writeAll("@min"); try ais.writer().writeAll("@min");
}
//
else if (mem.eql(u8, slice, "@boolToInt")) {
try ais.writer().writeAll("@intFromBool");
} else if (mem.eql(u8, slice, "@enumToInt")) {
try ais.writer().writeAll("@intFromEnum");
} else if (mem.eql(u8, slice, "@errorToInt")) {
try ais.writer().writeAll("@intFromError");
} else if (mem.eql(u8, slice, "@floatToInt")) {
try ais.writer().writeAll("@intFromFloat");
} else if (mem.eql(u8, slice, "@intToEnum")) {
try ais.writer().writeAll("@enumFromInt");
} else if (mem.eql(u8, slice, "@intToError")) {
try ais.writer().writeAll("@errorFromInt");
} else if (mem.eql(u8, slice, "@intToFloat")) {
try ais.writer().writeAll("@floatFromInt");
} else if (mem.eql(u8, slice, "@intToPtr")) {
try ais.writer().writeAll("@ptrFromInt");
} else if (mem.eql(u8, slice, "@ptrToInt")) {
try ais.writer().writeAll("@intFromPtr");
} else { } else {
try renderToken(ais, tree, builtin_token, .none); // @name try renderToken(ais, tree, builtin_token, .none); // @name
} }

View file

@ -478,11 +478,11 @@ pub const Inst = struct {
/// Converts a pointer to its address. Result type is always `usize`. /// Converts a pointer to its address. Result type is always `usize`.
/// Pointer type size may be any, including slice. /// Pointer type size may be any, including slice.
/// Uses the `un_op` field. /// Uses the `un_op` field.
ptrtoint, int_from_ptr,
/// Given a boolean, returns 0 or 1. /// Given a boolean, returns 0 or 1.
/// Result type is always `u1`. /// Result type is always `u1`.
/// Uses the `un_op` field. /// Uses the `un_op` field.
bool_to_int, int_from_bool,
/// Return a value from a function. /// Return a value from a function.
/// Result type is always noreturn; no instructions in a block follow this one. /// Result type is always noreturn; no instructions in a block follow this one.
/// Uses the `un_op` field. /// Uses the `un_op` field.
@ -629,12 +629,12 @@ pub const Inst = struct {
array_to_slice, array_to_slice,
/// Given a float operand, return the integer with the closest mathematical meaning. /// Given a float operand, return the integer with the closest mathematical meaning.
/// Uses the `ty_op` field. /// Uses the `ty_op` field.
float_to_int, int_from_float,
/// Same as `float_to_int` with optimized float mode. /// Same as `int_from_float` with optimized float mode.
float_to_int_optimized, int_from_float_optimized,
/// Given an integer operand, return the float with the closest mathematical meaning. /// Given an integer operand, return the float with the closest mathematical meaning.
/// Uses the `ty_op` field. /// Uses the `ty_op` field.
int_to_float, float_from_int,
/// Transforms a vector into a scalar value by performing a sequential /// Transforms a vector into a scalar value by performing a sequential
/// horizontal reduction of its elements using the specified operator. /// horizontal reduction of its elements using the specified operator.
@ -1337,9 +1337,9 @@ pub fn typeOfIndex(air: Air, inst: Air.Inst.Index, ip: *const InternPool) Type {
.struct_field_ptr_index_2, .struct_field_ptr_index_2,
.struct_field_ptr_index_3, .struct_field_ptr_index_3,
.array_to_slice, .array_to_slice,
.float_to_int, .int_from_float,
.float_to_int_optimized, .int_from_float_optimized,
.int_to_float, .float_from_int,
.splat, .splat,
.get_union_tag, .get_union_tag,
.clz, .clz,
@ -1387,7 +1387,7 @@ pub fn typeOfIndex(air: Air, inst: Air.Inst.Index, ip: *const InternPool) Type {
.c_va_end, .c_va_end,
=> return Type.void, => return Type.void,
.ptrtoint, .int_from_ptr,
.slice_len, .slice_len,
.ret_addr, .ret_addr,
.frame_addr, .frame_addr,
@ -1397,7 +1397,7 @@ pub fn typeOfIndex(air: Air, inst: Air.Inst.Index, ip: *const InternPool) Type {
.wasm_memory_grow => return Type.i32, .wasm_memory_grow => return Type.i32,
.wasm_memory_size => return Type.u32, .wasm_memory_size => return Type.u32,
.bool_to_int => return Type.u1, .int_from_bool => return Type.u1,
.tag_name, .error_name => return Type.slice_const_u8_sentinel_0, .tag_name, .error_name => return Type.slice_const_u8_sentinel_0,
@ -1687,8 +1687,8 @@ pub fn mustLower(air: Air, inst: Air.Inst.Index, ip: *const InternPool) bool {
.is_non_err_ptr, .is_non_err_ptr,
.bool_and, .bool_and,
.bool_or, .bool_or,
.ptrtoint, .int_from_ptr,
.bool_to_int, .int_from_bool,
.fptrunc, .fptrunc,
.fpext, .fpext,
.intcast, .intcast,
@ -1718,9 +1718,9 @@ pub fn mustLower(air: Air, inst: Air.Inst.Index, ip: *const InternPool) bool {
.slice_elem_ptr, .slice_elem_ptr,
.ptr_elem_ptr, .ptr_elem_ptr,
.array_to_slice, .array_to_slice,
.float_to_int, .int_from_float,
.float_to_int_optimized, .int_from_float_optimized,
.int_to_float, .float_from_int,
.reduce, .reduce,
.reduce_optimized, .reduce_optimized,
.splat, .splat,

View file

@ -2626,15 +2626,15 @@ fn addEnsureResult(gz: *GenZir, maybe_unused_result: Zir.Inst.Ref, statement: As
.error_set_decl, .error_set_decl,
.error_set_decl_anon, .error_set_decl_anon,
.error_set_decl_func, .error_set_decl_func,
.int_to_enum, .enum_from_int,
.enum_to_int, .int_from_enum,
.type_info, .type_info,
.size_of, .size_of,
.bit_size_of, .bit_size_of,
.typeof_log2_int_type, .typeof_log2_int_type,
.ptr_to_int, .int_from_ptr,
.align_of, .align_of,
.bool_to_int, .int_from_bool,
.embed_file, .embed_file,
.error_name, .error_name,
.sqrt, .sqrt,
@ -2655,9 +2655,9 @@ fn addEnsureResult(gz: *GenZir, maybe_unused_result: Zir.Inst.Ref, statement: As
.type_name, .type_name,
.frame_type, .frame_type,
.frame_size, .frame_size,
.float_to_int, .int_from_float,
.int_to_float, .float_from_int,
.int_to_ptr, .ptr_from_int,
.float_cast, .float_cast,
.int_cast, .int_cast,
.ptr_cast, .ptr_cast,
@ -8281,11 +8281,11 @@ fn builtinCall(
.bit_size_of => return simpleUnOpType(gz, scope, ri, node, params[0], .bit_size_of), .bit_size_of => return simpleUnOpType(gz, scope, ri, node, params[0], .bit_size_of),
.align_of => return simpleUnOpType(gz, scope, ri, node, params[0], .align_of), .align_of => return simpleUnOpType(gz, scope, ri, node, params[0], .align_of),
.ptr_to_int => return simpleUnOp(gz, scope, ri, node, .{ .rl = .none }, params[0], .ptr_to_int), .int_from_ptr => return simpleUnOp(gz, scope, ri, node, .{ .rl = .none }, params[0], .int_from_ptr),
.compile_error => return simpleUnOp(gz, scope, ri, node, .{ .rl = .{ .ty = .slice_const_u8_type } }, params[0], .compile_error), .compile_error => return simpleUnOp(gz, scope, ri, node, .{ .rl = .{ .ty = .slice_const_u8_type } }, params[0], .compile_error),
.set_eval_branch_quota => return simpleUnOp(gz, scope, ri, node, .{ .rl = .{ .coerced_ty = .u32_type } }, params[0], .set_eval_branch_quota), .set_eval_branch_quota => return simpleUnOp(gz, scope, ri, node, .{ .rl = .{ .coerced_ty = .u32_type } }, params[0], .set_eval_branch_quota),
.enum_to_int => return simpleUnOp(gz, scope, ri, node, .{ .rl = .none }, params[0], .enum_to_int), .int_from_enum => return simpleUnOp(gz, scope, ri, node, .{ .rl = .none }, params[0], .int_from_enum),
.bool_to_int => return simpleUnOp(gz, scope, ri, node, bool_ri, params[0], .bool_to_int), .int_from_bool => return simpleUnOp(gz, scope, ri, node, bool_ri, params[0], .int_from_bool),
.embed_file => return simpleUnOp(gz, scope, ri, node, .{ .rl = .{ .ty = .slice_const_u8_type } }, params[0], .embed_file), .embed_file => return simpleUnOp(gz, scope, ri, node, .{ .rl = .{ .ty = .slice_const_u8_type } }, params[0], .embed_file),
.error_name => return simpleUnOp(gz, scope, ri, node, .{ .rl = .{ .ty = .anyerror_type } }, params[0], .error_name), .error_name => return simpleUnOp(gz, scope, ri, node, .{ .rl = .{ .ty = .anyerror_type } }, params[0], .error_name),
.set_runtime_safety => return simpleUnOp(gz, scope, ri, node, bool_ri, params[0], .set_runtime_safety), .set_runtime_safety => return simpleUnOp(gz, scope, ri, node, bool_ri, params[0], .set_runtime_safety),
@ -8308,10 +8308,10 @@ fn builtinCall(
.Frame => return simpleUnOp(gz, scope, ri, node, .{ .rl = .none }, params[0], .frame_type), .Frame => return simpleUnOp(gz, scope, ri, node, .{ .rl = .none }, params[0], .frame_type),
.frame_size => return simpleUnOp(gz, scope, ri, node, .{ .rl = .none }, params[0], .frame_size), .frame_size => return simpleUnOp(gz, scope, ri, node, .{ .rl = .none }, params[0], .frame_size),
.float_to_int => return typeCast(gz, scope, ri, node, params[0], params[1], .float_to_int), .int_from_float => return typeCast(gz, scope, ri, node, params[0], params[1], .int_from_float),
.int_to_float => return typeCast(gz, scope, ri, node, params[0], params[1], .int_to_float), .float_from_int => return typeCast(gz, scope, ri, node, params[0], params[1], .float_from_int),
.int_to_ptr => return typeCast(gz, scope, ri, node, params[0], params[1], .int_to_ptr), .ptr_from_int => return typeCast(gz, scope, ri, node, params[0], params[1], .ptr_from_int),
.int_to_enum => return typeCast(gz, scope, ri, node, params[0], params[1], .int_to_enum), .enum_from_int => return typeCast(gz, scope, ri, node, params[0], params[1], .enum_from_int),
.float_cast => return typeCast(gz, scope, ri, node, params[0], params[1], .float_cast), .float_cast => return typeCast(gz, scope, ri, node, params[0], params[1], .float_cast),
.int_cast => return typeCast(gz, scope, ri, node, params[0], params[1], .int_cast), .int_cast => return typeCast(gz, scope, ri, node, params[0], params[1], .int_cast),
.ptr_cast => return typeCast(gz, scope, ri, node, params[0], params[1], .ptr_cast), .ptr_cast => return typeCast(gz, scope, ri, node, params[0], params[1], .ptr_cast),
@ -8352,17 +8352,17 @@ fn builtinCall(
_ = try gz.addNode(.trap, node); _ = try gz.addNode(.trap, node);
return rvalue(gz, ri, .unreachable_value, node); return rvalue(gz, ri, .unreachable_value, node);
}, },
.error_to_int => { .int_from_error => {
const operand = try expr(gz, scope, .{ .rl = .none }, params[0]); const operand = try expr(gz, scope, .{ .rl = .none }, params[0]);
const result = try gz.addExtendedPayload(.error_to_int, Zir.Inst.UnNode{ const result = try gz.addExtendedPayload(.int_from_error, Zir.Inst.UnNode{
.node = gz.nodeIndexToRelative(node), .node = gz.nodeIndexToRelative(node),
.operand = operand, .operand = operand,
}); });
return rvalue(gz, ri, result, node); return rvalue(gz, ri, result, node);
}, },
.int_to_error => { .error_from_int => {
const operand = try expr(gz, scope, .{ .rl = .{ .coerced_ty = .u16_type } }, params[0]); const operand = try expr(gz, scope, .{ .rl = .{ .coerced_ty = .u16_type } }, params[0]);
const result = try gz.addExtendedPayload(.int_to_error, Zir.Inst.UnNode{ const result = try gz.addExtendedPayload(.error_from_int, Zir.Inst.UnNode{
.node = gz.nodeIndexToRelative(node), .node = gz.nodeIndexToRelative(node),
.operand = operand, .operand = operand,
}); });
@ -8769,7 +8769,7 @@ fn simpleUnOp(
else else
try expr(gz, scope, operand_ri, operand_node); try expr(gz, scope, operand_ri, operand_node);
switch (tag) { switch (tag) {
.tag_name, .error_name, .ptr_to_int => try emitDbgStmt(gz, cursor), .tag_name, .error_name, .int_from_ptr => try emitDbgStmt(gz, cursor),
else => {}, else => {},
} }
const result = try gz.addUnNode(tag, operand, node); const result = try gz.addUnNode(tag, operand, node);

View file

@ -1473,7 +1473,7 @@ fn walkInstruction(
// builtin functions // builtin functions
.align_of, .align_of,
.bool_to_int, .int_from_bool,
.embed_file, .embed_file,
.error_name, .error_name,
.panic, .panic,
@ -1496,7 +1496,7 @@ fn walkInstruction(
.type_name, .type_name,
.frame_type, .frame_type,
.frame_size, .frame_size,
.ptr_to_int, .int_from_ptr,
.bit_not, .bit_not,
// @check // @check
.clz, .clz,
@ -1521,10 +1521,10 @@ fn walkInstruction(
}; };
}, },
.float_to_int, .int_from_float,
.int_to_float, .float_from_int,
.int_to_ptr, .ptr_from_int,
.int_to_enum, .enum_from_int,
.float_cast, .float_cast,
.int_cast, .int_cast,
.ptr_cast, .ptr_cast,
@ -1936,7 +1936,7 @@ fn walkInstruction(
.expr = .{ .bitSizeOf = operand_index }, .expr = .{ .bitSizeOf = operand_index },
}; };
}, },
.enum_to_int => { .int_from_enum => {
// not working correctly with `align()` // not working correctly with `align()`
const un_node = data[inst_index].un_node; const un_node = data[inst_index].un_node;
const operand = try self.walkRef( const operand = try self.walkRef(
@ -3021,8 +3021,8 @@ fn walkInstruction(
}, },
}; };
}, },
.error_to_int, .int_from_error,
.int_to_error, .error_from_int,
.reify, .reify,
.const_cast, .const_cast,
.volatile_cast, .volatile_cast,

View file

@ -12,7 +12,7 @@ pub const Tag = enum {
atomic_store, atomic_store,
bit_cast, bit_cast,
bit_offset_of, bit_offset_of,
bool_to_int, int_from_bool,
bit_size_of, bit_size_of,
breakpoint, breakpoint,
mul_add, mul_add,
@ -39,10 +39,10 @@ pub const Tag = enum {
div_floor, div_floor,
div_trunc, div_trunc,
embed_file, embed_file,
enum_to_int, int_from_enum,
error_name, error_name,
error_return_trace, error_return_trace,
error_to_int, int_from_error,
err_set_cast, err_set_cast,
@"export", @"export",
@"extern", @"extern",
@ -50,7 +50,7 @@ pub const Tag = enum {
field, field,
field_parent_ptr, field_parent_ptr,
float_cast, float_cast,
float_to_int, int_from_float,
frame, frame,
Frame, Frame,
frame_address, frame_address,
@ -60,10 +60,10 @@ pub const Tag = enum {
import, import,
in_comptime, in_comptime,
int_cast, int_cast,
int_to_enum, enum_from_int,
int_to_error, error_from_int,
int_to_float, float_from_int,
int_to_ptr, ptr_from_int,
max, max,
memcpy, memcpy,
memset, memset,
@ -76,7 +76,7 @@ pub const Tag = enum {
pop_count, pop_count,
prefetch, prefetch,
ptr_cast, ptr_cast,
ptr_to_int, int_from_ptr,
rem, rem,
return_address, return_address,
select, select,
@ -238,9 +238,9 @@ pub const list = list: {
}, },
}, },
.{ .{
"@boolToInt", "@intFromBool",
.{ .{
.tag = .bool_to_int, .tag = .int_from_bool,
.param_count = 1, .param_count = 1,
}, },
}, },
@ -425,9 +425,9 @@ pub const list = list: {
}, },
}, },
.{ .{
"@enumToInt", "@intFromEnum",
.{ .{
.tag = .enum_to_int, .tag = .int_from_enum,
.param_count = 1, .param_count = 1,
}, },
}, },
@ -446,9 +446,9 @@ pub const list = list: {
}, },
}, },
.{ .{
"@errorToInt", "@intFromError",
.{ .{
.tag = .error_to_int, .tag = .int_from_error,
.param_count = 1, .param_count = 1,
}, },
}, },
@ -506,9 +506,9 @@ pub const list = list: {
}, },
}, },
.{ .{
"@floatToInt", "@intFromFloat",
.{ .{
.tag = .float_to_int, .tag = .int_from_float,
.param_count = 2, .param_count = 2,
}, },
}, },
@ -576,31 +576,31 @@ pub const list = list: {
}, },
}, },
.{ .{
"@intToEnum", "@enumFromInt",
.{ .{
.tag = .int_to_enum, .tag = .enum_from_int,
.param_count = 2, .param_count = 2,
}, },
}, },
.{ .{
"@intToError", "@errorFromInt",
.{ .{
.tag = .int_to_error, .tag = .error_from_int,
.eval_to_error = .always, .eval_to_error = .always,
.param_count = 1, .param_count = 1,
}, },
}, },
.{ .{
"@intToFloat", "@floatFromInt",
.{ .{
.tag = .int_to_float, .tag = .float_from_int,
.param_count = 2, .param_count = 2,
}, },
}, },
.{ .{
"@intToPtr", "@ptrFromInt",
.{ .{
.tag = .int_to_ptr, .tag = .ptr_from_int,
.param_count = 2, .param_count = 2,
}, },
}, },
@ -689,9 +689,9 @@ pub const list = list: {
}, },
}, },
.{ .{
"@ptrToInt", "@intFromPtr",
.{ .{
.tag = .ptr_to_int, .tag = .int_from_ptr,
.param_count = 1, .param_count = 1,
}, },
}, },

View file

@ -371,9 +371,9 @@ pub fn categorizeOperand(
.struct_field_ptr_index_2, .struct_field_ptr_index_2,
.struct_field_ptr_index_3, .struct_field_ptr_index_3,
.array_to_slice, .array_to_slice,
.float_to_int, .int_from_float,
.float_to_int_optimized, .int_from_float_optimized,
.int_to_float, .float_from_int,
.get_union_tag, .get_union_tag,
.clz, .clz,
.ctz, .ctz,
@ -407,8 +407,8 @@ pub fn categorizeOperand(
.is_non_err, .is_non_err,
.is_err_ptr, .is_err_ptr,
.is_non_err_ptr, .is_non_err_ptr,
.ptrtoint, .int_from_ptr,
.bool_to_int, .int_from_bool,
.is_named_enum_value, .is_named_enum_value,
.tag_name, .tag_name,
.error_name, .error_name,
@ -1007,9 +1007,9 @@ fn analyzeInst(
.struct_field_ptr_index_2, .struct_field_ptr_index_2,
.struct_field_ptr_index_3, .struct_field_ptr_index_3,
.array_to_slice, .array_to_slice,
.float_to_int, .int_from_float,
.float_to_int_optimized, .int_from_float_optimized,
.int_to_float, .float_from_int,
.get_union_tag, .get_union_tag,
.clz, .clz,
.ctz, .ctz,
@ -1034,8 +1034,8 @@ fn analyzeInst(
.is_non_err, .is_non_err,
.is_err_ptr, .is_err_ptr,
.is_non_err_ptr, .is_non_err_ptr,
.ptrtoint, .int_from_ptr,
.bool_to_int, .int_from_bool,
.is_named_enum_value, .is_named_enum_value,
.tag_name, .tag_name,
.error_name, .error_name,

View file

@ -97,9 +97,9 @@ fn verifyBody(self: *Verify, body: []const Air.Inst.Index) Error!void {
.struct_field_ptr_index_2, .struct_field_ptr_index_2,
.struct_field_ptr_index_3, .struct_field_ptr_index_3,
.array_to_slice, .array_to_slice,
.float_to_int, .int_from_float,
.float_to_int_optimized, .int_from_float_optimized,
.int_to_float, .float_from_int,
.get_union_tag, .get_union_tag,
.clz, .clz,
.ctz, .ctz,
@ -123,8 +123,8 @@ fn verifyBody(self: *Verify, body: []const Air.Inst.Index) Error!void {
.is_non_err, .is_non_err,
.is_err_ptr, .is_err_ptr,
.is_non_err_ptr, .is_non_err_ptr,
.ptrtoint, .int_from_ptr,
.bool_to_int, .int_from_bool,
.is_named_enum_value, .is_named_enum_value,
.tag_name, .tag_name,
.error_name, .error_name,

View file

@ -961,8 +961,8 @@ fn analyzeBodyInner(
.elem_val_node => try sema.zirElemValNode(block, inst), .elem_val_node => try sema.zirElemValNode(block, inst),
.elem_type_index => try sema.zirElemTypeIndex(block, inst), .elem_type_index => try sema.zirElemTypeIndex(block, inst),
.enum_literal => try sema.zirEnumLiteral(block, inst), .enum_literal => try sema.zirEnumLiteral(block, inst),
.enum_to_int => try sema.zirEnumToInt(block, inst), .int_from_enum => try sema.zirIntFromEnum(block, inst),
.int_to_enum => try sema.zirIntToEnum(block, inst), .enum_from_int => try sema.zirEnumFromInt(block, inst),
.err_union_code => try sema.zirErrUnionCode(block, inst), .err_union_code => try sema.zirErrUnionCode(block, inst),
.err_union_code_ptr => try sema.zirErrUnionCodePtr(block, inst), .err_union_code_ptr => try sema.zirErrUnionCodePtr(block, inst),
.err_union_payload_unsafe => try sema.zirErrUnionPayload(block, inst), .err_union_payload_unsafe => try sema.zirErrUnionPayload(block, inst),
@ -1028,18 +1028,18 @@ fn analyzeBodyInner(
.union_init => try sema.zirUnionInit(block, inst), .union_init => try sema.zirUnionInit(block, inst),
.field_type => try sema.zirFieldType(block, inst), .field_type => try sema.zirFieldType(block, inst),
.field_type_ref => try sema.zirFieldTypeRef(block, inst), .field_type_ref => try sema.zirFieldTypeRef(block, inst),
.ptr_to_int => try sema.zirPtrToInt(block, inst), .int_from_ptr => try sema.zirIntFromPtr(block, inst),
.align_of => try sema.zirAlignOf(block, inst), .align_of => try sema.zirAlignOf(block, inst),
.bool_to_int => try sema.zirBoolToInt(block, inst), .int_from_bool => try sema.zirIntFromBool(block, inst),
.embed_file => try sema.zirEmbedFile(block, inst), .embed_file => try sema.zirEmbedFile(block, inst),
.error_name => try sema.zirErrorName(block, inst), .error_name => try sema.zirErrorName(block, inst),
.tag_name => try sema.zirTagName(block, inst), .tag_name => try sema.zirTagName(block, inst),
.type_name => try sema.zirTypeName(block, inst), .type_name => try sema.zirTypeName(block, inst),
.frame_type => try sema.zirFrameType(block, inst), .frame_type => try sema.zirFrameType(block, inst),
.frame_size => try sema.zirFrameSize(block, inst), .frame_size => try sema.zirFrameSize(block, inst),
.float_to_int => try sema.zirFloatToInt(block, inst), .int_from_float => try sema.zirIntFromFloat(block, inst),
.int_to_float => try sema.zirIntToFloat(block, inst), .float_from_int => try sema.zirFloatFromInt(block, inst),
.int_to_ptr => try sema.zirIntToPtr(block, inst), .ptr_from_int => try sema.zirPtrFromInt(block, inst),
.float_cast => try sema.zirFloatCast(block, inst), .float_cast => try sema.zirFloatCast(block, inst),
.int_cast => try sema.zirIntCast(block, inst), .int_cast => try sema.zirIntCast(block, inst),
.ptr_cast => try sema.zirPtrCast(block, inst), .ptr_cast => try sema.zirPtrCast(block, inst),
@ -1167,8 +1167,8 @@ fn analyzeBodyInner(
.err_set_cast => try sema.zirErrSetCast( block, extended), .err_set_cast => try sema.zirErrSetCast( block, extended),
.await_nosuspend => try sema.zirAwaitNosuspend( block, extended), .await_nosuspend => try sema.zirAwaitNosuspend( block, extended),
.select => try sema.zirSelect( block, extended), .select => try sema.zirSelect( block, extended),
.error_to_int => try sema.zirErrorToInt( block, extended), .int_from_error => try sema.zirIntFromError( block, extended),
.int_to_error => try sema.zirIntToError( block, extended), .error_from_int => try sema.zirErrorFromInt( block, extended),
.reify => try sema.zirReify( block, extended, inst), .reify => try sema.zirReify( block, extended, inst),
.builtin_async_call => try sema.zirBuiltinAsyncCall( block, extended), .builtin_async_call => try sema.zirBuiltinAsyncCall( block, extended),
.cmpxchg => try sema.zirCmpxchg( block, extended), .cmpxchg => try sema.zirCmpxchg( block, extended),
@ -8116,7 +8116,7 @@ fn zirErrorValue(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
} })).toValue()); } })).toValue());
} }
fn zirErrorToInt(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!Air.Inst.Ref { fn zirIntFromError(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!Air.Inst.Ref {
const tracy = trace(@src()); const tracy = trace(@src());
defer tracy.end(); defer tracy.end();
@ -8156,7 +8156,7 @@ fn zirErrorToInt(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat
return block.addBitCast(Type.err_int, operand); return block.addBitCast(Type.err_int, operand);
} }
fn zirIntToError(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!Air.Inst.Ref { fn zirErrorFromInt(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!Air.Inst.Ref {
const tracy = trace(@src()); const tracy = trace(@src());
defer tracy.end(); defer tracy.end();
@ -8258,7 +8258,7 @@ fn zirEnumLiteral(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
})).toValue()); })).toValue());
} }
fn zirEnumToInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { fn zirIntFromEnum(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
const mod = sema.mod; const mod = sema.mod;
const inst_data = sema.code.instructions.items(.data)[inst].un_node; const inst_data = sema.code.instructions.items(.data)[inst].un_node;
const src = inst_data.src(); const src = inst_data.src();
@ -8303,7 +8303,7 @@ fn zirEnumToInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
return block.addBitCast(int_tag_ty, enum_tag); return block.addBitCast(int_tag_ty, enum_tag);
} }
fn zirIntToEnum(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { fn zirEnumFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
const mod = sema.mod; const mod = sema.mod;
const inst_data = sema.code.instructions.items(.data)[inst].pl_node; const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
@ -9518,7 +9518,7 @@ fn analyzeAs(
}; };
} }
fn zirPtrToInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { fn zirIntFromPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
const tracy = trace(@src()); const tracy = trace(@src());
defer tracy.end(); defer tracy.end();
@ -9537,7 +9537,7 @@ fn zirPtrToInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
); );
} }
try sema.requireRuntimeBlock(block, inst_data.src(), ptr_src); try sema.requireRuntimeBlock(block, inst_data.src(), ptr_src);
return block.addUnOp(.ptrtoint, ptr); return block.addUnOp(.int_from_ptr, ptr);
} }
fn zirFieldVal(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { fn zirFieldVal(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
@ -19426,7 +19426,7 @@ fn zirAlignOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
return sema.addConstant(Type.comptime_int, val); return sema.addConstant(Type.comptime_int, val);
} }
fn zirBoolToInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { fn zirIntFromBool(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
const mod = sema.mod; const mod = sema.mod;
const inst_data = sema.code.instructions.items(.data)[inst].un_node; const inst_data = sema.code.instructions.items(.data)[inst].un_node;
const operand = try sema.resolveInst(inst_data.operand); const operand = try sema.resolveInst(inst_data.operand);
@ -19435,7 +19435,7 @@ fn zirBoolToInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
if (val.toBool()) return sema.addConstant(Type.u1, try mod.intValue(Type.u1, 1)); if (val.toBool()) return sema.addConstant(Type.u1, try mod.intValue(Type.u1, 1));
return sema.addConstant(Type.u1, try mod.intValue(Type.u1, 0)); return sema.addConstant(Type.u1, try mod.intValue(Type.u1, 0));
} }
return block.addUnOp(.bool_to_int, operand); return block.addUnOp(.int_from_bool, operand);
} }
fn zirErrorName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { fn zirErrorName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
@ -20748,7 +20748,7 @@ fn zirFrameSize(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
return sema.failWithUseOfAsync(block, src); return sema.failWithUseOfAsync(block, src);
} }
fn zirFloatToInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { fn zirIntFromFloat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
const mod = sema.mod; const mod = sema.mod;
const inst_data = sema.code.instructions.items(.data)[inst].pl_node; const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
@ -20776,9 +20776,9 @@ fn zirFloatToInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
} }
return sema.addConstant(dest_ty, try mod.intValue(dest_ty, 0)); return sema.addConstant(dest_ty, try mod.intValue(dest_ty, 0));
} }
const result = try block.addTyOp(if (block.float_mode == .Optimized) .float_to_int_optimized else .float_to_int, dest_ty, operand); const result = try block.addTyOp(if (block.float_mode == .Optimized) .int_from_float_optimized else .int_from_float, dest_ty, operand);
if (block.wantSafety()) { if (block.wantSafety()) {
const back = try block.addTyOp(.int_to_float, operand_ty, result); const back = try block.addTyOp(.float_from_int, operand_ty, result);
const diff = try block.addBinOp(.sub, operand, back); const diff = try block.addBinOp(.sub, operand, back);
const ok_pos = try block.addBinOp(if (block.float_mode == .Optimized) .cmp_lt_optimized else .cmp_lt, diff, try sema.addConstant(operand_ty, try mod.floatValue(operand_ty, 1.0))); const ok_pos = try block.addBinOp(if (block.float_mode == .Optimized) .cmp_lt_optimized else .cmp_lt, diff, try sema.addConstant(operand_ty, try mod.floatValue(operand_ty, 1.0)));
const ok_neg = try block.addBinOp(if (block.float_mode == .Optimized) .cmp_gt_optimized else .cmp_gt, diff, try sema.addConstant(operand_ty, try mod.floatValue(operand_ty, -1.0))); const ok_neg = try block.addBinOp(if (block.float_mode == .Optimized) .cmp_gt_optimized else .cmp_gt, diff, try sema.addConstant(operand_ty, try mod.floatValue(operand_ty, -1.0)));
@ -20788,7 +20788,7 @@ fn zirFloatToInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
return result; return result;
} }
fn zirIntToFloat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { fn zirFloatFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
const mod = sema.mod; const mod = sema.mod;
const inst_data = sema.code.instructions.items(.data)[inst].pl_node; const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
@ -20809,10 +20809,10 @@ fn zirIntToFloat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
} }
try sema.requireRuntimeBlock(block, inst_data.src(), operand_src); try sema.requireRuntimeBlock(block, inst_data.src(), operand_src);
return block.addTyOp(.int_to_float, dest_ty, operand); return block.addTyOp(.float_from_int, dest_ty, operand);
} }
fn zirIntToPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { fn zirPtrFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
const mod = sema.mod; const mod = sema.mod;
const inst_data = sema.code.instructions.items(.data)[inst].pl_node; const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
const src = inst_data.src(); const src = inst_data.src();
@ -21084,7 +21084,7 @@ fn zirPtrCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
if (block.wantSafety() and operand_ty.ptrAllowsZero(mod) and !dest_ty.ptrAllowsZero(mod) and if (block.wantSafety() and operand_ty.ptrAllowsZero(mod) and !dest_ty.ptrAllowsZero(mod) and
(try sema.typeHasRuntimeBits(dest_ty.elemType2(mod)) or dest_ty.elemType2(mod).zigTypeTag(mod) == .Fn)) (try sema.typeHasRuntimeBits(dest_ty.elemType2(mod)) or dest_ty.elemType2(mod).zigTypeTag(mod) == .Fn))
{ {
const ptr_int = try block.addUnOp(.ptrtoint, ptr); const ptr_int = try block.addUnOp(.int_from_ptr, ptr);
const is_non_zero = try block.addBinOp(.cmp_neq, ptr_int, .zero_usize); const is_non_zero = try block.addBinOp(.cmp_neq, ptr_int, .zero_usize);
const ok = if (operand_is_slice) ok: { const ok = if (operand_is_slice) ok: {
const len = try sema.analyzeSliceLen(block, operand_src, operand); const len = try sema.analyzeSliceLen(block, operand_src, operand);
@ -21265,7 +21265,7 @@ fn zirAlignCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
try sema.analyzeSlicePtr(block, ptr_src, ptr, ptr_ty) try sema.analyzeSlicePtr(block, ptr_src, ptr, ptr_ty)
else else
ptr; ptr;
const ptr_int = try block.addUnOp(.ptrtoint, actual_ptr); const ptr_int = try block.addUnOp(.int_from_ptr, actual_ptr);
const remainder = try block.addBinOp(.bit_and, ptr_int, align_minus_1); const remainder = try block.addBinOp(.bit_and, ptr_int, align_minus_1);
const is_aligned = try block.addBinOp(.cmp_eq, remainder, .zero_usize); const is_aligned = try block.addBinOp(.cmp_eq, remainder, .zero_usize);
const ok = if (ptr_ty.isSlice(mod)) ok: { const ok = if (ptr_ty.isSlice(mod)) ok: {
@ -29504,7 +29504,7 @@ fn coerceCompatiblePtrs(
try sema.analyzeSlicePtr(block, inst_src, inst, inst_ty) try sema.analyzeSlicePtr(block, inst_src, inst, inst_ty)
else else
inst; inst;
const ptr_int = try block.addUnOp(.ptrtoint, actual_ptr); const ptr_int = try block.addUnOp(.int_from_ptr, actual_ptr);
const is_non_zero = try block.addBinOp(.cmp_neq, ptr_int, .zero_usize); const is_non_zero = try block.addBinOp(.cmp_neq, ptr_int, .zero_usize);
const ok = if (inst_ty.isSlice(mod)) ok: { const ok = if (inst_ty.isSlice(mod)) ok: {
const len = try sema.analyzeSliceLen(block, inst_src, inst); const len = try sema.analyzeSliceLen(block, inst_src, inst);

View file

@ -749,9 +749,9 @@ pub const Inst = struct {
/// Implements the `@bitSizeOf` builtin. Uses `un_node`. /// Implements the `@bitSizeOf` builtin. Uses `un_node`.
bit_size_of, bit_size_of,
/// Implement builtin `@ptrToInt`. Uses `un_node`. /// Implement builtin `@intFromPtr`. Uses `un_node`.
/// Convert a pointer to a `usize` integer. /// Convert a pointer to a `usize` integer.
ptr_to_int, int_from_ptr,
/// Emit an error message and fail compilation. /// Emit an error message and fail compilation.
/// Uses the `un_node` field. /// Uses the `un_node` field.
compile_error, compile_error,
@ -761,11 +761,11 @@ pub const Inst = struct {
set_eval_branch_quota, set_eval_branch_quota,
/// Converts an enum value into an integer. Resulting type will be the tag type /// Converts an enum value into an integer. Resulting type will be the tag type
/// of the enum. Uses `un_node`. /// of the enum. Uses `un_node`.
enum_to_int, int_from_enum,
/// Implement builtin `@alignOf`. Uses `un_node`. /// Implement builtin `@alignOf`. Uses `un_node`.
align_of, align_of,
/// Implement builtin `@boolToInt`. Uses `un_node`. /// Implement builtin `@intFromBool`. Uses `un_node`.
bool_to_int, int_from_bool,
/// Implement builtin `@embedFile`. Uses `un_node`. /// Implement builtin `@embedFile`. Uses `un_node`.
embed_file, embed_file,
/// Implement builtin `@errorName`. Uses `un_node`. /// Implement builtin `@errorName`. Uses `un_node`.
@ -814,18 +814,18 @@ pub const Inst = struct {
/// Implement builtin `@frameSize`. Uses `un_node`. /// Implement builtin `@frameSize`. Uses `un_node`.
frame_size, frame_size,
/// Implements the `@floatToInt` builtin. /// Implements the `@intFromFloat` builtin.
/// Uses `pl_node` with payload `Bin`. `lhs` is dest type, `rhs` is operand. /// Uses `pl_node` with payload `Bin`. `lhs` is dest type, `rhs` is operand.
float_to_int, int_from_float,
/// Implements the `@intToFloat` builtin. /// Implements the `@floatFromInt` builtin.
/// Uses `pl_node` with payload `Bin`. `lhs` is dest type, `rhs` is operand. /// Uses `pl_node` with payload `Bin`. `lhs` is dest type, `rhs` is operand.
int_to_float, float_from_int,
/// Implements the `@intToPtr` builtin. /// Implements the `@ptrFromInt` builtin.
/// Uses `pl_node` with payload `Bin`. `lhs` is dest type, `rhs` is operand. /// Uses `pl_node` with payload `Bin`. `lhs` is dest type, `rhs` is operand.
int_to_ptr, ptr_from_int,
/// Converts an integer into an enum value. /// Converts an integer into an enum value.
/// Uses `pl_node` with payload `Bin`. `lhs` is dest type, `rhs` is operand. /// Uses `pl_node` with payload `Bin`. `lhs` is dest type, `rhs` is operand.
int_to_enum, enum_from_int,
/// Convert a larger float type to any other float type, possibly causing /// Convert a larger float type to any other float type, possibly causing
/// a loss of precision. /// a loss of precision.
/// Uses the `pl_node` field. AST is the `@floatCast` syntax. /// Uses the `pl_node` field. AST is the `@floatCast` syntax.
@ -1136,14 +1136,14 @@ pub const Inst = struct {
.union_init, .union_init,
.field_type, .field_type,
.field_type_ref, .field_type_ref,
.int_to_enum, .enum_from_int,
.enum_to_int, .int_from_enum,
.type_info, .type_info,
.size_of, .size_of,
.bit_size_of, .bit_size_of,
.ptr_to_int, .int_from_ptr,
.align_of, .align_of,
.bool_to_int, .int_from_bool,
.embed_file, .embed_file,
.error_name, .error_name,
.set_runtime_safety, .set_runtime_safety,
@ -1165,9 +1165,9 @@ pub const Inst = struct {
.type_name, .type_name,
.frame_type, .frame_type,
.frame_size, .frame_size,
.float_to_int, .int_from_float,
.int_to_float, .float_from_int,
.int_to_ptr, .ptr_from_int,
.float_cast, .float_cast,
.int_cast, .int_cast,
.ptr_cast, .ptr_cast,
@ -1419,14 +1419,14 @@ pub const Inst = struct {
.union_init, .union_init,
.field_type, .field_type,
.field_type_ref, .field_type_ref,
.int_to_enum, .enum_from_int,
.enum_to_int, .int_from_enum,
.type_info, .type_info,
.size_of, .size_of,
.bit_size_of, .bit_size_of,
.ptr_to_int, .int_from_ptr,
.align_of, .align_of,
.bool_to_int, .int_from_bool,
.embed_file, .embed_file,
.error_name, .error_name,
.sqrt, .sqrt,
@ -1447,9 +1447,9 @@ pub const Inst = struct {
.type_name, .type_name,
.frame_type, .frame_type,
.frame_size, .frame_size,
.float_to_int, .int_from_float,
.int_to_float, .float_from_int,
.int_to_ptr, .ptr_from_int,
.float_cast, .float_cast,
.int_cast, .int_cast,
.ptr_cast, .ptr_cast,
@ -1679,12 +1679,12 @@ pub const Inst = struct {
.size_of = .un_node, .size_of = .un_node,
.bit_size_of = .un_node, .bit_size_of = .un_node,
.ptr_to_int = .un_node, .int_from_ptr = .un_node,
.compile_error = .un_node, .compile_error = .un_node,
.set_eval_branch_quota = .un_node, .set_eval_branch_quota = .un_node,
.enum_to_int = .un_node, .int_from_enum = .un_node,
.align_of = .un_node, .align_of = .un_node,
.bool_to_int = .un_node, .int_from_bool = .un_node,
.embed_file = .un_node, .embed_file = .un_node,
.error_name = .un_node, .error_name = .un_node,
.panic = .un_node, .panic = .un_node,
@ -1709,10 +1709,10 @@ pub const Inst = struct {
.frame_type = .un_node, .frame_type = .un_node,
.frame_size = .un_node, .frame_size = .un_node,
.float_to_int = .pl_node, .int_from_float = .pl_node,
.int_to_float = .pl_node, .float_from_int = .pl_node,
.int_to_ptr = .pl_node, .ptr_from_int = .pl_node,
.int_to_enum = .pl_node, .enum_from_int = .pl_node,
.float_cast = .pl_node, .float_cast = .pl_node,
.int_cast = .pl_node, .int_cast = .pl_node,
.ptr_cast = .pl_node, .ptr_cast = .pl_node,
@ -1933,10 +1933,10 @@ pub const Inst = struct {
select, select,
/// Implement builtin `@errToInt`. /// Implement builtin `@errToInt`.
/// `operand` is payload index to `UnNode`. /// `operand` is payload index to `UnNode`.
error_to_int, int_from_error,
/// Implement builtin `@intToError`. /// Implement builtin `@intToError`.
/// `operand` is payload index to `UnNode`. /// `operand` is payload index to `UnNode`.
int_to_error, error_from_int,
/// Implement builtin `@Type`. /// Implement builtin `@Type`.
/// `operand` is payload index to `UnNode`. /// `operand` is payload index to `UnNode`.
/// `small` contains `NameStrategy`. /// `small` contains `NameStrategy`.

View file

@ -752,7 +752,7 @@ fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void {
.fpext => try self.airFpext(inst), .fpext => try self.airFpext(inst),
.intcast => try self.airIntCast(inst), .intcast => try self.airIntCast(inst),
.trunc => try self.airTrunc(inst), .trunc => try self.airTrunc(inst),
.bool_to_int => try self.airBoolToInt(inst), .int_from_bool => try self.airIntFromBool(inst),
.is_non_null => try self.airIsNonNull(inst), .is_non_null => try self.airIsNonNull(inst),
.is_non_null_ptr => try self.airIsNonNullPtr(inst), .is_non_null_ptr => try self.airIsNonNullPtr(inst),
.is_null => try self.airIsNull(inst), .is_null => try self.airIsNull(inst),
@ -764,7 +764,7 @@ fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void {
.load => try self.airLoad(inst), .load => try self.airLoad(inst),
.loop => try self.airLoop(inst), .loop => try self.airLoop(inst),
.not => try self.airNot(inst), .not => try self.airNot(inst),
.ptrtoint => try self.airPtrToInt(inst), .int_from_ptr => try self.airIntFromPtr(inst),
.ret => try self.airRet(inst), .ret => try self.airRet(inst),
.ret_load => try self.airRetLoad(inst), .ret_load => try self.airRetLoad(inst),
.store => try self.airStore(inst, false), .store => try self.airStore(inst, false),
@ -772,8 +772,8 @@ fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void {
.struct_field_ptr=> try self.airStructFieldPtr(inst), .struct_field_ptr=> try self.airStructFieldPtr(inst),
.struct_field_val=> try self.airStructFieldVal(inst), .struct_field_val=> try self.airStructFieldVal(inst),
.array_to_slice => try self.airArrayToSlice(inst), .array_to_slice => try self.airArrayToSlice(inst),
.int_to_float => try self.airIntToFloat(inst), .float_from_int => try self.airFloatFromInt(inst),
.float_to_int => try self.airFloatToInt(inst), .int_from_float => try self.airIntFromFloat(inst),
.cmpxchg_strong => try self.airCmpxchg(inst), .cmpxchg_strong => try self.airCmpxchg(inst),
.cmpxchg_weak => try self.airCmpxchg(inst), .cmpxchg_weak => try self.airCmpxchg(inst),
.atomic_rmw => try self.airAtomicRmw(inst), .atomic_rmw => try self.airAtomicRmw(inst),
@ -885,7 +885,7 @@ fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void {
.cmp_neq_optimized, .cmp_neq_optimized,
.cmp_vector_optimized, .cmp_vector_optimized,
.reduce_optimized, .reduce_optimized,
.float_to_int_optimized, .int_from_float_optimized,
=> return self.fail("TODO implement optimized float mode", .{}), => return self.fail("TODO implement optimized float mode", .{}),
.is_named_enum_value => return self.fail("TODO implement is_named_enum_value", .{}), .is_named_enum_value => return self.fail("TODO implement is_named_enum_value", .{}),
@ -1310,7 +1310,7 @@ fn airTrunc(self: *Self, inst: Air.Inst.Index) !void {
return self.finishAir(inst, result, .{ ty_op.operand, .none, .none }); return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
} }
fn airBoolToInt(self: *Self, inst: Air.Inst.Index) !void { fn airIntFromBool(self: *Self, inst: Air.Inst.Index) !void {
const un_op = self.air.instructions.items(.data)[inst].un_op; const un_op = self.air.instructions.items(.data)[inst].un_op;
const operand = try self.resolveInst(un_op); const operand = try self.resolveInst(un_op);
const result: MCValue = if (self.liveness.isUnused(inst)) .dead else operand; const result: MCValue = if (self.liveness.isUnused(inst)) .dead else operand;
@ -5903,7 +5903,7 @@ fn genSetStackArgument(self: *Self, ty: Type, stack_offset: u32, mcv: MCValue) I
} }
} }
fn airPtrToInt(self: *Self, inst: Air.Inst.Index) !void { fn airIntFromPtr(self: *Self, inst: Air.Inst.Index) !void {
const un_op = self.air.instructions.items(.data)[inst].un_op; const un_op = self.air.instructions.items(.data)[inst].un_op;
const result = try self.resolveInst(un_op); const result = try self.resolveInst(un_op);
return self.finishAir(inst, result, .{ un_op, .none, .none }); return self.finishAir(inst, result, .{ un_op, .none, .none });
@ -5950,17 +5950,17 @@ fn airArrayToSlice(self: *Self, inst: Air.Inst.Index) !void {
return self.finishAir(inst, result, .{ ty_op.operand, .none, .none }); return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
} }
fn airIntToFloat(self: *Self, inst: Air.Inst.Index) !void { fn airFloatFromInt(self: *Self, inst: Air.Inst.Index) !void {
const ty_op = self.air.instructions.items(.data)[inst].ty_op; const ty_op = self.air.instructions.items(.data)[inst].ty_op;
const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airIntToFloat for {}", .{ const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airFloatFromInt for {}", .{
self.target.cpu.arch, self.target.cpu.arch,
}); });
return self.finishAir(inst, result, .{ ty_op.operand, .none, .none }); return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
} }
fn airFloatToInt(self: *Self, inst: Air.Inst.Index) !void { fn airIntFromFloat(self: *Self, inst: Air.Inst.Index) !void {
const ty_op = self.air.instructions.items(.data)[inst].ty_op; const ty_op = self.air.instructions.items(.data)[inst].ty_op;
const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airFloatToInt for {}", .{ const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airIntFromFloat for {}", .{
self.target.cpu.arch, self.target.cpu.arch,
}); });
return self.finishAir(inst, result, .{ ty_op.operand, .none, .none }); return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });

View file

@ -736,7 +736,7 @@ fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void {
.fpext => try self.airFpext(inst), .fpext => try self.airFpext(inst),
.intcast => try self.airIntCast(inst), .intcast => try self.airIntCast(inst),
.trunc => try self.airTrunc(inst), .trunc => try self.airTrunc(inst),
.bool_to_int => try self.airBoolToInt(inst), .int_from_bool => try self.airIntFromBool(inst),
.is_non_null => try self.airIsNonNull(inst), .is_non_null => try self.airIsNonNull(inst),
.is_non_null_ptr => try self.airIsNonNullPtr(inst), .is_non_null_ptr => try self.airIsNonNullPtr(inst),
.is_null => try self.airIsNull(inst), .is_null => try self.airIsNull(inst),
@ -748,7 +748,7 @@ fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void {
.load => try self.airLoad(inst), .load => try self.airLoad(inst),
.loop => try self.airLoop(inst), .loop => try self.airLoop(inst),
.not => try self.airNot(inst), .not => try self.airNot(inst),
.ptrtoint => try self.airPtrToInt(inst), .int_from_ptr => try self.airIntFromPtr(inst),
.ret => try self.airRet(inst), .ret => try self.airRet(inst),
.ret_load => try self.airRetLoad(inst), .ret_load => try self.airRetLoad(inst),
.store => try self.airStore(inst, false), .store => try self.airStore(inst, false),
@ -756,8 +756,8 @@ fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void {
.struct_field_ptr=> try self.airStructFieldPtr(inst), .struct_field_ptr=> try self.airStructFieldPtr(inst),
.struct_field_val=> try self.airStructFieldVal(inst), .struct_field_val=> try self.airStructFieldVal(inst),
.array_to_slice => try self.airArrayToSlice(inst), .array_to_slice => try self.airArrayToSlice(inst),
.int_to_float => try self.airIntToFloat(inst), .float_from_int => try self.airFloatFromInt(inst),
.float_to_int => try self.airFloatToInt(inst), .int_from_float => try self.airIntFromFloat(inst),
.cmpxchg_strong => try self.airCmpxchg(inst), .cmpxchg_strong => try self.airCmpxchg(inst),
.cmpxchg_weak => try self.airCmpxchg(inst), .cmpxchg_weak => try self.airCmpxchg(inst),
.atomic_rmw => try self.airAtomicRmw(inst), .atomic_rmw => try self.airAtomicRmw(inst),
@ -869,7 +869,7 @@ fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void {
.cmp_neq_optimized, .cmp_neq_optimized,
.cmp_vector_optimized, .cmp_vector_optimized,
.reduce_optimized, .reduce_optimized,
.float_to_int_optimized, .int_from_float_optimized,
=> return self.fail("TODO implement optimized float mode", .{}), => return self.fail("TODO implement optimized float mode", .{}),
.is_named_enum_value => return self.fail("TODO implement is_named_enum_value", .{}), .is_named_enum_value => return self.fail("TODO implement is_named_enum_value", .{}),
@ -1269,7 +1269,7 @@ fn airTrunc(self: *Self, inst: Air.Inst.Index) !void {
return self.finishAir(inst, result, .{ ty_op.operand, .none, .none }); return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
} }
fn airBoolToInt(self: *Self, inst: Air.Inst.Index) !void { fn airIntFromBool(self: *Self, inst: Air.Inst.Index) !void {
const un_op = self.air.instructions.items(.data)[inst].un_op; const un_op = self.air.instructions.items(.data)[inst].un_op;
const operand = try self.resolveInst(un_op); const operand = try self.resolveInst(un_op);
const result: MCValue = if (self.liveness.isUnused(inst)) .dead else operand; const result: MCValue = if (self.liveness.isUnused(inst)) .dead else operand;
@ -5857,7 +5857,7 @@ fn genSetStackArgument(self: *Self, ty: Type, stack_offset: u32, mcv: MCValue) I
} }
} }
fn airPtrToInt(self: *Self, inst: Air.Inst.Index) !void { fn airIntFromPtr(self: *Self, inst: Air.Inst.Index) !void {
const un_op = self.air.instructions.items(.data)[inst].un_op; const un_op = self.air.instructions.items(.data)[inst].un_op;
const result = try self.resolveInst(un_op); const result = try self.resolveInst(un_op);
return self.finishAir(inst, result, .{ un_op, .none, .none }); return self.finishAir(inst, result, .{ un_op, .none, .none });
@ -5903,17 +5903,17 @@ fn airArrayToSlice(self: *Self, inst: Air.Inst.Index) !void {
return self.finishAir(inst, result, .{ ty_op.operand, .none, .none }); return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
} }
fn airIntToFloat(self: *Self, inst: Air.Inst.Index) !void { fn airFloatFromInt(self: *Self, inst: Air.Inst.Index) !void {
const ty_op = self.air.instructions.items(.data)[inst].ty_op; const ty_op = self.air.instructions.items(.data)[inst].ty_op;
const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airIntToFloat for {}", .{ const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airFloatFromInt for {}", .{
self.target.cpu.arch, self.target.cpu.arch,
}); });
return self.finishAir(inst, result, .{ ty_op.operand, .none, .none }); return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
} }
fn airFloatToInt(self: *Self, inst: Air.Inst.Index) !void { fn airIntFromFloat(self: *Self, inst: Air.Inst.Index) !void {
const ty_op = self.air.instructions.items(.data)[inst].ty_op; const ty_op = self.air.instructions.items(.data)[inst].ty_op;
const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airFloatToInt for {}", .{ const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airIntFromFloat for {}", .{
self.target.cpu.arch, self.target.cpu.arch,
}); });
return self.finishAir(inst, result, .{ ty_op.operand, .none, .none }); return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });

View file

@ -566,7 +566,7 @@ fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void {
.fpext => try self.airFpext(inst), .fpext => try self.airFpext(inst),
.intcast => try self.airIntCast(inst), .intcast => try self.airIntCast(inst),
.trunc => try self.airTrunc(inst), .trunc => try self.airTrunc(inst),
.bool_to_int => try self.airBoolToInt(inst), .int_from_bool => try self.airIntFromBool(inst),
.is_non_null => try self.airIsNonNull(inst), .is_non_null => try self.airIsNonNull(inst),
.is_non_null_ptr => try self.airIsNonNullPtr(inst), .is_non_null_ptr => try self.airIsNonNullPtr(inst),
.is_null => try self.airIsNull(inst), .is_null => try self.airIsNull(inst),
@ -578,7 +578,7 @@ fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void {
.load => try self.airLoad(inst), .load => try self.airLoad(inst),
.loop => try self.airLoop(inst), .loop => try self.airLoop(inst),
.not => try self.airNot(inst), .not => try self.airNot(inst),
.ptrtoint => try self.airPtrToInt(inst), .int_from_ptr => try self.airIntFromPtr(inst),
.ret => try self.airRet(inst), .ret => try self.airRet(inst),
.ret_load => try self.airRetLoad(inst), .ret_load => try self.airRetLoad(inst),
.store => try self.airStore(inst, false), .store => try self.airStore(inst, false),
@ -586,8 +586,8 @@ fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void {
.struct_field_ptr=> try self.airStructFieldPtr(inst), .struct_field_ptr=> try self.airStructFieldPtr(inst),
.struct_field_val=> try self.airStructFieldVal(inst), .struct_field_val=> try self.airStructFieldVal(inst),
.array_to_slice => try self.airArrayToSlice(inst), .array_to_slice => try self.airArrayToSlice(inst),
.int_to_float => try self.airIntToFloat(inst), .float_from_int => try self.airFloatFromInt(inst),
.float_to_int => try self.airFloatToInt(inst), .int_from_float => try self.airIntFromFloat(inst),
.cmpxchg_strong => try self.airCmpxchg(inst), .cmpxchg_strong => try self.airCmpxchg(inst),
.cmpxchg_weak => try self.airCmpxchg(inst), .cmpxchg_weak => try self.airCmpxchg(inst),
.atomic_rmw => try self.airAtomicRmw(inst), .atomic_rmw => try self.airAtomicRmw(inst),
@ -699,7 +699,7 @@ fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void {
.cmp_neq_optimized, .cmp_neq_optimized,
.cmp_vector_optimized, .cmp_vector_optimized,
.reduce_optimized, .reduce_optimized,
.float_to_int_optimized, .int_from_float_optimized,
=> return self.fail("TODO implement optimized float mode", .{}), => return self.fail("TODO implement optimized float mode", .{}),
.is_named_enum_value => return self.fail("TODO implement is_named_enum_value", .{}), .is_named_enum_value => return self.fail("TODO implement is_named_enum_value", .{}),
@ -920,7 +920,7 @@ fn airTrunc(self: *Self, inst: Air.Inst.Index) !void {
// return self.finishAir(inst, result, .{ ty_op.operand, .none, .none }); // return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
} }
fn airBoolToInt(self: *Self, inst: Air.Inst.Index) !void { fn airIntFromBool(self: *Self, inst: Air.Inst.Index) !void {
const un_op = self.air.instructions.items(.data)[inst].un_op; const un_op = self.air.instructions.items(.data)[inst].un_op;
const operand = try self.resolveInst(un_op); const operand = try self.resolveInst(un_op);
const result: MCValue = if (self.liveness.isUnused(inst)) .dead else operand; const result: MCValue = if (self.liveness.isUnused(inst)) .dead else operand;
@ -2361,7 +2361,7 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void
} }
} }
fn airPtrToInt(self: *Self, inst: Air.Inst.Index) !void { fn airIntFromPtr(self: *Self, inst: Air.Inst.Index) !void {
const un_op = self.air.instructions.items(.data)[inst].un_op; const un_op = self.air.instructions.items(.data)[inst].un_op;
const result = try self.resolveInst(un_op); const result = try self.resolveInst(un_op);
return self.finishAir(inst, result, .{ un_op, .none, .none }); return self.finishAir(inst, result, .{ un_op, .none, .none });
@ -2394,17 +2394,17 @@ fn airArrayToSlice(self: *Self, inst: Air.Inst.Index) !void {
return self.finishAir(inst, result, .{ ty_op.operand, .none, .none }); return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
} }
fn airIntToFloat(self: *Self, inst: Air.Inst.Index) !void { fn airFloatFromInt(self: *Self, inst: Air.Inst.Index) !void {
const ty_op = self.air.instructions.items(.data)[inst].ty_op; const ty_op = self.air.instructions.items(.data)[inst].ty_op;
const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airIntToFloat for {}", .{ const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airFloatFromInt for {}", .{
self.target.cpu.arch, self.target.cpu.arch,
}); });
return self.finishAir(inst, result, .{ ty_op.operand, .none, .none }); return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
} }
fn airFloatToInt(self: *Self, inst: Air.Inst.Index) !void { fn airIntFromFloat(self: *Self, inst: Air.Inst.Index) !void {
const ty_op = self.air.instructions.items(.data)[inst].ty_op; const ty_op = self.air.instructions.items(.data)[inst].ty_op;
const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airFloatToInt for {}", .{ const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airIntFromFloat for {}", .{
self.target.cpu.arch, self.target.cpu.arch,
}); });
return self.finishAir(inst, result, .{ ty_op.operand, .none, .none }); return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });

View file

@ -583,7 +583,7 @@ fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void {
.fpext => @panic("TODO try self.airFpext(inst)"), .fpext => @panic("TODO try self.airFpext(inst)"),
.intcast => try self.airIntCast(inst), .intcast => try self.airIntCast(inst),
.trunc => try self.airTrunc(inst), .trunc => try self.airTrunc(inst),
.bool_to_int => try self.airBoolToInt(inst), .int_from_bool => try self.airIntFromBool(inst),
.is_non_null => try self.airIsNonNull(inst), .is_non_null => try self.airIsNonNull(inst),
.is_non_null_ptr => @panic("TODO try self.airIsNonNullPtr(inst)"), .is_non_null_ptr => @panic("TODO try self.airIsNonNullPtr(inst)"),
.is_null => try self.airIsNull(inst), .is_null => try self.airIsNull(inst),
@ -595,7 +595,7 @@ fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void {
.load => try self.airLoad(inst), .load => try self.airLoad(inst),
.loop => try self.airLoop(inst), .loop => try self.airLoop(inst),
.not => try self.airNot(inst), .not => try self.airNot(inst),
.ptrtoint => try self.airPtrToInt(inst), .int_from_ptr => try self.airIntFromPtr(inst),
.ret => try self.airRet(inst), .ret => try self.airRet(inst),
.ret_load => try self.airRetLoad(inst), .ret_load => try self.airRetLoad(inst),
.store => try self.airStore(inst, false), .store => try self.airStore(inst, false),
@ -603,8 +603,8 @@ fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void {
.struct_field_ptr=> try self.airStructFieldPtr(inst), .struct_field_ptr=> try self.airStructFieldPtr(inst),
.struct_field_val=> try self.airStructFieldVal(inst), .struct_field_val=> try self.airStructFieldVal(inst),
.array_to_slice => try self.airArrayToSlice(inst), .array_to_slice => try self.airArrayToSlice(inst),
.int_to_float => try self.airIntToFloat(inst), .float_from_int => try self.airFloatFromInt(inst),
.float_to_int => try self.airFloatToInt(inst), .int_from_float => try self.airIntFromFloat(inst),
.cmpxchg_strong, .cmpxchg_strong,
.cmpxchg_weak, .cmpxchg_weak,
=> try self.airCmpxchg(inst), => try self.airCmpxchg(inst),
@ -717,7 +717,7 @@ fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void {
.cmp_neq_optimized, .cmp_neq_optimized,
.cmp_vector_optimized, .cmp_vector_optimized,
.reduce_optimized, .reduce_optimized,
.float_to_int_optimized, .int_from_float_optimized,
=> @panic("TODO implement optimized float mode"), => @panic("TODO implement optimized float mode"),
.is_named_enum_value => @panic("TODO implement is_named_enum_value"), .is_named_enum_value => @panic("TODO implement is_named_enum_value"),
@ -1078,7 +1078,7 @@ fn airBinOp(self: *Self, inst: Air.Inst.Index, tag: Air.Inst.Tag) !void {
return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none }); return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });
} }
fn airBoolToInt(self: *Self, inst: Air.Inst.Index) !void { fn airIntFromBool(self: *Self, inst: Air.Inst.Index) !void {
const un_op = self.air.instructions.items(.data)[inst].un_op; const un_op = self.air.instructions.items(.data)[inst].un_op;
const operand = try self.resolveInst(un_op); const operand = try self.resolveInst(un_op);
const result: MCValue = if (self.liveness.isUnused(inst)) .dead else operand; const result: MCValue = if (self.liveness.isUnused(inst)) .dead else operand;
@ -1736,9 +1736,9 @@ fn airFence(self: *Self, inst: Air.Inst.Index) !void {
return self.finishAir(inst, .dead, .{ .none, .none, .none }); return self.finishAir(inst, .dead, .{ .none, .none, .none });
} }
fn airFloatToInt(self: *Self, inst: Air.Inst.Index) !void { fn airIntFromFloat(self: *Self, inst: Air.Inst.Index) !void {
const ty_op = self.air.instructions.items(.data)[inst].ty_op; const ty_op = self.air.instructions.items(.data)[inst].ty_op;
const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airFloatToInt for {}", .{ const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airIntFromFloat for {}", .{
self.target.cpu.arch, self.target.cpu.arch,
}); });
return self.finishAir(inst, result, .{ ty_op.operand, .none, .none }); return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
@ -1769,9 +1769,9 @@ fn airIntCast(self: *Self, inst: Air.Inst.Index) !void {
return self.fail("TODO implement intCast for {}", .{self.target.cpu.arch}); return self.fail("TODO implement intCast for {}", .{self.target.cpu.arch});
} }
fn airIntToFloat(self: *Self, inst: Air.Inst.Index) !void { fn airFloatFromInt(self: *Self, inst: Air.Inst.Index) !void {
const ty_op = self.air.instructions.items(.data)[inst].ty_op; const ty_op = self.air.instructions.items(.data)[inst].ty_op;
const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airIntToFloat for {}", .{ const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airFloatFromInt for {}", .{
self.target.cpu.arch, self.target.cpu.arch,
}); });
return self.finishAir(inst, result, .{ ty_op.operand, .none, .none }); return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
@ -2276,7 +2276,7 @@ fn airPtrSlicePtrPtr(self: *Self, inst: Air.Inst.Index) !void {
return self.finishAir(inst, result, .{ ty_op.operand, .none, .none }); return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
} }
fn airPtrToInt(self: *Self, inst: Air.Inst.Index) !void { fn airIntFromPtr(self: *Self, inst: Air.Inst.Index) !void {
const un_op = self.air.instructions.items(.data)[inst].un_op; const un_op = self.air.instructions.items(.data)[inst].un_op;
const result = try self.resolveInst(un_op); const result = try self.resolveInst(un_op);
return self.finishAir(inst, result, .{ un_op, .none, .none }); return self.finishAir(inst, result, .{ un_op, .none, .none });

View file

@ -1902,13 +1902,13 @@ fn genInst(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
.trap => func.airTrap(inst), .trap => func.airTrap(inst),
.breakpoint => func.airBreakpoint(inst), .breakpoint => func.airBreakpoint(inst),
.br => func.airBr(inst), .br => func.airBr(inst),
.bool_to_int => func.airBoolToInt(inst), .int_from_bool => func.airIntFromBool(inst),
.cond_br => func.airCondBr(inst), .cond_br => func.airCondBr(inst),
.intcast => func.airIntcast(inst), .intcast => func.airIntcast(inst),
.fptrunc => func.airFptrunc(inst), .fptrunc => func.airFptrunc(inst),
.fpext => func.airFpext(inst), .fpext => func.airFpext(inst),
.float_to_int => func.airFloatToInt(inst), .int_from_float => func.airIntFromFloat(inst),
.int_to_float => func.airIntToFloat(inst), .float_from_int => func.airFloatFromInt(inst),
.get_union_tag => func.airGetUnionTag(inst), .get_union_tag => func.airGetUnionTag(inst),
.@"try" => func.airTry(inst), .@"try" => func.airTry(inst),
@ -1951,7 +1951,7 @@ fn genInst(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
.ptr_sub => func.airPtrBinOp(inst, .sub), .ptr_sub => func.airPtrBinOp(inst, .sub),
.ptr_elem_ptr => func.airPtrElemPtr(inst), .ptr_elem_ptr => func.airPtrElemPtr(inst),
.ptr_elem_val => func.airPtrElemVal(inst), .ptr_elem_val => func.airPtrElemVal(inst),
.ptrtoint => func.airPtrToInt(inst), .int_from_ptr => func.airIntFromPtr(inst),
.ret => func.airRet(inst), .ret => func.airRet(inst),
.ret_ptr => func.airRetPtr(inst), .ret_ptr => func.airRetPtr(inst),
.ret_load => func.airRetLoad(inst), .ret_load => func.airRetLoad(inst),
@ -2061,7 +2061,7 @@ fn genInst(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
.cmp_neq_optimized, .cmp_neq_optimized,
.cmp_vector_optimized, .cmp_vector_optimized,
.reduce_optimized, .reduce_optimized,
.float_to_int_optimized, .int_from_float_optimized,
=> return func.fail("TODO implement optimized float mode", .{}), => return func.fail("TODO implement optimized float mode", .{}),
.work_item_id, .work_item_id,
@ -4480,7 +4480,7 @@ fn trunc(func: *CodeGen, operand: WValue, wanted_ty: Type, given_ty: Type) Inner
return result; return result;
} }
fn airBoolToInt(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { fn airIntFromBool(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
const un_op = func.air.instructions.items(.data)[inst].un_op; const un_op = func.air.instructions.items(.data)[inst].un_op;
const operand = try func.resolveInst(un_op); const operand = try func.resolveInst(un_op);
const result = func.reuseOperand(un_op, operand); const result = func.reuseOperand(un_op, operand);
@ -4511,7 +4511,7 @@ fn airArrayToSlice(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
func.finishAir(inst, slice_local, &.{ty_op.operand}); func.finishAir(inst, slice_local, &.{ty_op.operand});
} }
fn airPtrToInt(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { fn airIntFromPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
const mod = func.bin_file.base.options.module.?; const mod = func.bin_file.base.options.module.?;
const un_op = func.air.instructions.items(.data)[inst].un_op; const un_op = func.air.instructions.items(.data)[inst].un_op;
const operand = try func.resolveInst(un_op); const operand = try func.resolveInst(un_op);
@ -4812,7 +4812,7 @@ fn airArrayElemVal(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
func.finishAir(inst, elem_result, &.{ bin_op.lhs, bin_op.rhs }); func.finishAir(inst, elem_result, &.{ bin_op.lhs, bin_op.rhs });
} }
fn airFloatToInt(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { fn airIntFromFloat(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
const mod = func.bin_file.base.options.module.?; const mod = func.bin_file.base.options.module.?;
const ty_op = func.air.instructions.items(.data)[inst].ty_op; const ty_op = func.air.instructions.items(.data)[inst].ty_op;
@ -4837,7 +4837,7 @@ fn airFloatToInt(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
func.finishAir(inst, result, &.{ty_op.operand}); func.finishAir(inst, result, &.{ty_op.operand});
} }
fn airIntToFloat(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { fn airFloatFromInt(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
const mod = func.bin_file.base.options.module.?; const mod = func.bin_file.base.options.module.?;
const ty_op = func.air.instructions.items(.data)[inst].ty_op; const ty_op = func.air.instructions.items(.data)[inst].ty_op;

View file

@ -1835,7 +1835,7 @@ fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void {
.fpext => try self.airFpext(inst), .fpext => try self.airFpext(inst),
.intcast => try self.airIntCast(inst), .intcast => try self.airIntCast(inst),
.trunc => try self.airTrunc(inst), .trunc => try self.airTrunc(inst),
.bool_to_int => try self.airBoolToInt(inst), .int_from_bool => try self.airIntFromBool(inst),
.is_non_null => try self.airIsNonNull(inst), .is_non_null => try self.airIsNonNull(inst),
.is_non_null_ptr => try self.airIsNonNullPtr(inst), .is_non_null_ptr => try self.airIsNonNullPtr(inst),
.is_null => try self.airIsNull(inst), .is_null => try self.airIsNull(inst),
@ -1846,7 +1846,7 @@ fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void {
.is_err_ptr => try self.airIsErrPtr(inst), .is_err_ptr => try self.airIsErrPtr(inst),
.load => try self.airLoad(inst), .load => try self.airLoad(inst),
.loop => try self.airLoop(inst), .loop => try self.airLoop(inst),
.ptrtoint => try self.airPtrToInt(inst), .int_from_ptr => try self.airIntFromPtr(inst),
.ret => try self.airRet(inst), .ret => try self.airRet(inst),
.ret_load => try self.airRetLoad(inst), .ret_load => try self.airRetLoad(inst),
.store => try self.airStore(inst, false), .store => try self.airStore(inst, false),
@ -1854,8 +1854,8 @@ fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void {
.struct_field_ptr=> try self.airStructFieldPtr(inst), .struct_field_ptr=> try self.airStructFieldPtr(inst),
.struct_field_val=> try self.airStructFieldVal(inst), .struct_field_val=> try self.airStructFieldVal(inst),
.array_to_slice => try self.airArrayToSlice(inst), .array_to_slice => try self.airArrayToSlice(inst),
.int_to_float => try self.airIntToFloat(inst), .float_from_int => try self.airFloatFromInt(inst),
.float_to_int => try self.airFloatToInt(inst), .int_from_float => try self.airIntFromFloat(inst),
.cmpxchg_strong => try self.airCmpxchg(inst), .cmpxchg_strong => try self.airCmpxchg(inst),
.cmpxchg_weak => try self.airCmpxchg(inst), .cmpxchg_weak => try self.airCmpxchg(inst),
.atomic_rmw => try self.airAtomicRmw(inst), .atomic_rmw => try self.airAtomicRmw(inst),
@ -1967,7 +1967,7 @@ fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void {
.cmp_neq_optimized, .cmp_neq_optimized,
.cmp_vector_optimized, .cmp_vector_optimized,
.reduce_optimized, .reduce_optimized,
.float_to_int_optimized, .int_from_float_optimized,
=> return self.fail("TODO implement optimized float mode", .{}), => return self.fail("TODO implement optimized float mode", .{}),
.is_named_enum_value => return self.fail("TODO implement is_named_enum_value", .{}), .is_named_enum_value => return self.fail("TODO implement is_named_enum_value", .{}),
@ -2806,7 +2806,7 @@ fn airTrunc(self: *Self, inst: Air.Inst.Index) !void {
return self.finishAir(inst, result, .{ ty_op.operand, .none, .none }); return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
} }
fn airBoolToInt(self: *Self, inst: Air.Inst.Index) !void { fn airIntFromBool(self: *Self, inst: Air.Inst.Index) !void {
const un_op = self.air.instructions.items(.data)[inst].un_op; const un_op = self.air.instructions.items(.data)[inst].un_op;
const ty = self.typeOfIndex(inst); const ty = self.typeOfIndex(inst);
@ -10147,7 +10147,7 @@ fn genLazySymbolRef(
} }
} }
fn airPtrToInt(self: *Self, inst: Air.Inst.Index) !void { fn airIntFromPtr(self: *Self, inst: Air.Inst.Index) !void {
const un_op = self.air.instructions.items(.data)[inst].un_op; const un_op = self.air.instructions.items(.data)[inst].un_op;
const result = result: { const result = result: {
// TODO: handle case where the operand is a slice not a raw pointer // TODO: handle case where the operand is a slice not a raw pointer
@ -10246,7 +10246,7 @@ fn airArrayToSlice(self: *Self, inst: Air.Inst.Index) !void {
return self.finishAir(inst, result, .{ ty_op.operand, .none, .none }); return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
} }
fn airIntToFloat(self: *Self, inst: Air.Inst.Index) !void { fn airFloatFromInt(self: *Self, inst: Air.Inst.Index) !void {
const mod = self.bin_file.options.module.?; const mod = self.bin_file.options.module.?;
const ty_op = self.air.instructions.items(.data)[inst].ty_op; const ty_op = self.air.instructions.items(.data)[inst].ty_op;
@ -10260,7 +10260,7 @@ fn airIntToFloat(self: *Self, inst: Air.Inst.Index) !void {
.signed => src_bits, .signed => src_bits,
.unsigned => src_bits + 1, .unsigned => src_bits + 1,
}, 32), 8) catch unreachable; }, 32), 8) catch unreachable;
if (src_size > 8) return self.fail("TODO implement airIntToFloat from {} to {}", .{ if (src_size > 8) return self.fail("TODO implement airFloatFromInt from {} to {}", .{
src_ty.fmt(mod), dst_ty.fmt(mod), src_ty.fmt(mod), dst_ty.fmt(mod),
}); });
@ -10287,7 +10287,7 @@ fn airIntToFloat(self: *Self, inst: Air.Inst.Index) !void {
else => unreachable, else => unreachable,
}, },
else => null, else => null,
})) |tag| tag else return self.fail("TODO implement airIntToFloat from {} to {}", .{ })) |tag| tag else return self.fail("TODO implement airFloatFromInt from {} to {}", .{
src_ty.fmt(mod), dst_ty.fmt(mod), src_ty.fmt(mod), dst_ty.fmt(mod),
}); });
const dst_alias = dst_reg.to128(); const dst_alias = dst_reg.to128();
@ -10300,7 +10300,7 @@ fn airIntToFloat(self: *Self, inst: Air.Inst.Index) !void {
return self.finishAir(inst, dst_mcv, .{ ty_op.operand, .none, .none }); return self.finishAir(inst, dst_mcv, .{ ty_op.operand, .none, .none });
} }
fn airFloatToInt(self: *Self, inst: Air.Inst.Index) !void { fn airIntFromFloat(self: *Self, inst: Air.Inst.Index) !void {
const mod = self.bin_file.options.module.?; const mod = self.bin_file.options.module.?;
const ty_op = self.air.instructions.items(.data)[inst].ty_op; const ty_op = self.air.instructions.items(.data)[inst].ty_op;
@ -10314,7 +10314,7 @@ fn airFloatToInt(self: *Self, inst: Air.Inst.Index) !void {
.signed => dst_bits, .signed => dst_bits,
.unsigned => dst_bits + 1, .unsigned => dst_bits + 1,
}, 32), 8) catch unreachable; }, 32), 8) catch unreachable;
if (dst_size > 8) return self.fail("TODO implement airFloatToInt from {} to {}", .{ if (dst_size > 8) return self.fail("TODO implement airIntFromFloat from {} to {}", .{
src_ty.fmt(self.bin_file.options.module.?), dst_ty.fmt(self.bin_file.options.module.?), src_ty.fmt(self.bin_file.options.module.?), dst_ty.fmt(self.bin_file.options.module.?),
}); });
@ -10340,7 +10340,7 @@ fn airFloatToInt(self: *Self, inst: Air.Inst.Index) !void {
else => unreachable, else => unreachable,
}, },
else => null, else => null,
})) |tag| tag else return self.fail("TODO implement airFloatToInt from {} to {}", .{ })) |tag| tag else return self.fail("TODO implement airIntFromFloat from {} to {}", .{
src_ty.fmt(self.bin_file.options.module.?), dst_ty.fmt(self.bin_file.options.module.?), src_ty.fmt(self.bin_file.options.module.?), dst_ty.fmt(self.bin_file.options.module.?),
}), }),
registerAlias(dst_reg, dst_size), registerAlias(dst_reg, dst_size),

View file

@ -2943,7 +2943,7 @@ fn genBodyInner(f: *Function, body: []const Air.Inst.Index) error{ AnalysisFail,
.dbg_stmt => try airDbgStmt(f, inst), .dbg_stmt => try airDbgStmt(f, inst),
.intcast => try airIntCast(f, inst), .intcast => try airIntCast(f, inst),
.trunc => try airTrunc(f, inst), .trunc => try airTrunc(f, inst),
.bool_to_int => try airBoolToInt(f, inst), .int_from_bool => try airIntFromBool(f, inst),
.load => try airLoad(f, inst), .load => try airLoad(f, inst),
.ret => try airRet(f, inst, false), .ret => try airRet(f, inst, false),
.ret_load => try airRet(f, inst, true), .ret_load => try airRet(f, inst, true),
@ -3000,13 +3000,13 @@ fn genBodyInner(f: *Function, body: []const Air.Inst.Index) error{ AnalysisFail,
.call_never_tail => try airCall(f, inst, .never_tail), .call_never_tail => try airCall(f, inst, .never_tail),
.call_never_inline => try airCall(f, inst, .never_inline), .call_never_inline => try airCall(f, inst, .never_inline),
.int_to_float, .float_from_int,
.float_to_int, .int_from_float,
.fptrunc, .fptrunc,
.fpext, .fpext,
=> try airFloatCast(f, inst), => try airFloatCast(f, inst),
.ptrtoint => try airPtrToInt(f, inst), .int_from_ptr => try airIntFromPtr(f, inst),
.atomic_store_unordered => try airAtomicStore(f, inst, toMemoryOrder(.Unordered)), .atomic_store_unordered => try airAtomicStore(f, inst, toMemoryOrder(.Unordered)),
.atomic_store_monotonic => try airAtomicStore(f, inst, toMemoryOrder(.Monotonic)), .atomic_store_monotonic => try airAtomicStore(f, inst, toMemoryOrder(.Monotonic)),
@ -3068,7 +3068,7 @@ fn genBodyInner(f: *Function, body: []const Air.Inst.Index) error{ AnalysisFail,
.cmp_neq_optimized, .cmp_neq_optimized,
.cmp_vector_optimized, .cmp_vector_optimized,
.reduce_optimized, .reduce_optimized,
.float_to_int_optimized, .int_from_float_optimized,
=> return f.fail("TODO implement optimized float mode", .{}), => return f.fail("TODO implement optimized float mode", .{}),
.is_named_enum_value => return f.fail("TODO: C backend: implement is_named_enum_value", .{}), .is_named_enum_value => return f.fail("TODO: C backend: implement is_named_enum_value", .{}),
@ -3562,7 +3562,7 @@ fn airTrunc(f: *Function, inst: Air.Inst.Index) !CValue {
return local; return local;
} }
fn airBoolToInt(f: *Function, inst: Air.Inst.Index) !CValue { fn airIntFromBool(f: *Function, inst: Air.Inst.Index) !CValue {
const un_op = f.air.instructions.items(.data)[inst].un_op; const un_op = f.air.instructions.items(.data)[inst].un_op;
const operand = try f.resolveInst(un_op); const operand = try f.resolveInst(un_op);
try reap(f, inst, &.{un_op}); try reap(f, inst, &.{un_op});
@ -5834,7 +5834,7 @@ fn airFloatCast(f: *Function, inst: Air.Inst.Index) !CValue {
return local; return local;
} }
fn airPtrToInt(f: *Function, inst: Air.Inst.Index) !CValue { fn airIntFromPtr(f: *Function, inst: Air.Inst.Index) !CValue {
const mod = f.object.dg.module; const mod = f.object.dg.module;
const un_op = f.air.instructions.items(.data)[inst].un_op; const un_op = f.air.instructions.items(.data)[inst].un_op;

View file

@ -4417,7 +4417,7 @@ pub const FuncGen = struct {
.ret_ptr => try self.airRetPtr(inst), .ret_ptr => try self.airRetPtr(inst),
.arg => try self.airArg(inst), .arg => try self.airArg(inst),
.bitcast => try self.airBitCast(inst), .bitcast => try self.airBitCast(inst),
.bool_to_int => try self.airBoolToInt(inst), .int_from_bool => try self.airIntFromBool(inst),
.block => try self.airBlock(inst), .block => try self.airBlock(inst),
.br => try self.airBr(inst), .br => try self.airBr(inst),
.switch_br => try self.airSwitchBr(inst), .switch_br => try self.airSwitchBr(inst),
@ -4432,7 +4432,7 @@ pub const FuncGen = struct {
.trunc => try self.airTrunc(inst), .trunc => try self.airTrunc(inst),
.fptrunc => try self.airFptrunc(inst), .fptrunc => try self.airFptrunc(inst),
.fpext => try self.airFpext(inst), .fpext => try self.airFpext(inst),
.ptrtoint => try self.airPtrToInt(inst), .int_from_ptr => try self.airIntFromPtr(inst),
.load => try self.airLoad(body[i..]), .load => try self.airLoad(body[i..]),
.loop => try self.airLoop(inst), .loop => try self.airLoop(inst),
.not => try self.airNot(inst), .not => try self.airNot(inst),
@ -4452,11 +4452,11 @@ pub const FuncGen = struct {
.ptr_slice_ptr_ptr => try self.airPtrSliceFieldPtr(inst, 0), .ptr_slice_ptr_ptr => try self.airPtrSliceFieldPtr(inst, 0),
.ptr_slice_len_ptr => try self.airPtrSliceFieldPtr(inst, 1), .ptr_slice_len_ptr => try self.airPtrSliceFieldPtr(inst, 1),
.float_to_int => try self.airFloatToInt(inst, false), .int_from_float => try self.airIntFromFloat(inst, false),
.float_to_int_optimized => try self.airFloatToInt(inst, true), .int_from_float_optimized => try self.airIntFromFloat(inst, true),
.array_to_slice => try self.airArrayToSlice(inst), .array_to_slice => try self.airArrayToSlice(inst),
.int_to_float => try self.airIntToFloat(inst), .float_from_int => try self.airFloatFromInt(inst),
.cmpxchg_weak => try self.airCmpxchg(inst, true), .cmpxchg_weak => try self.airCmpxchg(inst, true),
.cmpxchg_strong => try self.airCmpxchg(inst, false), .cmpxchg_strong => try self.airCmpxchg(inst, false),
.fence => try self.airFence(inst), .fence => try self.airFence(inst),
@ -5456,7 +5456,7 @@ pub const FuncGen = struct {
return self.builder.buildInsertValue(partial, len, 1, ""); return self.builder.buildInsertValue(partial, len, 1, "");
} }
fn airIntToFloat(self: *FuncGen, inst: Air.Inst.Index) !?*llvm.Value { fn airFloatFromInt(self: *FuncGen, inst: Air.Inst.Index) !?*llvm.Value {
const mod = self.dg.module; const mod = self.dg.module;
const ty_op = self.air.instructions.items(.data)[inst].ty_op; const ty_op = self.air.instructions.items(.data)[inst].ty_op;
@ -5513,7 +5513,7 @@ pub const FuncGen = struct {
return self.builder.buildCall(libc_fn.globalGetValueType(), libc_fn, &params, params.len, .C, .Auto, ""); return self.builder.buildCall(libc_fn.globalGetValueType(), libc_fn, &params, params.len, .C, .Auto, "");
} }
fn airFloatToInt(self: *FuncGen, inst: Air.Inst.Index, want_fast_math: bool) !?*llvm.Value { fn airIntFromFloat(self: *FuncGen, inst: Air.Inst.Index, want_fast_math: bool) !?*llvm.Value {
self.builder.setFastMath(want_fast_math); self.builder.setFastMath(want_fast_math);
const mod = self.dg.module; const mod = self.dg.module;
@ -7788,7 +7788,7 @@ pub const FuncGen = struct {
} }
} }
fn airPtrToInt(self: *FuncGen, inst: Air.Inst.Index) !?*llvm.Value { fn airIntFromPtr(self: *FuncGen, inst: Air.Inst.Index) !?*llvm.Value {
const un_op = self.air.instructions.items(.data)[inst].un_op; const un_op = self.air.instructions.items(.data)[inst].un_op;
const operand = try self.resolveInst(un_op); const operand = try self.resolveInst(un_op);
const ptr_ty = self.typeOf(un_op); const ptr_ty = self.typeOf(un_op);
@ -7922,7 +7922,7 @@ pub const FuncGen = struct {
return self.builder.buildBitCast(operand, llvm_dest_ty, ""); return self.builder.buildBitCast(operand, llvm_dest_ty, "");
} }
fn airBoolToInt(self: *FuncGen, inst: Air.Inst.Index) !?*llvm.Value { fn airIntFromBool(self: *FuncGen, inst: Air.Inst.Index) !?*llvm.Value {
const un_op = self.air.instructions.items(.data)[inst].un_op; const un_op = self.air.instructions.items(.data)[inst].un_op;
const operand = try self.resolveInst(un_op); const operand = try self.resolveInst(un_op);
return operand; return operand;

View file

@ -1721,9 +1721,9 @@ pub const DeclGen = struct {
.bitcast => try self.airBitCast(inst), .bitcast => try self.airBitCast(inst),
.intcast, .trunc => try self.airIntCast(inst), .intcast, .trunc => try self.airIntCast(inst),
.ptrtoint => try self.airPtrToInt(inst), .int_from_ptr => try self.airIntFromPtr(inst),
.int_to_float => try self.airIntToFloat(inst), .float_from_int => try self.airFloatFromInt(inst),
.float_to_int => try self.airFloatToInt(inst), .int_from_float => try self.airIntFromFloat(inst),
.not => try self.airNot(inst), .not => try self.airNot(inst),
.slice_ptr => try self.airSliceField(inst, 0), .slice_ptr => try self.airSliceField(inst, 0),
@ -2329,7 +2329,7 @@ pub const DeclGen = struct {
return result_id; return result_id;
} }
fn airPtrToInt(self: *DeclGen, inst: Air.Inst.Index) !?IdRef { fn airIntFromPtr(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {
if (self.liveness.isUnused(inst)) return null; if (self.liveness.isUnused(inst)) return null;
const un_op = self.air.instructions.items(.data)[inst].un_op; const un_op = self.air.instructions.items(.data)[inst].un_op;
@ -2345,7 +2345,7 @@ pub const DeclGen = struct {
return result_id; return result_id;
} }
fn airIntToFloat(self: *DeclGen, inst: Air.Inst.Index) !?IdRef { fn airFloatFromInt(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {
if (self.liveness.isUnused(inst)) return null; if (self.liveness.isUnused(inst)) return null;
const ty_op = self.air.instructions.items(.data)[inst].ty_op; const ty_op = self.air.instructions.items(.data)[inst].ty_op;
@ -2371,7 +2371,7 @@ pub const DeclGen = struct {
return result_id; return result_id;
} }
fn airFloatToInt(self: *DeclGen, inst: Air.Inst.Index) !?IdRef { fn airIntFromFloat(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {
if (self.liveness.isUnused(inst)) return null; if (self.liveness.isUnused(inst)) return null;
const ty_op = self.air.instructions.items(.data)[inst].ty_op; const ty_op = self.air.instructions.items(.data)[inst].ty_op;

View file

@ -183,8 +183,8 @@ const Writer = struct {
.is_non_err, .is_non_err,
.is_err_ptr, .is_err_ptr,
.is_non_err_ptr, .is_non_err_ptr,
.ptrtoint, .int_from_ptr,
.bool_to_int, .int_from_bool,
.ret, .ret,
.ret_load, .ret_load,
.is_named_enum_value, .is_named_enum_value,
@ -254,10 +254,10 @@ const Writer = struct {
.struct_field_ptr_index_2, .struct_field_ptr_index_2,
.struct_field_ptr_index_3, .struct_field_ptr_index_3,
.array_to_slice, .array_to_slice,
.int_to_float, .float_from_int,
.splat, .splat,
.float_to_int, .int_from_float,
.float_to_int_optimized, .int_from_float_optimized,
.get_union_tag, .get_union_tag,
.clz, .clz,
.ctz, .ctz,

View file

@ -187,12 +187,12 @@ const Writer = struct {
.size_of, .size_of,
.bit_size_of, .bit_size_of,
.typeof_log2_int_type, .typeof_log2_int_type,
.ptr_to_int, .int_from_ptr,
.compile_error, .compile_error,
.set_eval_branch_quota, .set_eval_branch_quota,
.enum_to_int, .int_from_enum,
.align_of, .align_of,
.bool_to_int, .int_from_bool,
.embed_file, .embed_file,
.error_name, .error_name,
.panic, .panic,
@ -321,10 +321,10 @@ const Writer = struct {
.merge_error_sets, .merge_error_sets,
.bit_and, .bit_and,
.bit_or, .bit_or,
.float_to_int, .int_from_float,
.int_to_float, .float_from_int,
.int_to_ptr, .ptr_from_int,
.int_to_enum, .enum_from_int,
.float_cast, .float_cast,
.int_cast, .int_cast,
.ptr_cast, .ptr_cast,
@ -502,8 +502,8 @@ const Writer = struct {
.set_align_stack, .set_align_stack,
.set_cold, .set_cold,
.wasm_memory_size, .wasm_memory_size,
.error_to_int, .int_from_error,
.int_to_error, .error_from_int,
.reify, .reify,
.c_va_copy, .c_va_copy,
.c_va_end, .c_va_end,

View file

@ -845,7 +845,7 @@ fn visitVarDecl(c: *Context, var_decl: *const clang.VarDecl, mangled_name: ?[]co
error.OutOfMemory => |e| return e, error.OutOfMemory => |e| return e,
}; };
if (!qualTypeIsBoolean(qual_type) and isBoolRes(init_node.?)) { if (!qualTypeIsBoolean(qual_type) and isBoolRes(init_node.?)) {
init_node = try Tag.bool_to_int.create(c.arena, init_node.?); init_node = try Tag.int_from_bool.create(c.arena, init_node.?);
} else if (init_node.?.tag() == .string_literal and qualTypeIsCharStar(qual_type)) { } else if (init_node.?.tag() == .string_literal and qualTypeIsCharStar(qual_type)) {
init_node = try stringLiteralToCharStar(c, init_node.?); init_node = try stringLiteralToCharStar(c, init_node.?);
} }
@ -1753,16 +1753,16 @@ fn transBinaryOperator(
const rhs_uncasted = try transExpr(c, scope, stmt.getRHS(), .used); const rhs_uncasted = try transExpr(c, scope, stmt.getRHS(), .used);
const lhs = if (isBoolRes(lhs_uncasted)) const lhs = if (isBoolRes(lhs_uncasted))
try Tag.bool_to_int.create(c.arena, lhs_uncasted) try Tag.int_from_bool.create(c.arena, lhs_uncasted)
else if (isPointerDiffExpr) else if (isPointerDiffExpr)
try Tag.ptr_to_int.create(c.arena, lhs_uncasted) try Tag.int_from_ptr.create(c.arena, lhs_uncasted)
else else
lhs_uncasted; lhs_uncasted;
const rhs = if (isBoolRes(rhs_uncasted)) const rhs = if (isBoolRes(rhs_uncasted))
try Tag.bool_to_int.create(c.arena, rhs_uncasted) try Tag.int_from_bool.create(c.arena, rhs_uncasted)
else if (isPointerDiffExpr) else if (isPointerDiffExpr)
try Tag.ptr_to_int.create(c.arena, rhs_uncasted) try Tag.int_from_ptr.create(c.arena, rhs_uncasted)
else else
rhs_uncasted; rhs_uncasted;
@ -1944,7 +1944,7 @@ fn transDeclStmtOne(
else else
Tag.undefined_literal.init(); Tag.undefined_literal.init();
if (!qualTypeIsBoolean(qual_type) and isBoolRes(init_node)) { if (!qualTypeIsBoolean(qual_type) and isBoolRes(init_node)) {
init_node = try Tag.bool_to_int.create(c.arena, init_node); init_node = try Tag.int_from_bool.create(c.arena, init_node);
} else if (init_node.tag() == .string_literal and qualTypeIsCharStar(qual_type)) { } else if (init_node.tag() == .string_literal and qualTypeIsCharStar(qual_type)) {
const dst_type_node = try transQualType(c, scope, qual_type, loc); const dst_type_node = try transQualType(c, scope, qual_type, loc);
init_node = try removeCVQualifiers(c, dst_type_node, init_node); init_node = try removeCVQualifiers(c, dst_type_node, init_node);
@ -2074,11 +2074,11 @@ fn transImplicitCastExpr(
return Tag.null_literal.init(); return Tag.null_literal.init();
}, },
.PointerToBoolean => { .PointerToBoolean => {
// @ptrToInt(val) != 0 // @intFromPtr(val) != 0
const ptr_node = try transExpr(c, scope, sub_expr, .used); const ptr_node = try transExpr(c, scope, sub_expr, .used);
const ptr_to_int = try Tag.ptr_to_int.create(c.arena, ptr_node); const int_from_ptr = try Tag.int_from_ptr.create(c.arena, ptr_node);
const ne = try Tag.not_equal.create(c.arena, .{ .lhs = ptr_to_int, .rhs = Tag.zero_literal.init() }); const ne = try Tag.not_equal.create(c.arena, .{ .lhs = int_from_ptr, .rhs = Tag.zero_literal.init() });
return maybeSuppressResult(c, result_used, ne); return maybeSuppressResult(c, result_used, ne);
}, },
.IntegralToBoolean, .FloatingToBoolean => { .IntegralToBoolean, .FloatingToBoolean => {
@ -2334,7 +2334,7 @@ fn transReturnStmt(
var rhs = try transExprCoercing(c, scope, val_expr, .used); var rhs = try transExprCoercing(c, scope, val_expr, .used);
const return_qt = scope.findBlockReturnType(); const return_qt = scope.findBlockReturnType();
if (isBoolRes(rhs) and !qualTypeIsBoolean(return_qt)) { if (isBoolRes(rhs) and !qualTypeIsBoolean(return_qt)) {
rhs = try Tag.bool_to_int.create(c.arena, rhs); rhs = try Tag.int_from_bool.create(c.arena, rhs);
} }
return Tag.@"return".create(c.arena, rhs); return Tag.@"return".create(c.arena, rhs);
} }
@ -2493,7 +2493,7 @@ fn transCCast(
var src_int_expr = expr; var src_int_expr = expr;
if (isBoolRes(src_int_expr)) { if (isBoolRes(src_int_expr)) {
src_int_expr = try Tag.bool_to_int.create(c.arena, src_int_expr); src_int_expr = try Tag.int_from_bool.create(c.arena, src_int_expr);
return Tag.as.create(c.arena, .{ .lhs = dst_node, .rhs = src_int_expr }); return Tag.as.create(c.arena, .{ .lhs = dst_node, .rhs = src_int_expr });
} }
@ -2521,34 +2521,34 @@ fn transCCast(
return Tag.bit_cast.create(c.arena, .{ .lhs = dst_node, .rhs = expr }); return Tag.bit_cast.create(c.arena, .{ .lhs = dst_node, .rhs = expr });
} }
if (cIsInteger(dst_type) and qualTypeIsPtr(src_type)) { if (cIsInteger(dst_type) and qualTypeIsPtr(src_type)) {
// @intCast(dest_type, @ptrToInt(val)) // @intCast(dest_type, @intFromPtr(val))
const ptr_to_int = try Tag.ptr_to_int.create(c.arena, expr); const int_from_ptr = try Tag.int_from_ptr.create(c.arena, expr);
return Tag.int_cast.create(c.arena, .{ .lhs = dst_node, .rhs = ptr_to_int }); return Tag.int_cast.create(c.arena, .{ .lhs = dst_node, .rhs = int_from_ptr });
} }
if (cIsInteger(src_type) and qualTypeIsPtr(dst_type)) { if (cIsInteger(src_type) and qualTypeIsPtr(dst_type)) {
// @intToPtr(dest_type, val) // @ptrFromInt(dest_type, val)
return Tag.int_to_ptr.create(c.arena, .{ .lhs = dst_node, .rhs = expr }); return Tag.ptr_from_int.create(c.arena, .{ .lhs = dst_node, .rhs = expr });
} }
if (cIsFloating(src_type) and cIsFloating(dst_type)) { if (cIsFloating(src_type) and cIsFloating(dst_type)) {
// @floatCast(dest_type, val) // @floatCast(dest_type, val)
return Tag.float_cast.create(c.arena, .{ .lhs = dst_node, .rhs = expr }); return Tag.float_cast.create(c.arena, .{ .lhs = dst_node, .rhs = expr });
} }
if (cIsFloating(src_type) and !cIsFloating(dst_type)) { if (cIsFloating(src_type) and !cIsFloating(dst_type)) {
// @floatToInt(dest_type, val) // @intFromFloat(dest_type, val)
return Tag.float_to_int.create(c.arena, .{ .lhs = dst_node, .rhs = expr }); return Tag.int_from_float.create(c.arena, .{ .lhs = dst_node, .rhs = expr });
} }
if (!cIsFloating(src_type) and cIsFloating(dst_type)) { if (!cIsFloating(src_type) and cIsFloating(dst_type)) {
var rhs = expr; var rhs = expr;
if (qualTypeIsBoolean(src_type)) rhs = try Tag.bool_to_int.create(c.arena, expr); if (qualTypeIsBoolean(src_type)) rhs = try Tag.int_from_bool.create(c.arena, expr);
// @intToFloat(dest_type, val) // @floatFromInt(dest_type, val)
return Tag.int_to_float.create(c.arena, .{ .lhs = dst_node, .rhs = rhs }); return Tag.float_from_int.create(c.arena, .{ .lhs = dst_node, .rhs = rhs });
} }
if (qualTypeIsBoolean(src_type) and !qualTypeIsBoolean(dst_type)) { if (qualTypeIsBoolean(src_type) and !qualTypeIsBoolean(dst_type)) {
// @boolToInt returns either a comptime_int or a u1 // @intFromBool returns a u1
// TODO: if dst_type is 1 bit & signed (bitfield) we need @bitCast // TODO: if dst_type is 1 bit & signed (bitfield) we need @bitCast
// instead of @as // instead of @as
const bool_to_int = try Tag.bool_to_int.create(c.arena, expr); const int_from_bool = try Tag.int_from_bool.create(c.arena, expr);
return Tag.as.create(c.arena, .{ .lhs = dst_node, .rhs = bool_to_int }); return Tag.as.create(c.arena, .{ .lhs = dst_node, .rhs = int_from_bool });
} }
// @as(dest_type, val) // @as(dest_type, val)
return Tag.as.create(c.arena, .{ .lhs = dst_node, .rhs = expr }); return Tag.as.create(c.arena, .{ .lhs = dst_node, .rhs = expr });
@ -3642,7 +3642,7 @@ fn transCallExpr(c: *Context, scope: *Scope, stmt: *const clang.CallExpr, result
if (i < param_count) { if (i < param_count) {
const param_qt = fn_proto.getParamType(@intCast(c_uint, i)); const param_qt = fn_proto.getParamType(@intCast(c_uint, i));
if (isBoolRes(arg) and cIsNativeInt(param_qt)) { if (isBoolRes(arg) and cIsNativeInt(param_qt)) {
arg = try Tag.bool_to_int.create(c.arena, arg); arg = try Tag.int_from_bool.create(c.arena, arg);
} else if (arg.tag() == .string_literal and qualTypeIsCharStar(param_qt)) { } else if (arg.tag() == .string_literal and qualTypeIsCharStar(param_qt)) {
const loc = @ptrCast(*const clang.Stmt, stmt).getBeginLoc(); const loc = @ptrCast(*const clang.Stmt, stmt).getBeginLoc();
const dst_type_node = try transQualType(c, scope, param_qt, loc); const dst_type_node = try transQualType(c, scope, param_qt, loc);
@ -3774,7 +3774,7 @@ fn transUnaryOperator(c: *Context, scope: *Scope, stmt: *const clang.UnaryOperat
const sub_expr_node = try transExpr(c, scope, op_expr, .used); const sub_expr_node = try transExpr(c, scope, op_expr, .used);
const to_negate = if (isBoolRes(sub_expr_node)) blk: { const to_negate = if (isBoolRes(sub_expr_node)) blk: {
const ty_node = try Tag.type.create(c.arena, "c_int"); const ty_node = try Tag.type.create(c.arena, "c_int");
const int_node = try Tag.bool_to_int.create(c.arena, sub_expr_node); const int_node = try Tag.int_from_bool.create(c.arena, sub_expr_node);
break :blk try Tag.as.create(c.arena, .{ .lhs = ty_node, .rhs = int_node }); break :blk try Tag.as.create(c.arena, .{ .lhs = ty_node, .rhs = int_node });
} else sub_expr_node; } else sub_expr_node;
return Tag.negate.create(c.arena, to_negate); return Tag.negate.create(c.arena, to_negate);
@ -4028,8 +4028,8 @@ fn transCreateCompoundAssign(
// Casting away const or volatile requires us to use @intToPtr // Casting away const or volatile requires us to use @intToPtr
fn removeCVQualifiers(c: *Context, dst_type_node: Node, expr: Node) Error!Node { fn removeCVQualifiers(c: *Context, dst_type_node: Node, expr: Node) Error!Node {
const ptr_to_int = try Tag.ptr_to_int.create(c.arena, expr); const int_from_ptr = try Tag.int_from_ptr.create(c.arena, expr);
return Tag.int_to_ptr.create(c.arena, .{ .lhs = dst_type_node, .rhs = ptr_to_int }); return Tag.ptr_from_int.create(c.arena, .{ .lhs = dst_type_node, .rhs = int_from_ptr });
} }
fn transCPtrCast( fn transCPtrCast(
@ -4132,12 +4132,12 @@ fn transBinaryConditionalOperator(c: *Context, scope: *Scope, stmt: *const clang
const cond_node = try finishBoolExpr(c, &cond_scope.base, cond_expr.getBeginLoc(), ty, cond_ident, .used); const cond_node = try finishBoolExpr(c, &cond_scope.base, cond_expr.getBeginLoc(), ty, cond_ident, .used);
var then_body = cond_ident; var then_body = cond_ident;
if (!res_is_bool and isBoolRes(init_node)) { if (!res_is_bool and isBoolRes(init_node)) {
then_body = try Tag.bool_to_int.create(c.arena, then_body); then_body = try Tag.int_from_bool.create(c.arena, then_body);
} }
var else_body = try transExpr(c, &block_scope.base, false_expr, .used); var else_body = try transExpr(c, &block_scope.base, false_expr, .used);
if (!res_is_bool and isBoolRes(else_body)) { if (!res_is_bool and isBoolRes(else_body)) {
else_body = try Tag.bool_to_int.create(c.arena, else_body); else_body = try Tag.int_from_bool.create(c.arena, else_body);
} }
const if_node = try Tag.@"if".create(c.arena, .{ const if_node = try Tag.@"if".create(c.arena, .{
.cond = cond_node, .cond = cond_node,
@ -4173,12 +4173,12 @@ fn transConditionalOperator(c: *Context, scope: *Scope, stmt: *const clang.Condi
var then_body = try transExpr(c, scope, true_expr, used); var then_body = try transExpr(c, scope, true_expr, used);
if (!res_is_bool and isBoolRes(then_body)) { if (!res_is_bool and isBoolRes(then_body)) {
then_body = try Tag.bool_to_int.create(c.arena, then_body); then_body = try Tag.int_from_bool.create(c.arena, then_body);
} }
var else_body = try transExpr(c, scope, false_expr, used); var else_body = try transExpr(c, scope, false_expr, used);
if (!res_is_bool and isBoolRes(else_body)) { if (!res_is_bool and isBoolRes(else_body)) {
else_body = try Tag.bool_to_int.create(c.arena, else_body); else_body = try Tag.int_from_bool.create(c.arena, else_body);
} }
const if_node = try Tag.@"if".create(c.arena, .{ const if_node = try Tag.@"if".create(c.arena, .{
@ -4556,7 +4556,7 @@ fn transCreateNodeAssign(
const lhs_node = try transExpr(c, scope, lhs, .used); const lhs_node = try transExpr(c, scope, lhs, .used);
var rhs_node = try transExprCoercing(c, scope, rhs, .used); var rhs_node = try transExprCoercing(c, scope, rhs, .used);
if (!exprIsBooleanType(lhs) and isBoolRes(rhs_node)) { if (!exprIsBooleanType(lhs) and isBoolRes(rhs_node)) {
rhs_node = try Tag.bool_to_int.create(c.arena, rhs_node); rhs_node = try Tag.int_from_bool.create(c.arena, rhs_node);
} }
return transCreateNodeInfixOp(c, .assign, lhs_node, rhs_node, .used); return transCreateNodeInfixOp(c, .assign, lhs_node, rhs_node, .used);
} }
@ -4574,7 +4574,7 @@ fn transCreateNodeAssign(
const tmp = try block_scope.reserveMangledName(c, "tmp"); const tmp = try block_scope.reserveMangledName(c, "tmp");
var rhs_node = try transExpr(c, &block_scope.base, rhs, .used); var rhs_node = try transExpr(c, &block_scope.base, rhs, .used);
if (!exprIsBooleanType(lhs) and isBoolRes(rhs_node)) { if (!exprIsBooleanType(lhs) and isBoolRes(rhs_node)) {
rhs_node = try Tag.bool_to_int.create(c.arena, rhs_node); rhs_node = try Tag.int_from_bool.create(c.arena, rhs_node);
} }
const tmp_decl = try Tag.var_simple.create(c.arena, .{ .name = tmp, .init = rhs_node }); const tmp_decl = try Tag.var_simple.create(c.arena, .{ .name = tmp, .init = rhs_node });
@ -6092,7 +6092,7 @@ fn macroBoolToInt(c: *Context, node: Node) !Node {
return node; return node;
} }
return Tag.bool_to_int.create(c.arena, node); return Tag.int_from_bool.create(c.arena, node);
} }
fn macroIntToBool(c: *Context, node: Node) !Node { fn macroIntToBool(c: *Context, node: Node) !Node {

View file

@ -128,8 +128,8 @@ pub const Node = extern union {
signed_remainder, signed_remainder,
/// @divTrunc(lhs, rhs) /// @divTrunc(lhs, rhs)
div_trunc, div_trunc,
/// @boolToInt(operand) /// @intFromBool(operand)
bool_to_int, int_from_bool,
/// @as(lhs, rhs) /// @as(lhs, rhs)
as, as,
/// @truncate(lhs, rhs) /// @truncate(lhs, rhs)
@ -138,14 +138,14 @@ pub const Node = extern union {
bit_cast, bit_cast,
/// @floatCast(lhs, rhs) /// @floatCast(lhs, rhs)
float_cast, float_cast,
/// @floatToInt(lhs, rhs) /// @intFromFloat(lhs, rhs)
float_to_int, int_from_float,
/// @intToFloat(lhs, rhs) /// @floatFromInt(lhs, rhs)
int_to_float, float_from_int,
/// @intToPtr(lhs, rhs) /// @ptrFromInt(lhs, rhs)
int_to_ptr, ptr_from_int,
/// @ptrToInt(operand) /// @intFromPtr(operand)
ptr_to_int, int_from_ptr,
/// @alignCast(lhs, rhs) /// @alignCast(lhs, rhs)
align_cast, align_cast,
/// @ptrCast(lhs, rhs) /// @ptrCast(lhs, rhs)
@ -263,7 +263,7 @@ pub const Node = extern union {
.address_of, .address_of,
.unwrap, .unwrap,
.deref, .deref,
.ptr_to_int, .int_from_ptr,
.empty_array, .empty_array,
.while_true, .while_true,
.if_not_break, .if_not_break,
@ -271,7 +271,7 @@ pub const Node = extern union {
.block_single, .block_single,
.helpers_sizeof, .helpers_sizeof,
.std_meta_alignment, .std_meta_alignment,
.bool_to_int, .int_from_bool,
.sizeof, .sizeof,
.alignof, .alignof,
.typeof, .typeof,
@ -319,9 +319,9 @@ pub const Node = extern union {
.truncate, .truncate,
.bit_cast, .bit_cast,
.float_cast, .float_cast,
.float_to_int, .int_from_float,
.int_to_float, .float_from_int,
.int_to_ptr, .ptr_from_int,
.array_cat, .array_cat,
.ellipsis3, .ellipsis3,
.assign, .assign,
@ -1355,9 +1355,9 @@ fn renderNode(c: *Context, node: Node) Allocator.Error!NodeIndex {
const payload = node.castTag(.div_trunc).?.data; const payload = node.castTag(.div_trunc).?.data;
return renderBuiltinCall(c, "@divTrunc", &.{ payload.lhs, payload.rhs }); return renderBuiltinCall(c, "@divTrunc", &.{ payload.lhs, payload.rhs });
}, },
.bool_to_int => { .int_from_bool => {
const payload = node.castTag(.bool_to_int).?.data; const payload = node.castTag(.int_from_bool).?.data;
return renderBuiltinCall(c, "@boolToInt", &.{payload}); return renderBuiltinCall(c, "@intFromBool", &.{payload});
}, },
.as => { .as => {
const payload = node.castTag(.as).?.data; const payload = node.castTag(.as).?.data;
@ -1375,21 +1375,21 @@ fn renderNode(c: *Context, node: Node) Allocator.Error!NodeIndex {
const payload = node.castTag(.float_cast).?.data; const payload = node.castTag(.float_cast).?.data;
return renderBuiltinCall(c, "@floatCast", &.{ payload.lhs, payload.rhs }); return renderBuiltinCall(c, "@floatCast", &.{ payload.lhs, payload.rhs });
}, },
.float_to_int => { .int_from_float => {
const payload = node.castTag(.float_to_int).?.data; const payload = node.castTag(.int_from_float).?.data;
return renderBuiltinCall(c, "@floatToInt", &.{ payload.lhs, payload.rhs }); return renderBuiltinCall(c, "@intFromFloat", &.{ payload.lhs, payload.rhs });
}, },
.int_to_float => { .float_from_int => {
const payload = node.castTag(.int_to_float).?.data; const payload = node.castTag(.float_from_int).?.data;
return renderBuiltinCall(c, "@intToFloat", &.{ payload.lhs, payload.rhs }); return renderBuiltinCall(c, "@floatFromInt", &.{ payload.lhs, payload.rhs });
}, },
.int_to_ptr => { .ptr_from_int => {
const payload = node.castTag(.int_to_ptr).?.data; const payload = node.castTag(.ptr_from_int).?.data;
return renderBuiltinCall(c, "@intToPtr", &.{ payload.lhs, payload.rhs }); return renderBuiltinCall(c, "@ptrFromInt", &.{ payload.lhs, payload.rhs });
}, },
.ptr_to_int => { .int_from_ptr => {
const payload = node.castTag(.ptr_to_int).?.data; const payload = node.castTag(.int_from_ptr).?.data;
return renderBuiltinCall(c, "@ptrToInt", &.{payload}); return renderBuiltinCall(c, "@intFromPtr", &.{payload});
}, },
.align_cast => { .align_cast => {
const payload = node.castTag(.align_cast).?.data; const payload = node.castTag(.align_cast).?.data;
@ -2326,13 +2326,13 @@ fn renderNodeGrouped(c: *Context, node: Node) !NodeIndex {
.truncate, .truncate,
.bit_cast, .bit_cast,
.float_cast, .float_cast,
.float_to_int, .int_from_float,
.int_to_float, .float_from_int,
.int_to_ptr, .ptr_from_int,
.std_mem_zeroes, .std_mem_zeroes,
.std_math_Log2Int, .std_math_Log2Int,
.log2_int_type, .log2_int_type,
.ptr_to_int, .int_from_ptr,
.sizeof, .sizeof,
.alignof, .alignof,
.typeof, .typeof,
@ -2371,7 +2371,7 @@ fn renderNodeGrouped(c: *Context, node: Node) !NodeIndex {
.call, .call,
.array_type, .array_type,
.null_sentinel_array_type, .null_sentinel_array_type,
.bool_to_int, .int_from_bool,
.div_exact, .div_exact,
.offset_of, .offset_of,
.shuffle, .shuffle,