authorgravatar for thatlemon@gmail.comLemonBoy <thatlemon@gmail.com> 2019-05-13 11:22:42+02:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-05-13 12:20:11-04:00
log08d41da916787ab0c19130dc4dc4e7b0e75c9fa8
treebd54f4198e37b5baf708375632fb8419fd2d52c8
parent66d86eccbe43e01500bd57dba13a4ce68aba8921

Fix formatting for multiline asm expressions


3 files changed, 51 insertions(+), 3 deletions(-)

std/valgrind.zig+2-2
...@@ -12,7 +12,7 @@ pub fn doClientRequest(default: usize, request: usize, a1: usize, a2: usize, a3:...@@ -12,7 +12,7 @@ pub fn doClientRequest(default: usize, request: usize, a1: usize, a2: usize, a3:
12 \\ roll $3, %%edi ; roll $13, %%edi12 \\ roll $3, %%edi ; roll $13, %%edi
13 \\ roll $29, %%edi ; roll $19, %%edi13 \\ roll $29, %%edi ; roll $19, %%edi
14 \\ xchgl %%ebx,%%ebx14 \\ xchgl %%ebx,%%ebx
15 : [_] "={edx}" (-> usize)15 : [_] "={edx}" (-> usize)
16 : [_] "{eax}" (&[]usize{ request, a1, a2, a3, a4, a5 }),16 : [_] "{eax}" (&[]usize{ request, a1, a2, a3, a4, a5 }),
17 [_] "0" (default)17 [_] "0" (default)
18 : "cc", "memory"18 : "cc", "memory"
...@@ -23,7 +23,7 @@ pub fn doClientRequest(default: usize, request: usize, a1: usize, a2: usize, a3:...@@ -23,7 +23,7 @@ pub fn doClientRequest(default: usize, request: usize, a1: usize, a2: usize, a3:
23 \\ rolq $3, %%rdi ; rolq $13, %%rdi23 \\ rolq $3, %%rdi ; rolq $13, %%rdi
24 \\ rolq $61, %%rdi ; rolq $51, %%rdi24 \\ rolq $61, %%rdi ; rolq $51, %%rdi
25 \\ xchgq %%rbx,%%rbx25 \\ xchgq %%rbx,%%rbx
26 : [_] "={rdx}" (-> usize)26 : [_] "={rdx}" (-> usize)
27 : [_] "{rax}" (&[]usize{ request, a1, a2, a3, a4, a5 }),27 : [_] "{rax}" (&[]usize{ request, a1, a2, a3, a4, a5 }),
28 [_] "0" (default)28 [_] "0" (default)
29 : "cc", "memory"29 : "cc", "memory"
std/zig/parser_test.zig+41
...@@ -2129,6 +2129,47 @@ test "zig fmt: comptime block in container" {...@@ -2129,6 +2129,47 @@ test "zig fmt: comptime block in container" {
2129 );2129 );
2130}2130}
21312131
2132test "zig fmt: inline asm parameter alignment" {
2133 try testCanonical(
2134 \\pub fn main() void {
2135 \\ asm volatile (
2136 \\ \\ foo
2137 \\ \\ bar
2138 \\ );
2139 \\ asm volatile (
2140 \\ \\ foo
2141 \\ \\ bar
2142 \\ : [_] "" (-> usize),
2143 \\ [_] "" (-> usize)
2144 \\ );
2145 \\ asm volatile (
2146 \\ \\ foo
2147 \\ \\ bar
2148 \\ :
2149 \\ : [_] "" (0),
2150 \\ [_] "" (0)
2151 \\ );
2152 \\ asm volatile (
2153 \\ \\ foo
2154 \\ \\ bar
2155 \\ :
2156 \\ :
2157 \\ : "", ""
2158 \\ );
2159 \\ asm volatile (
2160 \\ \\ foo
2161 \\ \\ bar
2162 \\ : [_] "" (-> usize),
2163 \\ [_] "" (-> usize)
2164 \\ : [_] "" (0),
2165 \\ [_] "" (0)
2166 \\ : "", ""
2167 \\ );
2168 \\}
2169 \\
2170 );
2171}
2172
2132const std = @import("std");2173const std = @import("std");
2133const mem = std.mem;2174const mem = std.mem;
2134const warn = std.debug.warn;2175const warn = std.debug.warn;
std/zig/render.zig+8-1
...@@ -1549,7 +1549,14 @@ fn renderExpression(...@@ -1549,7 +1549,14 @@ fn renderExpression(
1549 try renderExpression(allocator, stream, tree, indent, start_col, asm_node.template, Space.Newline);1549 try renderExpression(allocator, stream, tree, indent, start_col, asm_node.template, Space.Newline);
15501550
1551 const indent_once = indent + indent_delta;1551 const indent_once = indent + indent_delta;
1552 try stream.writeByteNTimes(' ', indent_once);1552
1553 if (asm_node.template.id == ast.Node.Id.MultilineStringLiteral) {
1554 // After rendering a multiline string literal the cursor is
1555 // already offset by indent
1556 try stream.writeByteNTimes(' ', indent_delta);
1557 } else {
1558 try stream.writeByteNTimes(' ', indent_once);
1559 }
15531560
1554 const colon1 = tree.nextToken(asm_node.template.lastToken());1561 const colon1 = tree.nextToken(asm_node.template.lastToken());
1555 const indent_extra = indent_once + 2;1562 const indent_extra = indent_once + 2;