authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-02-23 17:19:01-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-02-23 17:19:01-07:00
log08107a555eb1bc8d6e9aa8d80507896d08b2b18d
treea5f1d4bc3951daa8b0883da79539e583ca247090
parentbb89c619edbae8b02c826a2d334e2736c876c07d

zig fmt: fix inline assembly test cases

All zig fmt test cases are now passing again in this branch.

2 files changed, 95 insertions(+), 83 deletions(-)

lib/std/zig/parser_test.zig+73-80
...@@ -1863,46 +1863,42 @@ test "zig fmt: extra newlines at the end" {...@@ -1863,46 +1863,42 @@ test "zig fmt: extra newlines at the end" {
1863 );1863 );
1864}1864}
18651865
1866//test "zig fmt: simple asm" {1866test "zig fmt: simple asm" {
1867// try testTransform(1867 try testTransform(
1868// \\comptime {1868 \\comptime {
1869// \\ asm volatile (1869 \\ asm volatile (
1870// \\ \\.globl aoeu;1870 \\ \\.globl aoeu;
1871// \\ \\.type aoeu, @function;1871 \\ \\.type aoeu, @function;
1872// \\ \\.set aoeu, derp;1872 \\ \\.set aoeu, derp;
1873// \\ );1873 \\ );
1874// \\1874 \\
1875// \\ asm ("not real assembly"1875 \\ asm ("not real assembly"
1876// \\ :[a] "x" (x),);1876 \\ :[a] "x" (x),);
1877// \\ asm ("not real assembly"1877 \\ asm ("not real assembly"
1878// \\ :[a] "x" (->i32),:[a] "x" (1),);1878 \\ :[a] "x" (->i32),:[a] "x" (1),);
1879// \\ asm ("still not real assembly"1879 \\ asm ("still not real assembly"
1880// \\ :::"a","b",);1880 \\ :::"a","b",);
1881// \\}1881 \\}
1882// ,1882 ,
1883// \\comptime {1883 \\comptime {
1884// \\ asm volatile (1884 \\ asm volatile (
1885// \\ \\.globl aoeu;1885 \\ \\.globl aoeu;
1886// \\ \\.type aoeu, @function;1886 \\ \\.type aoeu, @function;
1887// \\ \\.set aoeu, derp;1887 \\ \\.set aoeu, derp;
1888// \\ );1888 \\ );
1889// \\1889 \\
1890// \\ asm ("not real assembly"1890 \\ asm ("not real assembly"
1891// \\ : [a] "x" (x)1891 \\ : [a] "x" (x)
1892// \\ );1892 \\ );
1893// \\ asm ("not real assembly"1893 \\ asm ("not real assembly"
1894// \\ : [a] "x" (-> i32)1894 \\ : [a] "x" (-> i32)
1895// \\ : [a] "x" (1)1895 \\ : [a] "x" (1)
1896// \\ );1896 \\ );
1897// \\ asm ("still not real assembly"1897 \\ asm ("still not real assembly" ::: "a", "b");
1898// \\ :1898 \\}
1899// \\ :1899 \\
1900// \\ : "a", "b"1900 );
1901// \\ );1901}
1902// \\}
1903// \\
1904// );
1905//}
19061902
1907test "zig fmt: nested struct literal with one item" {1903test "zig fmt: nested struct literal with one item" {
1908 try testCanonical(1904 try testCanonical(
...@@ -3363,46 +3359,43 @@ test "zig fmt: comptime block in container" {...@@ -3363,46 +3359,43 @@ test "zig fmt: comptime block in container" {
3363 );3359 );
3364}3360}
33653361
3366//test "zig fmt: inline asm parameter alignment" {3362test "zig fmt: inline asm parameter alignment" {
3367// try testCanonical(3363 try testCanonical(
3368// \\pub fn main() void {3364 \\pub fn main() void {
3369// \\ asm volatile (3365 \\ asm volatile (
3370// \\ \\ foo3366 \\ \\ foo
3371// \\ \\ bar3367 \\ \\ bar
3372// \\ );3368 \\ );
3373// \\ asm volatile (3369 \\ asm volatile (
3374// \\ \\ foo3370 \\ \\ foo
3375// \\ \\ bar3371 \\ \\ bar
3376// \\ : [_] "" (-> usize),3372 \\ : [_] "" (-> usize),
3377// \\ [_] "" (-> usize)3373 \\ [_] "" (-> usize)
3378// \\ );3374 \\ );
3379// \\ asm volatile (3375 \\ asm volatile (
3380// \\ \\ foo3376 \\ \\ foo
3381// \\ \\ bar3377 \\ \\ bar
3382// \\ :3378 \\ :
3383// \\ : [_] "" (0),3379 \\ : [_] "" (0),
3384// \\ [_] "" (0)3380 \\ [_] "" (0)
3385// \\ );3381 \\ );
3386// \\ asm volatile (3382 \\ asm volatile (
3387// \\ \\ foo3383 \\ \\ foo
3388// \\ \\ bar3384 \\ \\ bar
3389// \\ :3385 \\ ::: "", "");
3390// \\ :3386 \\ asm volatile (
3391// \\ : "", ""3387 \\ \\ foo
3392// \\ );3388 \\ \\ bar
3393// \\ asm volatile (3389 \\ : [_] "" (-> usize),
3394// \\ \\ foo3390 \\ [_] "" (-> usize)
3395// \\ \\ bar3391 \\ : [_] "" (0),
3396// \\ : [_] "" (-> usize),3392 \\ [_] "" (0)
3397// \\ [_] "" (-> usize)3393 \\ : "", ""
3398// \\ : [_] "" (0),3394 \\ );
3399// \\ [_] "" (0)3395 \\}
3400// \\ : "", ""3396 \\
3401// \\ );3397 );
3402// \\}3398}
3403// \\
3404// );
3405//}
34063399
3407test "zig fmt: multiline string in array" {3400test "zig fmt: multiline string in array" {
3408 try testCanonical(3401 try testCanonical(
lib/std/zig/render.zig+22-3
...@@ -1955,21 +1955,40 @@ fn renderAsm(...@@ -1955,21 +1955,40 @@ fn renderAsm(
1955 }1955 }
19561956
1957 if (asm_node.ast.items.len == 0) {1957 if (asm_node.ast.items.len == 0) {
1958 try renderExpression(gpa, ais, tree, asm_node.ast.template, .none);1958 ais.pushIndent();
1959 if (asm_node.first_clobber) |first_clobber| {1959 if (asm_node.first_clobber) |first_clobber| {
1960 // asm ("foo" ::: "a", "b")1960 // asm ("foo" ::: "a", "b")
1961 // asm ("foo" ::: "a", "b",)
1962 try renderExpression(gpa, ais, tree, asm_node.ast.template, .space);
1963 // Render the three colons.
1964 try renderToken(ais, tree, first_clobber - 3, .none);
1965 try renderToken(ais, tree, first_clobber - 2, .none);
1966 try renderToken(ais, tree, first_clobber - 1, .space);
1967
1961 var tok_i = first_clobber;1968 var tok_i = first_clobber;
1962 while (true) : (tok_i += 1) {1969 while (true) : (tok_i += 1) {
1963 try renderToken(ais, tree, tok_i, .none);1970 try renderToken(ais, tree, tok_i, .none);
1964 tok_i += 1;1971 tok_i += 1;
1965 switch (token_tags[tok_i]) {1972 switch (token_tags[tok_i]) {
1966 .r_paren => return renderToken(ais, tree, tok_i, space),1973 .r_paren => {
1967 .comma => try renderToken(ais, tree, tok_i, .space),1974 ais.popIndent();
1975 return renderToken(ais, tree, tok_i, space);
1976 },
1977 .comma => {
1978 if (token_tags[tok_i + 1] == .r_paren) {
1979 ais.popIndent();
1980 return renderToken(ais, tree, tok_i + 1, space);
1981 } else {
1982 try renderToken(ais, tree, tok_i, .space);
1983 }
1984 },
1968 else => unreachable,1985 else => unreachable,
1969 }1986 }
1970 }1987 }
1971 } else {1988 } else {
1972 // asm ("foo")1989 // asm ("foo")
1990 try renderExpression(gpa, ais, tree, asm_node.ast.template, .none);
1991 ais.popIndent();
1973 return renderToken(ais, tree, asm_node.ast.rparen, space); // rparen1992 return renderToken(ais, tree, asm_node.ast.rparen, space); // rparen
1974 }1993 }
1975 }1994 }