Function getAssociatedSrcHash [src]

Prototype

pub fn getAssociatedSrcHash(zir: Zir, inst: Zir.Inst.Index) ?std.zig.SrcHash

Parameters

zir: Zirinst: Zir.Inst.Index

Source

pub fn getAssociatedSrcHash(zir: Zir, inst: Zir.Inst.Index) ?std.zig.SrcHash { const tag = zir.instructions.items(.tag); const data = zir.instructions.items(.data); switch (tag[@intFromEnum(inst)]) { .declaration => { const declaration = data[@intFromEnum(inst)].declaration; const extra = zir.extraData(Inst.Declaration, declaration.payload_index); return @bitCast([4]u32{ extra.data.src_hash_0, extra.data.src_hash_1, extra.data.src_hash_2, extra.data.src_hash_3, }); }, .func, .func_inferred => { const pl_node = data[@intFromEnum(inst)].pl_node; const extra = zir.extraData(Inst.Func, pl_node.payload_index); if (extra.data.body_len == 0) { // Function type or extern fn - no associated hash return null; } const extra_index = extra.end + extra.data.ret_ty.body_len + extra.data.body_len + @typeInfo(Inst.Func.SrcLocs).@"struct".fields.len; return @bitCast([4]u32{ zir.extra[extra_index + 0], zir.extra[extra_index + 1], zir.extra[extra_index + 2], zir.extra[extra_index + 3], }); }, .func_fancy => { const pl_node = data[@intFromEnum(inst)].pl_node; const extra = zir.extraData(Inst.FuncFancy, pl_node.payload_index); if (extra.data.body_len == 0) { // Function type or extern fn - no associated hash return null; } const bits = extra.data.bits; var extra_index = extra.end; if (bits.has_cc_body) { const body_len = zir.extra[extra_index]; extra_index += 1 + body_len; } else extra_index += @intFromBool(bits.has_cc_ref); if (bits.has_ret_ty_body) { const body_len = zir.extra[extra_index]; extra_index += 1 + body_len; } else extra_index += @intFromBool(bits.has_ret_ty_ref); extra_index += @intFromBool(bits.has_any_noalias); extra_index += extra.data.body_len; extra_index += @typeInfo(Zir.Inst.Func.SrcLocs).@"struct".fields.len; return @bitCast([4]u32{ zir.extra[extra_index + 0], zir.extra[extra_index + 1], zir.extra[extra_index + 2], zir.extra[extra_index + 3], }); }, .extended => {}, else => return null, } const extended = data[@intFromEnum(inst)].extended; switch (extended.opcode) { .struct_decl => { const extra = zir.extraData(Inst.StructDecl, extended.operand).data; return @bitCast([4]u32{ extra.fields_hash_0, extra.fields_hash_1, extra.fields_hash_2, extra.fields_hash_3, }); }, .union_decl => { const extra = zir.extraData(Inst.UnionDecl, extended.operand).data; return @bitCast([4]u32{ extra.fields_hash_0, extra.fields_hash_1, extra.fields_hash_2, extra.fields_hash_3, }); }, .enum_decl => { const extra = zir.extraData(Inst.EnumDecl, extended.operand).data; return @bitCast([4]u32{ extra.fields_hash_0, extra.fields_hash_1, extra.fields_hash_2, extra.fields_hash_3, }); }, else => return null, } }