Building your first IRs
In this section, you will put to the test what you just learned by building an IR both at the LLVM IR and the Machine IR levels. The goal of this exercise is twofold:
- Manipulate the APIs to create instances of the classes
Module
,Function
,MachineFunction
, and so on. - Get a sense of what a frontend has to put with when it comes to producing an IR.
This exercise remains however artificial in the sense that at this point, you lack a lot of knowledge to build any complex IR. You will build this knowledge along the way, namely in Chapters 4, 7, and 10, but this gives you a good introduction to what is ahead and helps you solidify your current learning.
In this exercise, you will build the IR for the following snippet:
extern int baz();
extern void bar(int);
void foo(int a, int b) {
int var = a + b;
if (var == 0xFF) {
bar(var);
var = baz();
}
bar(var);
}
By default – in other words, when you do not enable...