==============================
== What I have learnt today ==
==============================

It's been a while

I have tried my best to complete the My First Language Frontend with LLVM tutorial as a learning path to llvm. It is quite an undertaking. I have nevertheless completed it, but without completely knowing what I am doing. So it has taken longer time that I think. I have also picked up other hobbies, so the updates has not be frequent.

It involves more things that I do not know. Other than C++, the author of the tutorial assumes the reader has some basic compiler design knowledge which I am lacking. The code snippets presented in the text are different from the complete code listing at the end. It seems that the content of each chapter is built upon the previous one, obviously except chapter one. Most of the time it is, but not at chapter 9. For chapter 8, I could not even compile the code listing. I changed the file name to t.cpp. It says

>  clang++ -g -O3 t.cpp `llvm-config --cxxflags --ldflags --system-libs --libs all` -o t
t.cpp:1260:36: error: no member named 'ObjectFile' in 'llvm::CodeGenFileType'
 1260 |   auto FileType = CodeGenFileType::ObjectFile;
      |                   ~~~~~~~~~~~~~~~~~^
1 error generated.

I nevertheless proceed to chapter 9. The code has changed quite a bit. For example, std::string getTokName(int Tok) is not invoked in the example.

The tutorial is trying to demonstrate a frontend use case of LLVM. As the warning says

Warning: In order to focus on teaching compiler techniques and LLVM specifically, this tutorial does not show best practices in software engineering principles. For example, the code uses global variables pervasively, doesn’t use visitors, etc… but instead keeps things simple and focuses on the topics at hand.

So from C++ learning perspective, I learnt inheritance and class implementation. There is no design patterns and global variables are all over the place.

But I have had the experience to work with a 1k line of code file, how to read diff -u3 outputs, and how to deal with the frustration when things did not work. Those are invaluable experiences.

I think I will come back to compiler and llvm one day.