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

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899604
Joined: Mon Aug 02, 2021 8:13 am

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

Post by answerhappygod »

4 A A Alice And Bob Are Writing A New Compiler For Java They Have An Argument About The Correct Behaviour Of A Featu 1
4 A A Alice And Bob Are Writing A New Compiler For Java They Have An Argument About The Correct Behaviour Of A Featu 1 (41.11 KiB) Viewed 20 times
4. a (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) (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); } return x; } (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)
(d) Consider the following intermediate language code: vl0 = 100 vll = 1 label: rl = 5*3 r2 =rl + 1 vll = vll + rl vl0 = v10 - 1 if (vlo !=0) jmp label return vll; 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) (ii) Loop unrolling (2 marks) (iii) Constant folding, (2 marks)
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply