ATLAS
A C compiler written from scratch in Rust.
Targets x86-64 Windows. Produces native PE32+ executables.
No LLVM. No external assembler. No external linker. No external dependencies.
Capabilities
Preprocessor
Full macro expansion — object-like, function-like, variadic (
__VA_ARGS__).
Token pasting (##) and stringification (#).
Recursive #include with cycle detection. #ifdef/#if/#elif.
#pragma pack push/pop. Automatic discovery of Windows SDK and MSVC
include paths — #include <windows.h> resolves without any configuration.
Semantic analysis
Dedicated type-checking pass before IR lowering. Collects function signatures,
struct field maps, typedef chains, globals, and enum constants.
Validates expressions, assignment compatibility, lvalue requirements,
and argument counts. Reports errors as
line:col: message.
Multi-file compilation
-c flag compiles a .c file to a custom .obj (magic CCOBJ001).
Multiple .c and .obj inputs can be mixed in one command.
Dead code elimination via BFS reachability from main over the merged relocation graph.
PE32+ writer
Hand-written PE32+ output — DOS stub, COFF header, optional header,
.text / .rdata / .data / .idata sections,
import directory, IAT, hint/name entries.
Entry trampoline aligns the stack and calls ExitProcess.
Peephole optimizer
Tracks which
[RBP+N] stack slots hold known values.
Eliminates redundant load-after-store sequences and mov r, r no-ops.
Runs to a fixed point before encoding.
Import resolution
Parses installed
.lib archives from the Windows SDK and MSVC toolchain.
Reads COFF Short Import Objects to map symbol names to DLLs.
No hardcoded lookup table. Unknown externs warn with a --import DLL:FUNC hint.
Precompiled headers
Binary serialization of the full parsed AST, all active macro definitions,
typedef names, and enum constants. Magic:
COMPPCH\x01.
Eliminates repeated parsing of heavy SDK headers.
x86-64 encoder
Emits raw bytes from machine IR — REX prefixes, ModR/M, SIB, displacements,
RIP-relative relocations patched by the PE writer.
8/16/32/64-bit load/store variants. No text assembly stage.
Pipeline
- 01preprocessormacros · #include · #ifdef · pack
- 02lexerspan-tracked tokens
- 03parserrecursive descent · full AST
- 04semantic analysistypes · scopes · lvalues
- 05IR loweringtyped IR · struct layout
- 06codegen + peepholex64 ABI · fixed-point opt
- 07encoderraw x86-64 bytes · relocs
- -c.obj outputCCOBJ001
- 08linker → .exemerge · DCE · PE32+
Quick start
build
git clone https://github.com/fusexyz/Atlas cd Atlas cargo build --release
compile and link
./target/release/compiler \ examples/sysinfo.c examples/sysinfo_format.c \ -o sysinfo.exe ./sysinfo.exe
separate compilation
./target/release/compiler -c examples/sysinfo.c -o sysinfo.obj ./target/release/compiler -c examples/sysinfo_format.c -o sysinfo_format.obj ./target/release/compiler sysinfo.obj sysinfo_format.obj -o sysinfo.exe
all flags
compiler [-c] <file.c|file.obj>... [-o output]
[--import DLL:FUNC ...]
[--make-pch FILE] [--use-pch FILE]
Example output
examples/sysinfo.c + sysinfo_format.c — Win32 APIs via #include <windows.h>
[*] Local System Time:
Date: 2026-06-10 (YYYY-MM-DD)
Time: 14:23:07
[*] Host Identity:
Host Computer Name: DESKTOP-XYZ
Current User: fuse
[*] Physical Memory (RAM):
Total RAM: 32678 MiB
Avail RAM: 18475 MiB
Memory Load: 43%
[*] CPU and Architecture:
Architecture: x64 (AMD64)
Processor Cores: 16
[*] Storage Status (C:\):
Total Capacity: 476837 MiB
Free Disk Space: 123456 MiB