diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2021-09-13 21:37:11 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2021-09-13 21:37:11 -0700 |
| commit | 97d69e3352ab50f88580c383b5f375b0edadacfd (patch) | |
| tree | 8245d3d55b3304c19ca18238a01d6532031e1ff8 /src/codegen/c.zig | |
| parent | a9a21c59888905e060915dee818633110cc54cfa (diff) | |
| download | zig-97d69e3352ab50f88580c383b5f375b0edadacfd.tar.gz zig-97d69e3352ab50f88580c383b5f375b0edadacfd.zip | |
stage2: add array_to_slice AIR instruction
Diffstat (limited to 'src/codegen/c.zig')
| -rw-r--r-- | src/codegen/c.zig | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/codegen/c.zig b/src/codegen/c.zig index fd964f2829..84bc6ceeb0 100644 --- a/src/codegen/c.zig +++ b/src/codegen/c.zig @@ -910,6 +910,7 @@ fn genBody(o: *Object, body: []const Air.Inst.Index) error{ AnalysisFail, OutOfM .switch_br => try airSwitchBr(o, inst), .wrap_optional => try airWrapOptional(o, inst), .struct_field_ptr => try airStructFieldPtr(o, inst), + .array_to_slice => try airArrayToSlice(o, inst), .struct_field_ptr_index_0 => try airStructFieldPtrIndex(o, inst, 0), .struct_field_ptr_index_1 => try airStructFieldPtrIndex(o, inst, 1), @@ -1860,6 +1861,23 @@ fn airIsErr( return local; } +fn airArrayToSlice(o: *Object, inst: Air.Inst.Index) !CValue { + if (o.liveness.isUnused(inst)) + return CValue.none; + + const inst_ty = o.air.typeOfIndex(inst); + const local = try o.allocLocal(inst_ty, .Const); + const ty_op = o.air.instructions.items(.data)[inst].ty_op; + const writer = o.writer(); + const operand = try o.resolveInst(ty_op.operand); + const array_len = o.air.typeOf(ty_op.operand).elemType().arrayLen(); + + try writer.writeAll(" = { .ptr = "); + try o.writeCValue(writer, operand); + try writer.print(", .len = {d} }};\n", .{array_len}); + return local; +} + fn IndentWriter(comptime UnderlyingWriter: type) type { return struct { const Self = @This(); |
