Skip to content
mrmonday edited this page Jan 22, 2012 · 4 revisions

Hacker Guide

When grepping for LDC specific code look for "LDC" and "LLVM" upper and lower case. dmd2 specific code is "DMDV2"

##File tour

LDC is built from files in subdirectories dmd, gen, and ir.

  • gen/main.cpp holds the main() function.
  • gen/toobj.cpp holds Module::genobjfile(). This is the main plug into the llvm backend.
  • gen/irstate declares IRState, an instance of which is created in Module::genobjfile() and available as gIR. Most codegen happens through that instance.
  • gen/dvalue holds DValue and derivaties, which basically contain a D type and LLVM value
  • gen/statements.cpp has codegen for most statements
  • gen/toir.cpp has codegen for most expressions
  • gen/llvmhelpers has codegen helpers, like DtoAssign
  • gen/tollvm has LLVM utilities, like DtoType which converts D types to LLVM types
  • gen/todebug produce, explain how debugging with llvm works: (http://llvm.org/docs/SourceLevelDebugging.html)

The other directories contain:

  • bin/ - This is where the compiled ldc binary resides, also holds ldc.conf/ini.
  • lib/ - The runtime library .so and .a files live in here.
  • runtime/ - Scripts for building Tango runtime and Tango patch
  • runtime/internal - LDC specific part of runtime
  • tango/ - Tango checkout.
  • lphobos/ - Phobos runtime. Unused for a long time, recently reactivated by downs.
  • tests/ - Mini tests and DStress tests
  • demos/ - Rarely used.

##Debugging help

  • To enable assertions in LDC, you need to have LLVM compiled with --enable-assertions
  • add -DDEBUG to the CPP_FLAGS in "ccmake ." to enable DEBUG sections in LDC
  • Set CMAKE_BUILD_TYPE to Debug in cmake to get a debug build of LDC. (works?)
  • Use ->toChars() on instances of DMDFE classes and ->dump() on LLVM values and types.

Build process

LDC and LLVM

Runtime

Phobos2

Tango

Clone this wiki locally