Conditional compilation inside asm and enum declarations

Tomas Lindquist Olsen tomas.l.olsen at gmail.com
Wed Jul 15 03:32:23 PDT 2009


On Wed, Jul 15, 2009 at 12:24 PM, Daniel
Keep<daniel.keep.lists at gmail.com> wrote:
>
> Tomas Lindquist Olsen wrote:
>> On Wed, Jul 15, 2009 at 2:18 AM, Walter
>> Bright<newshound1 at digitalmars.com> wrote:
>>> Don wrote:
>>>> In this case you may have a long function, with only a single instruction
>>>> right in the middle which needs to be changed.
>>> void foo()
>>> {
>>>    asm
>>>    {
>>>        mov EAX,EAX;
>>>        ... lots more instructions ...
>>>    }
>>>    version (bar) asm
>>>    {
>>>        mov EAX,EAX;
>>>    }
>>>    asm
>>>    {
>>>        ... even more instructions ...
>>>        mov EAX,EAX;
>>>    }
>>> }
>>>
>>
>>
>> Since when does D guarantee that no code is inserted before/after asm blocks?
>
> I think it was around the time that the mail service guaranteed that
> they wouldn't leave a dead cat in your mailbox on every alternate Wednesday.
>


Funny.

But seriously, it actually takes some effort to make sure all
successive asm statements are merged into a single asm block when
generating code for LLVM.
The DMD frontend "unpacks" asm blocks, so each line is a seperate
AsmStatement, and with version blocks, you have to look into blocks as
well.

LLVM will restore registers etc. when an asm block is done!

And besides this is not in the spec, it might be implied, somehow, but
it's not in the spec.



More information about the Digitalmars-d mailing list