Top Related Projects
Quick Overview
LDC (LLVM D Compiler) is an open-source compiler for the D programming language. It uses the LLVM Core libraries for code generation and optimization, aiming to provide a high-performance, portable D compiler with modern optimization techniques.
Pros
- High performance due to LLVM backend
- Cross-platform support (Windows, macOS, Linux, and more)
- Active development and community support
- Compatibility with both DMD and GDC frontends
Cons
- Smaller ecosystem compared to more mainstream languages
- Learning curve for D language newcomers
- Occasional compatibility issues with some D libraries
- Slower compile times compared to DMD in some cases
Code Examples
- Hello World example:
import std.stdio;
void main() {
writeln("Hello, World!");
}
- Array manipulation:
import std.algorithm;
import std.array;
import std.stdio;
void main() {
auto arr = [1, 2, 3, 4, 5];
auto doubled = arr.map!(a => a * 2).array;
writeln(doubled); // [2, 4, 6, 8, 10]
}
- Concurrency with fibers:
import std.stdio;
import core.thread;
void fiberFunc() {
writeln("Fiber started");
Fiber.yield();
writeln("Fiber resumed");
}
void main() {
auto fiber = new Fiber(&fiberFunc);
fiber.call();
writeln("Back in main");
fiber.call();
}
Getting Started
- Install LDC from the official website or package manager
- Create a new D file (e.g.,
hello.d
) with your code - Compile and run:
ldc2 hello.d -of=hello
./hello
For more advanced usage, you can use build tools like DUB:
dub init myproject
cd myproject
dub build --compiler=ldc2
dub run
Competitor Comparisons
dmd D Programming Language compiler
Pros of DMD
- Official reference compiler for D, ensuring full language specification compliance
- Faster compilation times for small to medium-sized projects
- More frequent releases and updates
Cons of DMD
- Limited optimization capabilities compared to LDC
- Generates less efficient machine code for certain use cases
- Lacks support for some target architectures that LDC covers
Code Comparison
DMD (frontend):
module dmd.frontend;
import dmd.astbase;
import dmd.parse;
import dmd.statement;
void parseModule(ref Module m) {
// DMD-specific parsing logic
}
LDC (LLVM integration):
module gen.llvmhelpers;
import llvm;
import gen.llvm.type;
void generateLLVMCode(IRBuilder builder) {
// LDC-specific LLVM code generation
}
DMD focuses on the D language frontend, parsing, and AST generation, while LDC integrates with LLVM for code generation and optimization. LDC leverages LLVM's powerful optimization capabilities, resulting in potentially better runtime performance for certain applications. However, DMD remains the reference implementation and may be preferred for its faster compilation times in many scenarios.
The standard library of the D programming language
Pros of Phobos
- Comprehensive standard library for D programming language
- Actively maintained by the core D language team
- Extensive documentation and community support
Cons of Phobos
- Larger codebase, potentially slower compilation times
- May include features not needed for all projects
- Tied to the D language ecosystem, less flexible for other languages
Code Comparison
Phobos (array sorting):
import std.algorithm : sort;
int[] arr = [3, 1, 4, 1, 5, 9];
arr.sort();
LDC (LLVM IR generation):
module example;
import ldc.llvmasm;
void main() {
__asm("mov eax, 42", "={eax}");
}
Key Differences
- Phobos is a standard library, while LDC is a compiler
- LDC focuses on LLVM-based compilation, Phobos on language features
- Phobos is D-specific, LDC supports multiple front-ends
Use Cases
- Phobos: General D programming, standard library functionality
- LDC: Performance-critical applications, cross-platform compilation
Community and Support
- Phobos: Larger community, official D language support
- LDC: Smaller, specialized community focused on LLVM integration
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
LDC â the LLVM-based D Compiler
The LDC project provides a portable D programming language compiler with modern optimization and code generation capabilities.
The compiler uses the official DMD frontend to support the latest version of D2, and relies on the LLVM Core libraries for code generation.
LDC is fully Open Source; the parts of the source code not taken/adapted from other projects are BSD-licensed (see the LICENSE file for details).
Please consult the D wiki for further information: https://wiki.dlang.org/LDC
D1 is no longer available; see the d1
Git branch for the last
version supporting it.
Installation
From a pre-built package
Portable stand-alone binary builds (and a Windows installer) for common platforms (incl. Linux, macOS, Windows, FreeBSD and Android) are available at the GitHub release page. For Windows, the Visual D installer also comes with a bundled LDC.
For bleeding-edge users, we also provide the latest successful Continuous Integration builds with enabled LLVM & LDC assertions (increasing compile times by roughly 50%).
The dlang.org install script can also be used to install these official packages from GitHub:
curl -fsS https://dlang.org/install.sh | bash -s ldc
In addition, LDC is available from various package managers (but note that these packages are community-maintained, might be outdated and not offer the full feature set of official packages from GitHub):
Command | |
---|---|
Alpine Linux | apk add ldc |
Android | in Termux app: pkg install ldc |
Arch Linux | pacman -S ldc |
Chocolatey | choco install ldc |
Debian | apt install ldc |
Docker | docker pull dlang2/ldc-ubuntu |
Fedora | dnf install ldc |
FreeBSD | pkg install ldc |
Gentoo | layman -a ldc |
Homebrew | brew install ldc |
Nix/NixOS | nix-env -i ldc |
OpenBSD | pkg_add ldc |
Snap | snap install --classic --channel=edge ldc2 |
Ubuntu | apt install ldc |
Void | xbps-install -S ldc |
Building from source
In-depth material on building and installing LDC and the standard libraries is available on the project wiki for Linux, macOS, BSD, and Android and Windows.
If you have a working C++/D build environment, CMake, and a recent LLVM version (⥠15) available, there should be no big surprises. Do not forget to make sure the Phobos submodule is up to date:
$ cd ldc
$ git submodule update --init
(DMD, GDC and LDC are supported as host compilers. For bootstrapping
purposes, we recommend GDC via its gdmd
wrapper.)
Cross-compilation
Similar to other LLVM-based compilers, cross-compiling with LDC is simple. Full instructions and example invocations are provided on the dedicated Wiki page.
Targeting Android
You can find full instructions on cross-compiling or natively compiling for Android on the wiki.
Contact
The best way to get in touch with the developers is either via the digitalmars.D.ldc forum/newsgroup/mailing list or our Gitter chat. There is also the #ldc IRC channel on FreeNode.
For further documentation, contributor information, etc. please see the D wiki.
Feedback of any kind is very much appreciated!
Top Related Projects
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot