zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit 08d41da916787ab0c19130dc4dc4e7b0e75c9fa8 (tree)
parent 66d86eccbe43e01500bd57dba13a4ce68aba8921
Author: LemonBoy <thatlemon@gmail.com>
Date:   Mon, 13 May 2019 11:22:42 +0200

Fix formatting for multiline asm expressions

Diffstat:
Mstd/valgrind.zig | 4++--
Mstd/zig/parser_test.zig | 41+++++++++++++++++++++++++++++++++++++++++
Mstd/zig/render.zig | 9++++++++-
3 files changed, 51 insertions(+), 3 deletions(-)

diff --git a/std/valgrind.zig b/std/valgrind.zig @@ -12,7 +12,7 @@ pub fn doClientRequest(default: usize, request: usize, a1: usize, a2: usize, a3: \\ roll $3, %%edi ; roll $13, %%edi \\ roll $29, %%edi ; roll $19, %%edi \\ xchgl %%ebx,%%ebx - : [_] "={edx}" (-> usize) + : [_] "={edx}" (-> usize) : [_] "{eax}" (&[]usize{ request, a1, a2, a3, a4, a5 }), [_] "0" (default) : "cc", "memory" @@ -23,7 +23,7 @@ pub fn doClientRequest(default: usize, request: usize, a1: usize, a2: usize, a3: \\ rolq $3, %%rdi ; rolq $13, %%rdi \\ rolq $61, %%rdi ; rolq $51, %%rdi \\ xchgq %%rbx,%%rbx - : [_] "={rdx}" (-> usize) + : [_] "={rdx}" (-> usize) : [_] "{rax}" (&[]usize{ request, a1, a2, a3, a4, a5 }), [_] "0" (default) : "cc", "memory" diff --git a/std/zig/parser_test.zig b/std/zig/parser_test.zig @@ -2129,6 +2129,47 @@ 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) + \\ : "", "" + \\ ); + \\} + \\ + ); +} + const std = @import("std"); const mem = std.mem; const warn = std.debug.warn; diff --git a/std/zig/render.zig b/std/zig/render.zig @@ -1549,7 +1549,14 @@ fn renderExpression( try renderExpression(allocator, stream, tree, indent, start_col, asm_node.template, Space.Newline); const indent_once = indent + indent_delta; - try stream.writeByteNTimes(' ', indent_once); + + if (asm_node.template.id == ast.Node.Id.MultilineStringLiteral) { + // After rendering a multiline string literal the cursor is + // already offset by indent + try stream.writeByteNTimes(' ', indent_delta); + } else { + try stream.writeByteNTimes(' ', indent_once); + } const colon1 = tree.nextToken(asm_node.template.lastToken()); const indent_extra = indent_once + 2;