• Re: CS606 GDB 1 Solution and Discussion

    Total Marks 5
    Starting Date Monday, February 15, 2021
    Closing Date Tuesday, February 16, 2021
    Status Open
    Question Title Intermediate Code Generation
    Question Description
    CS606 GDB Fall 2020

    Compilers are used to translate the source code in to machine code but there is an intermediate code is generated before the target machine code. Compilers can be developed to translate directly without generating machine code.

    Do you think intermediate code generation is extra and time consuming step while translating or it is necessary or beneficial in some way?

    Give your comments in favor or against it with proper reasons.

    Instructions:

    Read the following instructions carefully before sending your comments:

    GDB will have weightage of 5% of your total subject marks.
    Your discussion must be based on logical facts.
    You should post your comments on the Graded Discussion Board & not on the Regular MDB.
    Your comments should be relevant and to-the-point i.e. clear and concise (Maximum 4-5 lines answer using font style Times New Roman and Font Size 12).
    Books, websites and other reading material can be consulted but must be changed into your own wording before posting your comments. (Do not copy the material as it is.)
    No extra time will be given for discussion.


  • @laiba-javed said in CS606 GDB 1 Solution and Discussion:

    Do you think intermediate code generation is extra and time consuming step while translating or it is necessary or beneficial in some way?

    Stack Allocation
    We now need to access the ARs from the stack. The key distinction is that the location of the current AR is not known at compile time. Instead a pointer to the stack must be maintained dynamically.

    We dedicate a register, call it SP, for this purpose. In this chapter we let SP point to the bottom of the current AR, that is the entire AR is above the SP. Since we are not supporting varargs, there is no advantage to having SP point to the middle of the AR as in the previous chapter.

    The main procedure (or the run-time library code called before any user-written procedure) must initialize SP with
    LD SP, #stackStart
    where stackStart is a known-at-compile-time constant.

    The caller increments SP (which now points to the beginning of its AR) to point to the beginning of the callee’s AR. This requires an increment by the size of the caller’s AR, which of course the caller knows.

    Is this size a compile-time constant?

    The book treats it as a constant. The only part that is not known at compile time is the size of the dynamic arrays. Strictly speaking this is not part of the AR, but it must be skipped over since the callee’s AR starts after the caller’s dynamic arrays.

    Perhaps for simplicity we are assuming that there are no dynamic arrays being stored on the stack. If there are arrays, their size must be included in some way.


  • @zaasmi said in CS606 GDB 1 Solution and Discussion:

    ntermediate code generation

    As expected the input to the code generator is the output of the intermediate code generator. We assume that all syntactic and semantic error checks have been done by the front end. Also, all needed type conversions are already done and any type errors have been detected.

    We are using three address instructions for our intermediate language. These instructions have several representations, quads, triples, indirect triples, etc. In this chapter I will tend to use the term quad (for brevity) when I should really say three-address instruction, since the representation doesn’t matter.

Insaf Sehat Card Live Cricket Streaming
Quiz 100% Result Quiz 100% Result
| |