aboutsummaryrefslogtreecommitdiff
path: root/README.md
blob: 144c2ae9037ab94e166af555d7fc7f75fabc69e5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
(mirrored on [GitHub][GitHub mirror])

[![builds.sr.ht status](https://builds.sr.ht/~mcf/cc.svg)](https://builds.sr.ht/~mcf/cc)

This is a [C11] compiler using [QBE] as a backend. It is released under
the [ISC] license.

Several 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 C11 and can be built with
any conforming C11 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. Currently, my personal [QBE branch] is recommended, since
it may address some issues that have not yet made it upstream. 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 and
aarch64).

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`

## 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`.

If you don't have QBE installed, you can build it from the included
submodule (NOTE: BSD users will need to use gmake here), then add it to
your PATH so that the driver will be able to run it.

	make qbe
	PATH=$PWD/qbe/obj:$PATH

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 and trigraph sequences ([6.4.6p3] and [5.2.1.1], will not
  be implemented).
- Wide string literals and character constants ([#35] and [#36]).
- Variable-length arrays ([#1]).
- `volatile`-qualified types ([#7]).
- `_Thread_local` storage-class specifier ([#5]).
- `long double` type ([#3]).
- Inline assembly ([#5]).
- Preprocessor ([#6]).
- Generation of position independent code (i.e. shared libraries,
  modules, PIEs).

## Issue tracker

Please report any issues to https://todo.sr.ht/~mcf/cc-issues.

## Contributing

Send patches to me (address in commit log), or pull-requests on the
[GitHub mirror]. Once I decide on a project name, a mailing list will
be created, which will then become the preferred form of contribution.

[QBE]: https://c9x.me/compile/
[C11]: http://port70.net/~nsz/c/c11/n1570.html
[ISC]: https://git.sr.ht/~mcf/cc/blob/master/LICENSE
[extensions]: https://man.sr.ht/~mcf/cc/doc/extensions.md
[building software]: https://man.sr.ht/~mcf/cc/doc/software.md
[8cc]: https://github.com/rui314/8cc
[c]: https://github.com/andrewchambers/c
[lacc]: https://github.com/larmel/lacc
[scc]: http://www.simple-cc.org/
[QBE branch]: https://git.sr.ht/~mcf/qbe
[5.2.1.1]: http://port70.net/~nsz/c/c11/n1570.html#5.2.1.1
[6.4.6p3]: http://port70.net/~nsz/c/c11/n1570.html#6.4.6p3
[#1]: https://todo.sr.ht/~mcf/cc-issues/1
[#3]: https://todo.sr.ht/~mcf/cc-issues/3
[#5]: https://todo.sr.ht/~mcf/cc-issues/5
[#6]: https://todo.sr.ht/~mcf/cc-issues/6
[#7]: https://todo.sr.ht/~mcf/cc-issues/7
[#35]: https://todo.sr.ht/~mcf/cc-issues/35
[#36]: https://todo.sr.ht/~mcf/cc-issues/36
[#44]: https://todo.sr.ht/~mcf/cc-issues/44
[GitHub mirror]: https://github.com/michaelforney/cc