diff --git a/lib/std/zig/render.zig b/lib/std/zig/render.zig index 3930c9714a78..70c9d7209c27 100644 --- a/lib/std/zig/render.zig +++ b/lib/std/zig/render.zig @@ -1396,6 +1396,26 @@ fn renderBuiltinCall( try ais.writer().writeAll("@max"); } else if (mem.eql(u8, slice, "@minimum")) { 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 { try renderToken(ais, tree, builtin_token, .none); // @name } diff --git a/src/Air.zig b/src/Air.zig index b179a3c024ec..91e8d0da4df2 100644 --- a/src/Air.zig +++ b/src/Air.zig @@ -478,11 +478,11 @@ pub const Inst = struct { /// Converts a pointer to its address. Result type is always `usize`. /// Pointer type size may be any, including slice. /// Uses the `un_op` field. - ptrtoint, + int_from_ptr, /// Given a boolean, returns 0 or 1. /// Result type is always `u1`. /// Uses the `un_op` field. - bool_to_int, + int_from_bool, /// Return a value from a function. /// Result type is always noreturn; no instructions in a block follow this one. /// Uses the `un_op` field. @@ -629,12 +629,12 @@ pub const Inst = struct { array_to_slice, /// Given a float operand, return the integer with the closest mathematical meaning. /// Uses the `ty_op` field. - float_to_int, - /// Same as `float_to_int` with optimized float mode. - float_to_int_optimized, + int_from_float, + /// Same as `int_from_float` with optimized float mode. + int_from_float_optimized, /// Given an integer operand, return the float with the closest mathematical meaning. /// Uses the `ty_op` field. - int_to_float, + float_from_int, /// Transforms a vector into a scalar value by performing a sequential /// 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_3, .array_to_slice, - .float_to_int, - .float_to_int_optimized, - .int_to_float, + .int_from_float, + .int_from_float_optimized, + .float_from_int, .splat, .get_union_tag, .clz, @@ -1387,7 +1387,7 @@ pub fn typeOfIndex(air: Air, inst: Air.Inst.Index, ip: *const InternPool) Type { .c_va_end, => return Type.void, - .ptrtoint, + .int_from_ptr, .slice_len, .ret_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_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, @@ -1687,8 +1687,8 @@ pub fn mustLower(air: Air, inst: Air.Inst.Index, ip: *const InternPool) bool { .is_non_err_ptr, .bool_and, .bool_or, - .ptrtoint, - .bool_to_int, + .int_from_ptr, + .int_from_bool, .fptrunc, .fpext, .intcast, @@ -1718,9 +1718,9 @@ pub fn mustLower(air: Air, inst: Air.Inst.Index, ip: *const InternPool) bool { .slice_elem_ptr, .ptr_elem_ptr, .array_to_slice, - .float_to_int, - .float_to_int_optimized, - .int_to_float, + .int_from_float, + .int_from_float_optimized, + .float_from_int, .reduce, .reduce_optimized, .splat, diff --git a/src/AstGen.zig b/src/AstGen.zig index 86bd0fd4f4f2..05087042698c 100644 --- a/src/AstGen.zig +++ b/src/AstGen.zig @@ -2626,15 +2626,15 @@ fn addEnsureResult(gz: *GenZir, maybe_unused_result: Zir.Inst.Ref, statement: As .error_set_decl, .error_set_decl_anon, .error_set_decl_func, - .int_to_enum, - .enum_to_int, + .enum_from_int, + .int_from_enum, .type_info, .size_of, .bit_size_of, .typeof_log2_int_type, - .ptr_to_int, + .int_from_ptr, .align_of, - .bool_to_int, + .int_from_bool, .embed_file, .error_name, .sqrt, @@ -2655,9 +2655,9 @@ fn addEnsureResult(gz: *GenZir, maybe_unused_result: Zir.Inst.Ref, statement: As .type_name, .frame_type, .frame_size, - .float_to_int, - .int_to_float, - .int_to_ptr, + .int_from_float, + .float_from_int, + .ptr_from_int, .float_cast, .int_cast, .ptr_cast, @@ -8281,11 +8281,11 @@ fn builtinCall( .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), - .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), .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), - .bool_to_int => return simpleUnOp(gz, scope, ri, node, bool_ri, params[0], .bool_to_int), + .int_from_enum => return simpleUnOp(gz, scope, ri, node, .{ .rl = .none }, params[0], .int_from_enum), + .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), .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), @@ -8308,10 +8308,10 @@ fn builtinCall( .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), - .float_to_int => return typeCast(gz, scope, ri, node, params[0], params[1], .float_to_int), - .int_to_float => return typeCast(gz, scope, ri, node, params[0], params[1], .int_to_float), - .int_to_ptr => return typeCast(gz, scope, ri, node, params[0], params[1], .int_to_ptr), - .int_to_enum => return typeCast(gz, scope, ri, node, params[0], params[1], .int_to_enum), + .int_from_float => return typeCast(gz, scope, ri, node, params[0], params[1], .int_from_float), + .float_from_int => return typeCast(gz, scope, ri, node, params[0], params[1], .float_from_int), + .ptr_from_int => return typeCast(gz, scope, ri, node, params[0], params[1], .ptr_from_int), + .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), .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), @@ -8352,17 +8352,17 @@ fn builtinCall( _ = try gz.addNode(.trap, 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 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), .operand = operand, }); 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 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), .operand = operand, }); @@ -8769,7 +8769,7 @@ fn simpleUnOp( else try expr(gz, scope, operand_ri, operand_node); 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 => {}, } const result = try gz.addUnNode(tag, operand, node); diff --git a/src/Autodoc.zig b/src/Autodoc.zig index ce4665f1ea6b..e3580483fb40 100644 --- a/src/Autodoc.zig +++ b/src/Autodoc.zig @@ -1473,7 +1473,7 @@ fn walkInstruction( // builtin functions .align_of, - .bool_to_int, + .int_from_bool, .embed_file, .error_name, .panic, @@ -1496,7 +1496,7 @@ fn walkInstruction( .type_name, .frame_type, .frame_size, - .ptr_to_int, + .int_from_ptr, .bit_not, // @check .clz, @@ -1521,10 +1521,10 @@ fn walkInstruction( }; }, - .float_to_int, - .int_to_float, - .int_to_ptr, - .int_to_enum, + .int_from_float, + .float_from_int, + .ptr_from_int, + .enum_from_int, .float_cast, .int_cast, .ptr_cast, @@ -1936,7 +1936,7 @@ fn walkInstruction( .expr = .{ .bitSizeOf = operand_index }, }; }, - .enum_to_int => { + .int_from_enum => { // not working correctly with `align()` const un_node = data[inst_index].un_node; const operand = try self.walkRef( @@ -3021,8 +3021,8 @@ fn walkInstruction( }, }; }, - .error_to_int, - .int_to_error, + .int_from_error, + .error_from_int, .reify, .const_cast, .volatile_cast, diff --git a/src/BuiltinFn.zig b/src/BuiltinFn.zig index 426939afdf10..27b963f52871 100644 --- a/src/BuiltinFn.zig +++ b/src/BuiltinFn.zig @@ -12,7 +12,7 @@ pub const Tag = enum { atomic_store, bit_cast, bit_offset_of, - bool_to_int, + int_from_bool, bit_size_of, breakpoint, mul_add, @@ -39,10 +39,10 @@ pub const Tag = enum { div_floor, div_trunc, embed_file, - enum_to_int, + int_from_enum, error_name, error_return_trace, - error_to_int, + int_from_error, err_set_cast, @"export", @"extern", @@ -50,7 +50,7 @@ pub const Tag = enum { field, field_parent_ptr, float_cast, - float_to_int, + int_from_float, frame, Frame, frame_address, @@ -60,10 +60,10 @@ pub const Tag = enum { import, in_comptime, int_cast, - int_to_enum, - int_to_error, - int_to_float, - int_to_ptr, + enum_from_int, + error_from_int, + float_from_int, + ptr_from_int, max, memcpy, memset, @@ -76,7 +76,7 @@ pub const Tag = enum { pop_count, prefetch, ptr_cast, - ptr_to_int, + int_from_ptr, rem, return_address, select, @@ -238,9 +238,9 @@ pub const list = list: { }, }, .{ - "@boolToInt", + "@intFromBool", .{ - .tag = .bool_to_int, + .tag = .int_from_bool, .param_count = 1, }, }, @@ -425,9 +425,9 @@ pub const list = list: { }, }, .{ - "@enumToInt", + "@intFromEnum", .{ - .tag = .enum_to_int, + .tag = .int_from_enum, .param_count = 1, }, }, @@ -446,9 +446,9 @@ pub const list = list: { }, }, .{ - "@errorToInt", + "@intFromError", .{ - .tag = .error_to_int, + .tag = .int_from_error, .param_count = 1, }, }, @@ -506,9 +506,9 @@ pub const list = list: { }, }, .{ - "@floatToInt", + "@intFromFloat", .{ - .tag = .float_to_int, + .tag = .int_from_float, .param_count = 2, }, }, @@ -576,31 +576,31 @@ pub const list = list: { }, }, .{ - "@intToEnum", + "@enumFromInt", .{ - .tag = .int_to_enum, + .tag = .enum_from_int, .param_count = 2, }, }, .{ - "@intToError", + "@errorFromInt", .{ - .tag = .int_to_error, + .tag = .error_from_int, .eval_to_error = .always, .param_count = 1, }, }, .{ - "@intToFloat", + "@floatFromInt", .{ - .tag = .int_to_float, + .tag = .float_from_int, .param_count = 2, }, }, .{ - "@intToPtr", + "@ptrFromInt", .{ - .tag = .int_to_ptr, + .tag = .ptr_from_int, .param_count = 2, }, }, @@ -689,9 +689,9 @@ pub const list = list: { }, }, .{ - "@ptrToInt", + "@intFromPtr", .{ - .tag = .ptr_to_int, + .tag = .int_from_ptr, .param_count = 1, }, }, diff --git a/src/Liveness.zig b/src/Liveness.zig index b12b6382082e..ea922b1a8dc5 100644 --- a/src/Liveness.zig +++ b/src/Liveness.zig @@ -371,9 +371,9 @@ pub fn categorizeOperand( .struct_field_ptr_index_2, .struct_field_ptr_index_3, .array_to_slice, - .float_to_int, - .float_to_int_optimized, - .int_to_float, + .int_from_float, + .int_from_float_optimized, + .float_from_int, .get_union_tag, .clz, .ctz, @@ -407,8 +407,8 @@ pub fn categorizeOperand( .is_non_err, .is_err_ptr, .is_non_err_ptr, - .ptrtoint, - .bool_to_int, + .int_from_ptr, + .int_from_bool, .is_named_enum_value, .tag_name, .error_name, @@ -1007,9 +1007,9 @@ fn analyzeInst( .struct_field_ptr_index_2, .struct_field_ptr_index_3, .array_to_slice, - .float_to_int, - .float_to_int_optimized, - .int_to_float, + .int_from_float, + .int_from_float_optimized, + .float_from_int, .get_union_tag, .clz, .ctz, @@ -1034,8 +1034,8 @@ fn analyzeInst( .is_non_err, .is_err_ptr, .is_non_err_ptr, - .ptrtoint, - .bool_to_int, + .int_from_ptr, + .int_from_bool, .is_named_enum_value, .tag_name, .error_name, diff --git a/src/Liveness/Verify.zig b/src/Liveness/Verify.zig index a5fc59289422..904e38007353 100644 --- a/src/Liveness/Verify.zig +++ b/src/Liveness/Verify.zig @@ -97,9 +97,9 @@ fn verifyBody(self: *Verify, body: []const Air.Inst.Index) Error!void { .struct_field_ptr_index_2, .struct_field_ptr_index_3, .array_to_slice, - .float_to_int, - .float_to_int_optimized, - .int_to_float, + .int_from_float, + .int_from_float_optimized, + .float_from_int, .get_union_tag, .clz, .ctz, @@ -123,8 +123,8 @@ fn verifyBody(self: *Verify, body: []const Air.Inst.Index) Error!void { .is_non_err, .is_err_ptr, .is_non_err_ptr, - .ptrtoint, - .bool_to_int, + .int_from_ptr, + .int_from_bool, .is_named_enum_value, .tag_name, .error_name, diff --git a/src/Sema.zig b/src/Sema.zig index 36fe5a6ee8ec..c7115409e61c 100644 --- a/src/Sema.zig +++ b/src/Sema.zig @@ -961,8 +961,8 @@ fn analyzeBodyInner( .elem_val_node => try sema.zirElemValNode(block, inst), .elem_type_index => try sema.zirElemTypeIndex(block, inst), .enum_literal => try sema.zirEnumLiteral(block, inst), - .enum_to_int => try sema.zirEnumToInt(block, inst), - .int_to_enum => try sema.zirIntToEnum(block, inst), + .int_from_enum => try sema.zirIntFromEnum(block, inst), + .enum_from_int => try sema.zirEnumFromInt(block, inst), .err_union_code => try sema.zirErrUnionCode(block, inst), .err_union_code_ptr => try sema.zirErrUnionCodePtr(block, inst), .err_union_payload_unsafe => try sema.zirErrUnionPayload(block, inst), @@ -1028,18 +1028,18 @@ fn analyzeBodyInner( .union_init => try sema.zirUnionInit(block, inst), .field_type => try sema.zirFieldType(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), - .bool_to_int => try sema.zirBoolToInt(block, inst), + .int_from_bool => try sema.zirIntFromBool(block, inst), .embed_file => try sema.zirEmbedFile(block, inst), .error_name => try sema.zirErrorName(block, inst), .tag_name => try sema.zirTagName(block, inst), .type_name => try sema.zirTypeName(block, inst), .frame_type => try sema.zirFrameType(block, inst), .frame_size => try sema.zirFrameSize(block, inst), - .float_to_int => try sema.zirFloatToInt(block, inst), - .int_to_float => try sema.zirIntToFloat(block, inst), - .int_to_ptr => try sema.zirIntToPtr(block, inst), + .int_from_float => try sema.zirIntFromFloat(block, inst), + .float_from_int => try sema.zirFloatFromInt(block, inst), + .ptr_from_int => try sema.zirPtrFromInt(block, inst), .float_cast => try sema.zirFloatCast(block, inst), .int_cast => try sema.zirIntCast(block, inst), .ptr_cast => try sema.zirPtrCast(block, inst), @@ -1167,8 +1167,8 @@ fn analyzeBodyInner( .err_set_cast => try sema.zirErrSetCast( block, extended), .await_nosuspend => try sema.zirAwaitNosuspend( block, extended), .select => try sema.zirSelect( block, extended), - .error_to_int => try sema.zirErrorToInt( block, extended), - .int_to_error => try sema.zirIntToError( block, extended), + .int_from_error => try sema.zirIntFromError( block, extended), + .error_from_int => try sema.zirErrorFromInt( block, extended), .reify => try sema.zirReify( block, extended, inst), .builtin_async_call => try sema.zirBuiltinAsyncCall( block, extended), .cmpxchg => try sema.zirCmpxchg( block, extended), @@ -8116,7 +8116,7 @@ fn zirErrorValue(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! } })).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()); 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); } -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()); defer tracy.end(); @@ -8258,7 +8258,7 @@ fn zirEnumLiteral(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError })).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 inst_data = sema.code.instructions.items(.data)[inst].un_node; 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); } -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 inst_data = sema.code.instructions.items(.data)[inst].pl_node; 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()); 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); - 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 { @@ -19426,7 +19426,7 @@ fn zirAlignOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air 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 inst_data = sema.code.instructions.items(.data)[inst].un_node; 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)); 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 { @@ -20748,7 +20748,7 @@ fn zirFrameSize(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A 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 inst_data = sema.code.instructions.items(.data)[inst].pl_node; 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)); } - 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()) { - 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 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))); @@ -20788,7 +20788,7 @@ fn zirFloatToInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! 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 inst_data = sema.code.instructions.items(.data)[inst].pl_node; 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); - 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 inst_data = sema.code.instructions.items(.data)[inst].pl_node; 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 (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 ok = if (operand_is_slice) ok: { 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) else 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 is_aligned = try block.addBinOp(.cmp_eq, remainder, .zero_usize); const ok = if (ptr_ty.isSlice(mod)) ok: { @@ -29504,7 +29504,7 @@ fn coerceCompatiblePtrs( try sema.analyzeSlicePtr(block, inst_src, inst, inst_ty) else 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 ok = if (inst_ty.isSlice(mod)) ok: { const len = try sema.analyzeSliceLen(block, inst_src, inst); diff --git a/src/Zir.zig b/src/Zir.zig index 81b02bb469db..5b00dc22aa52 100644 --- a/src/Zir.zig +++ b/src/Zir.zig @@ -749,9 +749,9 @@ pub const Inst = struct { /// Implements the `@bitSizeOf` builtin. Uses `un_node`. bit_size_of, - /// Implement builtin `@ptrToInt`. Uses `un_node`. + /// Implement builtin `@intFromPtr`. Uses `un_node`. /// Convert a pointer to a `usize` integer. - ptr_to_int, + int_from_ptr, /// Emit an error message and fail compilation. /// Uses the `un_node` field. compile_error, @@ -761,11 +761,11 @@ pub const Inst = struct { set_eval_branch_quota, /// Converts an enum value into an integer. Resulting type will be the tag type /// of the enum. Uses `un_node`. - enum_to_int, + int_from_enum, /// Implement builtin `@alignOf`. Uses `un_node`. align_of, - /// Implement builtin `@boolToInt`. Uses `un_node`. - bool_to_int, + /// Implement builtin `@intFromBool`. Uses `un_node`. + int_from_bool, /// Implement builtin `@embedFile`. Uses `un_node`. embed_file, /// Implement builtin `@errorName`. Uses `un_node`. @@ -814,18 +814,18 @@ pub const Inst = struct { /// Implement builtin `@frameSize`. Uses `un_node`. frame_size, - /// Implements the `@floatToInt` builtin. + /// Implements the `@intFromFloat` builtin. /// Uses `pl_node` with payload `Bin`. `lhs` is dest type, `rhs` is operand. - float_to_int, - /// Implements the `@intToFloat` builtin. + int_from_float, + /// Implements the `@floatFromInt` builtin. /// Uses `pl_node` with payload `Bin`. `lhs` is dest type, `rhs` is operand. - int_to_float, - /// Implements the `@intToPtr` builtin. + float_from_int, + /// Implements the `@ptrFromInt` builtin. /// 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. /// 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 /// a loss of precision. /// Uses the `pl_node` field. AST is the `@floatCast` syntax. @@ -1136,14 +1136,14 @@ pub const Inst = struct { .union_init, .field_type, .field_type_ref, - .int_to_enum, - .enum_to_int, + .enum_from_int, + .int_from_enum, .type_info, .size_of, .bit_size_of, - .ptr_to_int, + .int_from_ptr, .align_of, - .bool_to_int, + .int_from_bool, .embed_file, .error_name, .set_runtime_safety, @@ -1165,9 +1165,9 @@ pub const Inst = struct { .type_name, .frame_type, .frame_size, - .float_to_int, - .int_to_float, - .int_to_ptr, + .int_from_float, + .float_from_int, + .ptr_from_int, .float_cast, .int_cast, .ptr_cast, @@ -1419,14 +1419,14 @@ pub const Inst = struct { .union_init, .field_type, .field_type_ref, - .int_to_enum, - .enum_to_int, + .enum_from_int, + .int_from_enum, .type_info, .size_of, .bit_size_of, - .ptr_to_int, + .int_from_ptr, .align_of, - .bool_to_int, + .int_from_bool, .embed_file, .error_name, .sqrt, @@ -1447,9 +1447,9 @@ pub const Inst = struct { .type_name, .frame_type, .frame_size, - .float_to_int, - .int_to_float, - .int_to_ptr, + .int_from_float, + .float_from_int, + .ptr_from_int, .float_cast, .int_cast, .ptr_cast, @@ -1679,12 +1679,12 @@ pub const Inst = struct { .size_of = .un_node, .bit_size_of = .un_node, - .ptr_to_int = .un_node, + .int_from_ptr = .un_node, .compile_error = .un_node, .set_eval_branch_quota = .un_node, - .enum_to_int = .un_node, + .int_from_enum = .un_node, .align_of = .un_node, - .bool_to_int = .un_node, + .int_from_bool = .un_node, .embed_file = .un_node, .error_name = .un_node, .panic = .un_node, @@ -1709,10 +1709,10 @@ pub const Inst = struct { .frame_type = .un_node, .frame_size = .un_node, - .float_to_int = .pl_node, - .int_to_float = .pl_node, - .int_to_ptr = .pl_node, - .int_to_enum = .pl_node, + .int_from_float = .pl_node, + .float_from_int = .pl_node, + .ptr_from_int = .pl_node, + .enum_from_int = .pl_node, .float_cast = .pl_node, .int_cast = .pl_node, .ptr_cast = .pl_node, @@ -1933,10 +1933,10 @@ pub const Inst = struct { select, /// Implement builtin `@errToInt`. /// `operand` is payload index to `UnNode`. - error_to_int, + int_from_error, /// Implement builtin `@intToError`. /// `operand` is payload index to `UnNode`. - int_to_error, + error_from_int, /// Implement builtin `@Type`. /// `operand` is payload index to `UnNode`. /// `small` contains `NameStrategy`. diff --git a/src/arch/aarch64/CodeGen.zig b/src/arch/aarch64/CodeGen.zig index 1355f96231c4..b93b9b212a8c 100644 --- a/src/arch/aarch64/CodeGen.zig +++ b/src/arch/aarch64/CodeGen.zig @@ -752,7 +752,7 @@ fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void { .fpext => try self.airFpext(inst), .intcast => try self.airIntCast(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_ptr => try self.airIsNonNullPtr(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), .loop => try self.airLoop(inst), .not => try self.airNot(inst), - .ptrtoint => try self.airPtrToInt(inst), + .int_from_ptr => try self.airIntFromPtr(inst), .ret => try self.airRet(inst), .ret_load => try self.airRetLoad(inst), .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_val=> try self.airStructFieldVal(inst), .array_to_slice => try self.airArrayToSlice(inst), - .int_to_float => try self.airIntToFloat(inst), - .float_to_int => try self.airFloatToInt(inst), + .float_from_int => try self.airFloatFromInt(inst), + .int_from_float => try self.airIntFromFloat(inst), .cmpxchg_strong => try self.airCmpxchg(inst), .cmpxchg_weak => try self.airCmpxchg(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_vector_optimized, .reduce_optimized, - .float_to_int_optimized, + .int_from_float_optimized, => return self.fail("TODO implement optimized float mode", .{}), .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 }); } -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 operand = try self.resolveInst(un_op); 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 result = try self.resolveInst(un_op); 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 }); } -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 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, }); 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 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, }); return self.finishAir(inst, result, .{ ty_op.operand, .none, .none }); diff --git a/src/arch/arm/CodeGen.zig b/src/arch/arm/CodeGen.zig index a2a5a3d4d3bd..2ad9a8775cb3 100644 --- a/src/arch/arm/CodeGen.zig +++ b/src/arch/arm/CodeGen.zig @@ -736,7 +736,7 @@ fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void { .fpext => try self.airFpext(inst), .intcast => try self.airIntCast(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_ptr => try self.airIsNonNullPtr(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), .loop => try self.airLoop(inst), .not => try self.airNot(inst), - .ptrtoint => try self.airPtrToInt(inst), + .int_from_ptr => try self.airIntFromPtr(inst), .ret => try self.airRet(inst), .ret_load => try self.airRetLoad(inst), .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_val=> try self.airStructFieldVal(inst), .array_to_slice => try self.airArrayToSlice(inst), - .int_to_float => try self.airIntToFloat(inst), - .float_to_int => try self.airFloatToInt(inst), + .float_from_int => try self.airFloatFromInt(inst), + .int_from_float => try self.airIntFromFloat(inst), .cmpxchg_strong => try self.airCmpxchg(inst), .cmpxchg_weak => try self.airCmpxchg(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_vector_optimized, .reduce_optimized, - .float_to_int_optimized, + .int_from_float_optimized, => return self.fail("TODO implement optimized float mode", .{}), .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 }); } -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 operand = try self.resolveInst(un_op); 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 result = try self.resolveInst(un_op); 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 }); } -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 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, }); 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 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, }); return self.finishAir(inst, result, .{ ty_op.operand, .none, .none }); diff --git a/src/arch/riscv64/CodeGen.zig b/src/arch/riscv64/CodeGen.zig index c6ac3255c608..57383b3043b5 100644 --- a/src/arch/riscv64/CodeGen.zig +++ b/src/arch/riscv64/CodeGen.zig @@ -566,7 +566,7 @@ fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void { .fpext => try self.airFpext(inst), .intcast => try self.airIntCast(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_ptr => try self.airIsNonNullPtr(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), .loop => try self.airLoop(inst), .not => try self.airNot(inst), - .ptrtoint => try self.airPtrToInt(inst), + .int_from_ptr => try self.airIntFromPtr(inst), .ret => try self.airRet(inst), .ret_load => try self.airRetLoad(inst), .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_val=> try self.airStructFieldVal(inst), .array_to_slice => try self.airArrayToSlice(inst), - .int_to_float => try self.airIntToFloat(inst), - .float_to_int => try self.airFloatToInt(inst), + .float_from_int => try self.airFloatFromInt(inst), + .int_from_float => try self.airIntFromFloat(inst), .cmpxchg_strong => try self.airCmpxchg(inst), .cmpxchg_weak => try self.airCmpxchg(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_vector_optimized, .reduce_optimized, - .float_to_int_optimized, + .int_from_float_optimized, => return self.fail("TODO implement optimized float mode", .{}), .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 }); } -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 operand = try self.resolveInst(un_op); 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 result = try self.resolveInst(un_op); 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 }); } -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 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, }); 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 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, }); return self.finishAir(inst, result, .{ ty_op.operand, .none, .none }); diff --git a/src/arch/sparc64/CodeGen.zig b/src/arch/sparc64/CodeGen.zig index e339794fd480..97bb2f8ab175 100644 --- a/src/arch/sparc64/CodeGen.zig +++ b/src/arch/sparc64/CodeGen.zig @@ -583,7 +583,7 @@ fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void { .fpext => @panic("TODO try self.airFpext(inst)"), .intcast => try self.airIntCast(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_ptr => @panic("TODO try self.airIsNonNullPtr(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), .loop => try self.airLoop(inst), .not => try self.airNot(inst), - .ptrtoint => try self.airPtrToInt(inst), + .int_from_ptr => try self.airIntFromPtr(inst), .ret => try self.airRet(inst), .ret_load => try self.airRetLoad(inst), .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_val=> try self.airStructFieldVal(inst), .array_to_slice => try self.airArrayToSlice(inst), - .int_to_float => try self.airIntToFloat(inst), - .float_to_int => try self.airFloatToInt(inst), + .float_from_int => try self.airFloatFromInt(inst), + .int_from_float => try self.airIntFromFloat(inst), .cmpxchg_strong, .cmpxchg_weak, => try self.airCmpxchg(inst), @@ -717,7 +717,7 @@ fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void { .cmp_neq_optimized, .cmp_vector_optimized, .reduce_optimized, - .float_to_int_optimized, + .int_from_float_optimized, => @panic("TODO implement optimized float mode"), .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 }); } -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 operand = try self.resolveInst(un_op); 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 }); } -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 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, }); 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}); } -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 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, }); 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 }); } -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 result = try self.resolveInst(un_op); return self.finishAir(inst, result, .{ un_op, .none, .none }); diff --git a/src/arch/wasm/CodeGen.zig b/src/arch/wasm/CodeGen.zig index 495ca7f6dd2a..4c92b093ae4e 100644 --- a/src/arch/wasm/CodeGen.zig +++ b/src/arch/wasm/CodeGen.zig @@ -1902,13 +1902,13 @@ fn genInst(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { .trap => func.airTrap(inst), .breakpoint => func.airBreakpoint(inst), .br => func.airBr(inst), - .bool_to_int => func.airBoolToInt(inst), + .int_from_bool => func.airIntFromBool(inst), .cond_br => func.airCondBr(inst), .intcast => func.airIntcast(inst), .fptrunc => func.airFptrunc(inst), .fpext => func.airFpext(inst), - .float_to_int => func.airFloatToInt(inst), - .int_to_float => func.airIntToFloat(inst), + .int_from_float => func.airIntFromFloat(inst), + .float_from_int => func.airFloatFromInt(inst), .get_union_tag => func.airGetUnionTag(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_elem_ptr => func.airPtrElemPtr(inst), .ptr_elem_val => func.airPtrElemVal(inst), - .ptrtoint => func.airPtrToInt(inst), + .int_from_ptr => func.airIntFromPtr(inst), .ret => func.airRet(inst), .ret_ptr => func.airRetPtr(inst), .ret_load => func.airRetLoad(inst), @@ -2061,7 +2061,7 @@ fn genInst(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { .cmp_neq_optimized, .cmp_vector_optimized, .reduce_optimized, - .float_to_int_optimized, + .int_from_float_optimized, => return func.fail("TODO implement optimized float mode", .{}), .work_item_id, @@ -4480,7 +4480,7 @@ fn trunc(func: *CodeGen, operand: WValue, wanted_ty: Type, given_ty: Type) Inner 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 operand = try func.resolveInst(un_op); 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}); } -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 un_op = func.air.instructions.items(.data)[inst].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 }); } -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 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}); } -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 ty_op = func.air.instructions.items(.data)[inst].ty_op; diff --git a/src/arch/x86_64/CodeGen.zig b/src/arch/x86_64/CodeGen.zig index a33faecca311..375b72bad5f5 100644 --- a/src/arch/x86_64/CodeGen.zig +++ b/src/arch/x86_64/CodeGen.zig @@ -1835,7 +1835,7 @@ fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void { .fpext => try self.airFpext(inst), .intcast => try self.airIntCast(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_ptr => try self.airIsNonNullPtr(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), .load => try self.airLoad(inst), .loop => try self.airLoop(inst), - .ptrtoint => try self.airPtrToInt(inst), + .int_from_ptr => try self.airIntFromPtr(inst), .ret => try self.airRet(inst), .ret_load => try self.airRetLoad(inst), .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_val=> try self.airStructFieldVal(inst), .array_to_slice => try self.airArrayToSlice(inst), - .int_to_float => try self.airIntToFloat(inst), - .float_to_int => try self.airFloatToInt(inst), + .float_from_int => try self.airFloatFromInt(inst), + .int_from_float => try self.airIntFromFloat(inst), .cmpxchg_strong => try self.airCmpxchg(inst), .cmpxchg_weak => try self.airCmpxchg(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_vector_optimized, .reduce_optimized, - .float_to_int_optimized, + .int_from_float_optimized, => return self.fail("TODO implement optimized float mode", .{}), .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 }); } -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 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 result = result: { // 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 }); } -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 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, .unsigned => src_bits + 1, }, 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), }); @@ -10287,7 +10287,7 @@ fn airIntToFloat(self: *Self, inst: Air.Inst.Index) !void { else => unreachable, }, 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), }); 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 }); } -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 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, .unsigned => dst_bits + 1, }, 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.?), }); @@ -10340,7 +10340,7 @@ fn airFloatToInt(self: *Self, inst: Air.Inst.Index) !void { else => unreachable, }, 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.?), }), registerAlias(dst_reg, dst_size), diff --git a/src/codegen/c.zig b/src/codegen/c.zig index d06f01c2c32a..a5110a34b014 100644 --- a/src/codegen/c.zig +++ b/src/codegen/c.zig @@ -2943,7 +2943,7 @@ fn genBodyInner(f: *Function, body: []const Air.Inst.Index) error{ AnalysisFail, .dbg_stmt => try airDbgStmt(f, inst), .intcast => try airIntCast(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), .ret => try airRet(f, inst, false), .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_inline => try airCall(f, inst, .never_inline), - .int_to_float, - .float_to_int, + .float_from_int, + .int_from_float, .fptrunc, .fpext, => 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_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_vector_optimized, .reduce_optimized, - .float_to_int_optimized, + .int_from_float_optimized, => return f.fail("TODO implement optimized float mode", .{}), .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; } -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 operand = try f.resolveInst(un_op); try reap(f, inst, &.{un_op}); @@ -5834,7 +5834,7 @@ fn airFloatCast(f: *Function, inst: Air.Inst.Index) !CValue { 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 un_op = f.air.instructions.items(.data)[inst].un_op; diff --git a/src/codegen/llvm.zig b/src/codegen/llvm.zig index 11cd75200011..1868298edb81 100644 --- a/src/codegen/llvm.zig +++ b/src/codegen/llvm.zig @@ -4417,7 +4417,7 @@ pub const FuncGen = struct { .ret_ptr => try self.airRetPtr(inst), .arg => try self.airArg(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), .br => try self.airBr(inst), .switch_br => try self.airSwitchBr(inst), @@ -4432,7 +4432,7 @@ pub const FuncGen = struct { .trunc => try self.airTrunc(inst), .fptrunc => try self.airFptrunc(inst), .fpext => try self.airFpext(inst), - .ptrtoint => try self.airPtrToInt(inst), + .int_from_ptr => try self.airIntFromPtr(inst), .load => try self.airLoad(body[i..]), .loop => try self.airLoop(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_len_ptr => try self.airPtrSliceFieldPtr(inst, 1), - .float_to_int => try self.airFloatToInt(inst, false), - .float_to_int_optimized => try self.airFloatToInt(inst, true), + .int_from_float => try self.airIntFromFloat(inst, false), + .int_from_float_optimized => try self.airIntFromFloat(inst, true), .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_strong => try self.airCmpxchg(inst, false), .fence => try self.airFence(inst), @@ -5456,7 +5456,7 @@ pub const FuncGen = struct { 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 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, ¶ms, 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); 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 operand = try self.resolveInst(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, ""); } - 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 operand = try self.resolveInst(un_op); return operand; diff --git a/src/codegen/spirv.zig b/src/codegen/spirv.zig index dc1f23dad442..2e614d90d1ff 100644 --- a/src/codegen/spirv.zig +++ b/src/codegen/spirv.zig @@ -1721,9 +1721,9 @@ pub const DeclGen = struct { .bitcast => try self.airBitCast(inst), .intcast, .trunc => try self.airIntCast(inst), - .ptrtoint => try self.airPtrToInt(inst), - .int_to_float => try self.airIntToFloat(inst), - .float_to_int => try self.airFloatToInt(inst), + .int_from_ptr => try self.airIntFromPtr(inst), + .float_from_int => try self.airFloatFromInt(inst), + .int_from_float => try self.airIntFromFloat(inst), .not => try self.airNot(inst), .slice_ptr => try self.airSliceField(inst, 0), @@ -2329,7 +2329,7 @@ pub const DeclGen = struct { 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; const un_op = self.air.instructions.items(.data)[inst].un_op; @@ -2345,7 +2345,7 @@ pub const DeclGen = struct { 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; const ty_op = self.air.instructions.items(.data)[inst].ty_op; @@ -2371,7 +2371,7 @@ pub const DeclGen = struct { 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; const ty_op = self.air.instructions.items(.data)[inst].ty_op; diff --git a/src/print_air.zig b/src/print_air.zig index f963ecdd9524..ddb63ac17c88 100644 --- a/src/print_air.zig +++ b/src/print_air.zig @@ -183,8 +183,8 @@ const Writer = struct { .is_non_err, .is_err_ptr, .is_non_err_ptr, - .ptrtoint, - .bool_to_int, + .int_from_ptr, + .int_from_bool, .ret, .ret_load, .is_named_enum_value, @@ -254,10 +254,10 @@ const Writer = struct { .struct_field_ptr_index_2, .struct_field_ptr_index_3, .array_to_slice, - .int_to_float, + .float_from_int, .splat, - .float_to_int, - .float_to_int_optimized, + .int_from_float, + .int_from_float_optimized, .get_union_tag, .clz, .ctz, diff --git a/src/print_zir.zig b/src/print_zir.zig index 35050f172811..b3359e2e31d1 100644 --- a/src/print_zir.zig +++ b/src/print_zir.zig @@ -187,12 +187,12 @@ const Writer = struct { .size_of, .bit_size_of, .typeof_log2_int_type, - .ptr_to_int, + .int_from_ptr, .compile_error, .set_eval_branch_quota, - .enum_to_int, + .int_from_enum, .align_of, - .bool_to_int, + .int_from_bool, .embed_file, .error_name, .panic, @@ -321,10 +321,10 @@ const Writer = struct { .merge_error_sets, .bit_and, .bit_or, - .float_to_int, - .int_to_float, - .int_to_ptr, - .int_to_enum, + .int_from_float, + .float_from_int, + .ptr_from_int, + .enum_from_int, .float_cast, .int_cast, .ptr_cast, @@ -502,8 +502,8 @@ const Writer = struct { .set_align_stack, .set_cold, .wasm_memory_size, - .error_to_int, - .int_to_error, + .int_from_error, + .error_from_int, .reify, .c_va_copy, .c_va_end, diff --git a/src/translate_c.zig b/src/translate_c.zig index 67176ff74b65..37717950626d 100644 --- a/src/translate_c.zig +++ b/src/translate_c.zig @@ -845,7 +845,7 @@ fn visitVarDecl(c: *Context, var_decl: *const clang.VarDecl, mangled_name: ?[]co error.OutOfMemory => |e| return e, }; 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)) { init_node = try stringLiteralToCharStar(c, init_node.?); } @@ -1753,16 +1753,16 @@ fn transBinaryOperator( const rhs_uncasted = try transExpr(c, scope, stmt.getRHS(), .used); 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) - try Tag.ptr_to_int.create(c.arena, lhs_uncasted) + try Tag.int_from_ptr.create(c.arena, lhs_uncasted) else lhs_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) - try Tag.ptr_to_int.create(c.arena, rhs_uncasted) + try Tag.int_from_ptr.create(c.arena, rhs_uncasted) else rhs_uncasted; @@ -1944,7 +1944,7 @@ fn transDeclStmtOne( else Tag.undefined_literal.init(); 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)) { const dst_type_node = try transQualType(c, scope, qual_type, loc); init_node = try removeCVQualifiers(c, dst_type_node, init_node); @@ -2074,11 +2074,11 @@ fn transImplicitCastExpr( return Tag.null_literal.init(); }, .PointerToBoolean => { - // @ptrToInt(val) != 0 + // @intFromPtr(val) != 0 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); }, .IntegralToBoolean, .FloatingToBoolean => { @@ -2334,7 +2334,7 @@ fn transReturnStmt( var rhs = try transExprCoercing(c, scope, val_expr, .used); const return_qt = scope.findBlockReturnType(); 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); } @@ -2493,7 +2493,7 @@ fn transCCast( var src_int_expr = 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 }); } @@ -2521,34 +2521,34 @@ fn transCCast( return Tag.bit_cast.create(c.arena, .{ .lhs = dst_node, .rhs = expr }); } if (cIsInteger(dst_type) and qualTypeIsPtr(src_type)) { - // @intCast(dest_type, @ptrToInt(val)) - const ptr_to_int = try Tag.ptr_to_int.create(c.arena, expr); - return Tag.int_cast.create(c.arena, .{ .lhs = dst_node, .rhs = ptr_to_int }); + // @intCast(dest_type, @intFromPtr(val)) + const int_from_ptr = try Tag.int_from_ptr.create(c.arena, expr); + return Tag.int_cast.create(c.arena, .{ .lhs = dst_node, .rhs = int_from_ptr }); } if (cIsInteger(src_type) and qualTypeIsPtr(dst_type)) { - // @intToPtr(dest_type, val) - return Tag.int_to_ptr.create(c.arena, .{ .lhs = dst_node, .rhs = expr }); + // @ptrFromInt(dest_type, val) + return Tag.ptr_from_int.create(c.arena, .{ .lhs = dst_node, .rhs = expr }); } if (cIsFloating(src_type) and cIsFloating(dst_type)) { // @floatCast(dest_type, val) return Tag.float_cast.create(c.arena, .{ .lhs = dst_node, .rhs = expr }); } if (cIsFloating(src_type) and !cIsFloating(dst_type)) { - // @floatToInt(dest_type, val) - return Tag.float_to_int.create(c.arena, .{ .lhs = dst_node, .rhs = expr }); + // @intFromFloat(dest_type, val) + return Tag.int_from_float.create(c.arena, .{ .lhs = dst_node, .rhs = expr }); } if (!cIsFloating(src_type) and cIsFloating(dst_type)) { var rhs = expr; - if (qualTypeIsBoolean(src_type)) rhs = try Tag.bool_to_int.create(c.arena, expr); - // @intToFloat(dest_type, val) - return Tag.int_to_float.create(c.arena, .{ .lhs = dst_node, .rhs = rhs }); + if (qualTypeIsBoolean(src_type)) rhs = try Tag.int_from_bool.create(c.arena, expr); + // @floatFromInt(dest_type, val) + return Tag.float_from_int.create(c.arena, .{ .lhs = dst_node, .rhs = rhs }); } 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 // instead of @as - const bool_to_int = try Tag.bool_to_int.create(c.arena, expr); - return Tag.as.create(c.arena, .{ .lhs = dst_node, .rhs = bool_to_int }); + const int_from_bool = try Tag.int_from_bool.create(c.arena, expr); + return Tag.as.create(c.arena, .{ .lhs = dst_node, .rhs = int_from_bool }); } // @as(dest_type, val) 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) { const param_qt = fn_proto.getParamType(@intCast(c_uint, i)); 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)) { const loc = @ptrCast(*const clang.Stmt, stmt).getBeginLoc(); 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 to_negate = if (isBoolRes(sub_expr_node)) blk: { 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 }); } else sub_expr_node; return Tag.negate.create(c.arena, to_negate); @@ -4028,8 +4028,8 @@ fn transCreateCompoundAssign( // Casting away const or volatile requires us to use @intToPtr 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); - return Tag.int_to_ptr.create(c.arena, .{ .lhs = dst_type_node, .rhs = ptr_to_int }); + const int_from_ptr = try Tag.int_from_ptr.create(c.arena, expr); + return Tag.ptr_from_int.create(c.arena, .{ .lhs = dst_type_node, .rhs = int_from_ptr }); } 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); var then_body = cond_ident; 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); 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, .{ .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); 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); 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, .{ @@ -4556,7 +4556,7 @@ fn transCreateNodeAssign( const lhs_node = try transExpr(c, scope, lhs, .used); var rhs_node = try transExprCoercing(c, scope, rhs, .used); 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); } @@ -4574,7 +4574,7 @@ fn transCreateNodeAssign( const tmp = try block_scope.reserveMangledName(c, "tmp"); var rhs_node = try transExpr(c, &block_scope.base, rhs, .used); 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 }); @@ -6092,7 +6092,7 @@ fn macroBoolToInt(c: *Context, node: Node) !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 { diff --git a/src/translate_c/ast.zig b/src/translate_c/ast.zig index 443c56a84a33..942844ec4e48 100644 --- a/src/translate_c/ast.zig +++ b/src/translate_c/ast.zig @@ -128,8 +128,8 @@ pub const Node = extern union { signed_remainder, /// @divTrunc(lhs, rhs) div_trunc, - /// @boolToInt(operand) - bool_to_int, + /// @intFromBool(operand) + int_from_bool, /// @as(lhs, rhs) as, /// @truncate(lhs, rhs) @@ -138,14 +138,14 @@ pub const Node = extern union { bit_cast, /// @floatCast(lhs, rhs) float_cast, - /// @floatToInt(lhs, rhs) - float_to_int, - /// @intToFloat(lhs, rhs) - int_to_float, - /// @intToPtr(lhs, rhs) - int_to_ptr, - /// @ptrToInt(operand) - ptr_to_int, + /// @intFromFloat(lhs, rhs) + int_from_float, + /// @floatFromInt(lhs, rhs) + float_from_int, + /// @ptrFromInt(lhs, rhs) + ptr_from_int, + /// @intFromPtr(operand) + int_from_ptr, /// @alignCast(lhs, rhs) align_cast, /// @ptrCast(lhs, rhs) @@ -263,7 +263,7 @@ pub const Node = extern union { .address_of, .unwrap, .deref, - .ptr_to_int, + .int_from_ptr, .empty_array, .while_true, .if_not_break, @@ -271,7 +271,7 @@ pub const Node = extern union { .block_single, .helpers_sizeof, .std_meta_alignment, - .bool_to_int, + .int_from_bool, .sizeof, .alignof, .typeof, @@ -319,9 +319,9 @@ pub const Node = extern union { .truncate, .bit_cast, .float_cast, - .float_to_int, - .int_to_float, - .int_to_ptr, + .int_from_float, + .float_from_int, + .ptr_from_int, .array_cat, .ellipsis3, .assign, @@ -1355,9 +1355,9 @@ fn renderNode(c: *Context, node: Node) Allocator.Error!NodeIndex { const payload = node.castTag(.div_trunc).?.data; return renderBuiltinCall(c, "@divTrunc", &.{ payload.lhs, payload.rhs }); }, - .bool_to_int => { - const payload = node.castTag(.bool_to_int).?.data; - return renderBuiltinCall(c, "@boolToInt", &.{payload}); + .int_from_bool => { + const payload = node.castTag(.int_from_bool).?.data; + return renderBuiltinCall(c, "@intFromBool", &.{payload}); }, .as => { 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; return renderBuiltinCall(c, "@floatCast", &.{ payload.lhs, payload.rhs }); }, - .float_to_int => { - const payload = node.castTag(.float_to_int).?.data; - return renderBuiltinCall(c, "@floatToInt", &.{ payload.lhs, payload.rhs }); + .int_from_float => { + const payload = node.castTag(.int_from_float).?.data; + return renderBuiltinCall(c, "@intFromFloat", &.{ payload.lhs, payload.rhs }); }, - .int_to_float => { - const payload = node.castTag(.int_to_float).?.data; - return renderBuiltinCall(c, "@intToFloat", &.{ payload.lhs, payload.rhs }); + .float_from_int => { + const payload = node.castTag(.float_from_int).?.data; + return renderBuiltinCall(c, "@floatFromInt", &.{ payload.lhs, payload.rhs }); }, - .int_to_ptr => { - const payload = node.castTag(.int_to_ptr).?.data; - return renderBuiltinCall(c, "@intToPtr", &.{ payload.lhs, payload.rhs }); + .ptr_from_int => { + const payload = node.castTag(.ptr_from_int).?.data; + return renderBuiltinCall(c, "@ptrFromInt", &.{ payload.lhs, payload.rhs }); }, - .ptr_to_int => { - const payload = node.castTag(.ptr_to_int).?.data; - return renderBuiltinCall(c, "@ptrToInt", &.{payload}); + .int_from_ptr => { + const payload = node.castTag(.int_from_ptr).?.data; + return renderBuiltinCall(c, "@intFromPtr", &.{payload}); }, .align_cast => { const payload = node.castTag(.align_cast).?.data; @@ -2326,13 +2326,13 @@ fn renderNodeGrouped(c: *Context, node: Node) !NodeIndex { .truncate, .bit_cast, .float_cast, - .float_to_int, - .int_to_float, - .int_to_ptr, + .int_from_float, + .float_from_int, + .ptr_from_int, .std_mem_zeroes, .std_math_Log2Int, .log2_int_type, - .ptr_to_int, + .int_from_ptr, .sizeof, .alignof, .typeof, @@ -2371,7 +2371,7 @@ fn renderNodeGrouped(c: *Context, node: Node) !NodeIndex { .call, .array_type, .null_sentinel_array_type, - .bool_to_int, + .int_from_bool, .div_exact, .offset_of, .shuffle,