On Thursday, 15 March 2012 at 08:35:48 UTC, Jay Norwood wrote:
Is there some option, similar to -E gcc option, that would generate the analogous listing for D?

You could add one to the compiler in just
a few lines; there's already a function that
does it, but it isn't called from anywhere.

Open up mars.c, and find this comment:
"Do not attempt to generate output files if errors"

It is line 1358 in my copy.


Right under that if(), add this:

        for (size_t i = 0; i < modules.dim; i++)
        {
            m = modules[i];
            m->gensymfile();
        }

compile your new compiler.

BACK UP YOUR FILES because this function overwrites
the original .d file!


$ cat test10.d
void main() {
   auto a = 0;
}

# we have to backup because otherwise our original source will be lost!
$ cp test10.d test10_original.d

# you'll have to pass the paths for phobos and druntime unless you bring in a dmd.conf... $ d/dmd2/src/dmd/dmd -Id/dmd2/src/druntime/import -Id/dmd2/src/phobos -L-Ld/dmd2/linux/lib32/ test10.d

$ cat test10.d
// Sym file generated from 'test10.d'
import object;
void main()
{
int a = 0;
return 0;
}





It gets ugly if you use a lot of features because this
outputs the dmd translations - so foreach becomes for
and other lowerings.

But you can see basically what the compiler is going
to generate for final code.

Reply via email to