authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-12-02 23:18:22-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-12-03 05:22:50-05:00
logf68bfe2eb70065b76e187c85a203493be5b4959e
tree51044fd5b5615366675e7dad9df64d9933910974
parent610d604f5b4be220ea0f404af871c4365026a6a7

CBE: no braces when lowering block instruction

This change alone solves the bracket-depth issue when compiling zig1.c with Clang.

1 files changed, 9 insertions(+), 8 deletions(-)

src/codegen/c.zig+9-8
...@@ -2548,12 +2548,16 @@ fn genBody(f: *Function, body: []const Air.Inst.Index) error{ AnalysisFail, OutO...@@ -2548,12 +2548,16 @@ fn genBody(f: *Function, body: []const Air.Inst.Index) error{ AnalysisFail, OutO
2548 const writer = f.object.writer();2548 const writer = f.object.writer();
2549 if (body.len == 0) {2549 if (body.len == 0) {
2550 try writer.writeAll("{}");2550 try writer.writeAll("{}");
2551 return;2551 } else {
2552 try writer.writeAll("{\n");
2553 f.object.indent_writer.pushIndent();
2554 try genBodyInner(f, body);
2555 f.object.indent_writer.popIndent();
2556 try writer.writeByte('}');
2552 }2557 }
2558}
25532559
2554 try writer.writeAll("{\n");2560fn genBodyInner(f: *Function, body: []const Air.Inst.Index) error{ AnalysisFail, OutOfMemory }!void {
2555 f.object.indent_writer.pushIndent();
2556
2557 const air_tags = f.air.instructions.items(.tag);2561 const air_tags = f.air.instructions.items(.tag);
25582562
2559 for (body) |inst| {2563 for (body) |inst| {
...@@ -2799,9 +2803,6 @@ fn genBody(f: *Function, body: []const Air.Inst.Index) error{ AnalysisFail, OutO...@@ -2799,9 +2803,6 @@ fn genBody(f: *Function, body: []const Air.Inst.Index) error{ AnalysisFail, OutO
2799 else => try f.value_map.putNoClobber(Air.indexToRef(inst), result_value),2803 else => try f.value_map.putNoClobber(Air.indexToRef(inst), result_value),
2800 }2804 }
2801 }2805 }
2802
2803 f.object.indent_writer.popIndent();
2804 try writer.writeByte('}');
2805}2806}
28062807
2807fn airSliceField(f: *Function, inst: Air.Inst.Index, is_ptr: bool, field_name: []const u8) !CValue {2808fn airSliceField(f: *Function, inst: Air.Inst.Index, is_ptr: bool, field_name: []const u8) !CValue {
...@@ -3775,7 +3776,7 @@ fn airBlock(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -3775,7 +3776,7 @@ fn airBlock(f: *Function, inst: Air.Inst.Index) !CValue {
3775 .result = result,3776 .result = result,
3776 });3777 });
37773778
3778 try genBody(f, body);3779 try genBodyInner(f, body);
3779 try f.object.indent_writer.insertNewline();3780 try f.object.indent_writer.insertNewline();
3780 // label must be followed by an expression, add an empty one.3781 // label must be followed by an expression, add an empty one.
3781 try writer.print("zig_block_{d}:;\n", .{block_id});3782 try writer.print("zig_block_{d}:;\n", .{block_id});