Question about GCC / GDC / LDC syntax of inline asm advanced

Cecil Ward cecil at cecilward.com
Fri Jul 7 12:18:47 UTC 2023


On Friday, 7 July 2023 at 11:39:44 UTC, Iain Buclaw wrote:
> On Thursday, 6 July 2023 at 23:11:08 UTC, Cecil Ward wrote:
>> In GDC and LDC’s inline asm syntax, the main asm part is 
>> separated from the constraints block by the first colon that 
>> begins the ‘outputs’ section. My question: how does GDC / LDC 
>> / GCC parse the first part, given that there can be umpteen 
>> kinds of assembler language. Is the parsing asm 
>> dialect-specific so that a full parse finds the first 
>> significant colon ?
>>
>
> The first part is parsed as an 
> [AssignExpression](https://dlang.org/spec/expression.html#assign_expressions), so you could have:
>
> ```
> asm {
>   (test ? "if-true-insn" : "if-false-insn")
>   ~ buildAsmString(foo, bar)
>   ~ test2() ? enumInsnTrue : enumInsnFalse // assign-expression 
> finishes here
>   : output-constraints
>   : ...
> }
> ```
> It's only at semantic-time that a "string-literal" result is 
> enforced using CTFE.
>
>> If not and the very first colon (outside double-quoted strings 
>> and comments) ends the first section, which is how I parse it, 
>> then there is a problem, as labels contain colons. And so I 
>> have a bug in my gramma for my kludge asm section parser, see 
>> thread elsewhere.
>>
>
> Labels are statements, so there shouldn't be any conflict 
> between the two.

Many thanks Iain. I am not doing a full parse so I shall simply 
have to warn the user that the ternary operator must be resolved 
at ctfe before I get the resulting string, and otherwise I have 
to forbid it, because for me, aside from detecting labels, I am 
treating colon as a section terminator. My kludge. But I don’t 
have months to spend.


More information about the Digitalmars-d mailing list