In the previous article we chose to generate code
for a virtual machine. But what is it exactly?
A virtual machine is an emulator of a computer system. There are two types of virtual machines:
- system virtual machines, those that emulate a complete computer system,
they can be used as a substitute of a real computer. They can execute
an entire operating system, and thus they are also called full virtualization VMs.
- process virtual machines, they are designed to execute computer programs in a platform-independent environment.
Finally, we reached our last step in the compilation process. We finished
static analysis, we have the
IR, we did some
optimization, and now there is only one thing
left to do.
The code generation.
Optimization is the process of transforming the code to make it more efficient (uses
fewer resources) while preserving its semantics (has the same meaning).
In general, during optimization less efficient high-level structures are replaced with
more efficient low-level structures. Optimization is usually implemented as a series of
optimizing transformations (algorithms). The main goal is usually to make the program run faster,
and - to a lesser degree - to use less memory.