Page 1 of 1

4. 4. Page 6 (a) Alice and Bob are writing a new compiler for Java. They have an argument about the correct behaviour of

Posted: Mon May 09, 2022 6:20 am
by answerhappygod
4 4 Page 6 A Alice And Bob Are Writing A New Compiler For Java They Have An Argument About The Correct Behaviour Of 1
4 4 Page 6 A Alice And Bob Are Writing A New Compiler For Java They Have An Argument About The Correct Behaviour Of 1 (119.14 KiB) Viewed 32 times
4. 4. Page 6 (a) Alice and Bob are writing a new compiler for Java. They have an argument about the correct behaviour of a feature of the language. How could they resolve their argument, ensuring they pick the correct behaviour? Suggest two ways. (4 marks) (b) In the context of an optimising compiler, what is optimisation? How does an optimised program differ from an unoptimised one? What metrics of a program might a compiler optimise? (6 marks) Page 7 (d) Consider the following intermediate language code: vl0 = 100 vll = 1 label: rl = 5*3 r2 =r1 + 1 vll = vll +r1 vl0 = vl0 - 1 if (vlO !=0) jmp label return vll; (c) Consider the following Java code: public void log(int x) { System.out.println("Called function log!"); } public int compute() { int x = 1; while (x < 100) { x=x*-1; log(x); } Explain briefly what each of the following optimisations does. Illustrate your answer by applying the optimisation to the code. (1) Dead code elimination. (2 marks) return x; } (ii) Loop unrolling (2 marks) (iii) Constant folding. (2 marks) (1) Alice says that removing the line "log(x)" from the function compute() will not change the return value of compute(). Is she correct? Explain your answer. (2 marks) (ii) Bob says that an optimising compiler ought to remove the line "log(x)" from the function compute(). Is he correct? Explain your answer. (2 marks)