Conversation
0e5cd6f to
21154e2
Compare
src/mars.d
Outdated
| -transition=? list all language changes | ||
| -unittest compile in unit tests | ||
| -v verbose | ||
| -vcg-ast generates .d.cg file with the ast right before obj-file generation |
There was a problem hiding this comment.
Please remove from the help menu, it's an internal tool and I wouldn't want to commit to it too much.
src/mars.d
Outdated
| if(global.params.vcg_ast) | ||
| { | ||
| import ddmd.hdrgen; | ||
| foreach(mod;modules) |
There was a problem hiding this comment.
Style, space after if and for
| auto modFilenameLength = strlen(modFilename); | ||
| auto cgFilename = cast(char*)allocmemory(modFilenameLength + 4); | ||
| strcpy(cgFilename, modFilename); | ||
| cgFilename[modFilenameLength .. modFilenameLength + 4] = ".cg\0"; |
There was a problem hiding this comment.
There are path tools in root, look at other path manipulating code in mars.d.
There was a problem hiding this comment.
this is a few lines above:
assert(*ext == '.');
newname = cast(char*)mem.xmalloc((ext - p) + 1);
memcpy(newname, p, ext - p);
newname[ext - p] = 0; // strip extension
name = newname;
There was a problem hiding this comment.
Some comment indicating what you're trying to do to the file name would be most helpful.
There was a problem hiding this comment.
I'm not sure what that code is doing to the filename, but in root.filename there are forceExt, defaultExt, etc.
There was a problem hiding this comment.
cgFilename = filename ~ ".cg";
| bool hdrgen; /// true if generating header file | ||
| bool ddoc; /// true if generating Ddoc file | ||
| bool fullDump; /// true if generarting a full ast_dump | ||
|
|
There was a problem hiding this comment.
Why are so many specializations needed?
There was a problem hiding this comment.
because fullDump has to behave differently then hdrgen and so does ddoc,
| buf.level++; | ||
| s.elsebody.accept(this); | ||
| if (!s.elsebody.isScopeStatement()) | ||
| if (!s.elsebody.isScopeStatement() && !s.elsebody.isIfStatement) |
There was a problem hiding this comment.
What does this change actually do?
There was a problem hiding this comment.
otherwise
if (a) {}
else if (b) {}
else if (c) {}
will be printed as
if (a) {}
else
if (b) {}
else
if (c) {}
| if (ti.aliasdecl) | ||
| { | ||
| ti.aliasdecl.accept(this); | ||
| } |
There was a problem hiding this comment.
And this? Commit message is not helpful here.
There was a problem hiding this comment.
it writes out the instanced body of the template.
|
Could we get a sample of the output? |
|
@jacob-carlborg you don't want to see this :) |
alias vec = __vector(int[4]);
vec binop(vec a)
{
vec b = a;
return b;
}import object;
alias vec = __vector(int[4]);
__vector(int[4]) op(__vector(int[4]) a)
{
return a;
}
__vector(int[4]) binop(__vector(int[4]) a)
{
return (__vector(int[4]) a = a;) , a;
}It's really only useful to debug dmd internal issues. |
|
It does have the utility of showing templates and mix-ins expanded. |
|
Cool. Perhaps a nitpick, but this isn't really the AST itself that is printed, rather the result after lowering/semantic pass. I think having I've been working on a visitor that prints the data in the AST itself, which I initially thought this was. |
|
-vcg-ast stands for |
As far as I can see It's a good tool to learn the AST and understand the compiler. |
|
@jacob-carlborg where is that work ? |
In my local branch 😃. I can extract and make it publicly available if it's of any interest. It's not complete, I've added types and fields when needed. |
|
@jacob-carlborg please push it. I'd like to have a look. |
|
I just extracted it from my other branch without compiling it. The file is not added to the makefiles or anything. https://github.com/jacob-carlborg/dmd/blob/ast-printer/src/ast_printer.d |
|
Not a comment on the code, but maybe a useful tip: for inspecting large ASTs, it can be practical if nodes in the tree can be collapsed and expanded while you are looking at it. This can be done by writing the tree out as HTML5 using the <detail> tag (not supported by IE though). Here is an example. The code that generated this is in https://github.com/PhilippeSigaud/Pegged/blob/master/pegged/tohtml.d. |
|
The output is actually some kind of JavaScript format. I paste that in my editor, enable JavaScript as the language and then code folding works. Both human readable and collapsing works. |
|
General comment: there are zero comments in the code. For example, it seems like "print template instances" ought to be a comment somewhere in the commit entitled "print template instances". Little nudges like these can be very helpful. |
src/mars.d
Outdated
| auto modFilename = mod.srcfile.toChars(); | ||
| auto modFilenameLength = strlen(modFilename); | ||
| auto cgFilename = cast(char*)allocmemory(modFilenameLength + 4); | ||
| strcpy(cgFilename, modFilename); |
There was a problem hiding this comment.
One reason I dislike ad-hoc C string manipulation is the use of strcpy here. It should be memcpy(cgFilename, modFilename, modFilenameLength) because the length is already computed, and strcpy will compute it again, and strcpy will also add a 0 which will get promptly overwritten.
…-fullDump output for enums
c02be1a to
06fb773
Compare
|
Doesn't seem like any blocker for a debug tool. |
|
Auto-merge toggled on |
|
What version of the compiler did this make it into? Can it be put into the changelog? Every time I want to use this feature, I have to search for Stefan's posts to the forums to figure out the name of the switch. It's not listed in dmd --help, and not on the changelog. It's a super-handy feature, especially when trying to figure out which templates are instantiated, and how are they implemented. |
|
@schveiguy it should be in 2.073 ? |
|
Just today, I used it to determine the exact implementation of Having a tool to understand exactly how the compiler is going to interpret your templates and other code is sometimes indispensable, especially for a language like D where so much meta-code is happening. Note, if you didn't want it to be public facing, you shouldn't have posted about it on the newsgroup :) |
|
@schveiguy I want users to know about it. |
There has to be a way that it can be documented somewhere, but not "official". Again, I just want to be able to remember the name of the switch (it's not intuitive to me). |
|
@schveiguy "view code gen - a s t" |
|
I get that the name stands for something, but I just can't remember it :) Haven't you ever misremembered an option of a tool, looked for it using --help, and if not there, tried man, or online docs? The issue is that there isn't any existing doc that shows it. |
|
@schveiguy I put it in the wiki |
Apparently AST for ldc is an abuse of terminology, as it doesn't produces anything resembling a syntax tree: dlang/dmd#6556 (comment) . It is potentially meaningful only to ldc developers. Anyway the `generateAST` result type is fixed, along with some other small stuff around.
In order to debug the inliner I found a need to print the write-out AST after all semantic steps have been done (akin to
gcc -E).This is a developer tool and is therefore not covered by the test-suite.