Skip to content

improve the C backend lowering of Zig types to C types #10061

@andrewrk

Description

@andrewrk

There are two functions where we lower Zig types to C types:

zig/src/codegen/c.zig

Lines 727 to 733 in 83a4bb6

fn renderTypeAndName(
dg: *DeclGen,
w: anytype,
ty: Type,
name: CValue,
mutability: Mutability,
) error{ OutOfMemory, AnalysisFail }!void {

fn renderType(dg: *DeclGen, w: anytype, t: Type) error{ OutOfMemory, AnalysisFail }!void {

Right now it is hacky and not correct for more complex types. It needs to be improved to fully support C types, particularly regarding function pointers.

Thankfully, @Vexu already solved this problem in arocc so we can borrow from this project:

https://github.com/Vexu/arocc/blob/361274f0e4b5a4b1f1cab029077ac968914fa255/src/Type.zig#L1285

Part of this issue is coming up with complex Zig types as test cases and making sure they properly lower to C types.

Metadata

Metadata

Assignees

No one assigned

    Labels

    backend-cThe C backend (CBE) outputs C source code.contributor friendlyThis issue is limited in scope and/or knowledge of Zig internals.enhancementSolving this issue will likely involve adding new logic or components to the codebase.frontendTokenization, parsing, AstGen, Sema, and Liveness.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions