The front-end of a compiler reads the source code, parses it, and checks for syntax and semantic errors. It ensures the code is valid before any translation or optimization.
The back-end takes the intermediate representation and generates optimized machine code suitable for the target hardware.
The front-end produces an intermediate representation (IR) of the source code, which is then used by the back-end to generate machine code.
Separating front-end and back-end allows reuse of the back-end for different source languages and reuse of the front-end for different machine architectures, promoting modularity and reuse.
The register allocator is part of the back-end because it deals with assigning variables to machine registers during code generation.