diff --git a/lib/std/zig/parser_test.zig b/lib/std/zig/parser_test.zig index 44f4dc509a..e32a37a3c6 100644 --- a/lib/std/zig/parser_test.zig +++ b/lib/std/zig/parser_test.zig @@ -1863,46 +1863,42 @@ test "zig fmt: extra newlines at the end" { ); } -//test "zig fmt: simple asm" { -// try testTransform( -// \\comptime { -// \\ asm volatile ( -// \\ \\.globl aoeu; -// \\ \\.type aoeu, @function; -// \\ \\.set aoeu, derp; -// \\ ); -// \\ -// \\ asm ("not real assembly" -// \\ :[a] "x" (x),); -// \\ asm ("not real assembly" -// \\ :[a] "x" (->i32),:[a] "x" (1),); -// \\ asm ("still not real assembly" -// \\ :::"a","b",); -// \\} -// , -// \\comptime { -// \\ asm volatile ( -// \\ \\.globl aoeu; -// \\ \\.type aoeu, @function; -// \\ \\.set aoeu, derp; -// \\ ); -// \\ -// \\ asm ("not real assembly" -// \\ : [a] "x" (x) -// \\ ); -// \\ asm ("not real assembly" -// \\ : [a] "x" (-> i32) -// \\ : [a] "x" (1) -// \\ ); -// \\ asm ("still not real assembly" -// \\ : -// \\ : -// \\ : "a", "b" -// \\ ); -// \\} -// \\ -// ); -//} +test "zig fmt: simple asm" { + try testTransform( + \\comptime { + \\ asm volatile ( + \\ \\.globl aoeu; + \\ \\.type aoeu, @function; + \\ \\.set aoeu, derp; + \\ ); + \\ + \\ asm ("not real assembly" + \\ :[a] "x" (x),); + \\ asm ("not real assembly" + \\ :[a] "x" (->i32),:[a] "x" (1),); + \\ asm ("still not real assembly" + \\ :::"a","b",); + \\} + , + \\comptime { + \\ asm volatile ( + \\ \\.globl aoeu; + \\ \\.type aoeu, @function; + \\ \\.set aoeu, derp; + \\ ); + \\ + \\ asm ("not real assembly" + \\ : [a] "x" (x) + \\ ); + \\ asm ("not real assembly" + \\ : [a] "x" (-> i32) + \\ : [a] "x" (1) + \\ ); + \\ asm ("still not real assembly" ::: "a", "b"); + \\} + \\ + ); +} test "zig fmt: nested struct literal with one item" { try testCanonical( @@ -3363,46 +3359,43 @@ test "zig fmt: comptime block in container" { ); } -//test "zig fmt: inline asm parameter alignment" { -// try testCanonical( -// \\pub fn main() void { -// \\ asm volatile ( -// \\ \\ foo -// \\ \\ bar -// \\ ); -// \\ asm volatile ( -// \\ \\ foo -// \\ \\ bar -// \\ : [_] "" (-> usize), -// \\ [_] "" (-> usize) -// \\ ); -// \\ asm volatile ( -// \\ \\ foo -// \\ \\ bar -// \\ : -// \\ : [_] "" (0), -// \\ [_] "" (0) -// \\ ); -// \\ asm volatile ( -// \\ \\ foo -// \\ \\ bar -// \\ : -// \\ : -// \\ : "", "" -// \\ ); -// \\ asm volatile ( -// \\ \\ foo -// \\ \\ bar -// \\ : [_] "" (-> usize), -// \\ [_] "" (-> usize) -// \\ : [_] "" (0), -// \\ [_] "" (0) -// \\ : "", "" -// \\ ); -// \\} -// \\ -// ); -//} +test "zig fmt: inline asm parameter alignment" { + try testCanonical( + \\pub fn main() void { + \\ asm volatile ( + \\ \\ foo + \\ \\ bar + \\ ); + \\ asm volatile ( + \\ \\ foo + \\ \\ bar + \\ : [_] "" (-> usize), + \\ [_] "" (-> usize) + \\ ); + \\ asm volatile ( + \\ \\ foo + \\ \\ bar + \\ : + \\ : [_] "" (0), + \\ [_] "" (0) + \\ ); + \\ asm volatile ( + \\ \\ foo + \\ \\ bar + \\ ::: "", ""); + \\ asm volatile ( + \\ \\ foo + \\ \\ bar + \\ : [_] "" (-> usize), + \\ [_] "" (-> usize) + \\ : [_] "" (0), + \\ [_] "" (0) + \\ : "", "" + \\ ); + \\} + \\ + ); +} test "zig fmt: multiline string in array" { try testCanonical( diff --git a/lib/std/zig/render.zig b/lib/std/zig/render.zig index 53a541ab61..cd1d4a562b 100644 --- a/lib/std/zig/render.zig +++ b/lib/std/zig/render.zig @@ -1955,21 +1955,40 @@ fn renderAsm( } if (asm_node.ast.items.len == 0) { - try renderExpression(gpa, ais, tree, asm_node.ast.template, .none); + ais.pushIndent(); if (asm_node.first_clobber) |first_clobber| { // asm ("foo" ::: "a", "b") + // asm ("foo" ::: "a", "b",) + try renderExpression(gpa, ais, tree, asm_node.ast.template, .space); + // Render the three colons. + try renderToken(ais, tree, first_clobber - 3, .none); + try renderToken(ais, tree, first_clobber - 2, .none); + try renderToken(ais, tree, first_clobber - 1, .space); + var tok_i = first_clobber; while (true) : (tok_i += 1) { try renderToken(ais, tree, tok_i, .none); tok_i += 1; switch (token_tags[tok_i]) { - .r_paren => return renderToken(ais, tree, tok_i, space), - .comma => try renderToken(ais, tree, tok_i, .space), + .r_paren => { + ais.popIndent(); + return renderToken(ais, tree, tok_i, space); + }, + .comma => { + if (token_tags[tok_i + 1] == .r_paren) { + ais.popIndent(); + return renderToken(ais, tree, tok_i + 1, space); + } else { + try renderToken(ais, tree, tok_i, .space); + } + }, else => unreachable, } } } else { // asm ("foo") + try renderExpression(gpa, ais, tree, asm_node.ast.template, .none); + ais.popIndent(); return renderToken(ais, tree, asm_node.ast.rparen, space); // rparen } }