Conditional compilation inside asm and enum declarations
Jarrett Billingsley
jarrett.billingsley at gmail.com
Mon Jul 13 08:40:38 PDT 2009
On Mon, Jul 13, 2009 at 11:15 AM, Julian Salazar<julian at ifeelrandom.com> wrote:
> Hi, I'm new here to the community but I've been using D for a while now, and
> I have to say that it's a great programming language. I'd like to get
> involved in this community and help shape this language.
Man, so would I ;)
> I'm just wondering about a minor issue: why are conditional blocks invalid
> within expressions such as enum and asm? I mean, in trivial cases it's fine,
> but in instances where code duplication is a big maintainability nightmare,
> making conditional compilation more flexible would have benefits for
> developers.
>
> Something like (I know it's a trivial example, but you get the point):
>
> asm {
> version(x86) mov EAX, 1;
> else version(x86_64) mov EAX, 2;
> }
>
> would trigger an error. Also, though I know enum qualifies as a
> constant/datatype cross, structs and classes are perfectly fine with
> conditional compilation. Couldn't the lexical stuff be changed to support it
> for enum and asm as well?
That'd be nice. If you'd like, you could file an enhancement in D's
bugzilla, at http://d.puremagic.com/issues/.
> Also, I noticed that there is no formal specification page for x86-64 inline
> assembly. You define a predefined version identifier such as
> D_InlineAsm_X86_64, but you don't define registers and instructions
> pertaining to it. In GDC for example, using the RAX register in the D inline
> ASM syntax is invalid. Not sure what the case is in LDC (they probably do
> implement it for x86-64), and I know DMD does not have a 64-bit version, but
> the spec should at least have a definition for compilers that do implement
> 64-bit support.
I'm pretty sure LDC does implement x64 inline assembly. It doesn't
seem to be documented yet.
GDC supports inline assembly for just about any platform but with a
nonstandard GCC-based syntax; see the "Extended Assembler" section
here: http://dgcc.sourceforge.net/gdc/manual.html I've personally
used it for x64 assembly with great success :)
More information about the Digitalmars-d
mailing list