larmel/lacc logo

larmel/lacc

Free

A simple, self-hosting C compiler

FreeFree tier
Type
Open Source

About larmel/lacc

lacc is a simple, self-hosting C compiler written in C. It aims to compile itself and primarily targets x86_64 architecture, outputting GNU-style assembly, ELF object files, or preprocessed source. The compiler supports the C89 standard along with select features from later standards. It builds a rich intermediate representation using control flow graphs with basic blocks of three-address code, enabling basic dataflow analysis and optimization. The command-line interface is similar to GCC, accepting common flags such as -std=, -O levels, -g for debug info, and -D for macros. Recognized platforms include Linux (with glibc or musl) and OpenBSD. lacc also provides compiler-specific standard library headers for stddef.h and stdarg.h.

Key Features

Self-hosting: can compile its own source code
Full C89 support with some later standard features
Targets x86_64 assembly (GNU syntax), ELF object files, or preprocessing
Rich intermediate representation with control flow graphs and three-address code
GCC-like command-line interface with common flags (-std=, -O, -g, -D, etc.)
Supports Linux (glibc, musl) and OpenBSD platforms
Provides compiler-specific standard library headers (stddef.h, stdarg.h)

Pros & Cons

Pros
  • Self-hosting capability demonstrates correctness and completeness
  • Simple codebase suitable for educational purposes
  • Rich intermediate representation allows for basic optimization and analysis
  • Command-line interface familiar to GCC users
  • Supports commonly used C standards (C89) with some later features
Cons
  • Limited to x86_64 architecture only
  • Only fully targets Linux and OpenBSD platforms
  • Primarily supports C89; later standards only partially implemented
  • Described as a toy project, may not be suitable for production use
  • No native AI or machine learning capabilities (not an AI tool)

Best For

Compiling C89 and compatible C source code for x86_64 systemsLearning about compiler design and implementation through a practical exampleSelf-hosting compilation: building the compiler with itselfGenerating x86_64 assembly or object files for small C projectsExploring intermediate representation and optimization in a lightweight compiler

FAQ

What is lacc?
lacc is a simple, self-hosting C compiler written in C. It can compile its own source code and targets x86_64 machines, outputting assembly, object files, or preprocessed source.
What C standards does lacc support?
lacc has complete support for C89 and includes some features from later standards (C99 and C11).
How do I install lacc?
Clone the repository from GitHub, run ./configure, then make, and optionally make install. The binary will be placed in bin/lacc.
What platforms does lacc support?
lacc recognizes Linux with glibc or musl, and OpenBSD. It includes environment probing to detect the target platform.
Does lacc generate executable binaries?
lacc can output object files (-c) which can then be linked using the system linker. It also can act as a wrapper for /bin/ld to produce executables.