| ... | @@ -522,7 +522,7 @@ pub const Object = struct { | ... | @@ -522,7 +522,7 @@ pub const Object = struct { |
| 522 | pub const DeclGen = struct { | 522 | pub const DeclGen = struct { |
| 523 | gpa: mem.Allocator, | 523 | gpa: mem.Allocator, |
| 524 | module: *Module, | 524 | module: *Module, |
| 525 | decl_index: Decl.OptionalIndex, | 525 | pass: Pass, |
| 526 | is_naked_fn: bool, | 526 | is_naked_fn: bool, |
| 527 | /// This is a borrowed reference from `link.C`. | 527 | /// This is a borrowed reference from `link.C`. |
| 528 | fwd_decl: std.ArrayList(u8), | 528 | fwd_decl: std.ArrayList(u8), |
| ... | @@ -533,10 +533,16 @@ pub const DeclGen = struct { | ... | @@ -533,10 +533,16 @@ pub const DeclGen = struct { |
| 533 | anon_decl_deps: std.AutoArrayHashMapUnmanaged(InternPool.Index, C.DeclBlock), | 533 | anon_decl_deps: std.AutoArrayHashMapUnmanaged(InternPool.Index, C.DeclBlock), |
| 534 | aligned_anon_decls: std.AutoArrayHashMapUnmanaged(InternPool.Index, Alignment), | 534 | aligned_anon_decls: std.AutoArrayHashMapUnmanaged(InternPool.Index, Alignment), |
| 535 | | 535 | |
| | 536 | pub const Pass = union(enum) { |
| | 537 | decl: Decl.Index, |
| | 538 | anon: InternPool.Index, |
| | 539 | flush, |
| | 540 | }; |
| | 541 | |
| 536 | fn fail(dg: *DeclGen, comptime format: []const u8, args: anytype) error{ AnalysisFail, OutOfMemory } { | 542 | fn fail(dg: *DeclGen, comptime format: []const u8, args: anytype) error{ AnalysisFail, OutOfMemory } { |
| 537 | @setCold(true); | 543 | @setCold(true); |
| 538 | const mod = dg.module; | 544 | const mod = dg.module; |
| 539 | const decl_index = dg.decl_index.unwrap().?; | 545 | const decl_index = dg.pass.decl; |
| 540 | const decl = mod.declPtr(decl_index); | 546 | const decl = mod.declPtr(decl_index); |
| 541 | const src = LazySrcLoc.nodeOffset(0); | 547 | const src = LazySrcLoc.nodeOffset(0); |
| 542 | const src_loc = src.toSrcLoc(decl, mod); | 548 | const src_loc = src.toSrcLoc(decl, mod); |
| ... | @@ -1566,18 +1572,11 @@ pub const DeclGen = struct { | ... | @@ -1566,18 +1572,11 @@ pub const DeclGen = struct { |
| 1566 | else => unreachable, | 1572 | else => unreachable, |
| 1567 | } | 1573 | } |
| 1568 | } | 1574 | } |
| 1569 | if (fn_decl.val.getFunction(mod)) |func| if (func.analysis(ip).is_cold) try w.writeAll("zig_cold "); | 1575 | if (fn_decl.val.getFunction(mod)) |func| if (func.analysis(ip).is_cold) |
| | 1576 | try w.writeAll("zig_cold "); |
| 1570 | if (fn_info.return_type == .noreturn_type) try w.writeAll("zig_noreturn "); | 1577 | if (fn_info.return_type == .noreturn_type) try w.writeAll("zig_noreturn "); |
| 1571 | | 1578 | |
| 1572 | const trailing = try renderTypePrefix( | 1579 | const trailing = try renderTypePrefix(dg.pass, store.*, mod, w, fn_cty_idx, .suffix, .{}); |
| 1573 | dg.decl_index, | | |
| 1574 | store.*, | | |
| 1575 | mod, | | |
| 1576 | w, | | |
| 1577 | fn_cty_idx, | | |
| 1578 | .suffix, | | |
| 1579 | .{}, | | |
| 1580 | ); | | |
| 1581 | try w.print("{}", .{trailing}); | 1580 | try w.print("{}", .{trailing}); |
| 1582 | | 1581 | |
| 1583 | if (toCallingConvention(fn_info.cc)) |call_conv| { | 1582 | if (toCallingConvention(fn_info.cc)) |call_conv| { |
| ... | @@ -1597,7 +1596,7 @@ pub const DeclGen = struct { | ... | @@ -1597,7 +1596,7 @@ pub const DeclGen = struct { |
| 1597 | } | 1596 | } |
| 1598 | | 1597 | |
| 1599 | try renderTypeSuffix( | 1598 | try renderTypeSuffix( |
| 1600 | dg.decl_index, | 1599 | dg.pass, |
| 1601 | store.*, | 1600 | store.*, |
| 1602 | mod, | 1601 | mod, |
| 1603 | w, | 1602 | w, |
| ... | @@ -1652,8 +1651,8 @@ pub const DeclGen = struct { | ... | @@ -1652,8 +1651,8 @@ pub const DeclGen = struct { |
| 1652 | fn renderCType(dg: *DeclGen, w: anytype, idx: CType.Index) error{ OutOfMemory, AnalysisFail }!void { | 1651 | fn renderCType(dg: *DeclGen, w: anytype, idx: CType.Index) error{ OutOfMemory, AnalysisFail }!void { |
| 1653 | const store = &dg.ctypes.set; | 1652 | const store = &dg.ctypes.set; |
| 1654 | const mod = dg.module; | 1653 | const mod = dg.module; |
| 1655 | _ = try renderTypePrefix(dg.decl_index, store.*, mod, w, idx, .suffix, .{}); | 1654 | _ = try renderTypePrefix(dg.pass, store.*, mod, w, idx, .suffix, .{}); |
| 1656 | try renderTypeSuffix(dg.decl_index, store.*, mod, w, idx, .suffix, .{}); | 1655 | try renderTypeSuffix(dg.pass, store.*, mod, w, idx, .suffix, .{}); |
| 1657 | } | 1656 | } |
| 1658 | | 1657 | |
| 1659 | const IntCastContext = union(enum) { | 1658 | const IntCastContext = union(enum) { |
| ... | @@ -1799,11 +1798,10 @@ pub const DeclGen = struct { | ... | @@ -1799,11 +1798,10 @@ pub const DeclGen = struct { |
| 1799 | .gt => try w.print("zig_align({}) ", .{alignas.toByteUnits()}), | 1798 | .gt => try w.print("zig_align({}) ", .{alignas.toByteUnits()}), |
| 1800 | } | 1799 | } |
| 1801 | | 1800 | |
| 1802 | const trailing = | 1801 | const trailing = try renderTypePrefix(dg.pass, store.*, mod, w, cty_idx, .suffix, qualifiers); |
| 1803 | try renderTypePrefix(dg.decl_index, store.*, mod, w, cty_idx, .suffix, qualifiers); | | |
| 1804 | try w.print("{}", .{trailing}); | 1802 | try w.print("{}", .{trailing}); |
| 1805 | try dg.writeCValue(w, name); | 1803 | try dg.writeCValue(w, name); |
| 1806 | try renderTypeSuffix(dg.decl_index, store.*, mod, w, cty_idx, .suffix, .{}); | 1804 | try renderTypeSuffix(dg.pass, store.*, mod, w, cty_idx, .suffix, .{}); |
| 1807 | } | 1805 | } |
| 1808 | | 1806 | |
| 1809 | fn declIsGlobal(dg: *DeclGen, tv: TypedValue) bool { | 1807 | fn declIsGlobal(dg: *DeclGen, tv: TypedValue) bool { |
| ... | @@ -2070,7 +2068,7 @@ fn renderTypeName( | ... | @@ -2070,7 +2068,7 @@ fn renderTypeName( |
| 2070 | } | 2068 | } |
| 2071 | } | 2069 | } |
| 2072 | fn renderTypePrefix( | 2070 | fn renderTypePrefix( |
| 2073 | decl: Decl.OptionalIndex, | 2071 | pass: DeclGen.Pass, |
| 2074 | store: CType.Store.Set, | 2072 | store: CType.Store.Set, |
| 2075 | mod: *Module, | 2073 | mod: *Module, |
| 2076 | w: anytype, | 2074 | w: anytype, |
| ... | @@ -2128,7 +2126,7 @@ fn renderTypePrefix( | ... | @@ -2128,7 +2126,7 @@ fn renderTypePrefix( |
| 2128 | => |tag| { | 2126 | => |tag| { |
| 2129 | const child_idx = cty.cast(CType.Payload.Child).?.data; | 2127 | const child_idx = cty.cast(CType.Payload.Child).?.data; |
| 2130 | const child_trailing = try renderTypePrefix( | 2128 | const child_trailing = try renderTypePrefix( |
| 2131 | decl, | 2129 | pass, |
| 2132 | store, | 2130 | store, |
| 2133 | mod, | 2131 | mod, |
| 2134 | w, | 2132 | w, |
| ... | @@ -2152,15 +2150,8 @@ fn renderTypePrefix( | ... | @@ -2152,15 +2150,8 @@ fn renderTypePrefix( |
| 2152 | .vector, | 2150 | .vector, |
| 2153 | => { | 2151 | => { |
| 2154 | const child_idx = cty.cast(CType.Payload.Sequence).?.data.elem_type; | 2152 | const child_idx = cty.cast(CType.Payload.Sequence).?.data.elem_type; |
| 2155 | const child_trailing = try renderTypePrefix( | 2153 | const child_trailing = |
| 2156 | decl, | 2154 | try renderTypePrefix(pass, store, mod, w, child_idx, .suffix, qualifiers); |
| 2157 | store, | | |
| 2158 | mod, | | |
| 2159 | w, | | |
| 2160 | child_idx, | | |
| 2161 | .suffix, | | |
| 2162 | qualifiers, | | |
| 2163 | ); | | |
| 2164 | switch (parent_fix) { | 2155 | switch (parent_fix) { |
| 2165 | .prefix => { | 2156 | .prefix => { |
| 2166 | try w.print("{}(", .{child_trailing}); | 2157 | try w.print("{}(", .{child_trailing}); |
| ... | @@ -2172,10 +2163,11 @@ fn renderTypePrefix( | ... | @@ -2172,10 +2163,11 @@ fn renderTypePrefix( |
| 2172 | | 2163 | |
| 2173 | .fwd_anon_struct, | 2164 | .fwd_anon_struct, |
| 2174 | .fwd_anon_union, | 2165 | .fwd_anon_union, |
| 2175 | => if (decl.unwrap()) |decl_index| | 2166 | => switch (pass) { |
| 2176 | try w.print("anon__{d}_{d}", .{ @intFromEnum(decl_index), idx }) | 2167 | .decl => |decl_index| try w.print("decl__{d}_{d}", .{ @intFromEnum(decl_index), idx }), |
| 2177 | else | 2168 | .anon => |anon_decl| try w.print("anon__{d}_{d}", .{ @intFromEnum(anon_decl), idx }), |
| 2178 | try renderTypeName(mod, w, idx, cty, ""), | 2169 | .flush => try renderTypeName(mod, w, idx, cty, ""), |
| | 2170 | }, |
| 2179 | | 2171 | |
| 2180 | .fwd_struct, | 2172 | .fwd_struct, |
| 2181 | .fwd_union, | 2173 | .fwd_union, |
| ... | @@ -2201,7 +2193,7 @@ fn renderTypePrefix( | ... | @@ -2201,7 +2193,7 @@ fn renderTypePrefix( |
| 2201 | .packed_struct, | 2193 | .packed_struct, |
| 2202 | .packed_union, | 2194 | .packed_union, |
| 2203 | => return renderTypePrefix( | 2195 | => return renderTypePrefix( |
| 2204 | decl, | 2196 | pass, |
| 2205 | store, | 2197 | store, |
| 2206 | mod, | 2198 | mod, |
| 2207 | w, | 2199 | w, |
| ... | @@ -2214,7 +2206,7 @@ fn renderTypePrefix( | ... | @@ -2214,7 +2206,7 @@ fn renderTypePrefix( |
| 2214 | .varargs_function, | 2206 | .varargs_function, |
| 2215 | => { | 2207 | => { |
| 2216 | const child_trailing = try renderTypePrefix( | 2208 | const child_trailing = try renderTypePrefix( |
| 2217 | decl, | 2209 | pass, |
| 2218 | store, | 2210 | store, |
| 2219 | mod, | 2211 | mod, |
| 2220 | w, | 2212 | w, |
| ... | @@ -2241,7 +2233,7 @@ fn renderTypePrefix( | ... | @@ -2241,7 +2233,7 @@ fn renderTypePrefix( |
| 2241 | return trailing; | 2233 | return trailing; |
| 2242 | } | 2234 | } |
| 2243 | fn renderTypeSuffix( | 2235 | fn renderTypeSuffix( |
| 2244 | decl: Decl.OptionalIndex, | 2236 | pass: DeclGen.Pass, |
| 2245 | store: CType.Store.Set, | 2237 | store: CType.Store.Set, |
| 2246 | mod: *Module, | 2238 | mod: *Module, |
| 2247 | w: anytype, | 2239 | w: anytype, |
| ... | @@ -2295,7 +2287,7 @@ fn renderTypeSuffix( | ... | @@ -2295,7 +2287,7 @@ fn renderTypeSuffix( |
| 2295 | .pointer_volatile, | 2287 | .pointer_volatile, |
| 2296 | .pointer_const_volatile, | 2288 | .pointer_const_volatile, |
| 2297 | => try renderTypeSuffix( | 2289 | => try renderTypeSuffix( |
| 2298 | decl, | 2290 | pass, |
| 2299 | store, | 2291 | store, |
| 2300 | mod, | 2292 | mod, |
| 2301 | w, | 2293 | w, |
| ... | @@ -2314,7 +2306,7 @@ fn renderTypeSuffix( | ... | @@ -2314,7 +2306,7 @@ fn renderTypeSuffix( |
| 2314 | | 2306 | |
| 2315 | try w.print("[{}]", .{cty.cast(CType.Payload.Sequence).?.data.len}); | 2307 | try w.print("[{}]", .{cty.cast(CType.Payload.Sequence).?.data.len}); |
| 2316 | try renderTypeSuffix( | 2308 | try renderTypeSuffix( |
| 2317 | decl, | 2309 | pass, |
| 2318 | store, | 2310 | store, |
| 2319 | mod, | 2311 | mod, |
| 2320 | w, | 2312 | w, |
| ... | @@ -2356,9 +2348,9 @@ fn renderTypeSuffix( | ... | @@ -2356,9 +2348,9 @@ fn renderTypeSuffix( |
| 2356 | if (need_comma) try w.writeAll(", "); | 2348 | if (need_comma) try w.writeAll(", "); |
| 2357 | need_comma = true; | 2349 | need_comma = true; |
| 2358 | const trailing = | 2350 | const trailing = |
| 2359 | try renderTypePrefix(decl, store, mod, w, param_type, .suffix, qualifiers); | 2351 | try renderTypePrefix(pass, store, mod, w, param_type, .suffix, qualifiers); |
| 2360 | if (qualifiers.contains(.@"const")) try w.print("{}a{d}", .{ trailing, param_i }); | 2352 | if (qualifiers.contains(.@"const")) try w.print("{}a{d}", .{ trailing, param_i }); |
| 2361 | try renderTypeSuffix(decl, store, mod, w, param_type, .suffix, .{}); | 2353 | try renderTypeSuffix(pass, store, mod, w, param_type, .suffix, .{}); |
| 2362 | } | 2354 | } |
| 2363 | switch (tag) { | 2355 | switch (tag) { |
| 2364 | .function => {}, | 2356 | .function => {}, |
| ... | @@ -2372,7 +2364,7 @@ fn renderTypeSuffix( | ... | @@ -2372,7 +2364,7 @@ fn renderTypeSuffix( |
| 2372 | if (!need_comma) try w.writeAll("void"); | 2364 | if (!need_comma) try w.writeAll("void"); |
| 2373 | try w.writeByte(')'); | 2365 | try w.writeByte(')'); |
| 2374 | | 2366 | |
| 2375 | try renderTypeSuffix(decl, store, mod, w, data.return_type, .suffix, .{}); | 2367 | try renderTypeSuffix(pass, store, mod, w, data.return_type, .suffix, .{}); |
| 2376 | }, | 2368 | }, |
| 2377 | } | 2369 | } |
| 2378 | } | 2370 | } |
| ... | @@ -2392,9 +2384,9 @@ fn renderAggregateFields( | ... | @@ -2392,9 +2384,9 @@ fn renderAggregateFields( |
| 2392 | .eq => {}, | 2384 | .eq => {}, |
| 2393 | .gt => try writer.print("zig_align({}) ", .{field.alignas.toByteUnits()}), | 2385 | .gt => try writer.print("zig_align({}) ", .{field.alignas.toByteUnits()}), |
| 2394 | } | 2386 | } |
| 2395 | const trailing = try renderTypePrefix(.none, store, mod, writer, field.type, .suffix, .{}); | 2387 | const trailing = try renderTypePrefix(.flush, store, mod, writer, field.type, .suffix, .{}); |
| 2396 | try writer.print("{}{ }", .{ trailing, fmtIdent(mem.span(field.name)) }); | 2388 | try writer.print("{}{ }", .{ trailing, fmtIdent(mem.span(field.name)) }); |
| 2397 | try renderTypeSuffix(.none, store, mod, writer, field.type, .suffix, .{}); | 2389 | try renderTypeSuffix(.flush, store, mod, writer, field.type, .suffix, .{}); |
| 2398 | try writer.writeAll(";\n"); | 2390 | try writer.writeAll(";\n"); |
| 2399 | } | 2391 | } |
| 2400 | try writer.writeByteNTimes(' ', indent); | 2392 | try writer.writeByteNTimes(' ', indent); |
| ... | @@ -2406,18 +2398,18 @@ pub fn genTypeDecl( | ... | @@ -2406,18 +2398,18 @@ pub fn genTypeDecl( |
| 2406 | writer: anytype, | 2398 | writer: anytype, |
| 2407 | global_store: CType.Store.Set, | 2399 | global_store: CType.Store.Set, |
| 2408 | global_idx: CType.Index, | 2400 | global_idx: CType.Index, |
| 2409 | decl: Decl.OptionalIndex, | 2401 | pass: DeclGen.Pass, |
| 2410 | decl_store: CType.Store.Set, | 2402 | decl_store: CType.Store.Set, |
| 2411 | decl_idx: CType.Index, | 2403 | decl_idx: CType.Index, |
| 2412 | found_existing: bool, | 2404 | found_existing: bool, |
| 2413 | ) !void { | 2405 | ) !void { |
| 2414 | const global_cty = global_store.indexToCType(global_idx); | 2406 | const global_cty = global_store.indexToCType(global_idx); |
| 2415 | switch (global_cty.tag()) { | 2407 | switch (global_cty.tag()) { |
| 2416 | .fwd_anon_struct => if (decl != .none) { | 2408 | .fwd_anon_struct => if (pass != .flush) { |
| 2417 | try writer.writeAll("typedef "); | 2409 | try writer.writeAll("typedef "); |
| 2418 | _ = try renderTypePrefix(.none, global_store, mod, writer, global_idx, .suffix, .{}); | 2410 | _ = try renderTypePrefix(.flush, global_store, mod, writer, global_idx, .suffix, .{}); |
| 2419 | try writer.writeByte(' '); | 2411 | try writer.writeByte(' '); |
| 2420 | _ = try renderTypePrefix(decl, decl_store, mod, writer, decl_idx, .suffix, .{}); | 2412 | _ = try renderTypePrefix(pass, decl_store, mod, writer, decl_idx, .suffix, .{}); |
| 2421 | try writer.writeAll(";\n"); | 2413 | try writer.writeAll(";\n"); |
| 2422 | }, | 2414 | }, |
| 2423 | | 2415 | |
| ... | @@ -2435,7 +2427,15 @@ pub fn genTypeDecl( | ... | @@ -2435,7 +2427,15 @@ pub fn genTypeDecl( |
| 2435 | .fwd_union, | 2427 | .fwd_union, |
| 2436 | => { | 2428 | => { |
| 2437 | const owner_decl = global_cty.cast(CType.Payload.FwdDecl).?.data; | 2429 | const owner_decl = global_cty.cast(CType.Payload.FwdDecl).?.data; |
| 2438 | _ = try renderTypePrefix(.none, global_store, mod, writer, global_idx, .suffix, .{}); | 2430 | _ = try renderTypePrefix( |
| | 2431 | .flush, |
| | 2432 | global_store, |
| | 2433 | mod, |
| | 2434 | writer, |
| | 2435 | global_idx, |
| | 2436 | .suffix, |
| | 2437 | .{}, |
| | 2438 | ); |
| 2439 | try writer.writeAll("; // "); | 2439 | try writer.writeAll("; // "); |
| 2440 | try mod.declPtr(owner_decl).renderFullyQualifiedName(mod, writer); | 2440 | try mod.declPtr(owner_decl).renderFullyQualifiedName(mod, writer); |
| 2441 | try writer.writeByte('\n'); | 2441 | try writer.writeByte('\n'); |
| ... | @@ -2552,7 +2552,7 @@ fn genExports(o: *Object) !void { | ... | @@ -2552,7 +2552,7 @@ fn genExports(o: *Object) !void { |
| 2552 | | 2552 | |
| 2553 | const mod = o.dg.module; | 2553 | const mod = o.dg.module; |
| 2554 | const ip = &mod.intern_pool; | 2554 | const ip = &mod.intern_pool; |
| 2555 | const decl_index = o.dg.decl_index.unwrap().?; | 2555 | const decl_index = o.dg.pass.decl; |
| 2556 | const decl = mod.declPtr(decl_index); | 2556 | const decl = mod.declPtr(decl_index); |
| 2557 | const tv: TypedValue = .{ .ty = decl.ty, .val = (try decl.internValue(mod)).toValue() }; | 2557 | const tv: TypedValue = .{ .ty = decl.ty, .val = (try decl.internValue(mod)).toValue() }; |
| 2558 | const fwd = o.dg.fwd_decl.writer(); | 2558 | const fwd = o.dg.fwd_decl.writer(); |
| ... | @@ -2692,7 +2692,7 @@ pub fn genFunc(f: *Function) !void { | ... | @@ -2692,7 +2692,7 @@ pub fn genFunc(f: *Function) !void { |
| 2692 | const o = &f.object; | 2692 | const o = &f.object; |
| 2693 | const mod = o.dg.module; | 2693 | const mod = o.dg.module; |
| 2694 | const gpa = o.dg.gpa; | 2694 | const gpa = o.dg.gpa; |
| 2695 | const decl_index = o.dg.decl_index.unwrap().?; | 2695 | const decl_index = o.dg.pass.decl; |
| 2696 | const decl = mod.declPtr(decl_index); | 2696 | const decl = mod.declPtr(decl_index); |
| 2697 | const tv: TypedValue = .{ | 2697 | const tv: TypedValue = .{ |
| 2698 | .ty = decl.ty, | 2698 | .ty = decl.ty, |
| ... | @@ -2779,7 +2779,7 @@ pub fn genDecl(o: *Object) !void { | ... | @@ -2779,7 +2779,7 @@ pub fn genDecl(o: *Object) !void { |
| 2779 | defer tracy.end(); | 2779 | defer tracy.end(); |
| 2780 | | 2780 | |
| 2781 | const mod = o.dg.module; | 2781 | const mod = o.dg.module; |
| 2782 | const decl_index = o.dg.decl_index.unwrap().?; | 2782 | const decl_index = o.dg.pass.decl; |
| 2783 | const decl = mod.declPtr(decl_index); | 2783 | const decl = mod.declPtr(decl_index); |
| 2784 | const tv: TypedValue = .{ .ty = decl.ty, .val = (try decl.internValue(mod)).toValue() }; | 2784 | const tv: TypedValue = .{ .ty = decl.ty, .val = (try decl.internValue(mod)).toValue() }; |
| 2785 | | 2785 | |
| ... | @@ -2825,13 +2825,13 @@ pub fn genDeclValue( | ... | @@ -2825,13 +2825,13 @@ pub fn genDeclValue( |
| 2825 | alignment: Alignment, | 2825 | alignment: Alignment, |
| 2826 | link_section: InternPool.OptionalNullTerminatedString, | 2826 | link_section: InternPool.OptionalNullTerminatedString, |
| 2827 | ) !void { | 2827 | ) !void { |
| | 2828 | const mod = o.dg.module; |
| 2828 | const fwd_decl_writer = o.dg.fwd_decl.writer(); | 2829 | const fwd_decl_writer = o.dg.fwd_decl.writer(); |
| 2829 | | 2830 | |
| 2830 | try fwd_decl_writer.writeAll(if (is_global) "zig_extern " else "static "); | 2831 | try fwd_decl_writer.writeAll(if (is_global) "zig_extern " else "static "); |
| 2831 | try o.dg.renderTypeAndName(fwd_decl_writer, tv.ty, decl_c_value, Const, alignment, .complete); | 2832 | try o.dg.renderTypeAndName(fwd_decl_writer, tv.ty, decl_c_value, Const, alignment, .complete); |
| 2832 | try fwd_decl_writer.writeAll(";\n"); | 2833 | try fwd_decl_writer.writeAll(";\n"); |
| 2833 | | 2834 | |
| 2834 | const mod = o.dg.module; | | |
| 2835 | const w = o.writer(); | 2835 | const w = o.writer(); |
| 2836 | if (!is_global) try w.writeAll("static "); | 2836 | if (!is_global) try w.writeAll("static "); |
| 2837 | if (mod.intern_pool.stringToSliceUnwrap(link_section)) |s| | 2837 | if (mod.intern_pool.stringToSliceUnwrap(link_section)) |s| |
| ... | @@ -2848,7 +2848,7 @@ pub fn genHeader(dg: *DeclGen) error{ AnalysisFail, OutOfMemory }!void { | ... | @@ -2848,7 +2848,7 @@ pub fn genHeader(dg: *DeclGen) error{ AnalysisFail, OutOfMemory }!void { |
| 2848 | defer tracy.end(); | 2848 | defer tracy.end(); |
| 2849 | | 2849 | |
| 2850 | const mod = dg.module; | 2850 | const mod = dg.module; |
| 2851 | const decl_index = dg.decl_index.unwrap().?; | 2851 | const decl_index = dg.pass.decl; |
| 2852 | const decl = mod.declPtr(decl_index); | 2852 | const decl = mod.declPtr(decl_index); |
| 2853 | const tv: TypedValue = .{ | 2853 | const tv: TypedValue = .{ |
| 2854 | .ty = decl.ty, | 2854 | .ty = decl.ty, |
| ... | @@ -2861,7 +2861,7 @@ pub fn genHeader(dg: *DeclGen) error{ AnalysisFail, OutOfMemory }!void { | ... | @@ -2861,7 +2861,7 @@ pub fn genHeader(dg: *DeclGen) error{ AnalysisFail, OutOfMemory }!void { |
| 2861 | const is_global = dg.declIsGlobal(tv); | 2861 | const is_global = dg.declIsGlobal(tv); |
| 2862 | if (is_global) { | 2862 | if (is_global) { |
| 2863 | try writer.writeAll("zig_extern "); | 2863 | try writer.writeAll("zig_extern "); |
| 2864 | try dg.renderFunctionSignature(writer, dg.decl_index.unwrap().?, .complete, .{ .export_index = 0 }); | 2864 | try dg.renderFunctionSignature(writer, dg.pass.decl, .complete, .{ .export_index = 0 }); |
| 2865 | try dg.fwd_decl.appendSlice(";\n"); | 2865 | try dg.fwd_decl.appendSlice(";\n"); |
| 2866 | } | 2866 | } |
| 2867 | }, | 2867 | }, |
| ... | @@ -7279,7 +7279,7 @@ fn airMulAdd(f: *Function, inst: Air.Inst.Index) !CValue { | ... | @@ -7279,7 +7279,7 @@ fn airMulAdd(f: *Function, inst: Air.Inst.Index) !CValue { |
| 7279 | fn airCVaStart(f: *Function, inst: Air.Inst.Index) !CValue { | 7279 | fn airCVaStart(f: *Function, inst: Air.Inst.Index) !CValue { |
| 7280 | const mod = f.object.dg.module; | 7280 | const mod = f.object.dg.module; |
| 7281 | const inst_ty = f.typeOfIndex(inst); | 7281 | const inst_ty = f.typeOfIndex(inst); |
| 7282 | const decl_index = f.object.dg.decl_index.unwrap().?; | 7282 | const decl_index = f.object.dg.pass.decl; |
| 7283 | const decl = mod.declPtr(decl_index); | 7283 | const decl = mod.declPtr(decl_index); |
| 7284 | const fn_cty = try f.typeToCType(decl.ty, .complete); | 7284 | const fn_cty = try f.typeToCType(decl.ty, .complete); |
| 7285 | const param_len = fn_cty.castTag(.varargs_function).?.data.param_types.len; | 7285 | const param_len = fn_cty.castTag(.varargs_function).?.data.param_types.len; |