Using LDC

From D Wiki
Jump to: navigation, search

Generally, LDC should be straightforward to use, like any other compiler. It comes with two different »drivers«, i.e. executables a user invokes to compile D code: ldc2, which offers many customization options, some of which are internal to LLVM, and ldmd2, which tries to accurately replicate the DMD command line interface and can be used as a drop-in replacement for DMD.

Configuration file search path

LDC looks for a file called ldc.conf resp. ldc2.conf in the follow directories in order:

  1. current working directory
  2. next to binary
  3. ~/.ldc
  4. user home directory (Windows-only)
  5. in an etc directory next to the directory where the binary resides
  6. install-prefix (Windows-only)
  7. install-prefix/etc
  8. install-prefix/etc/ldc
  9. /etc
  10. /etc/ldc

ldc2 command line options

  1. | -mdcompute-targets=<ocl-210,cuda-350>
  2. | DCompute targets to generate for:OpenCl (ocl-xy0 for x.y) CUDA (cuda-xy0 for cc x.y)
  3. |-
-D Generate Documentation
-Dd=<docdir> Write documentation file to <docdir> directory
-Df=<filename> Write documentation file to <filename>
-H Generate 'header' file
-Hd=<hdrdir> Write 'header' file to <hdrdir> directory
-Hf=<filename> Write 'header' file to <filename>
-Hkeep-all-bodies Keep all function bodies in .di files
-I=<path> Where to look for imports
-J=<path> Where to look for string imports
-L=<linkerflag> Pass <linkerflag> to the linker
Setting the optimization level:
-O Equivalent to -O3
-O0 No optimizations (default)
-O1 Simple optimisations
-O2 Good optimisations
-O3 Aggressive optimisations
-O4 Equivalent to -O3
-O5 Equivalent to -O3
-Os Like -O2 with extra optimizations for size
-Oz Like -Os but reduces code size further
-X Generate JSON file
-Xf=<filename> Write JSON file to <filename>
-aarch64-neon-syntax Choose style of NEON code to emit from AArch64 backend:
=generic Emit generic NEON assembly
=apple Emit Apple-style NEON assembly
-allinst generate code for all template instantiations
-boundscheck Enable array bounds check
=off no array bounds checks
=safeonly array bounds checks for safe functions only
=on array bounds checks for all functions
-c Do not link
-check-printf-calls Validate printf call format strings against arguments
-code-model Code model
=default Target default code model
=small Small code model
=kernel Kernel code model
=medium Medium code model
=large Large code model
-conf=<filename> Use configuration file <filename>
-cov Compile-in code coverage analysis (use -cov=n for n% minimum required coverage)
Allow deprecated code/language features:
-de Do not allow deprecated features
-d Silently allow deprecated features
-dw Warn about the use of deprecated features
-d-debug=<level/idents> Compile in debug code >= <level> or identified by <idents>.
-d-version=<level/idents> Compile in version code >= <level> or identified by <idents>
-debuglib=<lib1,lib2,...> Debug versions of default libraries (overrides previous)
-defaultlib=<lib1,lib2,...> Default libraries to link with (overrides previous)
-deps=<filename> Write module dependencies to filename (only imports)
-dip25 implement http://wiki.dlang.org/DIP25 (experimental)
-enable-asserts (*) Enable assertions
=enable-asserts (*) Enable assertions
-enable-color Force colored console output
=enable-color Force colored console output
-disable-d-passes Disable all D-specific passes
-disable-fp-elim Disable frame pointer elimination optimisation
-disable-gc2stack Disable promotion of GC allocations to stack memory
-enable-inlining Enable function inlining (default in -O2 and higher)
=enable-inlining Enable function inlining (default in -O2 and higher)
-enable-invariants (*) Enable invariants
=enable-invariants (*) Enable invariants
-disable-linker-strip-dead Do not try to remove unused symbols during linking
-disable-loop-unrolling Disable loop unrolling in all relevant passes
-disable-loop-vectorization Disable the loop vectorization pass
-enable-preconditions (*) Enable function preconditions
=enable-preconditions (*) Enable function preconditions
-disable-red-zone Do not emit code that uses the red zone.
-disable-simplify-drtcalls Disable simplification of druntime calls
-disable-simplify-libcalls Disable simplification of well-known C runtime calls
-disable-slp-vectorization Disable the slp vectorization pass
-enable-contracts (*) Enable function pre- and post-conditions
=enable-contracts (*) Enable function pre- and post-conditions
-enable-postconditions (*) Enable function postconditions
=enable-postconditions (*) Enable function postconditions
-float-abi ABI/operations to use for floating-point types:
=default Target default floating-point ABI
=soft Software floating-point ABI and operations
=softfp Soft-float ABI, but hardware floating-point instructions
=hard Hardware floating-point ABI and instructions
-fthread-model Thread model
=global-dynamic Global dynamic TLS model (default)
=local-dynamic Local dynamic TLS model
=initial-exec Initial exec TLS model
=local-exec Local exec TLS model
Generating debug information:
-g Generate debug information
-gc Same as -g, but pretend to be C
-hash-threshold=<uint> hash symbol names longer than this threshold (experimental)
-help Display available options (-help-hidden for more)
-ignore Ignore unsupported pragmas
-ir2obj-cache=<cache dir> Use <cache dir> to cache object files for whole IR modules (experimental)
-ir2obj-cache-prune Enable cache pruning.
-ir2obj-cache-prune-expiration=<dur> Sets the pruning expiration time of cache files to <dur> seconds (default: 1 week). Implies -ir2obj-cache-prune.
-ir2obj-cache-prune-interval=<dur> Sets the cache pruning interval to <dur> seconds (default: 20 min). Set to 0 to force pruning. Implies -ir2obj-cache-prune.
-ir2obj-cache-prune-maxbytes=<size> Sets the maximum cache size to <size> bytes. Implies -ir2obj-cache-prune.
-ir2obj-cache-prune-maxpercentage=<perc> Sets the cache size limit to <perc> percent of the available space (default: 75%). Implies -ir2obj-cache-prune.
-lib Create static library
-link-debuglib Link with libraries specified in -debuglib, not -defaultlib
-linkonce-templates Use linkonce_odr linkage for template symbols instead of weak_odr
-m32 32 bit target
-m64 64 bit target
-main Add empty main() (e.g. for unittesting)
-march=<string> Architecture to generate code for:
-mattr=<a1,+a2,-a3,...> Target specific attributes (-mattr=help for details)
-mcpu=<cpu-name> Target a specific cpu type (-mcpu=help for details)
-mtriple=<string> Override target triple
-noasm Disallow use of inline assembler
-nogc Do not allow code that generates implicit garbage collector calls
-o- Do not write object file
-od=<objdir> Write object files to directory <objdir>
-of=<filename> Use <filename> as output file name
-op Do not strip paths from source file
-oq Write object files with fully qualified names
-output-bc Write LLVM bitcode
-output-ll Write LLVM IR
-output-o Write native object
-output-s Write native assembly
-property Enforce property syntax
-release Disables asserts, invariants, contracts and boundscheck
-relocation-model Relocation model
=default Target default relocation model
=static Non-relocatable code
=pic Fully relocatable, position independent code
=dynamic-no-pic Relocatable external references, non-relocatable code
-run=<string> Runs the resulting program, passing the remaining arguments to it
-sanitize Enable runtime instrumentation for bug detection
=address memory errors
=memory memory errors
=thread race detection
-shared Create shared library
-singleobj Create only a single output object file
-static Create a statically linked binary, including all system dependencies
-template-depth=<uint> (experimental) set maximum number of nested template instantiations
-transition=<idents> help with language change identified by <idents>, use ? for list
-unittest Compile in unit tests
-v Verbose
-v-cg Verbose codegen
-vcolumns print character (column) numbers in diagnostics
-verrors=<uint> limit the number of error messages (0 means unlimited)
-version
Display the version of this program
-vgc list all gc allocations including hidden ones
-vv Print front-end/glue code debug log
Warnings:
-w Enable warnings
-wi Enable informational warnings
-x86-asm-syntax Choose style of code to emit from X86 backend:
=att Emit AT&T-style assembly
=intel Emit Intel-style assembly