cproc tree with various improvements by me
Find a file
John Nunley 957ff4ec5d feat: Add -fno-builtin flag that does nothing
For gcc, -fno-builtin replaces built-in standard library functions with
gcc builtins that are faster. Some configure scripts for popular
packages test for this. However, cproc does not do this replacement. So,
we just make this flag do nothing.

Since there are now a few flags that do nothing but exist for
compatibility with other C compilers, I've added a mechanism to group
all of these ignored flags into one mechanism.

Signed-off-by: John Nunley <dev@notgull.net>
2025-08-10 12:55:48 -07:00
.builds CI: Add debian-riscv64 builder 2024-04-21 18:34:45 -07:00
doc decl: Support variadic functions with no other parameters 2024-04-15 01:24:32 -07:00
test decl: Allow union specifiers to contain structs/unions with flexible array members 2025-02-10 21:20:17 -08:00
.gitignore Add config.mk to .gitignore 2021-09-06 23:52:10 -07:00
arg.h Handle argv = { NULL } in ARGBEGIN 2019-07-06 15:33:46 -07:00
attr.c map: Use simpler fnv-1a hash function 2024-04-02 14:06:59 -07:00
cc.h Add missing section comment 2025-02-09 18:39:07 -08:00
configure Implement variable length arrays 2024-04-27 15:34:03 -07:00
cproc.1 Add cproc(1) manual page 2022-10-30 12:51:28 -07:00
decl.c decl: Allow union specifiers to contain structs/unions with flexible array members 2025-02-10 21:20:17 -08:00
driver.c feat: Add -fno-builtin flag that does nothing 2025-08-10 12:55:48 -07:00
eval.c eval: Reuse decl from compound expression parsing 2025-02-08 18:29:28 -08:00
expr.c Implement variable length arrays 2024-04-27 15:34:03 -07:00
init.c init: Fix check for VLA types 2025-02-10 14:28:17 -08:00
LICENSE LICENSE: Update copyright year 2024-04-03 00:22:37 -07:00
main.c map: Use simpler fnv-1a hash function 2024-04-02 14:06:59 -07:00
Makefile map: Use simpler fnv-1a hash function 2024-04-02 14:06:59 -07:00
map.c map: Use simpler fnv-1a hash function 2024-04-02 14:06:59 -07:00
ops.h qbe: Switch to new unsigned-float conversion operators 2022-02-10 15:49:16 -08:00
pp.c map: Use simpler fnv-1a hash function 2024-04-02 14:06:59 -07:00
qbe.c Store enum constant value in struct decl 2024-04-27 15:34:27 -07:00
README.md README: Add riscv64 to supported targets 2024-04-22 00:15:48 -07:00
runtests runtests: Don't include invalid tests in results 2025-02-10 13:42:10 -08:00
scan.c map: Use simpler fnv-1a hash function 2024-04-02 14:06:59 -07:00
scope.c decl: Add name field to decl struct 2024-04-12 00:46:22 -07:00
stmt.c map: Use simpler fnv-1a hash function 2024-04-02 14:06:59 -07:00
targ.c Store length expression in array types 2024-04-07 13:29:14 -07:00
token.c map: Use simpler fnv-1a hash function 2024-04-02 14:06:59 -07:00
tree.c map: Use simpler fnv-1a hash function 2024-04-02 14:06:59 -07:00
type.c Implement variable length arrays 2024-04-27 15:34:03 -07:00
utf.c Remove dependency on signed integer representation 2022-01-01 20:34:23 -08:00
utf.h Remove dependency on signed integer representation 2022-01-01 20:34:23 -08:00
util.c Use 'bool' in headers instead of '_Bool' 2024-04-03 00:01:03 -07:00
util.h Use 'bool' in headers instead of '_Bool' 2024-04-03 00:01:03 -07:00

(mirrored on GitHub)

builds.sr.ht status

cproc is a C11 compiler using QBE as a backend. It is released under the ISC license.

Some C23 features and GNU C extensions are also implemented.

There is still much to do, but it currently implements most of the language and is capable of building software including itself, mcpp, gcc 4.7, binutils, and more.

It was inspired by several other small C compilers including 8cc, c, lacc, and scc.

Requirements

The compiler itself is written in standard C99 and can be built with any conforming C99 compiler.

The POSIX driver depends on POSIX.1-2008 interfaces, and the Makefile requires a POSIX-compatible make(1).

At runtime, you will need QBE, an assembler, and a linker for the target system. Since the preprocessor is not yet implemented, an external one is currently required as well.

Supported targets

All architectures supported by QBE should work (currently x86_64, aarch64, and riscv64).

The following targets are tested by the continuous build and known to bootstrap and pass all tests:

  • x86_64-linux-musl
  • x86_64-linux-gnu
  • x86_64-freebsd
  • aarch64-linux-musl
  • aarch64-linux-gnu
  • riscv64-linux-gnu

Building

Run ./configure to create a config.h and config.mk appropriate for your system. If your system is not supported by the configure script, you can create these files manually. config.h should define several string arrays (static char *[]):

  • startfiles: Objects to pass to the linker at the beginning of the link command.
  • endfiles: Objects to pass to the linker at the end of the link command (including libc).
  • preprocesscmd: The preprocessor command, and any necessary flags for the target system.
  • codegencmd: The QBE command, and possibly explicit target flags.
  • assemblecmd: The assembler command.
  • linkcmd: The linker command.

You may also want to customize your environment or config.mk with the appropriate CC, CFLAGS and LDFLAGS.

Once this is done, you can build with

make

Bootstrap

The Makefile includes several other targets that can be used for bootstrapping. These targets require the ability to run the tools specified in config.h.

  • stage2: Build the compiler with the initial (stage1) output.
  • stage3: Build the compiler with the stage2 output.
  • bootstrap: Build the stage2 and stage3 compilers, and verify that they are byte-wise identical.

What's missing

  • Digraph sequences (6.4.6p3, will not be implemented).
  • Variable-length arrays (#1).
  • volatile-qualified types (#7).
  • long double type (#3).
  • Inline assembly (#5).
  • Preprocessor (#6).
  • Generation of position independent code (i.e. shared libraries, modules, PIEs).

Mailing list

There is a mailing list at ~mcf/cproc@lists.sr.ht. Feel free to use it for general discussion, questions, patches, or bug reports (if you don't have an sr.ht account).

Issue tracker

Please report any issues to ~mcf/cproc@todo.sr.ht.

Contributing

Patches are greatly appreciated. Send them to the mailing list (preferred), or as pull-requests on the GitHub mirror.