diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2022-02-26 20:59:36 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2022-02-26 20:59:36 -0700 |
| commit | 2687b8f7f4825c9018af6998e1de140e6185f9cd (patch) | |
| tree | 4bbd5f609153618e883ad4cce09c7a8c920a22b0 /src/codegen/c.zig | |
| parent | 32e89a98d82c0f4505a3f3d4cd72e7db2eadfbb9 (diff) | |
| download | zig-2687b8f7f4825c9018af6998e1de140e6185f9cd.tar.gz zig-2687b8f7f4825c9018af6998e1de140e6185f9cd.zip | |
stage2: implement `@unionInit`
The ZIR instruction `union_init_ptr` is renamed to `union_init`.
I made it always use by-value semantics for now, not taking the time to
invest in result location semantics, in case we decide to change the
rules for unions. This way is much simpler.
There is a new AIR instruction: union_init. This is for a comptime known
tag, runtime-known field value.
vector_init is renamed to aggregate_init, which solves a TODO comment.
Diffstat (limited to 'src/codegen/c.zig')
| -rw-r--r-- | src/codegen/c.zig | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/src/codegen/c.zig b/src/codegen/c.zig index 2a0751a202..f09acaa47c 100644 --- a/src/codegen/c.zig +++ b/src/codegen/c.zig @@ -1713,7 +1713,8 @@ fn genBody(f: *Function, body: []const Air.Inst.Index) error{ AnalysisFail, OutO .tag_name => try airTagName(f, inst), .error_name => try airErrorName(f, inst), .splat => try airSplat(f, inst), - .vector_init => try airVectorInit(f, inst), + .aggregate_init => try airAggregateInit(f, inst), + .union_init => try airUnionInit(f, inst), .prefetch => try airPrefetch(f, inst), .int_to_float, @@ -3526,7 +3527,7 @@ fn airSplat(f: *Function, inst: Air.Inst.Index) !CValue { return f.fail("TODO: C backend: implement airSplat", .{}); } -fn airVectorInit(f: *Function, inst: Air.Inst.Index) !CValue { +fn airAggregateInit(f: *Function, inst: Air.Inst.Index) !CValue { if (f.liveness.isUnused(inst)) return CValue.none; const inst_ty = f.air.typeOfIndex(inst); @@ -3541,7 +3542,22 @@ fn airVectorInit(f: *Function, inst: Air.Inst.Index) !CValue { _ = elements; _ = local; - return f.fail("TODO: C backend: implement airVectorInit", .{}); + return f.fail("TODO: C backend: implement airAggregateInit", .{}); +} + +fn airUnionInit(f: *Function, inst: Air.Inst.Index) !CValue { + if (f.liveness.isUnused(inst)) return CValue.none; + + const inst_ty = f.air.typeOfIndex(inst); + const ty_pl = f.air.instructions.items(.data)[inst].ty_pl; + + const writer = f.object.writer(); + const local = try f.allocLocal(inst_ty, .Const); + try writer.writeAll(" = "); + + _ = local; + _ = ty_pl; + return f.fail("TODO: C backend: implement airUnionInit", .{}); } fn airPrefetch(f: *Function, inst: Air.Inst.Index) !CValue { |
