dfmt icon indicating copy to clipboard operation
dfmt copied to clipboard

Error for GNU-style inline assembly

Open zyedidia opened this issue 2 years ago • 2 comments

Formatting this code causes an error and warning:

void write(Reg reg)(uintptr val) {
    asm {
        "csrw %0, %1" : : "i"(reg) "r"(val);
    }
}
test.d(3:36)[error]: Expected `;` instead of `"r"`
test.d(3:44)[warn]: Empty asm instruction

even though this is valid code in GDC/LDC (for the right target). Maybe there should be an option to disable formatting within asm blocks and it can just ignore them?

It still formats the code, so it's not really a problem, but it's annoying that it spits out an error and warning.

zyedidia avatar Nov 03 '22 22:11 zyedidia

I guess I am supposed to add a comma after the first argument: "i"(reg), "r"(val). It's interesting that gdc still accepts it without the comma. Sorry for the bother.

zyedidia avatar Nov 03 '22 23:11 zyedidia

if GDC accepts it, so should dfmt / libdparse

WebFreak001 avatar Nov 03 '22 23:11 WebFreak001