tree: 1b7ac6c2bf08d4a89ab8d1fbded9f850d5d73624 [path history] [tgz]
  1. common/
  2. res/
  3. root/
  4. access.d
  5. aggregate.d
  6. aggregate.h
  7. aliasthis.d
  8. aliasthis.h
  9. apply.d
  10. arrayop.d
  11. arraytypes.d
  12. arraytypes.h
  13. ast_node.d
  14. ast_node.h
  15. astcodegen.d
  16. astenums.d
  17. attrib.d
  18. attrib.h
  19. blockexit.d
  20. boostlicense.txt
  21. builtin.d
  22. canthrow.d
  23. chkformat.d
  24. clone.d
  25. compiler.d
  26. compiler.h
  27. cond.d
  28. cond.h
  29. constfold.d
  30. cparse.d
  31. cppmangle.d
  32. ctfe.h
  33. ctfeexpr.d
  34. ctorflow.d
  35. dcast.d
  36. dclass.d
  37. declaration.d
  38. declaration.h
  39. delegatize.d
  40. denum.d
  41. dimport.d
  42. dinterpret.d
  43. dmacro.d
  44. dmangle.d
  45. dmodule.d
  46. doc.d
  47. doc.h
  48. dscope.d
  49. dstruct.d
  50. dsymbol.d
  51. dsymbol.h
  52. dsymbolsem.d
  53. dtemplate.d
  54. dtoh.d
  55. dversion.d
  56. entity.d
  57. enum.h
  58. errors.d
  59. errors.h
  60. escape.d
  61. expression.d
  62. expression.h
  63. expressionsem.d
  64. file_manager.d
  65. file_manager.h
  66. foreachvar.d
  67. func.d
  68. globals.d
  69. globals.h
  70. gluelayer.d
  71. hdrgen.d
  72. hdrgen.h
  73. iasm.d
  74. iasmgcc.d
  75. id.d
  76. id.h
  77. identifier.d
  78. identifier.h
  79. impcnvtab.d
  80. imphint.d
  81. import.h
  82. importc.d
  83. init.d
  84. init.h
  85. initsem.d
  86. inline.d
  87. intrange.d
  88. json.d
  89. json.h
  90. lambdacomp.d
  91. lexer.d
  92. mangle.h
  93. MERGE
  94. module.h
  95. mtype.d
  96. mtype.h
  97. nogc.d
  98. nspace.d
  99. nspace.h
  100. ob.d
  101. objc.d
  102. objc.h
  103. opover.d
  104. optimize.d
  105. parse.d
  106. parsetimevisitor.d
  107. permissivevisitor.d
  108. printast.d
  110. safe.d
  111. sapply.d
  112. scope.h
  113. semantic2.d
  114. semantic3.d
  115. sideeffect.d
  116. statement.d
  117. statement.h
  118. statement_rewrite_walker.d
  119. statementsem.d
  120. staticassert.d
  121. staticassert.h
  122. staticcond.d
  123. stmtstate.d
  124. target.d
  125. target.h
  126. template.h
  127. templateparamsem.d
  128. tokens.d
  129. tokens.h
  130. traits.d
  131. transitivevisitor.d
  132. typesem.d
  133. typinf.d
  134. utils.d
  135. VERSION
  136. version.h
  137. visitor.d
  138. visitor.h

DMD Source code

This is the source code to the DMD compiler for the D Programming Language defined in the documents at

These sources are free, they are redistributable and modifiable under the terms of the Boost Software License, Version 1.0. The terms of this license are in the file boostlicense.txt, or see

If a particular file has a different license in it, that overrides this license for that file.

-Walter Bright

Directory structure

dmd/The dmd driver and front-end
dmd/backend/Code generation for x86 or x86-64. Shared by the Digital Mars C compiler, but not LDC or GDC.
dmd/common/Code shared by the front-end and back-end
dmd/root/Meant as a portable utility library, but “it wasn't very good and the only project left using it is dmd”.

DMD has a mostly flat directory structure, so this section aims to divide all source files into logical groups for easier navigation. The groups are roughly ordered by how late they appear in the compilation process. Note that these groups have no strict meaning, the category assignments are a bit subjective.


mars.dThe entry point. Contains main.
cli.dDefine the command line interface
dmdparams.dDMD-specific parameters
globals.dDefine a structure storing command line options
dinifile.dParse settings from .ini file (sc.ini / dmd.conf)
vsoptions.dDetect the Microsoft Visual Studio toolchain for linking
frontend.dAn interface for using DMD as a library
errors.dError reporting functionality
target.dManage target-specific parameters for cross-compiling (for LDC/GDC)
compiler.dDescribe a back-end compiler and implements compiler-specific actions

Lexing / parsing

lexer.dConvert source code into tokens for the D and ImportC parsers
entity.dDefine “\&Entity;” escape sequence for strings / character literals
tokens.dDefine lexical tokens.
parse.dD parser, converting tokens into an Abstract Syntax Tree (AST)
cparse.dImportC parser, converting tokens into an Abstract Syntax Tree (AST)

Semantic analysis

Symbols and declarations

dsymbol.dBase class for a D symbol, e.g. a variable, function, module, enum etc.
identifier.dRepresents the name of a Dsymbol
id.dDefine strings for pre-defined identifiers (e.g. sizeof, string)
dscope.dDefine a ‘scope’ on which symbol lookup can be performed
dtemplate.dA template declaration or instance
dmodule.dDefine a package and module
mtype.dDefine expression types such as int, char[], void function()
arraytypes.dFor certain Declaration nodes of type T, provides aliases for Array!T
declaration.dMisc. declarations of alias, variables, type tuples, ClassInfo etc.
denum.dDefines enum declarations and enum members
attrib.dDeclarations of ‘attributes’ such as private, pragma(), immutable, @UDA, align, extern(C++) and more
func.dDefine a function declaration (includes function literals, invariant, unittest)
dversion.dDefines a version symbol, e.g. version = ident, debug = ident

AST nodes

ast_node.dDefine an abstract AST node class
astbase.dNamespace of AST nodes that can be produced by the parser
astcodegen.dNamespace of AST nodes of a AST ready for code generation
astenums.dEnums common to DMD and AST
expression.dDefine expression AST nodes
statement.dDefine statement AST nodes
staticassert.dDefine a static assert AST node
aggregate.dDefine an aggregate (struct, union or class) AST node
dclass.dDefine a class AST node
dstruct.dDefine a struct or union AST node
init.dDefine variable initializers

AST visitors

parsetimevisitor.dGeneral visitor for AST nodes
permissivevisitor.dSubclass of ParseTimeVisitor that does not assert(0) on unimplemented nodes
strictvisitor.dVisitor that forces derived classes to implement visit for every possible node
visitor.dA visitor implementing visit for all nodes present in the compiler
transitivevisitor.dProvide a mixin template with visit methods for the parse time AST
apply.dDepth-first expression visitor
sapply.dDepth-first statement visitor
statement_rewrite_walker.dStatement visitor that allows replacing the currently visited node

Semantic passes

dsymbolsem.dDo semantic 1 pass (symbol identifiers/types)
semantic2.dDo semantic 2 pass (symbol initializers)
semantic3.dDo semantic 3 pass (function bodies)
inline.dDo inline pass (optimization pass that dmd does in the front-end)
inlinecost.dCompute the cost of inlining a function call.
expressionsem.dDo semantic analysis for expressions
statementsem.dDo semantic analysis for statements
initsem.dDo semantic analysis for initializers
templateparamsem.dDo semantic analysis for template parameters
typesem.dDo semantic analysis for types

Semantic helpers

opover.dOperator overloading
clone.dGenerate automatic opEquals, opAssign and constructors for structs
blockexit.dFind out in what ways control flow can exit a block
ctorflow.dControl flow in constructors
constfold.dDo constant folding of arithmetic expressions
optimize.dDo constant folding more generally
dcast.dImplicit or explicit cast(), finding common types e.g. in x ? a : b, integral promotions
impcnvtab.dDefine an implicit conversion table for basic types
importc.dHelpers specific to ImportC
sideeffect.dExtract side-effects of expressions for certain lowerings.

Compile Time Function Execution (CTFE)

dinterpret.dCTFE entry point
ctfeexpr.dCTFE for expressions involving pointers, slices, array concatenation etc.
builtin.dAllow CTFE of certain external functions (core.math, std.math and core.bitop)

Specific language features

Attribute checks

nogc.d@nogc checks
safe.d@safe checks
canthrow.dnothrow checks
escape.dscope checks
access.dpublic / private checks
ob.dOwnership / borrowing (@live) checks

Inline Assembly

iasm.dInline assembly depending on the compiler
iasmdmd.dInline assembly for DMD
iasmgcc.dInline assembly for GDC


aliasthis.dResolve implicit conversions for alias X this
lambdacomp.d__traits(isSame, x => y, z => w)
cond.dEvaluate static if, version debug
staticcond.dLazily evaluate static conditions for static if, static assert and template constraints
delegatize.dConverts expression to delegates for lazy parameters
eh.dGenerate tables for exception handling
nspace.dNamespace for extern (C++, Module)
intrange.dValue range propagation
dimport.dRenamed imports (import aliasSymbol = pkg1.pkg2.symbol)
arrayop.dArray operations (a[] = b[] + c[])
typinf.dGenerate typeinfo for typeid() (as well as internals)
chkformat.dValidate arguments with format specifiers for printf / scanf etc.
imphint.dGive a suggestion to e.g. import std.stdio when writeln could not be resolved.

Library files

lib.dAbstract library class
libelf.dLibrary in ELF format (Unix)
libmach.dLibrary in Mach-O format (macOS)
libmscoff.dLibrary in COFF format (32/64-bit Windows)
libomf.dLibrary in OMF format (legacy 32-bit Windows)
scanelf.dExtract symbol names from a library in ELF format
scanmach.dExtract symbol names from a library in Mach-O format
scanmscoff.dExtract symbol names from a library in COFF format
scanomf.dExtract symbol names from a library in OMF format

Code generation / back-end interfacing

dmsc.dConfigures and initializes the back-end
toobj.dConvert an AST that went through all semantic phases into an object file
toir.dConvert Dsymbols intermediate representation
e2ir.dConvert Expressions to intermediate representation
s2ir.dConvert Statements to intermediate representation
stmtstate.dUsed to help transform statement AST into flow graph
toctype.dConvert a D type to a type the back-end understands
tocsym.dConvert a D symbol to a symbol the linker understands (with mangled name)
argtypes_x86.dConvert a D type into simple (register) types for the 32-bit x86 ABI
argtypes_sysv_x64.d‘argtypes’ for the x86_64 System V ABI
argtypes_aarch64.d‘argtypes’ for the AArch64 ABI
glue.dGenerate the object file for function declarations
gluelayer.dDeclarations for back-end functions that the front-end invokes
todt.dConvert initializers into structures that the back-end will add to the data segment
tocvdebug.dGenerate debug info in the CV4 debug format.
objc.dObjective-C interfacing
objc_glue.dGlue code for Objective-C interop.

Name mangling

cppmangle.dC++ name mangling
cppmanglewin.dC++ name mangling for Windows
dmangle.dD name mangling


link.dInvoke the linker as a separate process

Special output

doc.dDocumentation generation
dmacro.dDDoc macro processing
hdrgen.dConvert an AST into D source code for .di header generation, as well as -vcg-ast and error messages
json.dDescribe the module in a .json file for the -X flag
dtoh.dC++ header generation from D source files


Note: many other utilities are in dmd/root.

console.dPrint error messages in color
file_manager.dKeep file contents in memory
utils.dUtility functions related to files and file paths
asttypename.dPrint the internal name of an AST node (for debugging only)
printast.dPrint the AST data structure
foreachvar.dUsed in ob.d to iterate over all variables in an expression