| author | |
| committer | |
| log | e57f553c07cff62871927146e072be43f13432e3 |
| tree | 8619261c86ef0a929f95619d0a99fde59fad2a84 |
| parent | 48bd0ed7f3f5d6c1c0f2046a791e7367ba0672ad |
This fixes a problem where empty strings where not emitted as null.
This should also emit a smaller stringtab as all metadata strings were
emitted in both the strtab and in the strings block inside the metadata
block.2 files changed, 193 insertions(+), 145 deletions(-)
src/codegen/llvm.zig+56-56| ... | @@ -872,8 +872,8 @@ pub const Object = struct { | ... | @@ -872,8 +872,8 @@ pub const Object = struct { |
| 872 | }; | 872 | }; |
| 873 | 873 | ||
| 874 | const debug_file = try builder.debugFile( | 874 | const debug_file = try builder.debugFile( |
| 875 | try builder.string(compile_unit_dir), | 875 | try builder.metadataString(compile_unit_dir), |
| 876 | try builder.string(comp.root_name), | 876 | try builder.metadataString(comp.root_name), |
| 877 | ); | 877 | ); |
| 878 | 878 | ||
| 879 | const debug_enums_fwd_ref = try builder.debugForwardReference(); | 879 | const debug_enums_fwd_ref = try builder.debugForwardReference(); |
| ... | @@ -883,7 +883,7 @@ pub const Object = struct { | ... | @@ -883,7 +883,7 @@ pub const Object = struct { |
| 883 | debug_file, | 883 | debug_file, |
| 884 | // Don't use the version string here; LLVM misparses it when it | 884 | // Don't use the version string here; LLVM misparses it when it |
| 885 | // includes the git revision. | 885 | // includes the git revision. |
| 886 | try builder.fmt("zig {d}.{d}.{d}", .{ | 886 | try builder.metadataStringFmt("zig {d}.{d}.{d}", .{ |
| 887 | build_options.semver.major, | 887 | build_options.semver.major, |
| 888 | build_options.semver.minor, | 888 | build_options.semver.minor, |
| 889 | build_options.semver.patch, | 889 | build_options.semver.patch, |
| ... | @@ -896,7 +896,7 @@ pub const Object = struct { | ... | @@ -896,7 +896,7 @@ pub const Object = struct { |
| 896 | if (!builder.strip) { | 896 | if (!builder.strip) { |
| 897 | const debug_info_version = try builder.debugModuleFlag( | 897 | const debug_info_version = try builder.debugModuleFlag( |
| 898 | try builder.debugConstant(try builder.intConst(.i32, 2)), | 898 | try builder.debugConstant(try builder.intConst(.i32, 2)), |
| 899 | try builder.string("Debug Info Version"), | 899 | try builder.metadataString("Debug Info Version"), |
| 900 | try builder.debugConstant(try builder.intConst(.i32, 3)), | 900 | try builder.debugConstant(try builder.intConst(.i32, 3)), |
| 901 | ); | 901 | ); |
| 902 | 902 | ||
| ... | @@ -904,12 +904,12 @@ pub const Object = struct { | ... | @@ -904,12 +904,12 @@ pub const Object = struct { |
| 904 | .dwarf => |f| { | 904 | .dwarf => |f| { |
| 905 | const dwarf_version = try builder.debugModuleFlag( | 905 | const dwarf_version = try builder.debugModuleFlag( |
| 906 | try builder.debugConstant(try builder.intConst(.i32, 2)), | 906 | try builder.debugConstant(try builder.intConst(.i32, 2)), |
| 907 | try builder.string("Dwarf Version"), | 907 | try builder.metadataString("Dwarf Version"), |
| 908 | try builder.debugConstant(try builder.intConst(.i32, 4)), | 908 | try builder.debugConstant(try builder.intConst(.i32, 4)), |
| 909 | ); | 909 | ); |
| 910 | switch (f) { | 910 | switch (f) { |
| 911 | .@"32" => { | 911 | .@"32" => { |
| 912 | try builder.debugNamed(try builder.string("llvm.module.flags"), &.{ | 912 | try builder.debugNamed(try builder.metadataString("llvm.module.flags"), &.{ |
| 913 | debug_info_version, | 913 | debug_info_version, |
| 914 | dwarf_version, | 914 | dwarf_version, |
| 915 | }); | 915 | }); |
| ... | @@ -917,10 +917,10 @@ pub const Object = struct { | ... | @@ -917,10 +917,10 @@ pub const Object = struct { |
| 917 | .@"64" => { | 917 | .@"64" => { |
| 918 | const dwarf64 = try builder.debugModuleFlag( | 918 | const dwarf64 = try builder.debugModuleFlag( |
| 919 | try builder.debugConstant(try builder.intConst(.i32, 2)), | 919 | try builder.debugConstant(try builder.intConst(.i32, 2)), |
| 920 | try builder.string("DWARF64"), | 920 | try builder.metadataString("DWARF64"), |
| 921 | try builder.debugConstant(try builder.intConst(.i32, 1)), | 921 | try builder.debugConstant(try builder.intConst(.i32, 1)), |
| 922 | ); | 922 | ); |
| 923 | try builder.debugNamed(try builder.string("llvm.module.flags"), &.{ | 923 | try builder.debugNamed(try builder.metadataString("llvm.module.flags"), &.{ |
| 924 | debug_info_version, | 924 | debug_info_version, |
| 925 | dwarf_version, | 925 | dwarf_version, |
| 926 | dwarf64, | 926 | dwarf64, |
| ... | @@ -931,10 +931,10 @@ pub const Object = struct { | ... | @@ -931,10 +931,10 @@ pub const Object = struct { |
| 931 | .code_view => { | 931 | .code_view => { |
| 932 | const code_view = try builder.debugModuleFlag( | 932 | const code_view = try builder.debugModuleFlag( |
| 933 | try builder.debugConstant(try builder.intConst(.i32, 2)), | 933 | try builder.debugConstant(try builder.intConst(.i32, 2)), |
| 934 | try builder.string("CodeView"), | 934 | try builder.metadataString("CodeView"), |
| 935 | try builder.debugConstant(try builder.intConst(.i32, 1)), | 935 | try builder.debugConstant(try builder.intConst(.i32, 1)), |
| 936 | ); | 936 | ); |
| 937 | try builder.debugNamed(try builder.string("llvm.module.flags"), &.{ | 937 | try builder.debugNamed(try builder.metadataString("llvm.module.flags"), &.{ |
| 938 | debug_info_version, | 938 | debug_info_version, |
| 939 | code_view, | 939 | code_view, |
| 940 | }); | 940 | }); |
| ... | @@ -942,7 +942,7 @@ pub const Object = struct { | ... | @@ -942,7 +942,7 @@ pub const Object = struct { |
| 942 | .strip => unreachable, | 942 | .strip => unreachable, |
| 943 | } | 943 | } |
| 944 | 944 | ||
| 945 | try builder.debugNamed(try builder.string("llvm.dbg.cu"), &.{debug_compile_unit}); | 945 | try builder.debugNamed(try builder.metadataString("llvm.dbg.cu"), &.{debug_compile_unit}); |
| 946 | } | 946 | } |
| 947 | 947 | ||
| 948 | const obj = try arena.create(Object); | 948 | const obj = try arena.create(Object); |
| ... | @@ -1654,8 +1654,8 @@ pub const Object = struct { | ... | @@ -1654,8 +1654,8 @@ pub const Object = struct { |
| 1654 | 1654 | ||
| 1655 | break :blk try o.builder.debugSubprogram( | 1655 | break :blk try o.builder.debugSubprogram( |
| 1656 | file, | 1656 | file, |
| 1657 | try o.builder.string(ip.stringToSlice(decl.name)), | 1657 | try o.builder.metadataString(ip.stringToSlice(decl.name)), |
| 1658 | function_index.name(&o.builder), | 1658 | try o.builder.metadataStringFromString(function_index.name(&o.builder)), |
| 1659 | line_number, | 1659 | line_number, |
| 1660 | line_number + func.lbrace_line, | 1660 | line_number + func.lbrace_line, |
| 1661 | debug_decl_type, | 1661 | debug_decl_type, |
| ... | @@ -1914,8 +1914,8 @@ pub const Object = struct { | ... | @@ -1914,8 +1914,8 @@ pub const Object = struct { |
| 1914 | 1914 | ||
| 1915 | fn getDebugFile(o: *Object, file: *const Module.File) Allocator.Error!Builder.Metadata { | 1915 | fn getDebugFile(o: *Object, file: *const Module.File) Allocator.Error!Builder.Metadata { |
| 1916 | return try o.builder.debugFile( | 1916 | return try o.builder.debugFile( |
| 1917 | if (std.fs.path.dirname(file.sub_file_path)) |dirname| try o.builder.string(dirname) else .empty, | 1917 | if (std.fs.path.dirname(file.sub_file_path)) |dirname| try o.builder.metadataString(dirname) else .none, |
| 1918 | try o.builder.string(std.fs.path.basename(file.sub_file_path)), | 1918 | try o.builder.metadataString(std.fs.path.basename(file.sub_file_path)), |
| 1919 | ); | 1919 | ); |
| 1920 | } | 1920 | } |
| 1921 | 1921 | ||
| ... | @@ -1936,7 +1936,7 @@ pub const Object = struct { | ... | @@ -1936,7 +1936,7 @@ pub const Object = struct { |
| 1936 | .NoReturn, | 1936 | .NoReturn, |
| 1937 | => { | 1937 | => { |
| 1938 | const debug_void_type = try o.builder.debugSignedType( | 1938 | const debug_void_type = try o.builder.debugSignedType( |
| 1939 | try o.builder.string("void"), | 1939 | try o.builder.metadataString("void"), |
| 1940 | 0, | 1940 | 0, |
| 1941 | ); | 1941 | ); |
| 1942 | try o.debug_type_map.put(gpa, ty, debug_void_type); | 1942 | try o.debug_type_map.put(gpa, ty, debug_void_type); |
| ... | @@ -1947,7 +1947,7 @@ pub const Object = struct { | ... | @@ -1947,7 +1947,7 @@ pub const Object = struct { |
| 1947 | assert(info.bits != 0); | 1947 | assert(info.bits != 0); |
| 1948 | const name = try o.allocTypeName(ty); | 1948 | const name = try o.allocTypeName(ty); |
| 1949 | defer gpa.free(name); | 1949 | defer gpa.free(name); |
| 1950 | const builder_name = try o.builder.string(name); | 1950 | const builder_name = try o.builder.metadataString(name); |
| 1951 | const debug_bits = ty.abiSize(mod) * 8; // lldb cannot handle non-byte sized types | 1951 | const debug_bits = ty.abiSize(mod) * 8; // lldb cannot handle non-byte sized types |
| 1952 | const debug_int_type = switch (info.signedness) { | 1952 | const debug_int_type = switch (info.signedness) { |
| 1953 | .signed => try o.builder.debugSignedType(builder_name, debug_bits), | 1953 | .signed => try o.builder.debugSignedType(builder_name, debug_bits), |
| ... | @@ -1984,7 +1984,7 @@ pub const Object = struct { | ... | @@ -1984,7 +1984,7 @@ pub const Object = struct { |
| 1984 | std.math.big.int.Mutable.init(&bigint_space.limbs, i).toConst(); | 1984 | std.math.big.int.Mutable.init(&bigint_space.limbs, i).toConst(); |
| 1985 | 1985 | ||
| 1986 | enumerators[i] = try o.builder.debugEnumerator( | 1986 | enumerators[i] = try o.builder.debugEnumerator( |
| 1987 | try o.builder.string(ip.stringToSlice(field_name_ip)), | 1987 | try o.builder.metadataString(ip.stringToSlice(field_name_ip)), |
| 1988 | int_ty.isUnsignedInt(mod), | 1988 | int_ty.isUnsignedInt(mod), |
| 1989 | int_info.bits, | 1989 | int_info.bits, |
| 1990 | bigint, | 1990 | bigint, |
| ... | @@ -1998,7 +1998,7 @@ pub const Object = struct { | ... | @@ -1998,7 +1998,7 @@ pub const Object = struct { |
| 1998 | defer gpa.free(name); | 1998 | defer gpa.free(name); |
| 1999 | 1999 | ||
| 2000 | const debug_enum_type = try o.builder.debugEnumerationType( | 2000 | const debug_enum_type = try o.builder.debugEnumerationType( |
| 2001 | try o.builder.string(name), | 2001 | try o.builder.metadataString(name), |
| 2002 | file, | 2002 | file, |
| 2003 | scope, | 2003 | scope, |
| 2004 | owner_decl.src_node + 1, // Line | 2004 | owner_decl.src_node + 1, // Line |
| ... | @@ -2017,7 +2017,7 @@ pub const Object = struct { | ... | @@ -2017,7 +2017,7 @@ pub const Object = struct { |
| 2017 | const name = try o.allocTypeName(ty); | 2017 | const name = try o.allocTypeName(ty); |
| 2018 | defer gpa.free(name); | 2018 | defer gpa.free(name); |
| 2019 | const debug_float_type = try o.builder.debugFloatType( | 2019 | const debug_float_type = try o.builder.debugFloatType( |
| 2020 | try o.builder.string(name), | 2020 | try o.builder.metadataString(name), |
| 2021 | bits, | 2021 | bits, |
| 2022 | ); | 2022 | ); |
| 2023 | try o.debug_type_map.put(gpa, ty, debug_float_type); | 2023 | try o.debug_type_map.put(gpa, ty, debug_float_type); |
| ... | @@ -2025,7 +2025,7 @@ pub const Object = struct { | ... | @@ -2025,7 +2025,7 @@ pub const Object = struct { |
| 2025 | }, | 2025 | }, |
| 2026 | .Bool => { | 2026 | .Bool => { |
| 2027 | const debug_bool_type = try o.builder.debugBoolType( | 2027 | const debug_bool_type = try o.builder.debugBoolType( |
| 2028 | try o.builder.string("bool"), | 2028 | try o.builder.metadataString("bool"), |
| 2029 | 8, // lldb cannot handle non-byte sized types | 2029 | 8, // lldb cannot handle non-byte sized types |
| 2030 | ); | 2030 | ); |
| 2031 | try o.debug_type_map.put(gpa, ty, debug_bool_type); | 2031 | try o.debug_type_map.put(gpa, ty, debug_bool_type); |
| ... | @@ -2085,7 +2085,7 @@ pub const Object = struct { | ... | @@ -2085,7 +2085,7 @@ pub const Object = struct { |
| 2085 | const len_offset = len_align.forward(ptr_size); | 2085 | const len_offset = len_align.forward(ptr_size); |
| 2086 | 2086 | ||
| 2087 | const debug_ptr_type = try o.builder.debugMemberType( | 2087 | const debug_ptr_type = try o.builder.debugMemberType( |
| 2088 | try o.builder.string("ptr"), | 2088 | try o.builder.metadataString("ptr"), |
| 2089 | Builder.Metadata.none, // File | 2089 | Builder.Metadata.none, // File |
| 2090 | debug_fwd_ref, | 2090 | debug_fwd_ref, |
| 2091 | 0, // Line | 2091 | 0, // Line |
| ... | @@ -2096,7 +2096,7 @@ pub const Object = struct { | ... | @@ -2096,7 +2096,7 @@ pub const Object = struct { |
| 2096 | ); | 2096 | ); |
| 2097 | 2097 | ||
| 2098 | const debug_len_type = try o.builder.debugMemberType( | 2098 | const debug_len_type = try o.builder.debugMemberType( |
| 2099 | try o.builder.string("len"), | 2099 | try o.builder.metadataString("len"), |
| 2100 | Builder.Metadata.none, // File | 2100 | Builder.Metadata.none, // File |
| 2101 | debug_fwd_ref, | 2101 | debug_fwd_ref, |
| 2102 | 0, // Line | 2102 | 0, // Line |
| ... | @@ -2107,7 +2107,7 @@ pub const Object = struct { | ... | @@ -2107,7 +2107,7 @@ pub const Object = struct { |
| 2107 | ); | 2107 | ); |
| 2108 | 2108 | ||
| 2109 | const debug_slice_type = try o.builder.debugStructType( | 2109 | const debug_slice_type = try o.builder.debugStructType( |
| 2110 | try o.builder.string(name), | 2110 | try o.builder.metadataString(name), |
| 2111 | Builder.Metadata.none, // File | 2111 | Builder.Metadata.none, // File |
| 2112 | o.debug_compile_unit, // Scope | 2112 | o.debug_compile_unit, // Scope |
| 2113 | line, | 2113 | line, |
| ... | @@ -2135,7 +2135,7 @@ pub const Object = struct { | ... | @@ -2135,7 +2135,7 @@ pub const Object = struct { |
| 2135 | defer gpa.free(name); | 2135 | defer gpa.free(name); |
| 2136 | 2136 | ||
| 2137 | const debug_ptr_type = try o.builder.debugPointerType( | 2137 | const debug_ptr_type = try o.builder.debugPointerType( |
| 2138 | try o.builder.string(name), | 2138 | try o.builder.metadataString(name), |
| 2139 | Builder.Metadata.none, // File | 2139 | Builder.Metadata.none, // File |
| 2140 | Builder.Metadata.none, // Scope | 2140 | Builder.Metadata.none, // Scope |
| 2141 | 0, // Line | 2141 | 0, // Line |
| ... | @@ -2156,7 +2156,7 @@ pub const Object = struct { | ... | @@ -2156,7 +2156,7 @@ pub const Object = struct { |
| 2156 | .Opaque => { | 2156 | .Opaque => { |
| 2157 | if (ty.toIntern() == .anyopaque_type) { | 2157 | if (ty.toIntern() == .anyopaque_type) { |
| 2158 | const debug_opaque_type = try o.builder.debugSignedType( | 2158 | const debug_opaque_type = try o.builder.debugSignedType( |
| 2159 | try o.builder.string("anyopaque"), | 2159 | try o.builder.metadataString("anyopaque"), |
| 2160 | 0, | 2160 | 0, |
| 2161 | ); | 2161 | ); |
| 2162 | try o.debug_type_map.put(gpa, ty, debug_opaque_type); | 2162 | try o.debug_type_map.put(gpa, ty, debug_opaque_type); |
| ... | @@ -2168,7 +2168,7 @@ pub const Object = struct { | ... | @@ -2168,7 +2168,7 @@ pub const Object = struct { |
| 2168 | const owner_decl_index = ty.getOwnerDecl(mod); | 2168 | const owner_decl_index = ty.getOwnerDecl(mod); |
| 2169 | const owner_decl = o.module.declPtr(owner_decl_index); | 2169 | const owner_decl = o.module.declPtr(owner_decl_index); |
| 2170 | const debug_opaque_type = try o.builder.debugStructType( | 2170 | const debug_opaque_type = try o.builder.debugStructType( |
| 2171 | try o.builder.string(name), | 2171 | try o.builder.metadataString(name), |
| 2172 | try o.getDebugFile(mod.namespacePtr(owner_decl.src_namespace).file_scope), | 2172 | try o.getDebugFile(mod.namespacePtr(owner_decl.src_namespace).file_scope), |
| 2173 | try o.namespaceToDebugScope(owner_decl.src_namespace), | 2173 | try o.namespaceToDebugScope(owner_decl.src_namespace), |
| 2174 | owner_decl.src_node + 1, // Line | 2174 | owner_decl.src_node + 1, // Line |
| ... | @@ -2182,7 +2182,7 @@ pub const Object = struct { | ... | @@ -2182,7 +2182,7 @@ pub const Object = struct { |
| 2182 | }, | 2182 | }, |
| 2183 | .Array => { | 2183 | .Array => { |
| 2184 | const debug_array_type = try o.builder.debugArrayType( | 2184 | const debug_array_type = try o.builder.debugArrayType( |
| 2185 | Builder.String.empty, // Name | 2185 | Builder.MetadataString.none, // Name |
| 2186 | Builder.Metadata.none, // File | 2186 | Builder.Metadata.none, // File |
| 2187 | Builder.Metadata.none, // Scope | 2187 | Builder.Metadata.none, // Scope |
| 2188 | 0, // Line | 2188 | 0, // Line |
| ... | @@ -2211,21 +2211,21 @@ pub const Object = struct { | ... | @@ -2211,21 +2211,21 @@ pub const Object = struct { |
| 2211 | assert(info.bits != 0); | 2211 | assert(info.bits != 0); |
| 2212 | const name = try o.allocTypeName(ty); | 2212 | const name = try o.allocTypeName(ty); |
| 2213 | defer gpa.free(name); | 2213 | defer gpa.free(name); |
| 2214 | const builder_name = try o.builder.string(name); | 2214 | const builder_name = try o.builder.metadataString(name); |
| 2215 | break :blk switch (info.signedness) { | 2215 | break :blk switch (info.signedness) { |
| 2216 | .signed => try o.builder.debugSignedType(builder_name, info.bits), | 2216 | .signed => try o.builder.debugSignedType(builder_name, info.bits), |
| 2217 | .unsigned => try o.builder.debugUnsignedType(builder_name, info.bits), | 2217 | .unsigned => try o.builder.debugUnsignedType(builder_name, info.bits), |
| 2218 | }; | 2218 | }; |
| 2219 | }, | 2219 | }, |
| 2220 | .Bool => try o.builder.debugBoolType( | 2220 | .Bool => try o.builder.debugBoolType( |
| 2221 | try o.builder.string("bool"), | 2221 | try o.builder.metadataString("bool"), |
| 2222 | 1, | 2222 | 1, |
| 2223 | ), | 2223 | ), |
| 2224 | else => try o.lowerDebugType(ty.childType(mod)), | 2224 | else => try o.lowerDebugType(ty.childType(mod)), |
| 2225 | }; | 2225 | }; |
| 2226 | 2226 | ||
| 2227 | const debug_vector_type = try o.builder.debugArrayType( | 2227 | const debug_vector_type = try o.builder.debugArrayType( |
| 2228 | Builder.String.empty, // Name | 2228 | Builder.MetadataString.none, // Name |
| 2229 | Builder.Metadata.none, // File | 2229 | Builder.Metadata.none, // File |
| 2230 | Builder.Metadata.none, // Scope | 2230 | Builder.Metadata.none, // Scope |
| 2231 | 0, // Line | 2231 | 0, // Line |
| ... | @@ -2249,7 +2249,7 @@ pub const Object = struct { | ... | @@ -2249,7 +2249,7 @@ pub const Object = struct { |
| 2249 | const child_ty = ty.optionalChild(mod); | 2249 | const child_ty = ty.optionalChild(mod); |
| 2250 | if (!child_ty.hasRuntimeBitsIgnoreComptime(mod)) { | 2250 | if (!child_ty.hasRuntimeBitsIgnoreComptime(mod)) { |
| 2251 | const debug_bool_type = try o.builder.debugBoolType( | 2251 | const debug_bool_type = try o.builder.debugBoolType( |
| 2252 | try o.builder.string(name), | 2252 | try o.builder.metadataString(name), |
| 2253 | 8, | 2253 | 8, |
| 2254 | ); | 2254 | ); |
| 2255 | try o.debug_type_map.put(gpa, ty, debug_bool_type); | 2255 | try o.debug_type_map.put(gpa, ty, debug_bool_type); |
| ... | @@ -2281,7 +2281,7 @@ pub const Object = struct { | ... | @@ -2281,7 +2281,7 @@ pub const Object = struct { |
| 2281 | const non_null_offset = non_null_align.forward(payload_size); | 2281 | const non_null_offset = non_null_align.forward(payload_size); |
| 2282 | 2282 | ||
| 2283 | const debug_data_type = try o.builder.debugMemberType( | 2283 | const debug_data_type = try o.builder.debugMemberType( |
| 2284 | try o.builder.string("data"), | 2284 | try o.builder.metadataString("data"), |
| 2285 | Builder.Metadata.none, // File | 2285 | Builder.Metadata.none, // File |
| 2286 | debug_fwd_ref, | 2286 | debug_fwd_ref, |
| 2287 | 0, // Line | 2287 | 0, // Line |
| ... | @@ -2292,7 +2292,7 @@ pub const Object = struct { | ... | @@ -2292,7 +2292,7 @@ pub const Object = struct { |
| 2292 | ); | 2292 | ); |
| 2293 | 2293 | ||
| 2294 | const debug_some_type = try o.builder.debugMemberType( | 2294 | const debug_some_type = try o.builder.debugMemberType( |
| 2295 | try o.builder.string("some"), | 2295 | try o.builder.metadataString("some"), |
| 2296 | Builder.Metadata.none, | 2296 | Builder.Metadata.none, |
| 2297 | debug_fwd_ref, | 2297 | debug_fwd_ref, |
| 2298 | 0, | 2298 | 0, |
| ... | @@ -2303,7 +2303,7 @@ pub const Object = struct { | ... | @@ -2303,7 +2303,7 @@ pub const Object = struct { |
| 2303 | ); | 2303 | ); |
| 2304 | 2304 | ||
| 2305 | const debug_optional_type = try o.builder.debugStructType( | 2305 | const debug_optional_type = try o.builder.debugStructType( |
| 2306 | try o.builder.string(name), | 2306 | try o.builder.metadataString(name), |
| 2307 | Builder.Metadata.none, // File | 2307 | Builder.Metadata.none, // File |
| 2308 | o.debug_compile_unit, // Scope | 2308 | o.debug_compile_unit, // Scope |
| 2309 | 0, // Line | 2309 | 0, // Line |
| ... | @@ -2361,7 +2361,7 @@ pub const Object = struct { | ... | @@ -2361,7 +2361,7 @@ pub const Object = struct { |
| 2361 | 2361 | ||
| 2362 | var fields: [2]Builder.Metadata = undefined; | 2362 | var fields: [2]Builder.Metadata = undefined; |
| 2363 | fields[error_index] = try o.builder.debugMemberType( | 2363 | fields[error_index] = try o.builder.debugMemberType( |
| 2364 | try o.builder.string("tag"), | 2364 | try o.builder.metadataString("tag"), |
| 2365 | Builder.Metadata.none, // File | 2365 | Builder.Metadata.none, // File |
| 2366 | debug_fwd_ref, | 2366 | debug_fwd_ref, |
| 2367 | 0, // Line | 2367 | 0, // Line |
| ... | @@ -2371,7 +2371,7 @@ pub const Object = struct { | ... | @@ -2371,7 +2371,7 @@ pub const Object = struct { |
| 2371 | error_offset * 8, | 2371 | error_offset * 8, |
| 2372 | ); | 2372 | ); |
| 2373 | fields[payload_index] = try o.builder.debugMemberType( | 2373 | fields[payload_index] = try o.builder.debugMemberType( |
| 2374 | try o.builder.string("value"), | 2374 | try o.builder.metadataString("value"), |
| 2375 | Builder.Metadata.none, // File | 2375 | Builder.Metadata.none, // File |
| 2376 | debug_fwd_ref, | 2376 | debug_fwd_ref, |
| 2377 | 0, // Line | 2377 | 0, // Line |
| ... | @@ -2382,7 +2382,7 @@ pub const Object = struct { | ... | @@ -2382,7 +2382,7 @@ pub const Object = struct { |
| 2382 | ); | 2382 | ); |
| 2383 | 2383 | ||
| 2384 | const debug_error_union_type = try o.builder.debugStructType( | 2384 | const debug_error_union_type = try o.builder.debugStructType( |
| 2385 | try o.builder.string(name), | 2385 | try o.builder.metadataString(name), |
| 2386 | Builder.Metadata.none, // File | 2386 | Builder.Metadata.none, // File |
| 2387 | o.debug_compile_unit, // Sope | 2387 | o.debug_compile_unit, // Sope |
| 2388 | 0, // Line | 2388 | 0, // Line |
| ... | @@ -2399,7 +2399,7 @@ pub const Object = struct { | ... | @@ -2399,7 +2399,7 @@ pub const Object = struct { |
| 2399 | }, | 2399 | }, |
| 2400 | .ErrorSet => { | 2400 | .ErrorSet => { |
| 2401 | const debug_error_set = try o.builder.debugUnsignedType( | 2401 | const debug_error_set = try o.builder.debugUnsignedType( |
| 2402 | try o.builder.string("anyerror"), | 2402 | try o.builder.metadataString("anyerror"), |
| 2403 | 16, | 2403 | 16, |
| 2404 | ); | 2404 | ); |
| 2405 | try o.debug_type_map.put(gpa, ty, debug_error_set); | 2405 | try o.debug_type_map.put(gpa, ty, debug_error_set); |
| ... | @@ -2413,7 +2413,7 @@ pub const Object = struct { | ... | @@ -2413,7 +2413,7 @@ pub const Object = struct { |
| 2413 | const backing_int_ty = struct_type.backingIntType(ip).*; | 2413 | const backing_int_ty = struct_type.backingIntType(ip).*; |
| 2414 | if (backing_int_ty != .none) { | 2414 | if (backing_int_ty != .none) { |
| 2415 | const info = Type.fromInterned(backing_int_ty).intInfo(mod); | 2415 | const info = Type.fromInterned(backing_int_ty).intInfo(mod); |
| 2416 | const builder_name = try o.builder.string(name); | 2416 | const builder_name = try o.builder.metadataString(name); |
| 2417 | const debug_int_type = switch (info.signedness) { | 2417 | const debug_int_type = switch (info.signedness) { |
| 2418 | .signed => try o.builder.debugSignedType(builder_name, ty.abiSize(mod) * 8), | 2418 | .signed => try o.builder.debugSignedType(builder_name, ty.abiSize(mod) * 8), |
| 2419 | .unsigned => try o.builder.debugUnsignedType(builder_name, ty.abiSize(mod) * 8), | 2419 | .unsigned => try o.builder.debugUnsignedType(builder_name, ty.abiSize(mod) * 8), |
| ... | @@ -2450,7 +2450,7 @@ pub const Object = struct { | ... | @@ -2450,7 +2450,7 @@ pub const Object = struct { |
| 2450 | defer if (tuple.names.len == 0) gpa.free(field_name); | 2450 | defer if (tuple.names.len == 0) gpa.free(field_name); |
| 2451 | 2451 | ||
| 2452 | fields.appendAssumeCapacity(try o.builder.debugMemberType( | 2452 | fields.appendAssumeCapacity(try o.builder.debugMemberType( |
| 2453 | try o.builder.string(field_name), | 2453 | try o.builder.metadataString(field_name), |
| 2454 | Builder.Metadata.none, // File | 2454 | Builder.Metadata.none, // File |
| 2455 | debug_fwd_ref, | 2455 | debug_fwd_ref, |
| 2456 | 0, | 2456 | 0, |
| ... | @@ -2462,7 +2462,7 @@ pub const Object = struct { | ... | @@ -2462,7 +2462,7 @@ pub const Object = struct { |
| 2462 | } | 2462 | } |
| 2463 | 2463 | ||
| 2464 | const debug_struct_type = try o.builder.debugStructType( | 2464 | const debug_struct_type = try o.builder.debugStructType( |
| 2465 | try o.builder.string(name), | 2465 | try o.builder.metadataString(name), |
| 2466 | Builder.Metadata.none, // File | 2466 | Builder.Metadata.none, // File |
| 2467 | o.debug_compile_unit, // Scope | 2467 | o.debug_compile_unit, // Scope |
| 2468 | 0, // Line | 2468 | 0, // Line |
| ... | @@ -2531,7 +2531,7 @@ pub const Object = struct { | ... | @@ -2531,7 +2531,7 @@ pub const Object = struct { |
| 2531 | try ip.getOrPutStringFmt(gpa, "{d}", .{field_index}); | 2531 | try ip.getOrPutStringFmt(gpa, "{d}", .{field_index}); |
| 2532 | 2532 | ||
| 2533 | fields.appendAssumeCapacity(try o.builder.debugMemberType( | 2533 | fields.appendAssumeCapacity(try o.builder.debugMemberType( |
| 2534 | try o.builder.string(ip.stringToSlice(field_name)), | 2534 | try o.builder.metadataString(ip.stringToSlice(field_name)), |
| 2535 | Builder.Metadata.none, // File | 2535 | Builder.Metadata.none, // File |
| 2536 | debug_fwd_ref, | 2536 | debug_fwd_ref, |
| 2537 | 0, // Line | 2537 | 0, // Line |
| ... | @@ -2543,7 +2543,7 @@ pub const Object = struct { | ... | @@ -2543,7 +2543,7 @@ pub const Object = struct { |
| 2543 | } | 2543 | } |
| 2544 | 2544 | ||
| 2545 | const debug_struct_type = try o.builder.debugStructType( | 2545 | const debug_struct_type = try o.builder.debugStructType( |
| 2546 | try o.builder.string(name), | 2546 | try o.builder.metadataString(name), |
| 2547 | Builder.Metadata.none, // File | 2547 | Builder.Metadata.none, // File |
| 2548 | o.debug_compile_unit, // Scope | 2548 | o.debug_compile_unit, // Scope |
| 2549 | 0, // Line | 2549 | 0, // Line |
| ... | @@ -2584,7 +2584,7 @@ pub const Object = struct { | ... | @@ -2584,7 +2584,7 @@ pub const Object = struct { |
| 2584 | 2584 | ||
| 2585 | if (layout.payload_size == 0) { | 2585 | if (layout.payload_size == 0) { |
| 2586 | const debug_union_type = try o.builder.debugStructType( | 2586 | const debug_union_type = try o.builder.debugStructType( |
| 2587 | try o.builder.string(name), | 2587 | try o.builder.metadataString(name), |
| 2588 | Builder.Metadata.none, // File | 2588 | Builder.Metadata.none, // File |
| 2589 | o.debug_compile_unit, // Scope | 2589 | o.debug_compile_unit, // Scope |
| 2590 | 0, // Line | 2590 | 0, // Line |
| ... | @@ -2622,7 +2622,7 @@ pub const Object = struct { | ... | @@ -2622,7 +2622,7 @@ pub const Object = struct { |
| 2622 | 2622 | ||
| 2623 | const field_name = union_obj.field_names.get(ip)[field_index]; | 2623 | const field_name = union_obj.field_names.get(ip)[field_index]; |
| 2624 | fields.appendAssumeCapacity(try o.builder.debugMemberType( | 2624 | fields.appendAssumeCapacity(try o.builder.debugMemberType( |
| 2625 | try o.builder.string(ip.stringToSlice(field_name)), | 2625 | try o.builder.metadataString(ip.stringToSlice(field_name)), |
| 2626 | Builder.Metadata.none, // File | 2626 | Builder.Metadata.none, // File |
| 2627 | debug_union_fwd_ref, | 2627 | debug_union_fwd_ref, |
| 2628 | 0, // Line | 2628 | 0, // Line |
| ... | @@ -2641,7 +2641,7 @@ pub const Object = struct { | ... | @@ -2641,7 +2641,7 @@ pub const Object = struct { |
| 2641 | }; | 2641 | }; |
| 2642 | 2642 | ||
| 2643 | const debug_union_type = try o.builder.debugUnionType( | 2643 | const debug_union_type = try o.builder.debugUnionType( |
| 2644 | try o.builder.string(union_name), | 2644 | try o.builder.metadataString(union_name), |
| 2645 | Builder.Metadata.none, // File | 2645 | Builder.Metadata.none, // File |
| 2646 | o.debug_compile_unit, // Scope | 2646 | o.debug_compile_unit, // Scope |
| 2647 | 0, // Line | 2647 | 0, // Line |
| ... | @@ -2672,7 +2672,7 @@ pub const Object = struct { | ... | @@ -2672,7 +2672,7 @@ pub const Object = struct { |
| 2672 | } | 2672 | } |
| 2673 | 2673 | ||
| 2674 | const debug_tag_type = try o.builder.debugMemberType( | 2674 | const debug_tag_type = try o.builder.debugMemberType( |
| 2675 | try o.builder.string("tag"), | 2675 | try o.builder.metadataString("tag"), |
| 2676 | Builder.Metadata.none, // File | 2676 | Builder.Metadata.none, // File |
| 2677 | debug_fwd_ref, | 2677 | debug_fwd_ref, |
| 2678 | 0, // Line | 2678 | 0, // Line |
| ... | @@ -2683,7 +2683,7 @@ pub const Object = struct { | ... | @@ -2683,7 +2683,7 @@ pub const Object = struct { |
| 2683 | ); | 2683 | ); |
| 2684 | 2684 | ||
| 2685 | const debug_payload_type = try o.builder.debugMemberType( | 2685 | const debug_payload_type = try o.builder.debugMemberType( |
| 2686 | try o.builder.string("payload"), | 2686 | try o.builder.metadataString("payload"), |
| 2687 | Builder.Metadata.none, // File | 2687 | Builder.Metadata.none, // File |
| 2688 | debug_fwd_ref, | 2688 | debug_fwd_ref, |
| 2689 | 0, // Line | 2689 | 0, // Line |
| ... | @@ -2700,7 +2700,7 @@ pub const Object = struct { | ... | @@ -2700,7 +2700,7 @@ pub const Object = struct { |
| 2700 | .{ debug_payload_type, debug_tag_type }; | 2700 | .{ debug_payload_type, debug_tag_type }; |
| 2701 | 2701 | ||
| 2702 | const debug_tagged_union_type = try o.builder.debugStructType( | 2702 | const debug_tagged_union_type = try o.builder.debugStructType( |
| 2703 | try o.builder.string(name), | 2703 | try o.builder.metadataString(name), |
| 2704 | Builder.Metadata.none, // File | 2704 | Builder.Metadata.none, // File |
| 2705 | o.debug_compile_unit, // Scope | 2705 | o.debug_compile_unit, // Scope |
| 2706 | 0, // Line | 2706 | 0, // Line |
| ... | @@ -2794,7 +2794,7 @@ pub const Object = struct { | ... | @@ -2794,7 +2794,7 @@ pub const Object = struct { |
| 2794 | const mod = o.module; | 2794 | const mod = o.module; |
| 2795 | const decl = mod.declPtr(decl_index); | 2795 | const decl = mod.declPtr(decl_index); |
| 2796 | return o.builder.debugStructType( | 2796 | return o.builder.debugStructType( |
| 2797 | try o.builder.string(mod.intern_pool.stringToSlice(decl.name)), // TODO use fully qualified name | 2797 | try o.builder.metadataString(mod.intern_pool.stringToSlice(decl.name)), // TODO use fully qualified name |
| 2798 | try o.getDebugFile(mod.namespacePtr(decl.src_namespace).file_scope), | 2798 | try o.getDebugFile(mod.namespacePtr(decl.src_namespace).file_scope), |
| 2799 | try o.namespaceToDebugScope(decl.src_namespace), | 2799 | try o.namespaceToDebugScope(decl.src_namespace), |
| 2800 | decl.src_line + 1, | 2800 | decl.src_line + 1, |
| ... | @@ -4699,8 +4699,8 @@ pub const DeclGen = struct { | ... | @@ -4699,8 +4699,8 @@ pub const DeclGen = struct { |
| 4699 | const debug_file = try o.getDebugFile(mod.namespacePtr(decl.src_namespace).file_scope); | 4699 | const debug_file = try o.getDebugFile(mod.namespacePtr(decl.src_namespace).file_scope); |
| 4700 | 4700 | ||
| 4701 | const debug_global_var = try o.builder.debugGlobalVar( | 4701 | const debug_global_var = try o.builder.debugGlobalVar( |
| 4702 | try o.builder.string(mod.intern_pool.stringToSlice(decl.name)), // Name | 4702 | try o.builder.metadataString(mod.intern_pool.stringToSlice(decl.name)), // Name |
| 4703 | variable_index.name(&o.builder), // Linkage name | 4703 | try o.builder.metadataStringFromString(variable_index.name(&o.builder)), // Linkage name |
| 4704 | debug_file, // File | 4704 | debug_file, // File |
| 4705 | debug_file, // Scope | 4705 | debug_file, // Scope |
| 4706 | line_number, | 4706 | line_number, |
| ... | @@ -6678,7 +6678,7 @@ pub const FuncGen = struct { | ... | @@ -6678,7 +6678,7 @@ pub const FuncGen = struct { |
| 6678 | const ptr_ty = self.typeOf(pl_op.operand); | 6678 | const ptr_ty = self.typeOf(pl_op.operand); |
| 6679 | 6679 | ||
| 6680 | const debug_local_var = try o.builder.debugLocalVar( | 6680 | const debug_local_var = try o.builder.debugLocalVar( |
| 6681 | try o.builder.string(name), | 6681 | try o.builder.metadataString(name), |
| 6682 | self.file, | 6682 | self.file, |
| 6683 | self.current_scope, | 6683 | self.current_scope, |
| 6684 | self.prev_dbg_line, | 6684 | self.prev_dbg_line, |
| ... | @@ -6712,7 +6712,7 @@ pub const FuncGen = struct { | ... | @@ -6712,7 +6712,7 @@ pub const FuncGen = struct { |
| 6712 | if (needDbgVarWorkaround(o)) return .none; | 6712 | if (needDbgVarWorkaround(o)) return .none; |
| 6713 | 6713 | ||
| 6714 | const debug_local_var = try o.builder.debugLocalVar( | 6714 | const debug_local_var = try o.builder.debugLocalVar( |
| 6715 | try o.builder.string(name), | 6715 | try o.builder.metadataString(name), |
| 6716 | self.file, | 6716 | self.file, |
| 6717 | self.current_scope, | 6717 | self.current_scope, |
| 6718 | self.prev_dbg_line, | 6718 | self.prev_dbg_line, |
| ... | @@ -8796,7 +8796,7 @@ pub const FuncGen = struct { | ... | @@ -8796,7 +8796,7 @@ pub const FuncGen = struct { |
| 8796 | const lbrace_col = func.lbrace_column + 1; | 8796 | const lbrace_col = func.lbrace_column + 1; |
| 8797 | 8797 | ||
| 8798 | const debug_parameter = try o.builder.debugParameter( | 8798 | const debug_parameter = try o.builder.debugParameter( |
| 8799 | try o.builder.string(mod.getParamName(func_index, src_index)), | 8799 | try o.builder.metadataString(mod.getParamName(func_index, src_index)), |
| 8800 | self.file, | 8800 | self.file, |
| 8801 | self.current_scope, | 8801 | self.current_scope, |
| 8802 | lbrace_line, | 8802 | lbrace_line, |
src/codegen/llvm/Builder.zig+137-89| ... | @@ -40,14 +40,17 @@ constant_limbs: std.ArrayListUnmanaged(std.math.big.Limb), | ... | @@ -40,14 +40,17 @@ constant_limbs: std.ArrayListUnmanaged(std.math.big.Limb), |
| 40 | metadata_map: std.AutoArrayHashMapUnmanaged(void, void), | 40 | metadata_map: std.AutoArrayHashMapUnmanaged(void, void), |
| 41 | metadata_items: std.MultiArrayList(Metadata.Item), | 41 | metadata_items: std.MultiArrayList(Metadata.Item), |
| 42 | metadata_extra: std.ArrayListUnmanaged(u32), | 42 | metadata_extra: std.ArrayListUnmanaged(u32), |
| 43 | metadata_strings: std.AutoArrayHashMapUnmanaged(String, void), | ||
| 44 | metadata_limbs: std.ArrayListUnmanaged(std.math.big.Limb), | 43 | metadata_limbs: std.ArrayListUnmanaged(std.math.big.Limb), |
| 45 | metadata_forward_references: std.ArrayListUnmanaged(Metadata), | 44 | metadata_forward_references: std.ArrayListUnmanaged(Metadata), |
| 46 | metadata_named: std.AutoArrayHashMapUnmanaged(String, struct { | 45 | metadata_named: std.AutoArrayHashMapUnmanaged(MetadataString, struct { |
| 47 | len: u32, | 46 | len: u32, |
| 48 | index: Metadata.Item.ExtraIndex, | 47 | index: Metadata.Item.ExtraIndex, |
| 49 | }), | 48 | }), |
| 50 | 49 | ||
| 50 | metadata_string_map: std.AutoArrayHashMapUnmanaged(void, void), | ||
| 51 | metadata_string_indices: std.ArrayListUnmanaged(u32), | ||
| 52 | metadata_string_bytes: std.ArrayListUnmanaged(u8), | ||
| 53 | |||
| 51 | pub const expected_args_len = 16; | 54 | pub const expected_args_len = 16; |
| 52 | pub const expected_attrs_len = 16; | 55 | pub const expected_attrs_len = 16; |
| 53 | pub const expected_fields_len = 32; | 56 | pub const expected_fields_len = 32; |
| ... | @@ -7553,7 +7556,26 @@ pub const Value = enum(u32) { | ... | @@ -7553,7 +7556,26 @@ pub const Value = enum(u32) { |
| 7553 | }; | 7556 | }; |
| 7554 | 7557 | ||
| 7555 | pub const MetadataString = enum(u32) { | 7558 | pub const MetadataString = enum(u32) { |
| 7559 | none = 0, | ||
| 7556 | _, | 7560 | _, |
| 7561 | |||
| 7562 | pub fn slice(self: MetadataString, b: *const Builder) []const u8 { | ||
| 7563 | const index = @intFromEnum(self); | ||
| 7564 | const start = b.metadata_string_indices.items[index]; | ||
| 7565 | const end = b.metadata_string_indices.items[index + 1]; | ||
| 7566 | return b.metadata_string_bytes.items[start..end]; | ||
| 7567 | } | ||
| 7568 | |||
| 7569 | const Adapter = struct { | ||
| 7570 | builder: *const Builder, | ||
| 7571 | pub fn hash(_: Adapter, key: []const u8) u32 { | ||
| 7572 | return @truncate(std.hash.Wyhash.hash(0, key)); | ||
| 7573 | } | ||
| 7574 | pub fn eql(ctx: Adapter, lhs_key: []const u8, _: void, rhs_index: usize) bool { | ||
| 7575 | const rhs_metadata_string: MetadataString = @enumFromInt(rhs_index); | ||
| 7576 | return std.mem.eql(u8, lhs_key, rhs_metadata_string.slice(ctx.builder)); | ||
| 7577 | } | ||
| 7578 | }; | ||
| 7557 | }; | 7579 | }; |
| 7558 | 7580 | ||
| 7559 | pub const Metadata = enum(u32) { | 7581 | pub const Metadata = enum(u32) { |
| ... | @@ -7829,10 +7851,12 @@ pub fn init(options: Options) InitError!Builder { | ... | @@ -7829,10 +7851,12 @@ pub fn init(options: Options) InitError!Builder { |
| 7829 | .metadata_map = .{}, | 7851 | .metadata_map = .{}, |
| 7830 | .metadata_items = .{}, | 7852 | .metadata_items = .{}, |
| 7831 | .metadata_extra = .{}, | 7853 | .metadata_extra = .{}, |
| 7832 | .metadata_strings = .{}, | ||
| 7833 | .metadata_limbs = .{}, | 7854 | .metadata_limbs = .{}, |
| 7834 | .metadata_forward_references = .{}, | 7855 | .metadata_forward_references = .{}, |
| 7835 | .metadata_named = .{}, | 7856 | .metadata_named = .{}, |
| 7857 | .metadata_string_map = .{}, | ||
| 7858 | .metadata_string_indices = .{}, | ||
| 7859 | .metadata_string_bytes = .{}, | ||
| 7836 | }; | 7860 | }; |
| 7837 | errdefer self.deinit(); | 7861 | errdefer self.deinit(); |
| 7838 | 7862 | ||
| ... | @@ -7876,6 +7900,9 @@ pub fn init(options: Options) InitError!Builder { | ... | @@ -7876,6 +7900,9 @@ pub fn init(options: Options) InitError!Builder { |
| 7876 | assert(try self.noneConst(.token) == .none); | 7900 | assert(try self.noneConst(.token) == .none); |
| 7877 | assert(try self.debugNone() == .none); | 7901 | assert(try self.debugNone() == .none); |
| 7878 | 7902 | ||
| 7903 | try self.metadata_string_indices.append(self.gpa, 0); | ||
| 7904 | assert(try self.metadataString("") == .none); | ||
| 7905 | |||
| 7879 | return self; | 7906 | return self; |
| 7880 | } | 7907 | } |
| 7881 | 7908 | ||
| ... | @@ -7914,11 +7941,14 @@ pub fn deinit(self: *Builder) void { | ... | @@ -7914,11 +7941,14 @@ pub fn deinit(self: *Builder) void { |
| 7914 | self.metadata_map.deinit(self.gpa); | 7941 | self.metadata_map.deinit(self.gpa); |
| 7915 | self.metadata_items.deinit(self.gpa); | 7942 | self.metadata_items.deinit(self.gpa); |
| 7916 | self.metadata_extra.deinit(self.gpa); | 7943 | self.metadata_extra.deinit(self.gpa); |
| 7917 | self.metadata_strings.deinit(self.gpa); | ||
| 7918 | self.metadata_limbs.deinit(self.gpa); | 7944 | self.metadata_limbs.deinit(self.gpa); |
| 7919 | self.metadata_forward_references.deinit(self.gpa); | 7945 | self.metadata_forward_references.deinit(self.gpa); |
| 7920 | self.metadata_named.deinit(self.gpa); | 7946 | self.metadata_named.deinit(self.gpa); |
| 7921 | 7947 | ||
| 7948 | self.metadata_string_map.deinit(self.gpa); | ||
| 7949 | self.metadata_string_indices.deinit(self.gpa); | ||
| 7950 | self.metadata_string_bytes.deinit(self.gpa); | ||
| 7951 | |||
| 7922 | self.* = undefined; | 7952 | self.* = undefined; |
| 7923 | } | 7953 | } |
| 7924 | 7954 | ||
| ... | @@ -10913,14 +10943,51 @@ fn metadataExtraData(self: *const Builder, comptime T: type, index: Metadata.Ite | ... | @@ -10913,14 +10943,51 @@ fn metadataExtraData(self: *const Builder, comptime T: type, index: Metadata.Ite |
| 10913 | return self.metadataExtraDataTrail(T, index).data; | 10943 | return self.metadataExtraDataTrail(T, index).data; |
| 10914 | } | 10944 | } |
| 10915 | 10945 | ||
| 10916 | fn metadataString(self: *Builder, str: String) Allocator.Error!MetadataString { | 10946 | pub fn metadataString(self: *Builder, bytes: []const u8) Allocator.Error!MetadataString { |
| 10917 | const gop = try self.metadata_strings.getOrPut(self.gpa, str); | 10947 | try self.metadata_string_bytes.ensureUnusedCapacity(self.gpa, bytes.len); |
| 10918 | if (!gop.found_existing) gop.key_ptr.* = str; | 10948 | try self.metadata_string_indices.ensureUnusedCapacity(self.gpa, 1); |
| 10949 | try self.metadata_string_map.ensureUnusedCapacity(self.gpa, 1); | ||
| 10950 | |||
| 10951 | const gop = self.metadata_string_map.getOrPutAssumeCapacityAdapted( | ||
| 10952 | bytes, | ||
| 10953 | MetadataString.Adapter{ .builder = self }, | ||
| 10954 | ); | ||
| 10955 | if (!gop.found_existing) { | ||
| 10956 | self.metadata_string_bytes.appendSliceAssumeCapacity(bytes); | ||
| 10957 | self.metadata_string_indices.appendAssumeCapacity(@intCast(self.metadata_string_bytes.items.len)); | ||
| 10958 | } | ||
| 10959 | return @enumFromInt(gop.index); | ||
| 10960 | } | ||
| 10961 | |||
| 10962 | pub fn metadataStringFromString(self: *Builder, str: String) Allocator.Error!MetadataString { | ||
| 10963 | if (str == .none or str == .empty) return MetadataString.none; | ||
| 10964 | |||
| 10965 | const slice = str.slice(self) orelse unreachable; | ||
| 10966 | return try self.metadataString(slice); | ||
| 10967 | } | ||
| 10968 | |||
| 10969 | pub fn metadataStringFmt(self: *Builder, comptime fmt_str: []const u8, fmt_args: anytype) Allocator.Error!MetadataString { | ||
| 10970 | try self.metadata_string_map.ensureUnusedCapacity(self.gpa, 1); | ||
| 10971 | try self.metadata_string_bytes.ensureUnusedCapacity(self.gpa, @intCast(std.fmt.count(fmt_str, fmt_args))); | ||
| 10972 | try self.metadata_string_indices.ensureUnusedCapacity(self.gpa, 1); | ||
| 10973 | return self.metadataStringFmtAssumeCapacity(fmt_str, fmt_args); | ||
| 10974 | } | ||
| 10919 | 10975 | ||
| 10976 | pub fn metadataStringFmtAssumeCapacity(self: *Builder, comptime fmt_str: []const u8, fmt_args: anytype) MetadataString { | ||
| 10977 | const start = self.metadata_string_bytes.items.len; | ||
| 10978 | self.metadata_string_bytes.writer(self.gpa).print(fmt_str, fmt_args) catch unreachable; | ||
| 10979 | const bytes: []const u8 = self.metadata_string_bytes.items[start..self.metadata_string_bytes.items.len]; | ||
| 10980 | |||
| 10981 | const gop = self.metadata_string_map.getOrPutAssumeCapacityAdapted(bytes, String.Adapter{ .builder = self }); | ||
| 10982 | if (gop.found_existing) { | ||
| 10983 | self.metadata_string_bytes.shrinkRetainingCapacity(start); | ||
| 10984 | } else { | ||
| 10985 | self.metadata_string_indices.appendAssumeCapacity(@intCast(self.metadata_string_bytes.items.len)); | ||
| 10986 | } | ||
| 10920 | return @enumFromInt(gop.index); | 10987 | return @enumFromInt(gop.index); |
| 10921 | } | 10988 | } |
| 10922 | 10989 | ||
| 10923 | pub fn debugNamed(self: *Builder, name: String, operands: []const Metadata) Allocator.Error!void { | 10990 | pub fn debugNamed(self: *Builder, name: MetadataString, operands: []const Metadata) Allocator.Error!void { |
| 10924 | try self.metadata_extra.ensureUnusedCapacity( | 10991 | try self.metadata_extra.ensureUnusedCapacity( |
| 10925 | self.gpa, | 10992 | self.gpa, |
| 10926 | operands.len * @sizeOf(Metadata), | 10993 | operands.len * @sizeOf(Metadata), |
| ... | @@ -10934,31 +11001,28 @@ fn debugNone(self: *Builder) Allocator.Error!Metadata { | ... | @@ -10934,31 +11001,28 @@ fn debugNone(self: *Builder) Allocator.Error!Metadata { |
| 10934 | return self.debugNoneAssumeCapacity(); | 11001 | return self.debugNoneAssumeCapacity(); |
| 10935 | } | 11002 | } |
| 10936 | 11003 | ||
| 10937 | pub fn debugFile(self: *Builder, path: String, name: String) Allocator.Error!Metadata { | 11004 | pub fn debugFile(self: *Builder, path: MetadataString, name: MetadataString) Allocator.Error!Metadata { |
| 10938 | try self.ensureUnusedMetadataCapacity(1, Metadata.File, 0); | 11005 | try self.ensureUnusedMetadataCapacity(1, Metadata.File, 0); |
| 10939 | const metadata_path = try self.metadataString(path); | 11006 | return self.debugFileAssumeCapacity(path, name); |
| 10940 | const metadata_name = try self.metadataString(name); | ||
| 10941 | return self.debugFileAssumeCapacity(metadata_path, metadata_name); | ||
| 10942 | } | 11007 | } |
| 10943 | 11008 | ||
| 10944 | pub fn debugCompileUnit( | 11009 | pub fn debugCompileUnit( |
| 10945 | self: *Builder, | 11010 | self: *Builder, |
| 10946 | file: Metadata, | 11011 | file: Metadata, |
| 10947 | producer: String, | 11012 | producer: MetadataString, |
| 10948 | enums: Metadata, | 11013 | enums: Metadata, |
| 10949 | globals: Metadata, | 11014 | globals: Metadata, |
| 10950 | flags: Metadata.CompileUnit.Flags, | 11015 | flags: Metadata.CompileUnit.Flags, |
| 10951 | ) Allocator.Error!Metadata { | 11016 | ) Allocator.Error!Metadata { |
| 10952 | try self.ensureUnusedMetadataCapacity(1, Metadata.CompileUnit, 0); | 11017 | try self.ensureUnusedMetadataCapacity(1, Metadata.CompileUnit, 0); |
| 10953 | const metadata_producer = try self.metadataString(producer); | 11018 | return self.debugCompileUnitAssumeCapacity(file, producer, enums, globals, flags); |
| 10954 | return self.debugCompileUnitAssumeCapacity(file, metadata_producer, enums, globals, flags); | ||
| 10955 | } | 11019 | } |
| 10956 | 11020 | ||
| 10957 | pub fn debugSubprogram( | 11021 | pub fn debugSubprogram( |
| 10958 | self: *Builder, | 11022 | self: *Builder, |
| 10959 | file: Metadata, | 11023 | file: Metadata, |
| 10960 | name: String, | 11024 | name: MetadataString, |
| 10961 | linkage_name: String, | 11025 | linkage_name: MetadataString, |
| 10962 | line: u32, | 11026 | line: u32, |
| 10963 | scope_line: u32, | 11027 | scope_line: u32, |
| 10964 | ty: Metadata, | 11028 | ty: Metadata, |
| ... | @@ -10966,12 +11030,10 @@ pub fn debugSubprogram( | ... | @@ -10966,12 +11030,10 @@ pub fn debugSubprogram( |
| 10966 | compile_unit: Metadata, | 11030 | compile_unit: Metadata, |
| 10967 | ) Allocator.Error!Metadata { | 11031 | ) Allocator.Error!Metadata { |
| 10968 | try self.ensureUnusedMetadataCapacity(1, Metadata.Subprogram, 0); | 11032 | try self.ensureUnusedMetadataCapacity(1, Metadata.Subprogram, 0); |
| 10969 | const metadata_name = try self.metadataString(name); | ||
| 10970 | const metadata_linkage_name = try self.metadataString(linkage_name); | ||
| 10971 | return self.debugSubprogramAssumeCapacity( | 11033 | return self.debugSubprogramAssumeCapacity( |
| 10972 | file, | 11034 | file, |
| 10973 | metadata_name, | 11035 | name, |
| 10974 | metadata_linkage_name, | 11036 | linkage_name, |
| 10975 | line, | 11037 | line, |
| 10976 | scope_line, | 11038 | scope_line, |
| 10977 | ty, | 11039 | ty, |
| ... | @@ -10990,28 +11052,24 @@ pub fn debugLocation(self: *Builder, scope: Metadata, line: u32, column: u32, in | ... | @@ -10990,28 +11052,24 @@ pub fn debugLocation(self: *Builder, scope: Metadata, line: u32, column: u32, in |
| 10990 | return self.debugLocationAssumeCapacity(scope, line, column, inlined_at); | 11052 | return self.debugLocationAssumeCapacity(scope, line, column, inlined_at); |
| 10991 | } | 11053 | } |
| 10992 | 11054 | ||
| 10993 | pub fn debugBoolType(self: *Builder, name: String, size_in_bits: u64) Allocator.Error!Metadata { | 11055 | pub fn debugBoolType(self: *Builder, name: MetadataString, size_in_bits: u64) Allocator.Error!Metadata { |
| 10994 | try self.ensureUnusedMetadataCapacity(1, Metadata.BasicType, 0); | 11056 | try self.ensureUnusedMetadataCapacity(1, Metadata.BasicType, 0); |
| 10995 | const metadata_name = try self.metadataString(name); | 11057 | return self.debugBoolTypeAssumeCapacity(name, size_in_bits); |
| 10996 | return self.debugBoolTypeAssumeCapacity(metadata_name, size_in_bits); | ||
| 10997 | } | 11058 | } |
| 10998 | 11059 | ||
| 10999 | pub fn debugUnsignedType(self: *Builder, name: String, size_in_bits: u64) Allocator.Error!Metadata { | 11060 | pub fn debugUnsignedType(self: *Builder, name: MetadataString, size_in_bits: u64) Allocator.Error!Metadata { |
| 11000 | try self.ensureUnusedMetadataCapacity(1, Metadata.BasicType, 0); | 11061 | try self.ensureUnusedMetadataCapacity(1, Metadata.BasicType, 0); |
| 11001 | const metadata_name = try self.metadataString(name); | 11062 | return self.debugUnsignedTypeAssumeCapacity(name, size_in_bits); |
| 11002 | return self.debugUnsignedTypeAssumeCapacity(metadata_name, size_in_bits); | ||
| 11003 | } | 11063 | } |
| 11004 | 11064 | ||
| 11005 | pub fn debugSignedType(self: *Builder, name: String, size_in_bits: u64) Allocator.Error!Metadata { | 11065 | pub fn debugSignedType(self: *Builder, name: MetadataString, size_in_bits: u64) Allocator.Error!Metadata { |
| 11006 | try self.ensureUnusedMetadataCapacity(1, Metadata.BasicType, 0); | 11066 | try self.ensureUnusedMetadataCapacity(1, Metadata.BasicType, 0); |
| 11007 | const metadata_name = try self.metadataString(name); | 11067 | return self.debugSignedTypeAssumeCapacity(name, size_in_bits); |
| 11008 | return self.debugSignedTypeAssumeCapacity(metadata_name, size_in_bits); | ||
| 11009 | } | 11068 | } |
| 11010 | 11069 | ||
| 11011 | pub fn debugFloatType(self: *Builder, name: String, size_in_bits: u64) Allocator.Error!Metadata { | 11070 | pub fn debugFloatType(self: *Builder, name: MetadataString, size_in_bits: u64) Allocator.Error!Metadata { |
| 11012 | try self.ensureUnusedMetadataCapacity(1, Metadata.BasicType, 0); | 11071 | try self.ensureUnusedMetadataCapacity(1, Metadata.BasicType, 0); |
| 11013 | const metadata_name = try self.metadataString(name); | 11072 | return self.debugFloatTypeAssumeCapacity(name, size_in_bits); |
| 11014 | return self.debugFloatTypeAssumeCapacity(metadata_name, size_in_bits); | ||
| 11015 | } | 11073 | } |
| 11016 | 11074 | ||
| 11017 | pub fn debugForwardReference(self: *Builder) Allocator.Error!Metadata { | 11075 | pub fn debugForwardReference(self: *Builder) Allocator.Error!Metadata { |
| ... | @@ -11021,7 +11079,7 @@ pub fn debugForwardReference(self: *Builder) Allocator.Error!Metadata { | ... | @@ -11021,7 +11079,7 @@ pub fn debugForwardReference(self: *Builder) Allocator.Error!Metadata { |
| 11021 | 11079 | ||
| 11022 | pub fn debugStructType( | 11080 | pub fn debugStructType( |
| 11023 | self: *Builder, | 11081 | self: *Builder, |
| 11024 | name: String, | 11082 | name: MetadataString, |
| 11025 | file: Metadata, | 11083 | file: Metadata, |
| 11026 | scope: Metadata, | 11084 | scope: Metadata, |
| 11027 | line: u32, | 11085 | line: u32, |
| ... | @@ -11031,9 +11089,8 @@ pub fn debugStructType( | ... | @@ -11031,9 +11089,8 @@ pub fn debugStructType( |
| 11031 | fields_tuple: Metadata, | 11089 | fields_tuple: Metadata, |
| 11032 | ) Allocator.Error!Metadata { | 11090 | ) Allocator.Error!Metadata { |
| 11033 | try self.ensureUnusedMetadataCapacity(1, Metadata.CompositeType, 0); | 11091 | try self.ensureUnusedMetadataCapacity(1, Metadata.CompositeType, 0); |
| 11034 | const metadata_name = try self.metadataString(name); | ||
| 11035 | return self.debugStructTypeAssumeCapacity( | 11092 | return self.debugStructTypeAssumeCapacity( |
| 11036 | metadata_name, | 11093 | name, |
| 11037 | file, | 11094 | file, |
| 11038 | scope, | 11095 | scope, |
| 11039 | line, | 11096 | line, |
| ... | @@ -11046,7 +11103,7 @@ pub fn debugStructType( | ... | @@ -11046,7 +11103,7 @@ pub fn debugStructType( |
| 11046 | 11103 | ||
| 11047 | pub fn debugUnionType( | 11104 | pub fn debugUnionType( |
| 11048 | self: *Builder, | 11105 | self: *Builder, |
| 11049 | name: String, | 11106 | name: MetadataString, |
| 11050 | file: Metadata, | 11107 | file: Metadata, |
| 11051 | scope: Metadata, | 11108 | scope: Metadata, |
| 11052 | line: u32, | 11109 | line: u32, |
| ... | @@ -11056,9 +11113,8 @@ pub fn debugUnionType( | ... | @@ -11056,9 +11113,8 @@ pub fn debugUnionType( |
| 11056 | fields_tuple: Metadata, | 11113 | fields_tuple: Metadata, |
| 11057 | ) Allocator.Error!Metadata { | 11114 | ) Allocator.Error!Metadata { |
| 11058 | try self.ensureUnusedMetadataCapacity(1, Metadata.CompositeType, 0); | 11115 | try self.ensureUnusedMetadataCapacity(1, Metadata.CompositeType, 0); |
| 11059 | const metadata_name = try self.metadataString(name); | ||
| 11060 | return self.debugUnionTypeAssumeCapacity( | 11116 | return self.debugUnionTypeAssumeCapacity( |
| 11061 | metadata_name, | 11117 | name, |
| 11062 | file, | 11118 | file, |
| 11063 | scope, | 11119 | scope, |
| 11064 | line, | 11120 | line, |
| ... | @@ -11071,7 +11127,7 @@ pub fn debugUnionType( | ... | @@ -11071,7 +11127,7 @@ pub fn debugUnionType( |
| 11071 | 11127 | ||
| 11072 | pub fn debugEnumerationType( | 11128 | pub fn debugEnumerationType( |
| 11073 | self: *Builder, | 11129 | self: *Builder, |
| 11074 | name: String, | 11130 | name: MetadataString, |
| 11075 | file: Metadata, | 11131 | file: Metadata, |
| 11076 | scope: Metadata, | 11132 | scope: Metadata, |
| 11077 | line: u32, | 11133 | line: u32, |
| ... | @@ -11081,9 +11137,8 @@ pub fn debugEnumerationType( | ... | @@ -11081,9 +11137,8 @@ pub fn debugEnumerationType( |
| 11081 | fields_tuple: Metadata, | 11137 | fields_tuple: Metadata, |
| 11082 | ) Allocator.Error!Metadata { | 11138 | ) Allocator.Error!Metadata { |
| 11083 | try self.ensureUnusedMetadataCapacity(1, Metadata.CompositeType, 0); | 11139 | try self.ensureUnusedMetadataCapacity(1, Metadata.CompositeType, 0); |
| 11084 | const metadata_name = try self.metadataString(name); | ||
| 11085 | return self.debugEnumerationTypeAssumeCapacity( | 11140 | return self.debugEnumerationTypeAssumeCapacity( |
| 11086 | metadata_name, | 11141 | name, |
| 11087 | file, | 11142 | file, |
| 11088 | scope, | 11143 | scope, |
| 11089 | line, | 11144 | line, |
| ... | @@ -11096,7 +11151,7 @@ pub fn debugEnumerationType( | ... | @@ -11096,7 +11151,7 @@ pub fn debugEnumerationType( |
| 11096 | 11151 | ||
| 11097 | pub fn debugArrayType( | 11152 | pub fn debugArrayType( |
| 11098 | self: *Builder, | 11153 | self: *Builder, |
| 11099 | name: String, | 11154 | name: MetadataString, |
| 11100 | file: Metadata, | 11155 | file: Metadata, |
| 11101 | scope: Metadata, | 11156 | scope: Metadata, |
| 11102 | line: u32, | 11157 | line: u32, |
| ... | @@ -11106,9 +11161,8 @@ pub fn debugArrayType( | ... | @@ -11106,9 +11161,8 @@ pub fn debugArrayType( |
| 11106 | fields_tuple: Metadata, | 11161 | fields_tuple: Metadata, |
| 11107 | ) Allocator.Error!Metadata { | 11162 | ) Allocator.Error!Metadata { |
| 11108 | try self.ensureUnusedMetadataCapacity(1, Metadata.CompositeType, 0); | 11163 | try self.ensureUnusedMetadataCapacity(1, Metadata.CompositeType, 0); |
| 11109 | const metadata_name = try self.metadataString(name); | ||
| 11110 | return self.debugArrayTypeAssumeCapacity( | 11164 | return self.debugArrayTypeAssumeCapacity( |
| 11111 | metadata_name, | 11165 | name, |
| 11112 | file, | 11166 | file, |
| 11113 | scope, | 11167 | scope, |
| 11114 | line, | 11168 | line, |
| ... | @@ -11121,7 +11175,7 @@ pub fn debugArrayType( | ... | @@ -11121,7 +11175,7 @@ pub fn debugArrayType( |
| 11121 | 11175 | ||
| 11122 | pub fn debugPointerType( | 11176 | pub fn debugPointerType( |
| 11123 | self: *Builder, | 11177 | self: *Builder, |
| 11124 | name: String, | 11178 | name: MetadataString, |
| 11125 | file: Metadata, | 11179 | file: Metadata, |
| 11126 | scope: Metadata, | 11180 | scope: Metadata, |
| 11127 | line: u32, | 11181 | line: u32, |
| ... | @@ -11131,9 +11185,8 @@ pub fn debugPointerType( | ... | @@ -11131,9 +11185,8 @@ pub fn debugPointerType( |
| 11131 | offset_in_bits: u64, | 11185 | offset_in_bits: u64, |
| 11132 | ) Allocator.Error!Metadata { | 11186 | ) Allocator.Error!Metadata { |
| 11133 | try self.ensureUnusedMetadataCapacity(1, Metadata.DerivedType, 0); | 11187 | try self.ensureUnusedMetadataCapacity(1, Metadata.DerivedType, 0); |
| 11134 | const metadata_name = try self.metadataString(name); | ||
| 11135 | return self.debugPointerTypeAssumeCapacity( | 11188 | return self.debugPointerTypeAssumeCapacity( |
| 11136 | metadata_name, | 11189 | name, |
| 11137 | file, | 11190 | file, |
| 11138 | scope, | 11191 | scope, |
| 11139 | line, | 11192 | line, |
| ... | @@ -11146,7 +11199,7 @@ pub fn debugPointerType( | ... | @@ -11146,7 +11199,7 @@ pub fn debugPointerType( |
| 11146 | 11199 | ||
| 11147 | pub fn debugMemberType( | 11200 | pub fn debugMemberType( |
| 11148 | self: *Builder, | 11201 | self: *Builder, |
| 11149 | name: String, | 11202 | name: MetadataString, |
| 11150 | file: Metadata, | 11203 | file: Metadata, |
| 11151 | scope: Metadata, | 11204 | scope: Metadata, |
| 11152 | line: u32, | 11205 | line: u32, |
| ... | @@ -11156,9 +11209,8 @@ pub fn debugMemberType( | ... | @@ -11156,9 +11209,8 @@ pub fn debugMemberType( |
| 11156 | offset_in_bits: u64, | 11209 | offset_in_bits: u64, |
| 11157 | ) Allocator.Error!Metadata { | 11210 | ) Allocator.Error!Metadata { |
| 11158 | try self.ensureUnusedMetadataCapacity(1, Metadata.DerivedType, 0); | 11211 | try self.ensureUnusedMetadataCapacity(1, Metadata.DerivedType, 0); |
| 11159 | const metadata_name = try self.metadataString(name); | ||
| 11160 | return self.debugMemberTypeAssumeCapacity( | 11212 | return self.debugMemberTypeAssumeCapacity( |
| 11161 | metadata_name, | 11213 | name, |
| 11162 | file, | 11214 | file, |
| 11163 | scope, | 11215 | scope, |
| 11164 | line, | 11216 | line, |
| ... | @@ -11179,7 +11231,7 @@ pub fn debugSubroutineType( | ... | @@ -11179,7 +11231,7 @@ pub fn debugSubroutineType( |
| 11179 | 11231 | ||
| 11180 | pub fn debugEnumerator( | 11232 | pub fn debugEnumerator( |
| 11181 | self: *Builder, | 11233 | self: *Builder, |
| 11182 | name: String, | 11234 | name: MetadataString, |
| 11183 | unsigned: bool, | 11235 | unsigned: bool, |
| 11184 | bit_width: u32, | 11236 | bit_width: u32, |
| 11185 | value: std.math.big.int.Const, | 11237 | value: std.math.big.int.Const, |
| ... | @@ -11187,8 +11239,7 @@ pub fn debugEnumerator( | ... | @@ -11187,8 +11239,7 @@ pub fn debugEnumerator( |
| 11187 | std.debug.assert(!(unsigned and !value.positive)); | 11239 | std.debug.assert(!(unsigned and !value.positive)); |
| 11188 | try self.ensureUnusedMetadataCapacity(1, Metadata.Enumerator, 0); | 11240 | try self.ensureUnusedMetadataCapacity(1, Metadata.Enumerator, 0); |
| 11189 | try self.metadata_limbs.ensureUnusedCapacity(self.gpa, value.limbs.len); | 11241 | try self.metadata_limbs.ensureUnusedCapacity(self.gpa, value.limbs.len); |
| 11190 | const metadata_name = try self.metadataString(name); | 11242 | return self.debugEnumeratorAssumeCapacity(name, unsigned, bit_width, value); |
| 11191 | return self.debugEnumeratorAssumeCapacity(metadata_name, unsigned, bit_width, value); | ||
| 11192 | } | 11243 | } |
| 11193 | 11244 | ||
| 11194 | pub fn debugSubrange( | 11245 | pub fn debugSubrange( |
| ... | @@ -11219,30 +11270,28 @@ pub fn debugTuple( | ... | @@ -11219,30 +11270,28 @@ pub fn debugTuple( |
| 11219 | pub fn debugModuleFlag( | 11270 | pub fn debugModuleFlag( |
| 11220 | self: *Builder, | 11271 | self: *Builder, |
| 11221 | behaviour: Metadata, | 11272 | behaviour: Metadata, |
| 11222 | name: String, | 11273 | name: MetadataString, |
| 11223 | constant: Metadata, | 11274 | constant: Metadata, |
| 11224 | ) Allocator.Error!Metadata { | 11275 | ) Allocator.Error!Metadata { |
| 11225 | try self.ensureUnusedMetadataCapacity(1, Metadata.ModuleFlag, 0); | 11276 | try self.ensureUnusedMetadataCapacity(1, Metadata.ModuleFlag, 0); |
| 11226 | const metadata_name = try self.metadataString(name); | 11277 | return self.debugModuleFlagAssumeCapacity(behaviour, name, constant); |
| 11227 | return self.debugModuleFlagAssumeCapacity(behaviour, metadata_name, constant); | ||
| 11228 | } | 11278 | } |
| 11229 | 11279 | ||
| 11230 | pub fn debugLocalVar( | 11280 | pub fn debugLocalVar( |
| 11231 | self: *Builder, | 11281 | self: *Builder, |
| 11232 | name: String, | 11282 | name: MetadataString, |
| 11233 | file: Metadata, | 11283 | file: Metadata, |
| 11234 | scope: Metadata, | 11284 | scope: Metadata, |
| 11235 | line: u32, | 11285 | line: u32, |
| 11236 | ty: Metadata, | 11286 | ty: Metadata, |
| 11237 | ) Allocator.Error!Metadata { | 11287 | ) Allocator.Error!Metadata { |
| 11238 | try self.ensureUnusedMetadataCapacity(1, Metadata.LocalVar, 0); | 11288 | try self.ensureUnusedMetadataCapacity(1, Metadata.LocalVar, 0); |
| 11239 | const metadata_name = try self.metadataString(name); | 11289 | return self.debugLocalVarAssumeCapacity(name, file, scope, line, ty); |
| 11240 | return self.debugLocalVarAssumeCapacity(metadata_name, file, scope, line, ty); | ||
| 11241 | } | 11290 | } |
| 11242 | 11291 | ||
| 11243 | pub fn debugParameter( | 11292 | pub fn debugParameter( |
| 11244 | self: *Builder, | 11293 | self: *Builder, |
| 11245 | name: String, | 11294 | name: MetadataString, |
| 11246 | file: Metadata, | 11295 | file: Metadata, |
| 11247 | scope: Metadata, | 11296 | scope: Metadata, |
| 11248 | line: u32, | 11297 | line: u32, |
| ... | @@ -11250,14 +11299,13 @@ pub fn debugParameter( | ... | @@ -11250,14 +11299,13 @@ pub fn debugParameter( |
| 11250 | arg_no: u32, | 11299 | arg_no: u32, |
| 11251 | ) Allocator.Error!Metadata { | 11300 | ) Allocator.Error!Metadata { |
| 11252 | try self.ensureUnusedMetadataCapacity(1, Metadata.Parameter, 0); | 11301 | try self.ensureUnusedMetadataCapacity(1, Metadata.Parameter, 0); |
| 11253 | const metadata_name = try self.metadataString(name); | 11302 | return self.debugParameterAssumeCapacity(name, file, scope, line, ty, arg_no); |
| 11254 | return self.debugParameterAssumeCapacity(metadata_name, file, scope, line, ty, arg_no); | ||
| 11255 | } | 11303 | } |
| 11256 | 11304 | ||
| 11257 | pub fn debugGlobalVar( | 11305 | pub fn debugGlobalVar( |
| 11258 | self: *Builder, | 11306 | self: *Builder, |
| 11259 | name: String, | 11307 | name: MetadataString, |
| 11260 | linkage_name: String, | 11308 | linkage_name: MetadataString, |
| 11261 | file: Metadata, | 11309 | file: Metadata, |
| 11262 | scope: Metadata, | 11310 | scope: Metadata, |
| 11263 | line: u32, | 11311 | line: u32, |
| ... | @@ -11266,11 +11314,9 @@ pub fn debugGlobalVar( | ... | @@ -11266,11 +11314,9 @@ pub fn debugGlobalVar( |
| 11266 | flags: Metadata.GlobalVar.Flags, | 11314 | flags: Metadata.GlobalVar.Flags, |
| 11267 | ) Allocator.Error!Metadata { | 11315 | ) Allocator.Error!Metadata { |
| 11268 | try self.ensureUnusedMetadataCapacity(1, Metadata.GlobalVar, 0); | 11316 | try self.ensureUnusedMetadataCapacity(1, Metadata.GlobalVar, 0); |
| 11269 | const metadata_name = try self.metadataString(name); | ||
| 11270 | const metadata_linkage_name = try self.metadataString(linkage_name); | ||
| 11271 | return self.debugGlobalVarAssumeCapacity( | 11317 | return self.debugGlobalVarAssumeCapacity( |
| 11272 | metadata_name, | 11318 | name, |
| 11273 | metadata_linkage_name, | 11319 | linkage_name, |
| 11274 | file, | 11320 | file, |
| 11275 | scope, | 11321 | scope, |
| 11276 | line, | 11322 | line, |
| ... | @@ -11347,7 +11393,8 @@ fn metadataSimpleAssumeCapacity(self: *Builder, tag: Metadata.Tag, value: anytyp | ... | @@ -11347,7 +11393,8 @@ fn metadataSimpleAssumeCapacity(self: *Builder, tag: Metadata.Tag, value: anytyp |
| 11347 | return @enumFromInt(gop.index); | 11393 | return @enumFromInt(gop.index); |
| 11348 | } | 11394 | } |
| 11349 | 11395 | ||
| 11350 | fn debugNamedAssumeCapacity(self: *Builder, name: String, operands: []const Metadata) void { | 11396 | fn debugNamedAssumeCapacity(self: *Builder, name: MetadataString, operands: []const Metadata) void { |
| 11397 | std.debug.assert(name != .none); | ||
| 11351 | const extra_index: u32 = @intCast(self.metadata_extra.items.len); | 11398 | const extra_index: u32 = @intCast(self.metadata_extra.items.len); |
| 11352 | self.metadata_extra.appendSliceAssumeCapacity(@ptrCast(operands)); | 11399 | self.metadata_extra.appendSliceAssumeCapacity(@ptrCast(operands)); |
| 11353 | 11400 | ||
| ... | @@ -12953,12 +13000,12 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co | ... | @@ -12953,12 +13000,12 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co |
| 12953 | 13000 | ||
| 12954 | pub fn getMetadataIndex(adapter: @This(), metadata: Metadata) u32 { | 13001 | pub fn getMetadataIndex(adapter: @This(), metadata: Metadata) u32 { |
| 12955 | if (metadata == .none) return 0; | 13002 | if (metadata == .none) return 0; |
| 12956 | return @intCast(adapter.builder.metadata_strings.count() + | 13003 | return @intCast(adapter.builder.metadata_string_map.count() + |
| 12957 | @intFromEnum(metadata.unwrap(adapter.builder))); | 13004 | @intFromEnum(metadata.unwrap(adapter.builder)) - 1); |
| 12958 | } | 13005 | } |
| 12959 | 13006 | ||
| 12960 | pub fn getMetadataStringIndex(_: @This(), metadata_string: MetadataString) u32 { | 13007 | pub fn getMetadataStringIndex(_: @This(), metadata_string: MetadataString) u32 { |
| 12961 | return @intFromEnum(metadata_string) + 1; | 13008 | return @intFromEnum(metadata_string); |
| 12962 | } | 13009 | } |
| 12963 | }; | 13010 | }; |
| 12964 | 13011 | ||
| ... | @@ -12976,11 +13023,11 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co | ... | @@ -12976,11 +13023,11 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co |
| 12976 | const strings_offset, const strings_size = blk: { | 13023 | const strings_offset, const strings_size = blk: { |
| 12977 | var strings_offset: u32 = 0; | 13024 | var strings_offset: u32 = 0; |
| 12978 | var strings_size: u32 = 0; | 13025 | var strings_size: u32 = 0; |
| 12979 | for (self.metadata_strings.keys()) |metadata_string| { | 13026 | for (1..self.metadata_string_map.count()) |metadata_string_index| { |
| 12980 | if (metadata_string.slice(self)) |slice| { | 13027 | const metadata_string: MetadataString = @enumFromInt(metadata_string_index); |
| 12981 | strings_offset += bitcode.bitsVBR(@as(u32, @intCast(slice.len)), 6); | 13028 | const slice = metadata_string.slice(self); |
| 12982 | strings_size += @intCast(slice.len * 8); | 13029 | strings_offset += bitcode.bitsVBR(@as(u32, @intCast(slice.len)), 6); |
| 12983 | } | 13030 | strings_size += @intCast(slice.len * 8); |
| 12984 | } | 13031 | } |
| 12985 | break :blk .{ | 13032 | break :blk .{ |
| 12986 | std.mem.alignForward(u32, strings_offset, 32) / 8, | 13033 | std.mem.alignForward(u32, strings_offset, 32) / 8, |
| ... | @@ -12993,25 +13040,26 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co | ... | @@ -12993,25 +13040,26 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co |
| 12993 | MetadataBlockWriter.abbrev_len, | 13040 | MetadataBlockWriter.abbrev_len, |
| 12994 | ); | 13041 | ); |
| 12995 | 13042 | ||
| 12996 | try bitcode.writeVBR(@as(u32, @intCast(self.metadata_strings.count())), 6); | 13043 | try bitcode.writeVBR(@as(u32, @intCast(self.metadata_string_map.count() - 1)), 6); |
| 12997 | try bitcode.writeVBR(strings_offset, 6); | 13044 | try bitcode.writeVBR(strings_offset, 6); |
| 12998 | 13045 | ||
| 12999 | try bitcode.writeVBR(strings_size + strings_offset, 6); | 13046 | try bitcode.writeVBR(strings_size + strings_offset, 6); |
| 13000 | 13047 | ||
| 13001 | try bitcode.alignTo32(); | 13048 | try bitcode.alignTo32(); |
| 13002 | 13049 | ||
| 13003 | for (self.metadata_strings.keys()) |metadata_string| { | 13050 | for (1..self.metadata_string_map.count()) |metadata_string_index| { |
| 13004 | if (metadata_string.slice(self)) |slice| | 13051 | const metadata_string: MetadataString = @enumFromInt(metadata_string_index); |
| 13005 | try bitcode.writeVBR(@as(u32, @intCast(slice.len)), 6); | 13052 | const slice = metadata_string.slice(self); |
| 13053 | try bitcode.writeVBR(@as(u32, @intCast(slice.len)), 6); | ||
| 13006 | } | 13054 | } |
| 13007 | 13055 | ||
| 13008 | try bitcode.alignTo32(); | 13056 | try bitcode.alignTo32(); |
| 13009 | 13057 | ||
| 13010 | for (self.metadata_strings.keys()) |metadata_string| { | 13058 | for (1..self.metadata_string_map.count()) |metadata_string_index| { |
| 13011 | if (metadata_string.slice(self)) |slice| { | 13059 | const metadata_string: MetadataString = @enumFromInt(metadata_string_index); |
| 13012 | for (slice) |c| { | 13060 | const slice = metadata_string.slice(self); |
| 13013 | try bitcode.writeBits(c, 8); | 13061 | for (slice) |c| { |
| 13014 | } | 13062 | try bitcode.writeBits(c, 8); |
| 13015 | } | 13063 | } |
| 13016 | } | 13064 | } |
| 13017 | 13065 | ||
| ... | @@ -13335,7 +13383,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co | ... | @@ -13335,7 +13383,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co |
| 13335 | 13383 | ||
| 13336 | // Write named metadata | 13384 | // Write named metadata |
| 13337 | for (self.metadata_named.keys(), self.metadata_named.values()) |name, operands| { | 13385 | for (self.metadata_named.keys(), self.metadata_named.values()) |name, operands| { |
| 13338 | const slice = name.slice(self).?; | 13386 | const slice = name.slice(self); |
| 13339 | try metadata_block.writeAbbrev(MetadataBlock.Name{ | 13387 | try metadata_block.writeAbbrev(MetadataBlock.Name{ |
| 13340 | .name = slice, | 13388 | .name = slice, |
| 13341 | }); | 13389 | }); |
| ... | @@ -13396,7 +13444,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co | ... | @@ -13396,7 +13444,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co |
| 13396 | 13444 | ||
| 13397 | return @intCast(@intFromEnum(metadata) - | 13445 | return @intCast(@intFromEnum(metadata) - |
| 13398 | Metadata.first_local_metadata + | 13446 | Metadata.first_local_metadata + |
| 13399 | adapter.metadata_adapter.builder.metadata_strings.count() + | 13447 | adapter.metadata_adapter.builder.metadata_string_map.count() - 1 + |
| 13400 | adapter.metadata_adapter.builder.metadata_map.count() - 1); | 13448 | adapter.metadata_adapter.builder.metadata_map.count() - 1); |
| 13401 | } else unreachable, | 13449 | } else unreachable, |
| 13402 | }); | 13450 | }); |