Fix misc style and spelling errors.
[matthijs/projects/internship.git] / Report / Main / Context / MontiumC.tex
1 \section{MontiumC}
2 \label{MontiumC}
3 Since having just a piece of hardware is not enough, we also need some way to
4 program the Montium. To this end, the MontiumC language was created. The
5 MontiumC language is a language very similar to C. It allows very fine grained
6 control over the Montium through a set of functions that can be called (where
7 the function called determines the operation mapped on the Montium).
8
9 MontiumC is, on one hand, a strict subset of C. Every MontiumC program is
10 therefore a valid C program as well. This is one of the strong points of
11 MontiumC: By using a normal C compiler, a MontiumC program can be functionally
12 simulated on normal hardware.
13
14 On the other hand, MontiumC defines a number of special functions which are
15 mapped onto the Montium ALU when compiling with the Montium-specific
16 backend. When compiling with a normal C compiler, these functions are
17 implemented by a library implemented in C.
18
19 Figure \ref{CompilingMontiumC} shows the flow for compiling a MontiumC program
20 into a Montium binary file, which can be loaded directly onto a Montium. The
21 process is roughly divided into two parts (each of which corresponds to a
22 different program in the compiler suite): The frontend and the backend.
23
24 The frontend takes in a MontiumC program and turns it into a lower level
25 description of the program (the Montium intermediate representation).
26 The frontend is responsible for mapping higher level C constructs onto
27 simpler instructions, for canonicalizing and simplifying the code. These
28 canonicalizations and simplifications ensure that the backend can be
29 kept simpler and does not have to deal with all the complexities of the
30 original program. 
31
32 The frontend is again divided into two pieces, the first of which
33 transforms C code into an intermediate representation (called LLVM IR).
34 For the first part the Clang compiler, part of the LLVM project, is used
35 mostly unmodified. See section \ref{LLVM} for an overview of the LLVM
36 project. The second part transforms this intermediate representation
37 into a simpler form, which is more suitable for mapping onto the Montium
38 hardware by the backend. The output of this transformation is again in
39 the the same format, but with a lot of additional constraints. This
40 extra constrained format is referred to as Montium IR.
41
42 The backend, in turn, takes in this reduced description of the program and
43 transforms this into a valid Montium binary. To do this, it must find an ALU
44 configuration to execute a given set of operations, trace values to allocate
45 them to registers, generate instructions for the adress generation units, etc.
46
47 \begin{figure}
48 \epsfig{file=Img/Compiling.ps, width=\textwidth}
49 \caption{MontiumC compilation flow}
50 \label{CompilingMontiumC}
51 \end{figure}