Compilers Flashcards
What are the three stages used with compilers
front end
optimiser
back end
what does the front end of compiling entail
converts source code into an intermediate representation
uses a lexer
uses a parser to build an abstract syntax tree
AST is an intermediate representation
what does a parser do and how
builds an abstract syntax tree
uses nodes for statements and expressions
aso builds a symbol table which contains all the variable names and information about them i.e type and scope
uses heirarchy to ensure local variables are used over global provided the same name
what does a lexer do
breaks input string into tokens
what does the optimisation stage entail
the IR transformations
what does the back end entail
converts IR into machine code
specific to architecture
register allocation
determie the location of variables in memoyr
what is common sub expression elimination
a = 2b +cd
e = 2b+f+g
–>
temp = 2b
a = temp+c+d
e = temp+f+g
what is dead code elimination
removes code that cannot be reached
what is constant foldin
combines all the constants in an equation into one
i.e
2 pi r^2 -> 6.28.. *r^2
what is hoisting loop invariants
if something is true every iteration of the loop take it outside the loop
i.e if x and y dont change
for i in range(1,10):
z +=x+y
–>
temp = x+y
for i in range(1,10):
z +=temp
what is function inlining
compiler rmeoves subroutine call by inlining the function (only done if small)
what is strength reduction
replaces expensive operations with cheaper operations