1 Compiler - Slide
1 Compiler - Slide
Compilation • In 1954, John Backus proposed a program that translated high level
expressions into native machine code for IBM 704 mainframe
Swarnendu Biswas • Fortran (Formula Translator) I project (1954-1957): The first compiler
was released
Semester 2022-2023-II
CSE, IIT Kanpur
Content influenced by many excellent references, see References slide for acknowledgements.
output
A Language-Processing System
Development Toolchain
skeletal source program
https://en.wikipedia.org/wiki/Buffalo_buffalo_Buffalo_buffalo_buffalo_buffalo_Buffalo_buffalo
https://blog.gopheracademy.com/advent-2018/llvm-ir-and-go/
Translation in a Compiler
• Direct translation from a high-level language to machine code is
difficult
• Mismatch in the abstraction level between source code and machine code
• Compare abstract data types and variables vs memory locations and registers
• Control flow constructs vs jump and returns
Phases in a Compiler • Some languages are farther from machine code than others
• For example, languages supporting object-oriented paradigm
intermediate code
semantic analyzer generator
id2 *
id3 60
LOAD/STORE take 3 cycles, MUL takes LOAD/STORE take 3 cycles, MUL takes
2 cycles, and ADD takes 1 cycle. 2 cycles, and ADD takes 1 cycle.
Naïve Instruction Scheduling Improved Instruction Schedule
LOAD @ADDR1, @OFF1 -> R1 LOAD @ADDR1, @OFF1 -> R1 LOAD @ADDR1, @OFF1 -> R1
ADD R1, R1 -> R1 ADD R1, R1 -> R1 LOAD @ADDR2, @OFF2 -> R2
LOAD @ADDR2, @OFF2 -> R2 LOAD @ADDR2, @OFF2 -> R2 LOAD @ADDR3, @OFF3 -> R3
MUL R1, R2 -> R1 MUL R1, R2 -> R1 ADD R1, R1 -> R1
LOAD @ADDR3, @OFF3 -> R2 LOAD @ADDR3, @OFF3 -> R2 MUL R1, R2 -> R1
MUL R1, R2 -> R1 MUL R1, R2 -> R1 MUL R1, R3 -> R1
STORE R1 -> @ADDR1, @OFF1 STORE R1 -> @ADDR1, @OFF1 STORE R1 -> @ADDR1, @OFF1