diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2023-07-19 09:36:57 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-07-19 09:36:57 -0700 |
| commit | 0aacb6369fdf3762b7ab6069955684abb63f1459 (patch) | |
| tree | 8a84783f2dd008e3e0aef59cbe6b9ad0e36c0831 /src/codegen/c.zig | |
| parent | 70c71935c7c9f20353dc2a50b497b752d70d3452 (diff) | |
| parent | d5d067211b55a9afbbe3ac52daa0f09d37e5f335 (diff) | |
| download | zig-0aacb6369fdf3762b7ab6069955684abb63f1459.tar.gz zig-0aacb6369fdf3762b7ab6069955684abb63f1459.zip | |
Merge pull request #16318 from ziglang/rework-generics
rework generic function calls
Diffstat (limited to 'src/codegen/c.zig')
| -rw-r--r-- | src/codegen/c.zig | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/src/codegen/c.zig b/src/codegen/c.zig index b685263759..1ab5a976cd 100644 --- a/src/codegen/c.zig +++ b/src/codegen/c.zig @@ -257,7 +257,8 @@ pub fn fmtIdent(ident: []const u8) std.fmt.Formatter(formatIdent) { return .{ .data = ident }; } -/// This data is available when outputting .c code for a `Module.Fn.Index`. +/// This data is available when outputting .c code for a `InternPool.Index` +/// that corresponds to `func`. /// It is not available when generating .h file. pub const Function = struct { air: Air, @@ -268,7 +269,7 @@ pub const Function = struct { next_block_index: usize = 0, object: Object, lazy_fns: LazyFnMap, - func_index: Module.Fn.Index, + func_index: InternPool.Index, /// All the locals, to be emitted at the top of the function. locals: std.ArrayListUnmanaged(Local) = .{}, /// Which locals are available for reuse, based on Type. @@ -1487,6 +1488,7 @@ pub const DeclGen = struct { ) !void { const store = &dg.ctypes.set; const mod = dg.module; + const ip = &mod.intern_pool; const fn_decl = mod.declPtr(fn_decl_index); const fn_cty_idx = try dg.typeToIndex(fn_decl.ty, kind); @@ -1499,7 +1501,7 @@ pub const DeclGen = struct { else => unreachable, } } - if (fn_decl.val.getFunction(mod)) |func| if (func.is_cold) try w.writeAll("zig_cold "); + if (fn_decl.val.getFunction(mod)) |func| if (func.analysis(ip).is_cold) try w.writeAll("zig_cold "); if (fn_info.return_type == .noreturn_type) try w.writeAll("zig_noreturn "); const trailing = try renderTypePrefix( @@ -1744,7 +1746,7 @@ pub const DeclGen = struct { return switch (mod.intern_pool.indexToKey(tv.val.ip_index)) { .variable => |variable| mod.decl_exports.contains(variable.decl), .extern_func => true, - .func => |func| mod.decl_exports.contains(mod.funcPtr(func.index).owner_decl), + .func => |func| mod.decl_exports.contains(func.owner_decl), else => unreachable, }; } @@ -1800,7 +1802,12 @@ pub const DeclGen = struct { } } - fn writeCValueMember(dg: *DeclGen, writer: anytype, c_value: CValue, member: CValue) !void { + fn writeCValueMember( + dg: *DeclGen, + writer: anytype, + c_value: CValue, + member: CValue, + ) error{ OutOfMemory, AnalysisFail }!void { try dg.writeCValue(writer, c_value); try writer.writeByte('.'); try dg.writeCValue(writer, member); @@ -4161,7 +4168,7 @@ fn airCall( const callee_val = (try f.air.value(pl_op.operand, mod)) orelse break :known; break :fn_decl switch (mod.intern_pool.indexToKey(callee_val.ip_index)) { .extern_func => |extern_func| extern_func.decl, - .func => |func| mod.funcPtr(func.index).owner_decl, + .func => |func| func.owner_decl, .ptr => |ptr| switch (ptr.addr) { .decl => |decl| decl, else => break :known, @@ -4238,9 +4245,9 @@ fn airDbgInline(f: *Function, inst: Air.Inst.Index) !CValue { const ty_fn = f.air.instructions.items(.data)[inst].ty_fn; const mod = f.object.dg.module; const writer = f.object.writer(); - const function = mod.funcPtr(ty_fn.func); + const owner_decl = mod.funcOwnerDeclPtr(ty_fn.func); try writer.print("/* dbg func:{s} */\n", .{ - mod.intern_pool.stringToSlice(mod.declPtr(function.owner_decl).name), + mod.intern_pool.stringToSlice(owner_decl.name), }); return .none; } |
