Understanding Compilers
Learn the process of compilation and the role of compilers in generating optimized machine code.
We'll cover the following
Programming languages are broadly classified into compiled and interpreted languages. In the compiled world, the code is first compiled into target machine code. This process of converting the code into binary is called compilation. The software program that converts the code into target machine code is called a compiler. During the compilation, the compiler runs a series of checks, passes, and validation on the written code and generates an efficient and optimized binary. A few examples of compiled languages are C, C++, and Rust.
In the interpreted world, the code is read and executed in a single pass. Since the compilation happens at runtime, the generated machine code is not as optimized as its compiled counterpart. Interpreted languages are significantly slower than compiled ones, but they provide dynamic typing and a smaller program size.
In this course, we’ll focus only on compiled languages.
Compiled languages
A compiler is a translator that translates source code into machine code (or in a more abstract way, converts the code from one programming language to another). A compiler is complicated because it should understand the language in which the source code is written (its syntax, semantics, and context); it should also understand the target machine code (its syntax, semantics, and context) and should create a representation that maps the source code into the target machine code.
A compiler has the following components:
Frontend: The frontend is responsible for handling the source language.
Optimizer: The optimizer is responsible for optimizing the code.
Backend: The backend is responsible for handling the target language.
Get hands-on with 1400+ tech skills courses.