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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
|
#[1]Andrew Chambers on Compilers - Atom [2]Andrew Chambers on Compilers
- RSS [3]Andrew Chambers on Compilers - Atom
[4]Andrew Chambers on Compilers
Monday 7 September 2015
A Smaller, Better compiler suite.
You should be able to get a C compiler, assembler, linker and libc for
any supported target in less than 30 seconds just by typing make... Or
at least thats my plan.
I have started work on a BSD licensed simple but powerful C compiler
suite here [5]https://github.com/andrewchambers/c (A C
port/continuation of my now frozen [6]Go based C compiler). After a few
months of work in my free time the compiler is building some non
trivial [7]test cases on amd64 Ubuntu, but no real software.
I encourage you to clone it and have a play around.
Some general goals I have in mind are:
* Compile times that are 2 - 5 times faster than gcc or clang. TCC is
10 times faster, but does not have text assembly or an AST.
* Be one to two orders of magnitude smaller than gcc and clang/llvm.
For every million lines of gcc code, we could have ten thousand
line of code.
* Emit assembly that has performance at least equal to tcc. This is a
modest performance goal so we don't focus prematurely on this over
compatibility.
* Have the whole system build from source in less than 30 seconds
(probably much less) on a modest desktop machine or even low end
arm systems.
* Be zero config compatible with the excellent [8]Musl libc on Linux.
To answer why I would start a new compiler suite from scratch, perhaps
the following will resonate with you.
[9]GCC and [10]Clang:
GCC is large and complicated and non standard. Generally porting it is
difficult and out of reach of hobbyists. Building these compilers from
source requires 20 minutes to many hours. LLVM and Clang suffer from
the same issues and they have added CMake to the list of things I can't
get behind.
For most of my use cases I question the need for hundreds of thousands
of lines of optimizer code. I think the Google Go toolchain + stdlib's
30 second build proves this nicely. I would prefer a simple C compiler
written in C, to a complicated C++ compiler written in C++ supporting
all of C++ with C on the side.
Bootstrapping these cross compilers with working libc's is so
complicated/arcane there are dedicated tools like buildroot and
crosstool-ng just to manage the complexity.
Both these compilers also seem to require more ram and cpu to self host
than modest hardware or emulators like qemu can provide. This is
actually a serious barrier to overcome when trying to work with many
platforms.
[11]TCC:
TCC is extremely fast and small, I generally use tcc as my primary C
compiler when I don't want to deal with GCC. I have two issues with
this compiler.
I don't think I am alone in saying the code style is terse, hard to
understand. Perhaps it was written with speed alone in mind, perhaps
the lack of AST has allowed some ugly hacks into the code base, or
perhaps my taste is just different. I would encourage you to make these
judgement call for yourself by comparing code.
The major limitation however, is that because TCC emits binary directly
with no text assembly, it is much harder to use with some hobby systems
which have existing assemblers. This was the main deal breaker for me.
[12]PCC and [13]8CC:
PCC is old, mature, and generates good code and can build real
programs. 8cc is simple and self hosting with a small and nice code
base.
These are the best candidate's so far to meet my goals. All I can
really say is I think we can take the best ideas from these projects,
and have no problem sharing code/design in order to create the best
system possible.
Posted by [14]andrewchambers at [15]21:01
[16]Email This[17]BlogThis![18]Share to Twitter[19]Share to
Facebook[20]Share to Pinterest
2 comments:
1. [21]beza1e1[22]20 September 2015 at 11:37
You might want to check out cparser/Firm:
http://pp.ipd.kit.edu/firm/
Reply[23]Delete
Replies
1. [24]andrewchambers[25]20 September 2015 at 17:01
The parser alone is 40k lines of code in cparser. This strikes
me as a bit odd considering tcc including 7 or 8 ports
including assemblers and some linker code is less than 40k
lines of code.
libfirm itself is nearly 200k lines of code. To me that is
crazy even for an SSA backend. Consider the Go toolchain which
has just added an SSA backend for a language more complicated
than C, this backend is 20k lines of code, or 10 times
smaller.
[26]Delete
Replies
Reply
Reply
Add comment
Load more...
[INS: :INS]
[27]Newer Post [28]Home
Subscribe to: [29]Post Comments (Atom)
About Me
[30]andrewchambers
[31]View my complete profile
Blog Archive
* [32]v [33]2015 (5)
+ [34]|> [35]December (1)
+ [36]|> [37]October (1)
+ [38]v [39]September (3)
o [40]Compiler Warnings Considered Harmful
o [41]Calling conventions are hard - Fuzz them!
o [42]A Smaller, Better compiler suite.
Awesome Inc. theme. Powered by [43]Blogger.
References
Visible links:
1. http://achacompilers.blogspot.com/feeds/posts/default
2. http://achacompilers.blogspot.com/feeds/posts/default?alt=rss
3. http://achacompilers.blogspot.com/feeds/4663521962662796311/comments/default
4. http://achacompilers.blogspot.com/
5. https://github.com/andrewchambers/c
6. https://github.com/andrewchambers/cc
7. https://github.com/andrewchambers/c/tree/master/test/execute
8. http://www.musl-libc.org/
9. https://gcc.gnu.org/
10. http://clang.llvm.org/
11. http://bellard.org/tcc/
12. http://pcc.ludd.ltu.se/
13. https://github.com/rui314/8cc
14. https://www.blogger.com/profile/02753522013571524462
15. http://achacompilers.blogspot.com/2015/09/a-smaller-better-compiler-suite.html
16. https://www.blogger.com/share-post.g?blogID=2925495181711940273&postID=4663521962662796311&target=email
17. https://www.blogger.com/share-post.g?blogID=2925495181711940273&postID=4663521962662796311&target=blog
18. https://www.blogger.com/share-post.g?blogID=2925495181711940273&postID=4663521962662796311&target=twitter
19. https://www.blogger.com/share-post.g?blogID=2925495181711940273&postID=4663521962662796311&target=facebook
20. https://www.blogger.com/share-post.g?blogID=2925495181711940273&postID=4663521962662796311&target=pinterest
21. https://www.blogger.com/profile/15355537726732337830
22. http://achacompilers.blogspot.com/2015/09/a-smaller-better-compiler-suite.html?showComment=1442774253666#c6174610279568287140
23. https://www.blogger.com/delete-comment.g?blogID=2925495181711940273&postID=6174610279568287140
24. https://www.blogger.com/profile/02753522013571524462
25. http://achacompilers.blogspot.com/2015/09/a-smaller-better-compiler-suite.html?showComment=1442793668132#c7584064544028773629
26. https://www.blogger.com/delete-comment.g?blogID=2925495181711940273&postID=7584064544028773629
27. http://achacompilers.blogspot.com/2015/09/calling-conventions-are-hard-fuzz-them.html
28. http://achacompilers.blogspot.com/
29. http://achacompilers.blogspot.com/feeds/4663521962662796311/comments/default
30. https://www.blogger.com/profile/02753522013571524462
31. https://www.blogger.com/profile/02753522013571524462
32. javascript:void(0)
33. http://achacompilers.blogspot.com/2015/
34. javascript:void(0)
35. http://achacompilers.blogspot.com/2015/12/
36. javascript:void(0)
37. http://achacompilers.blogspot.com/2015/10/
38. javascript:void(0)
39. http://achacompilers.blogspot.com/2015/09/
40. http://achacompilers.blogspot.com/2015/09/compiler-warnings-considered-harmful.html
41. http://achacompilers.blogspot.com/2015/09/calling-conventions-are-hard-fuzz-them.html
42. http://achacompilers.blogspot.com/2015/09/a-smaller-better-compiler-suite.html
43. https://www.blogger.com/
Hidden links:
45. https://www.blogger.com/post-edit.g?blogID=2925495181711940273&postID=4663521962662796311&from=pencil
46. https://www.blogger.com/comment/frame/2925495181711940273?po=4663521962662796311&hl=en-GB
|