Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

1. What is the purpose of code generation phase of compiler.

= Code generator decides what values to keep in the registers. Also, it decides the
registers to be used to keep these values. Ordering of instructions: At last, the code
generator decides the order in which the instruction will be executed. It creates schedules
for instructions to execute them.
2. Give the function of code optimization.
= Code optimization is any method of code modification to improve code quality and
efficiency. A program may be optimized so that it becomes a smaller size, consumes less
memory, executes more rapidly, or performs fewer input/output operations.
3. Define triples.
= Triple describes something as being made of three parts or being three times as great.
Triple also means a set of three.
4. Which intermediate code representations of expression are suitable for optimizing
compilers?
= Intermediate code generator receives input from its predecessor phase, semantic
analyzer, in the form of an annotated syntax tree. That syntax tree then can be converted
into a linear representation, e.g., postfix notation. Intermediate code tends to be machine
independent code.
5. Define postfix string.
= Postfix: An expression is called the postfix expression if the operator appears in the
expression after the operands. Simply of the form (operand1 operand2 operator).
6. Define flow graph.
= A flow graph is a form of digraph associated with a set of linear algebraic or differential
equations: "A signal flow graph is a network of nodes (or points) interconnected by directed
branches, representing a set of linear algebraic equations.
7. Why basic block is transformed into DAG? Give reason.
= The Directed Acyclic Graph (DAG) is used to represent the structure of basic blocks, to
visualize the flow of values between basic blocks, and to provide optimization techniques in
the basic block.
8. Define the term 'basic block'.
= Basic Block is a straight line code sequence that has no branches in and out branches
except to the entry and at the end respectively. Basic Block is a set of statements that
always executes one after other, in a sequence.
9. Define DAG.
= What Does Directed Acyclic Graph (DAG) Mean? In computer science and mathematics,
a directed acyclic graph (DAG) is a graph that is directed and without cycles connecting the
other edges. This means that it is impossible to traverse the entire graph starting at one
edge. The edges of the directed graph only go one way.
10. List code optimization techniques.
= Code Optimization Techniques-
Compile Time Evaluation.
Common sub-expression elimination.
Dead Code Elimination.
Code Movement.
Strength Reduction.
11. Give the DAG representation for the following basic block:
= x = a[i]
a[j] = y
12. List types of descriptors.
= There are two types of descriptors: data descriptors and non-data ones.
13. What is the use of register descriptor?
= A register descriptor is used to keep track of what is currently in each registers. The
register descriptors show that initially all the registers are empty. An address descriptor
stores the location where the current value of the name can be found at run time.
14. Define quadruple.
= 1 : having four units or members. 2 : being four times as great or as many. 3 : marked by
four beats per measure quadruple meter.
15. State any two advantages of code optimization.
= Cleaner Code Base. ...Higher Consistency. ...Faster Sites. ...Better Code
Readability. ...More Efficient Refactoring. ...More Straightforward Debugging. ...Improved
Workflow. ...
16. Define dead code.
= Dead code is any code that's never executed, or if executed, the execution has no effect
on the application's behaviour.
17. Define optimization.
= an act, process, or methodology of making something (such as a design, system, or
decision) as fully perfect, functional, or effective as possible specifically : the mathematical
procedures (such as finding the maximum of a function) involved in this.
18. What is frequency reduction.
= A statement or expression, which can be moved outside the loop body without affecting
the semantics of the program, is moved outside the loop.
19. Define basic block.
= Basic Block is a straight line code sequence that has no branches in and out branches
except to the entry and at the end respectively. Basic Block is a set of statements that
always executes one after other, in a sequence.
1. What is code generation? Explain in detail.
=In computing, code generation is part of the process chain of a compiler and converts
intermediate representation of source code into a form (e.g., machine code) that can be
readily executed by the target system. Sophisticated compilers typically perform multiple
passes over various intermediate forms.
2. What is code optimization? Explain in detail.
=The code optimization in the synthesis phase is a program transformation technique,
which tries to improve the intermediate code by making it consume fewer resources (i.e.
CPU, Memory) so that faster-running machine code will result.
3. Write a short note on: Compilations of expressions.
= It compiles expressions using the arithmetic operations built into the underlying operating
system, and is, therefore, referred to as the native compiler. Compilation takes place at
TABLE run time. This compiler is invoked by issuing the command SET DEFINES =
COMPILED.
4. What are register and operand descriptors? Explain with example. Also
differentiate them.
=A register descriptor contains the track of what is currently in each register. The register
descriptors show that all the registers are initially empty. An address descriptor is used to
store the location where current value of the name can be found at run time.
5. Describe intermediate code for expressions in detail.
=In the analysis-synthesis model of a compiler, the front end of a compiler translates a
source program into an independent intermediate code, then the back end of the compiler
uses this intermediate code to generate the target code (which can be understood by the
machine). The benefits of using machine-independent intermediate code are:
Because of the machine-independent intermediate code, portability will be enhanced. For
ex, suppose, if a compiler translates the source language to its target machine language
without having the option for generating intermediate code, then for each new machine, a
full native compiler is required. Because, obviously, there were some modifications in the
compiler itself according to the machine specifications.
Retargeting is facilitated.
6. What is three address code? Describe with example.
=Three address code is a type of intermediate code which is easy to generate and can be
easily converted to machine code.It makes use of at most three addresses and one
operator to represent an expression and the value computed at each instruction is stored in
temporary variable generated by compiler.
Example− Expression a = b + c + d can be converted into the following Three Address
Code. where t1 and t2 are temporary variables generated by the compiler. Most of the time
a statement includes less than three references, but it is still known as a threeaddress
statement.
8. What is quadruple? How to represent it? Explain with example.
=The definition of a quadruple is an amount four times as many. An example of a quadruple
is a cocktail with four shots of alcohol. noun. Being four times as long, as big or as many of
something.
10. What is meant by optimizing transformations? Enlist its types.
=Optimization is a program transformation technique, which tries to improve the code by
making it consume less resources (i.e. CPU, Memory) and deliver high speed. In
optimization, high-level general programming constructs are replaced by very efficient low-
level programming codes.
Compile Time Evaluation.
Common sub-expression elimination.
Dead Code Elimination.
Code Movement.
11. What is dead code? How to eliminate it? Explain with example?
=In some areas of computer programming, dead code is a section in the source code of a
program which is executed but whose result is never used in any other computation.
ECJ identifies the dead code. We are extending this compiler to eliminate the dead code.
13. What are the phases of optimization? Explain in detail.
=Optimizing an algorithm is beyond the scope of the code optimization phase. So the
program is optimized. And it may involve reducing the size of the code.
Machine Independent Optimization: This code optimization phase attempts to improve the
intermediate code to get a better target code as the output. The part of the intermediate
code which is transformed here does not involve any CPU registers or absolute memory
locations.
Machine Dependent Optimization: Machine-dependent optimization is done after the target
code has been generated and when the code is transformed according to the target
machine architecture. It involves CPU registers and may have absolute memory references
rather than relative references. Machine-dependent optimizers put efforts to take maximum
advantage of the memory hierarchy.
16. What is basic block? Explain with example.
=Basic Block is a straight line code sequence that has no branches in and out branches
except to the entry and at the end respectively. Basic Block is a set of statements that
always executes one after other, in a sequence. The first task is to partition a sequence of
three-address code into basic blocks.
18. What is flow graph? What is its purpose? Explain with example.
=Flow graph is a directed graph. It contains the flow of control information for the set of
basic block. A control flow graph is used to depict that how the program control is being
parsed among the blocks. It is useful in the loop optimization
Flow diagrams are used to structure and order a complex system, or to reveal the
underlying structure of the elements and their interaction.
19. With the help of example describe how to construct DAG using basic block.
=A DAG for basic block is a directed acyclic graph with the following labels on nodes: The
leaves of graph are labeled by unique identifier and that identifier can be variable names or
constants....
Example:
S1:= 4 * i.
S2:= a[S1]
S3:= 4 * i.
S4:= b[S3]
S5:= s2 * S4.
S6:= prod + S5.
Prod:= s6.
S7:= i+1.
21. What is expression tree? How tto create it? Explain wit hexample.
=The binary expression tree is a binary tree whose leaves are operands, such as constants
or variable names, and the other nodes contain operators. For example, the postfix notation
a b + c d e + * * results in the following expression tree.
If we get an operand in the given expression, then push it in the stack. ...
If an operator gets two values in the expression, then add in the expression tree as its child,
and push them in the current node.
Repeat Step-1 and Step-2 until we do not complete over the given expression.
20. What are the issues are in design of a code generator? Explain two of them in
derail.
=The final phase in compiler model is the code generator. It takes as input an intermediate
representation of the source program and produces as output an equivalent target
program. The code generation techniques presented below can be used whether or not an
optimizing phase occurs before code generation.
1. Input to code generator:
• The input to the code generation consists of the intermediate representation of the source
program produced by front end , together with information in the symbol table to determine
run-time addresses of the data objects denoted by the names in the intermediate
representation.
2. Target program:
• The output of the code generator is the target program. The output may be : a. Absolute
machine language
- It can be placed in a fixed memory location and can be executed immediately. b.
Relocatable machine language
- It allows subprograms to be compiled separately.
c. Assembly language
3. Memory management:
• Names in the source program are mapped to addresses of data objects in run-time
memory by the front end and code generator.
• It makes use of symbol table, that is, a name in a three-address statement refers to a
symbol-table entry for the name.
• Labels in three-address statements have to be converted to addresses of instructions.
For example,
4. Instruction selection:
• The instructions of target machine should be complete and uniform.
• Instruction speeds and machine idioms are important factors when efficiency of target
programis considered.
• The quality of the generated code is determined by its speed and size.

You might also like