Escolar Documentos
Profissional Documentos
Cultura Documentos
Office Hours
Contacting me
khrisat@mutah.edu.jo Office 224,Science Building (1) Office hours Can also catch me right after class
Khrisat 2004
-1-
CS Compiler Design
Course Grading
Components
Exams (2) 30% (15% each) Projects (1) 20% Final 50% Class participation and involvement 0% officially, but will matter
Khrisat 2004
-2-
CS Compiler Design
Exams
Format
Closed book / notes 1 hrs Lecture material, projects
Khrisat 2004
-3-
CS Compiler Design
Projects
Notes
Khrisat 2004
Project Grading
Khrisat 2004
-5-
CS Compiler Design
Class Participation
Khrisat 2004
-6-
CS Compiler Design
Why Compilers?
Compiler
A program that translates from 1 language to another It must preserve semantics of the source It should create an efficient version of the target language
Khrisat 2004
Compiler Structure
Source Program
Translator
Output
Source language
Fortran, Pascal, C, C++
Target language
Machine code, assembly High-level languages, simply actions
Khrisat 2004
CS Compiler Design
Build high-level IR
Back end
Assembly Code
Khrisat 2004
Extracts and identifies lowest level lexical elements from a source stream
Reserved words: for, if, switch Identifiers: i, j, table Constants: 3.14159, 17, %d\n Punctuation symbols: (, ), ,, +
Removes non-grammatical elements from the stream ie spaces, comments Implemented with a Finite State Automata (FSA)
Set of states partial inputs Transition functions to move between states
Khrisat 2004
- 10 -
CS Compiler Design
Lex/Flex
Lex/Flex
Given a specification of regular expressions Generate a table driven FSA Output is a C program that you compile to produce your scanner
Khrisat 2004
- 11 -
CS Compiler Design
Parser
Lots of variations
Hand coded, recursive descent? Table driven (top-down or bottom-up) For any non-trivial language, writing a correct parser is a challenge
Khrisat 2004
- 12 -
CS Compiler Design
Standard formalism used to define the application of semantic rules is the Attribute Grammar (AG)
Graph that provides for the migration of information around the parse tree Functions to apply to each node in the tree
Khrisat 2004
- 13 -
CS Compiler Design
Backend
Frontend
Statements, loops, etc These broken down into multiple assembly statements
Goals
Optimize code quality Map applicationi to real hardware
Khrisat 2004
- 14 -
CS Compiler Design
Provide the necessary information about variable usage and execution behavior to determine when a transformation is legal/illegal Dataflow analysis
Identify when variables contain interesting values Which instructions created values or consume values DEF, USE, GEN, KILL
Khrisat 2004
- 15 -
CS Compiler Design
Optimization
Machine dependent
Depends on processor architecture Memory system, branches, dependences
Khrisat 2004
- 16 -
CS Compiler Design
Code Generation
Mapping machine independent assembly code to the target architecture Virtual to physical binding
Instruction selection best machine opcodes to implement generic opcodes Register allocation infinite virtual registers to N physical registers Scheduling binding to resources (ie adder1) Assembly emission
Machine assembly is our output, assembler, linker take over to create binary
- 17 CS Compiler Design
Khrisat 2004