Answered step by step
Verified Expert Solution
Question
1 Approved Answer
(d) Many compilers don't generate machine code directly after lexing, parsing and semantic analysis. Instead they first generate machine-independent code, which is later, possibly after
(d) Many compilers don't generate machine code directly after lexing, parsing and semantic analysis. Instead they first generate machine-independent code, which is later, possibly after optimisation, used to generate code for the target architecture. Explain the characteristics of machine-independent code, and the advantages of using them as an intermediate layer in compilation. [10 marks] (e) Describe a scheme for the translation of function definitions and function calls into low-level code (e.g., RISC-V or stack machine code) based on a stack, as discussed in the lectures and the third task of the coursework. Assume that in the source language function calls are of the form f(e1, en) where el, en are expressions, function definitions are of the form f(x1, ...,xn) = BLOCK where BLOCK itself is an expression, and any expression evaluates to a 32- bit (i.e. 4-byte) integer. We also assume that code generation for other kinds of expressions is readily available, e.g., one can use genExp (BLOCK) and genExp (ei) directly. If you use uncommon instructions, please explain their semantics briefly. If you use activation records in your explanation, describe the layout of your activation records. Note that your answer comprises two parts: code generation for function definitions, and code generation for function calls
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started