aboutsummaryrefslogtreecommitdiff
path: root/src/codegen/c.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2021-10-21 17:12:04 -0400
committerGitHub <noreply@github.com>2021-10-21 17:12:04 -0400
commitd49c601d623d0b5a90f47c95cb931fe21a13d89e (patch)
tree76f107482d2b7bcf6279ce469da566df4197dc34 /src/codegen/c.zig
parente2a2e6c14fe181989187d6b59a79c5fc32961250 (diff)
parentfc034ca94f0682a06795616992f176f19ec9a83d (diff)
downloadzig-d49c601d623d0b5a90f47c95cb931fe21a13d89e.tar.gz
zig-d49c601d623d0b5a90f47c95cb931fe21a13d89e.zip
Merge pull request #9993 from Snektron/more-field-elem
stage2: More elemVal and elemPtr stuff
Diffstat (limited to 'src/codegen/c.zig')
-rw-r--r--src/codegen/c.zig21
1 files changed, 19 insertions, 2 deletions
diff --git a/src/codegen/c.zig b/src/codegen/c.zig
index 6e03de1cca..9050499fce 100644
--- a/src/codegen/c.zig
+++ b/src/codegen/c.zig
@@ -1081,10 +1081,9 @@ fn genBody(f: *Function, body: []const Air.Inst.Index) error{ AnalysisFail, OutO
.ptr_slice_ptr_ptr => try airPtrSliceFieldPtr(f, inst, ".ptr;\n"),
.ptr_elem_val => try airPtrElemVal(f, inst, "["),
- .ptr_ptr_elem_val => try airPtrElemVal(f, inst, "[0]["),
.ptr_elem_ptr => try airPtrElemPtr(f, inst),
.slice_elem_val => try airSliceElemVal(f, inst, "["),
- .ptr_slice_elem_val => try airSliceElemVal(f, inst, "[0]["),
+ .slice_elem_ptr => try airSliceElemPtr(f, inst),
.array_elem_val => try airArrayElemVal(f, inst),
.unwrap_errunion_payload => try airUnwrapErrUnionPay(f, inst),
@@ -1167,6 +1166,24 @@ fn airSliceElemVal(f: *Function, inst: Air.Inst.Index, prefix: []const u8) !CVal
return local;
}
+fn airSliceElemPtr(f: *Function, inst: Air.Inst.Index) !CValue {
+ if (f.liveness.isUnused(inst))
+ return CValue.none;
+ const ty_pl = f.air.instructions.items(.data)[inst].ty_pl;
+ const bin_op = f.air.extraData(Air.Bin, ty_pl.payload).data;
+
+ const slice = try f.resolveInst(bin_op.lhs);
+ const index = try f.resolveInst(bin_op.rhs);
+ const writer = f.object.writer();
+ const local = try f.allocLocal(f.air.typeOfIndex(inst), .Const);
+ try writer.writeAll(" = &");
+ try f.writeCValue(writer, slice);
+ try writer.writeByte('[');
+ try f.writeCValue(writer, index);
+ try writer.writeAll("];\n");
+ return local;
+}
+
fn airArrayElemVal(f: *Function, inst: Air.Inst.Index) !CValue {
if (f.liveness.isUnused(inst)) return CValue.none;