Hacker News new | ask | show | jobs
by omega_rythm 4151 days ago
Gcc code is arcane: it relies heavily on macros to define some kind of DSL for the compiler backends (check out the .def files), but if you want to contribute seriously you need to learn that DSL and how it works behind the scene somewhat, whereas llvm is C++. That being said, it's an interesting experience to dive into that code.
3 comments

I give you: https://github.com/llvm-mirror/llvm/blob/master/lib/Target/X...

I agree with you that gcc is much less pleasant than LLVM+Clang, but to say that LLVM is better becauses it uses C++ everywhere is simply incorrect. In fact, using this kind of DSL for backend definitions is good design.

The LLVM DSL engine is really annoying to use, mainly because the pattern matching engine is pretty simple, and it's possible to express patterns in the DSL language which the pattern matching engine is unable to actually match. Until you know where the limits are it's really frustrating; you write a pattern which should work and the compiler blows stack or produces an impenetrable internal error because the pattern matcher has given up or gone into a working loop.

A large part of any LLVM backend is actually custom C++ code for matching and expanding patterns which the pattern matcher either can't or is unwilling to do (e.g. custom backend-specific DAG nodes). I direct you at this file:

https://github.com/llvm-mirror/llvm/blob/master/lib/Target/X...

github will give you a warning before loading it because that single C++ source file is over a megabyte...

I must admit that my knowledge of llvm is very limited. I did make the (perhaps wrong) assumption that it would be easier to understand on that basis alone (well, and the fact that the people writing it know how to code C++ properly, I guess for major projects like Gcc and llvm you may expect well engineered code). I felt that the whole macro business isn't as solid nowadays as what templates could allow in terms of type checking (and perhaps some macros involved for syntactic sugar alone; caveat with the cryptic error messages for errors in templates), hence my previously stated opinion.

Note that I am not complaining about the DSL, just how things are quite difficult to figure out (and untyped macros, as stated above).

That looks very readable. Maybe the gripe was that GCC isn't readable? I don't know, I haven't looked at GCC code.
LLVM's target backends are also written in a custom DSL (tblgen). Is that not a good thing?
As opposed to LLVM's tblgen?