I got the following code to do what I want:

static this()
{
    void addOp(ref Opcode op)
    {
        assert (
            op.mnem !in iir,
            "duplicate op name " ~ op.mnem
        );

        iir[op.mnem] = &op;
    }

    foreach (memberName; __traits(allMembers, ir.ops))
    {
static if (__traits(compiles, addOp(__traits(getMember, ir.ops, memberName))))
        {
            writeln(memberName);
            addOp(__traits(getMember, ir.ops, memberName));
        }
    }
}


It's a bit of a hack, but it works. Is there any way to create some sort of alias for __traits(getMember, ir.ops, memberName) so that I don't have to write it out in full twice? Made some attempts but only got the compiler to complain.

Reply via email to