L1-Overview - Introduction to Compiler Design Overview of...

Info iconThis preview shows pages 1–10. Sign up to view the full content.

View Full Document Right Arrow Icon
Introduction to Compiler Design Overview of Compilers Professor Yi-Ping You Department of Computer Science http://www.cs.nctu.edu.tw/~ypyou/ Page 1 Introduction to Compiler Design, Spring 2010
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
High High-level View of a Compiler level View of a Compiler ource code achine code Compiler Source code Machine code Errors Implications Must recognize legal (and illegal) programs ust generate correct code Must generate correct code Must manage storage of all variables (and code) Page 2 Introduction to Compiler Design, Spring 2010
Background image of page 2
Traditional Two Traditional Two-pass Compiler pass Compiler urce code achine code Front End Source code Machine code Back End IR Implications Errors Use an intermediate representation (IR) Front end maps legal source code into IR Back end maps IR into target machine code Admits multiple front ends & multiple passes (better code) Typically, front end is O(n) or O(n log n), while back Page 3 Introduction to Compiler Design, Spring 2010 end is NPC
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Steps for Generating an Executable Program RONT- ND exical, syntactical analysis) myprog.c source program ASCII FRONT END (lexical, syntactical analysis) intermediate representation BACK-END (code generation) yprog s assembly program COMPILER myprog.s ASCII Other object ASSEMBLER myprog.o object program (non-executable) COFF / ELF / PE COFF… programs or Libraries a.out/exe object program (executable) OFF / ELF / PE COFF LINKER COFF = Common Object File Format (Unix) COFF / ELF / PE COFF… LOADER Page 4 Introduction to Compiler Design, Spring 2010 ELF = Executable and Linking Format (Linux) PE COFF = Portable Executable COFF (Windows) program in execution
Background image of page 4
The Structure of a Compiler Lexical Analyzer Source Code y (scanner) Syntax Analyzer (parser) Semantic Analyzer Front End Intermediate Code enerator (Analysis) Code Optimizer Generator Code Generator Back End ynthesis) Page 5 Introduction to Compiler Design, Spring 2010 Target Code (Synthesis)
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Reuse of Components C/C++ Java Fortran termediate Representation Intermediate Representation X86 MIPS ARM Page 6 Introduction to Compiler Design, Spring 2010
Background image of page 6
The Structure of a Compiler Lexical Analyzer Source Code y (scanner) Syntax Analyzer (parser) Semantic Analyzer Intermediate Code enerator Symbol Table Error Handler Code Optimizer Generator Code Generator Page 7 Introduction to Compiler Design, Spring 2010 Target Code
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Symbol Symbol-Table Management Table Management Essential function of a compiler To record the identifiers used in the source program and collect information about various attributes of each identifier E.g. allocated storage, type, scope, etc. Symbol table data structure containing a record for each identifier with A data structure containing a record for each identifier, with fields for the attributes When an identifier is detected by the lexical analysis, it is entered into the symbol table The attributes are determined during syntax analysis and mantic nalysis semantic analysis Page 8 Introduction to Compiler Design, Spring 2010
Background image of page 8
Error Handler Error handler is also involved in all phases f the compiler process
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 10
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 48

L1-Overview - Introduction to Compiler Design Overview of...

This preview shows document pages 1 - 10. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online