Stream: project-inline-asm

Topic: Formatting


Josh Triplett (Jan 22 2020 at 18:23, on Zulip):

I don't think we should do this in the current RFC (because I don't want to introduce a topic that leads to bikeshedding), but I think we should post a PR to https://github.com/rust-dev-tools/fmt-rfcs/ that proposes how to format asm! blocks.

Josh Triplett (Jan 22 2020 at 18:24, on Zulip):

Proposal:
Format on one line if it fits the line length. If it's long enough to break across lines, then format it as you would format a function with arguments, except that options should appear on the same line, and multiple operand specifications should appear on the same line unless they don't fit within the line length, in which case one operand should appear per line.

Josh Triplett (Jan 22 2020 at 18:25, on Zulip):

We should also specify how to format a multi-line asm string.

Amanieu (Jan 22 2020 at 18:27, on Zulip):

I expect multi-line asm to be very common.

Amanieu (Jan 22 2020 at 18:27, on Zulip):

Also use of concat!() in the asm string.

Josh Triplett (Jan 22 2020 at 18:29, on Zulip):

So:

asm!("short asm {}", in(reg) input_value);

asm!(
    "longer asm {x} {y} {z}",
    x = in(reg) expr1, y = in(reg) expr2, z = out(reg) expr3,
);

asm!(
    "longer asm {x} {y} {z}",
    x = in(reg) long_expression_1,
    y = in(reg) long_expression_2,
    z = out(reg) long_destination_3,
);
Josh Triplett (Jan 22 2020 at 18:30, on Zulip):

(Note the trailing commas, just like a multi-line function call.)

Amanieu (Jan 22 2020 at 18:36, on Zulip):

LGTM

Josh Triplett (Jan 22 2020 at 18:36, on Zulip):

For multi-line assembly text, the quotes surrounding the asm string may be treated like delimiters, and shouldn't be put on the same lines as assembly text:

asm!("
    multi-line assembly
    with multiple instructions
    but no operands
");

asm!("
    multi-line {x}
    with operands {y}
    ", x = in(reg) expr, y = out(reg) dest,
);
Amanieu (Jan 22 2020 at 18:36, on Zulip):

One thing I'm not too happy about is how to make the actual asm string look good when it is split over multiple lines

Josh Triplett (Jan 22 2020 at 18:37, on Zulip):

(I'm not certain about the multi-line with operands case; perhaps the closing quote in that case shouldn't be on the same line as the operands.)

Josh Triplett (Jan 22 2020 at 18:37, on Zulip):

(But it seems the least bad of several possibilities there.)

Josh Triplett (Jan 22 2020 at 18:38, on Zulip):

It helps that we don't especially care about the indentation of the emitted assembly, so we don't need things like \n\ or \n\t\ on every line.

Josh Triplett (Jan 22 2020 at 18:39, on Zulip):

It bugs me that the indentation of the closing " differs between the operand case and the no-operand case, though.

Last update: Feb 25 2020 at 04:25UTC