Chap 1
Interpretation
-Performing the operations implied by the source program
Compilation
-Translation of a program written in a source language into a semantically equivalent program written in a target language
cross-compiler
A compiler that runs on platform (A) and is capable of generating executable code for platform (B) is called a
Source-to-Source Compiler
A compiler that takes the source code of one programming language and translates it into the source code of another programming language is called a
syntax tree
A parse can be represented by a tree called a parse or
object file
The output of an assembler is called an
Multi pass
compiler may have to keep entire program representation in memory
abstract syntax tree
compilers often use an
object file
contains a combination of machine instructions as well as the data required to place these instructions in memory.
Analysis
determines the operations implied by the source program which are recorded in a tree structure
preprocessor
generally considered as a part of compiler, is a tool that produces input for compilers. It deals with macro-processing, augmentation, file inclusion, language extension, etc.
Linker
is a computer program that links and merges various object files together in order to make an executable file.
Compiler construction
is a microcosm of computer science
Loader
is a part of operating system and is responsible for loading executable files into memory and execute them. It calculates the size of a program (instructions and data) and creates memory space for it. It initializes various registers to initiate execution.
P
is a set of productions — P: N ® (N ÈT)*
Context-free syntax
is specified with a grammar, usually in Backus-Naur form (BNF)
interpreter
reads a statement from the input, converts it to an intermediate code, executes it, then takes the next statement in sequence.
compiler
reads the whole source code at once, creates tokens, checks semantics, generates intermediate code, executes the whole program and may involve many passes.
Synthesis
takes the tree structure and translates the operations therein into the target program
Linker
to search and locate referenced module/routines in a program and to determine the memory location where these codes will be loaded, making the program instruction to have absolute references.
assembler
translates assembly language programs into machine code.
interpreter
translates high-level language into low-level machine language.
Single pass
usually requires everything to be defined before being used in source program
Traditional three-pass compiler
•analyzes and changes IR •goal is to reduce runtime •must preserve values
Optimizer
•constant propagation and folding •code motion •reduction of operator strength •common sub-expression elimination •redundant store elimination •dead code elimination
Register allocation
•have value in a register when used •limited resources •changes instruction choices •can move loads and stores optimal allocation is difficult
Traditional two pass compiler
•intermediate representation (IR) •front end maps legal code into IR •back end maps IR onto target machine •simplify retargeting •allows multiple front ends •multiple passes Þ better code
N
•is a set of non-terminal symbols
T
•is a set of terminal symbols
S
•is the start-symbol
Scanner
•map characters to tokens •character string value for a token is a lexeme •eliminate white space
Instruction selection
•produce compact, fast code •use available addressing modes •pattern matching problem
Parser
•recognize context-free syntax •guide context-sensitive analysis •construct IR(s) •produce meaningful error messages •attempt error correction
Compiler
•recognize legal (and illegal) programs •generate correct code •manage storage of all variables and code •agree on format for object (or assembly) code
Front end
•recognize legal code •report errors •produce IR •preliminary storage map shape code for the back end
Back end
•translate IR into target machine code •choose instructions for each IR operation •decide what to keep in registers at each point •ensure conformance with system interfaces