<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><br class=""><div><br class=""><blockquote type="cite" class=""><div class="">On 9 Apr 2019, at 03:58, Mike Franklin via dmd-internals <<a href="mailto:dmd-internals@puremagic.com" class="">dmd-internals@puremagic.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div class=""><div class="ydp41d37f12yahoo-style-wrap" style="font-family:Helvetica Neue, Helvetica, Arial, sans-serif;font-size:13px;"><div class=""></div><span class=""></span><div class=""><span class="">That's an awfully broad question.  I'm no expert in DMD, but I do dabble in the source code often.  <br class=""><br class="">I'd start here: <a href="https://wiki.dlang.org/DMD_Source_Guide" class="">https://wiki.dlang.org/DMD_Source_Guide</a>  The information there is old but still relevant.<br class=""><br class="">This is my mental model and understanding<br class=""><br class="">source code --> lexer.d --> tokesn<br class="">tokens --> parse.d --> expressions (see expression.d)<br class="">expressions --> expressionsem.d --> lowered expressions<br class="">lowered expressions --> e2ir --> intermediate representation (I'm awufully vauge on this)<br class="">After that it's in the backend, and that's pretty much a black box to me.<br class=""></span></div></div></div></div></blockquote><div><br class=""></div><div>I can add to the above that the parser is a subclass of the lexer. The parser will retrieve the next token when it needs to, to continue parsing. The parsing is initiated from `Module.parse` in `dmodule.d` [1] which will then call `Parser.parseModule` in `parse.d`. After that the semantic analyzing phase will begin with the call to `dsymbolSemantic` for each module given to the compiler. This is all available in `mars.d`, which contains the entry point of the compiler.</div><div><br class=""></div><blockquote type="cite" class=""><div class=""><div class="ydp41d37f12yahoo-style-wrap" style="font-family:Helvetica Neue, Helvetica, Arial, sans-serif;font-size:13px;"><div class=""><span class="">Tracing with `<g class="gr_22 gr_inline_cards ContextualSpelling gr_run_anim gr_spell gr_ gr-alert" id="22" data-gr-id="22">printf</g>` is your friend, which is why you see so many commented `<g class="gr_inline_cards multiReplace ContextualSpelling gr_21 gr_run_anim gr_spell gr_ gr-alert ins-del" id="21" data-gr-id="21">printf</g>` statements in the source code.  You should be able to print out almost anything with with the `toChars()` method (e.g. `<g class="gr_inline_cards ContextualSpelling gr_run_anim gr_23 gr_spell gr_ gr-alert" id="23" data-gr-id="23">printf</g>("%s\n", whatever.toChars());`)</span></div></div></div></blockquote></div><div class=""><br class=""></div><div class="">For debugging I can also recommend tracing with `std.stdio.writeln` and `std.stdio.writefln`.  Although it's not allowed to use Phobos in the compiler, it’s perfectly fine to use it during development and debugging. Just make sure that all traces of Phobos are gone when making a PR. Most classes will have a `toString` method which is doing exactly the same thing as `toChars`, but it will return a D string instead of a C string. `writeln` knows about this and will call `toString` automatically. When printing an enum value with `writeln`, it will print the name of the enum member instead of it’s value, I like that very much. It’s also much easier to print D string with `writeln` than with `printf`. This is especially useful when we’re trying to get rid of all C strings and replace them with D strings.</div><div class=""><br class=""></div><div class="">[1] <a href="https://github.com/dlang/dmd/blob/b4429221e0b0024e5f0b99e084e075f02972e19a/src/dmd/dmodule.d#L654" class="">https://github.com/dlang/dmd/blob/b4429221e0b0024e5f0b99e084e075f02972e19a/src/dmd/dmodule.d#L654</a></div><br class=""><div class="">
<div style="color: rgb(0, 0, 0); font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;">-- <br class="">/Jacob Carlborg</div>

</div>
<br class=""></body></html>