Compilers Overview
Tool Chain
Preprocessor
- Takes source code and header files.
#pragma,#define,#includeare preprocessed and inserted into source code.cppis the default preprocessor.
Compiler
cc1is the default compiler.- Outputs assembly source code ending with
.s(as it was the only source back then)
Assembler
See assembly for assembly language.
asis the default assembler.- Generates Object Code (
.ofiles)
Linker
- Takes libraries such as
libc.a,libm.aand object code. .afile is actually a bunch of.ofiles, in static linking, only needed functions are included.- Dynamic libraries (
libc.so) - There is a small overhead time for dynamically linked programs — since the program needs to find the location of the shared libraries.
- Generates executables.
Within Compiler
- Input = Source Code Raw Bytes (individual characters/character stream)
- Scanner
- Reads raw bytes into tokens
- Regular Expression, which can be turned into NFA, then to DFA.
- The tools used is
Flex
- Parser
- Semantic Routines
- Make sure that the “sentence” is valid.
- Optimizer
- Takes and generates IR (= Intermediate Representation)
- Code Generator → Target Assembly Language.