authorgravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2022-10-24 20:53:55-04:00
committergravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2022-10-25 05:11:29-04:00
log361035fe7a74fed71303a92d15465daa647ac83e
treec12736db13914610f121434ea46d656a60bf3088
parente470cf361fb190863341c8859eccf9edda6d122c

cbe: implement cmp_lt_errors_len


2 files changed, 16 insertions(+), 3 deletions(-)

src/codegen/c.zig+16-2
...@@ -2078,7 +2078,6 @@ pub fn genGlobalAsm(mod: *Module, code: *std.ArrayList(u8)) !void {...@@ -2078,7 +2078,6 @@ pub fn genGlobalAsm(mod: *Module, code: *std.ArrayList(u8)) !void {
2078}2078}
20792079
2080pub fn genErrDecls(o: *Object) !void {2080pub fn genErrDecls(o: *Object) !void {
2081 if (o.dg.module.global_error_set.size == 0) return;
2082 const writer = o.writer();2081 const writer = o.writer();
20832082
2084 try writer.writeAll("enum {\n");2083 try writer.writeAll("enum {\n");
...@@ -2373,7 +2372,7 @@ fn genBody(f: *Function, body: []const Air.Inst.Index) error{ AnalysisFail, OutO...@@ -2373,7 +2372,7 @@ fn genBody(f: *Function, body: []const Air.Inst.Index) error{ AnalysisFail, OutO
2373 .cmp_neq => try airEquality(f, inst, "!((", "!="),2372 .cmp_neq => try airEquality(f, inst, "!((", "!="),
23742373
2375 .cmp_vector => return f.fail("TODO: C backend: implement cmp_vector", .{}),2374 .cmp_vector => return f.fail("TODO: C backend: implement cmp_vector", .{}),
2376 .cmp_lt_errors_len => return f.fail("TODO: C backend: implement cmp_lt_errors_len", .{}),2375 .cmp_lt_errors_len => try airCmpLtErrorsLen(f, inst),
23772376
2378 // bool_and and bool_or are non-short-circuit operations2377 // bool_and and bool_or are non-short-circuit operations
2379 .bool_and, .bit_and => try airBinOp(f, inst, "&", "and", .None),2378 .bool_and, .bit_and => try airBinOp(f, inst, "&", "and", .None),
...@@ -3176,6 +3175,21 @@ fn airEquality(...@@ -3176,6 +3175,21 @@ fn airEquality(
3176 return local;3175 return local;
3177}3176}
31783177
3178fn airCmpLtErrorsLen(f: *Function, inst: Air.Inst.Index) !CValue {
3179 if (f.liveness.isUnused(inst)) return CValue.none;
3180
3181 const un_op = f.air.instructions.items(.data)[inst].un_op;
3182 const inst_ty = f.air.typeOfIndex(inst);
3183 const operand = try f.resolveInst(un_op);
3184
3185 const writer = f.object.writer();
3186 const local = try f.allocLocal(inst_ty, .Const);
3187 try writer.writeAll(" = ");
3188 try f.writeCValue(writer, operand, .Other);
3189 try writer.print(" < sizeof({ }) / sizeof(*{0 });\n", .{fmtIdent("zig_errorName")});
3190 return local;
3191}
3192
3179fn airPtrAddSub(f: *Function, inst: Air.Inst.Index, operator: u8) !CValue {3193fn airPtrAddSub(f: *Function, inst: Air.Inst.Index, operator: u8) !CValue {
3180 if (f.liveness.isUnused(inst)) return CValue.none;3194 if (f.liveness.isUnused(inst)) return CValue.none;
31813195
test/behavior/cast.zig-1
...@@ -394,7 +394,6 @@ test "expected [*c]const u8, found [*:0]const u8" {...@@ -394,7 +394,6 @@ test "expected [*c]const u8, found [*:0]const u8" {
394test "explicit cast from integer to error type" {394test "explicit cast from integer to error type" {
395 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest;395 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest;
396 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO396 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO
397 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO
398 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;397 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
399 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO398 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
400399