forked from ldc-developers/ldc
-
Notifications
You must be signed in to change notification settings - Fork 0
Hacker Guide
redstar edited this page Jul 29, 2012
·
5 revisions
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.
- driver/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/druntime - Druntime checkout.
- runtime/phobos - Phobos checkout.
- tests/ - Mini tests and DStress tests.
- vcbuild/ - Contains files specific for MSVC.
##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.