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" {
18631863 );
18641864}
18651865
1866//test "zig fmt: simple asm" {
1867// try testTransform(
1868// \\comptime {
1869// \\ asm volatile (
1870// \\ \\.globl aoeu;
1871// \\ \\.type aoeu, @function;
1872// \\ \\.set aoeu, derp;
1873// \\ );
1874// \\
1875// \\ asm ("not real assembly"
1876// \\ :[a] "x" (x),);
1877// \\ asm ("not real assembly"
1878// \\ :[a] "x" (->i32),:[a] "x" (1),);
1879// \\ asm ("still not real assembly"
1880// \\ :::"a","b",);
1881// \\}
1882// ,
1883// \\comptime {
1884// \\ asm volatile (
1885// \\ \\.globl aoeu;
1886// \\ \\.type aoeu, @function;
1887// \\ \\.set aoeu, derp;
1888// \\ );
1889// \\
1890// \\ asm ("not real assembly"
1891// \\ : [a] "x" (x)
1892// \\ );
1893// \\ asm ("not real assembly"
1894// \\ : [a] "x" (-> i32)
1895// \\ : [a] "x" (1)
1896// \\ );
1897// \\ asm ("still not real assembly"
1898// \\ :
1899// \\ :
1900// \\ : "a", "b"
1901// \\ );
1902// \\}
1903// \\
1904// );
1905//}
1866test "zig fmt: simple asm" {
1867 try testTransform(
1868 \\comptime {
1869 \\ asm volatile (
1870 \\ \\.globl aoeu;
1871 \\ \\.type aoeu, @function;
1872 \\ \\.set aoeu, derp;
1873 \\ );
1874 \\
1875 \\ asm ("not real assembly"
1876 \\ :[a] "x" (x),);
1877 \\ asm ("not real assembly"
1878 \\ :[a] "x" (->i32),:[a] "x" (1),);
1879 \\ asm ("still not real assembly"
1880 \\ :::"a","b",);
1881 \\}
1882 ,
1883 \\comptime {
1884 \\ asm volatile (
1885 \\ \\.globl aoeu;
1886 \\ \\.type aoeu, @function;
1887 \\ \\.set aoeu, derp;
1888 \\ );
1889 \\
1890 \\ asm ("not real assembly"
1891 \\ : [a] "x" (x)
1892 \\ );
1893 \\ asm ("not real assembly"
1894 \\ : [a] "x" (-> i32)
1895 \\ : [a] "x" (1)
1896 \\ );
1897 \\ asm ("still not real assembly" ::: "a", "b");
1898 \\}
1899 \\
1900 );
1901}
19061902
19071903test "zig fmt: nested struct literal with one item" {
19081904 try testCanonical(
......@@ -3363,46 +3359,43 @@ test "zig fmt: comptime block in container" {
33633359 );
33643360}
33653361
3366//test "zig fmt: inline asm parameter alignment" {
3367// try testCanonical(
3368// \\pub fn main() void {
3369// \\ asm volatile (
3370// \\ \\ foo
3371// \\ \\ bar
3372// \\ );
3373// \\ asm volatile (
3374// \\ \\ foo
3375// \\ \\ bar
3376// \\ : [_] "" (-> usize),
3377// \\ [_] "" (-> usize)
3378// \\ );
3379// \\ asm volatile (
3380// \\ \\ foo
3381// \\ \\ bar
3382// \\ :
3383// \\ : [_] "" (0),
3384// \\ [_] "" (0)
3385// \\ );
3386// \\ asm volatile (
3387// \\ \\ foo
3388// \\ \\ bar
3389// \\ :
3390// \\ :
3391// \\ : "", ""
3392// \\ );
3393// \\ asm volatile (
3394// \\ \\ foo
3395// \\ \\ bar
3396// \\ : [_] "" (-> usize),
3397// \\ [_] "" (-> usize)
3398// \\ : [_] "" (0),
3399// \\ [_] "" (0)
3400// \\ : "", ""
3401// \\ );
3402// \\}
3403// \\
3404// );
3405//}
3362test "zig fmt: inline asm parameter alignment" {
3363 try testCanonical(
3364 \\pub fn main() void {
3365 \\ asm volatile (
3366 \\ \\ foo
3367 \\ \\ bar
3368 \\ );
3369 \\ asm volatile (
3370 \\ \\ foo
3371 \\ \\ bar
3372 \\ : [_] "" (-> usize),
3373 \\ [_] "" (-> usize)
3374 \\ );
3375 \\ asm volatile (
3376 \\ \\ foo
3377 \\ \\ bar
3378 \\ :
3379 \\ : [_] "" (0),
3380 \\ [_] "" (0)
3381 \\ );
3382 \\ asm volatile (
3383 \\ \\ foo
3384 \\ \\ bar
3385 \\ ::: "", "");
3386 \\ asm volatile (
3387 \\ \\ foo
3388 \\ \\ bar
3389 \\ : [_] "" (-> usize),
3390 \\ [_] "" (-> usize)
3391 \\ : [_] "" (0),
3392 \\ [_] "" (0)
3393 \\ : "", ""
3394 \\ );
3395 \\}
3396 \\
3397 );
3398}
34063399
34073400test "zig fmt: multiline string in array" {
34083401 try testCanonical(
lib/std/zig/render.zig+22-3
......@@ -1955,21 +1955,40 @@ fn renderAsm(
19551955 }
19561956
19571957 if (asm_node.ast.items.len == 0) {
1958 try renderExpression(gpa, ais, tree, asm_node.ast.template, .none);
1958 ais.pushIndent();
19591959 if (asm_node.first_clobber) |first_clobber| {
19601960 // 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
19611968 var tok_i = first_clobber;
19621969 while (true) : (tok_i += 1) {
19631970 try renderToken(ais, tree, tok_i, .none);
19641971 tok_i += 1;
19651972 switch (token_tags[tok_i]) {
1966 .r_paren => return renderToken(ais, tree, tok_i, space),
1967 .comma => try renderToken(ais, tree, tok_i, .space),
1973 .r_paren => {
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 },
19681985 else => unreachable,
19691986 }
19701987 }
19711988 } else {
19721989 // asm ("foo")
1990 try renderExpression(gpa, ais, tree, asm_node.ast.template, .none);
1991 ais.popIndent();
19731992 return renderToken(ais, tree, asm_node.ast.rparen, space); // rparen
19741993 }
19751994 }