www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 5051] New: dmd flag for partial compilation (similar to just running preprocessor in C/C++)

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5051

           Summary: dmd flag for partial compilation (similar to just
                    running preprocessor in C/C++)
           Product: D
           Version: unspecified
          Platform: Other
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: jmdavisProg gmx.com



PDT ---
Many C and C++ compilers have the option to just run the preprocessor and let
you see the output. That way you can see macro expansions and the like. It
would be extremely useful to be able to do something similar in D.

Given that D has mixins (both and string and template) as well as quite a few
constructs for conditional compilation, it would be useful to be able to see
what the code generated by all that looks like before it gets fully compiled by
dmd. So, for instance, you could see that mixin("a = b + 5;"); became

a = b + 5;

Obviously, in such a simple case it wouldn't be all that helpful, but it's easy
to get very complicated string mixins and debugging them can be quite
difficult. Being able to see the mixed in code could really help. Seeing
instantiated templates as well as the actually compiled in code for static ifs
and version blocks could be useful as well. Also, showing the lowerings for
stuff like operator overloads and scope statements could be useful, though I
don't think that it's quite as obviously useful.

Regardless, being able to see the generated code (and potentially lowered code)
could be extremely useful, and I think that it would be a great addition to dmd
to include a flag that did that.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 13 2010
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5051


Don <clugdbug yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |clugdbug yahoo.com.au



Agreed, I actually use this a lot when debugging backend bugs.
What I do is modify FuncDeclaration::toObjFile() in glue.c.
To do it properly would require a (fairly simple) pass over the syntax tree,
but the function case one is the most important by far. As you can see, it's
very simple.
Incidentally, when properly implemented, this feature would bring us much of
the way towards having a C backend.


                //printf("'%s' is SCfastpar\n",sp->Sident);
            }
        }
    }
+ if (!parent->isDeclaration()) {    
+       printf("%s ", ((TypeFunction *)(func->type))->next->toChars());
+       printf("%s(%s)\n{\n %s}\n\n", func->toChars(),
+            parameters?parameters->toChars() : "",
+            func->fbody->toChars());
+ }
    if (func->fbody)
    {   block *b;
        Blockx bx;
        Statement *sbody;

        localgot = NULL;

        sbody = func->fbody;

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 19 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5051


Rainer Schuetze <r.sagitario gmx.de> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |r.sagitario gmx.de



PDT ---
Some time ago, I have been playing around with a patch to dmd that would dunp
any mixin expansion into a file passed on the command line. After compilation,
you could look them up, but even better, you can single step through the code
with a debugger (at least, if there are line feeds in the mixin). 

Another benefit: source line numbers in mixins do not overlap with the source
code after the mixin anymore, but the patch was not good enough to show the
place of instantiation in an error message.

If there is interest, I can dig it up and create a diff to current svn.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 19 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5051


Trass3r <mrmocool gmx.de> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |mrmocool gmx.de



Yeah, post it, please.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Dec 02 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5051




PST ---
Created an attachment (id=839)
write mixin expansions to file

Here it is against svn 780.

Usage is: dmd test.d -mixin=mixins.d

What's missing is the instantiation backtrace for the line numbers in the error
messages, but the resulting mixin file shows the source line number of the
instantiation in a comment.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Dec 05 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5051




Here's another proposal:
https://github.com/D-Programming-Language/dmd/pull/426

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 06 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5051




According to Walter, dmd has a --b flag (purportedly only in debug builds?)
that prints the expression trees sent to the backend. Not quite preprocessed D
code per se, but close enough for debugging purposes.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 01 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5051


yebblies <yebblies gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |yebblies gmail.com



No, --b prints out stuff like this:

********* Basic Block 003B7D28 ************
el:003B9488 cnt=0 cs=0 ,  TYvoid 003B8C20 003B9450
 el:003B8C20 cnt=0 cs=0 =  TY* 003B8B40 003B8BE8
  el:003B8B40 cnt=0 cs=0 var  TY*  c
  el:003B8BE8 cnt=0 cs=0 call  TY* 003B8BB0 003B8B78
   el:003B8BB0 cnt=0 cs=0 var  TYC func  _d_newclass
   el:003B8B78 cnt=0 cs=0 relconst  TY*  0+& _D5testx5C16877__ClassZ
 el:003B9450 cnt=0 cs=0 ||  TYvoid 003B9230 003B9418
  el:003B9230 cnt=0 cs=0 ==  TYbool 003B8DA8 003B91F8
   el:003B8DA8 cnt=0 cs=0 *  TY* 003B8D70
    el:003B8D70 cnt=0 cs=0 +  TY* 003B8C90 003B8D38
     el:003B8C90 cnt=0 cs=0 *  TY* 003B8C58
      el:003B8C58 cnt=0 cs=0 var  TY*  c
     el:003B8D38 cnt=0 cs=0 *  TYunsigned 003B8CC8 003B8D00
      el:003B8CC8 cnt=0 cs=0 const  TYunsigned 0L
      el:003B8D00 cnt=0 cs=0 const  TYunsigned 4L
   el:003B91F8 cnt=0 cs=0 *  TY* 003B91C0
    el:003B91C0 cnt=0 cs=0 +  TY* 003B9150 003B9188
     el:003B9150 cnt=0 cs=0 ,  TY* 003B9070 003B9118
      el:003B9070 cnt=0 cs=0 =  TYlong long 003B8EB0 003B9038
       el:003B8EB0 cnt=0 cs=0 var  TYlong long  __dgtmp4

Not really usable for debugging anything except the glue layer.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 01 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5051


Maxim Fomin <maxim maxim-fomin.ru> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |maxim maxim-fomin.ru



---
I also find this usefull and in the absence of such feature currently use
expression dumping (exp->toChars()) during IR stage -
https://github.com/mxfm/dmd/compare/patched, but Don's way is probably better.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 01 2013
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5051


bearophile_hugs eml.cc changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bearophile_hugs eml.cc



Just don't such switch "partial compilation" because in computer science
"partial compilation" or "partial evaluation" mean something different for
compilations:
http://en.wikipedia.org/wiki/Partial_evaluation

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 02 2013