| tags: [ Compiler ] categories: [ Development ]
小型 C 编译器
统计截止 2024-12-31。
- tcc:极品黑客 Fabrice Bellard 打造的极品编译器;
- pcc:Bell Labs 出品,Dennis Ritchie 背书,名门闺秀,差点成为 BSD 系标配,被 Clang 顶翻了;
- cparser:德国 Karlsruhe 大学出品,基于图表示的优化框架;
- nwcc:个人作品,已停止开发;
- ack:Amsterdam Compiler Kit,Andrew Tanenbaum 出品,Minix 1 & 2 御用,不支持 64bit,在 Minix 3 中被 Clang 代替;
- watcom:Open Watcom C/C++,当年与 Borland、Microsoft 竞争的编译器和 IDE,64bit 支持开发中;
- vbcc:支持很多 32bit CPU 架构,有一定优化能力;
- scc & cproc:基于 QBE 编译器后端,QBE 定位于用 10% 代码实现工业级 C 编译器 70% 的性能;
- kefir & lacc:个人练手作品;
- lcc & chibicc: C 编译器编写教学;
编译器 | tcc | pcc | cparser | nwcc | ack | watcom | vbcc | scc | cproc | kefir | lacc | lcc | chibicc |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
源码库 | TinyCC | pcc-libs, pcc | cparser | nwcc | ack | open-watcom-v2 | vbcc | simple-cc | cproc | kefir | lacc | lcc | chibicc |
许可证 | LGPL / MIT-like | BSD | GPLv2 + LGPLv2.1 | BSD | BSD-like | GPL-like | BSD | Caldera / ISC | MIT-like | GPLv3 | MIT | LCC | MIT |
最新版本 | 0.9.271 | 1.1.02 | 1.22.03 | 0.8.34 | 6.0-pre55 | 1.96 | N/A | N/A | N/A | 0.4.0 | N/A | 4.27 | N/A |
发布时间 | 2017-12-13 | 2014-12-10 | 2016-01-01 | 2014-08-17 | 2016-06-02 | 2010-06-02 | 2022-04-29 | 2024-12-31 | 2024-04-28 | 2024-09-11 | 2022-05-22 | 2007-02-19 | 2020-12-07 |
C 标准 | C99 | C99 | C11 | C99 | C89 | C99, C++98 | C99 | C99 | C11 | C17 | C89 | C89 | C11 |
预处理器(cpp) | ✅ | ✅ | ✅ | ✅ 8 | ✅ | ✅ | ✅ | ✅ | ❌ | ✅ | ✅ | ✅ | ✅ |
汇编器(as) | ✅ | ❌ | ❌ | ❌ | ✅ | ✅ | ❌ | ✅ | ❌ | ❌ | ✅ | ❌ | ❌ |
链接器(ld) | ✅ | ❌ | ❌ | ❌ | ✅ | ✅ | ❌ | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ |
位置无关代码(PIC) | ✅ | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ | ✅ | ✅ | ❌ | ✅ |
线程局部存储(TLS) | ❌ | ❌ | ✅ | ❌ | ❌ | ✅ | ❌ | ❌ | ✅ | ✅ | ❌ | ❌ | ✅ |
易失变量(volatile) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ | ❌ | ✅ | ✅ | ✅ | ❌ |
变长数组(VLA) | ✅ | ✅ | ✅ | ✅ | ❌ | ❌ | ✅ | ❌ | ❌ | ✅ | ✅ | ❌ | ✅ |
复数 | ❌ | ✅ | ✅ | ✅ | ❌ | ✅ | ❌ | ❌ | ❌ | ✅ | ❌ | ❌ | ❌ |
内联汇编 | ✅ | ✅ | ❌ | ✅ | ❌ | ✅ | ✅ | ❌ | ❌ | ✅ | ✅ | ❌ | ❌ |
GCC 兼容 | partial | partial | partial | partial | ❌ | ❌ | partial | ❌ | ❌ | partial | partial | ❌ | ❌ |
CPU 架构 | i386/x86_64, arm/aarch64, riscv64 | i386/amd64, arm/aarch64, mips, … | i386/amd64, arm, riscv32, mips, … | x86/amd64, mips, … | i386, arm, mips, … | i386/x64, arm, ppc, … | i386, arm, ppc, … | i386/amd64, ppc/ppc64 | amd64, arm64, riscv64 | amd64 | amd64 | x86, mips, sparc | amd64 |
操作系统 | Linux, BSD, macOS, Win32 | Linux, BSD, macOS, Win32 | Linux, BSD, macOS, Win32 | Linux, BSD, macOS | Linux, BSD, macOS, Win32 | Linux, macOS, DOS, Win32 | Linux, BSD, Win32 | Linux, BSD | Linux, BSD | Linux, BSD | Linux, BSD | Linux, Win32 | Linux, BSD |
优化能力 | ❌ | partial | partial | partial | partial | well | well | partial | partial | partial | partial | ❌ | ❌ |
调试符号 | ✅ | ✅ | ✅ | ❌ | ❌ | ✅ | ✅ | ❌ | ❌ | ✅ | ✅ | ❌ | ❌ |
性能剖析 | ❌ | ✅ | ✅ | ❌ | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ | ❌ | ✅ | ❌ |
代码行数 | 10w | 12w | 16w9 | 9w | 34w | 170w10 | 10w | 3w11 | 2w12 | 11w | 1.9w | 2w | 7k |
其它值得一提的 C 编译器:
GitHub - Vexu/arocc: A C compiler written in Zig: Currently most of standard C is supported up to C23 and as are many of the common extensions from GNU, MSVC, and Clang.
smorgasbordet - Pelles C: Pelles C is a complete development kit for Desktop Windows. It contains among other things an optimizing C compiler, a macro assembler, a linker, a resource compiler, a message compiler, a code signing utility, a make utility and an install builder.
It also contains an integrated development environment (IDE) with project management, debugger, profiler, source code editor, and resource editors for dialogs, menus, string tables, accelerator tables, bitmaps, icons, cursors, animated cursors, animation videos (AVI’s without sound), versions and manifests.
The compiler was originally based on LCC (by Chris Fraser and David Hanson), but since then enhanced with support for C99/C11/C17/C2x, a global optimizer, a new register allocator, a function inliner, intrinsic functions, and many Microsoft C extensions.
lcc-win: A Compiler system for windows: The system is self contained: you do not need anything else to get started programming in C in the Win32 environment. You get
- Code generator (compiler, assembler, linker, resource compiler, librarian)
- Integrated development environment with editor, debugger, make file generation, resource editor, etc.
- User manual and technical documentation.
SDCC - Small Device C Compiler: SDCC is a retargettable, optimizing Standard C (ANSI C89, ISO C99, ISO C11, ISO C23) compiler suite that targets the Intel MCS51 based microprocessors (8031, 8032, 8051, 8052, etc.), Maxim(formerly Dallas) DS80C390 variants, Freescale (formerly Motorola) HC08 based (hc08, s08), Zilog Z80 based MCUs (Z80, Z180, SM83, Rabbit 2000, 2000A, 3000A, TLCS-90, R800), Padauk (pdk14, pdk15), STMicroelectronics STM8, MOS 6502 and WDC 65C02. Work is in progress on supporting the Padauk pdk13 target; Microchip PIC16 and PIC18 targets are unmaintained.
一些 C 语言的替代品:
- Zig: https://ziglang.org
- Dlang’s Better C: https://dlang.org/spec/betterc.html
- C2: http://c2lang.org
- C3: https://c3-lang.org
- Odin: http://odin-lang.org
- Nim: https://nim-lang.org
- Hare: https://harelang.org
- Vale: https://vale.dev
- Hylo: https://www.hylo-lang.org
- Vala: https://vala.dev