Starting from:

$30

COMP442_6421-Code Generation Solved

In this assignment, you are to implement a code generation phase for the language as described in the previous assignments. The following section lists the different specific constructs/concepts for which code generation needs to be implemented for all the aspects of the language to become executable.

 

Problem statement
 

1.             Memory allocation: As variables are declared, memory space must be allocated that will eventually be used to store their values. Memory cells are either identified using a unique Moon assembly code label, or an offset relative to the stack frame on which the variable will reside during execution of the function scope in which it is declared. The size of the allocated memory block should depend on the declared type/kind of variable (integer, float, array, object, array of objects, etc.) and should be stored in the symbol table entries for each declared variable.  

  

2.             Functions: The code generated for functions should be associated with a Moon assembly code subroutine, i.e. a block of code that can be jumped to using a label, then when the function resolves, jump back to the instruction following the initial jump. Parameters should be passed/received during the function call. The return value should be passed to the calling function when the function resolves. If a call to a member function is made, the member function should have access to the data members of the object from which it was called.  

 

3.             Statements: Every kind of statement as defined in the grammar should be implemented: assignment statement, conditional statement, loop statement, input/output statements, and return statement, etc.    

 

4.             Aggregate data elements access: Aggregate data types such as arrays and objects contain a group of data values. The code must be generated so that contained member values in such an aggregated value can be accessed when referred to as factors in an expression or the left-hand side of an assignment statement. This includes access to array elements and object members. Access to these should be implemented using offset calculation.   

 

5.             Expressions: Computing of the resulting value of an entire expression, including the simple case when an expression is either a variable name or a single literal value, up to complex expressions involving all kinds of operators (arithmetic, logical, and relational), array indexed with expressions, deeply nested object member access, etc. This involves memory allocation for temporary results, and register allocation/deallocation when necessary.    


Document
 

You must provide a short document that includes the following sections:  

 

Section 1.  Analysis : Using the (1-5) itemized list provided below (see “Implementation”), provide a checklist that identifies what code generation items are either implemented or not implemented in your assignment.   

Section 2.  Design : I – Overall design – Description/rationale of the overall structure of the solution and the roles of the individual components used in the applied solution. II – Phases – Description of the purpose of each phase involved in the implementation of this assignment.  

Section 3.  Use of tools : Identify all the tools/libraries/techniques that you have used in your implementation and justify why you have used these particular ones as opposed to others.  

 

Input/output statement: execution of a keyboard input statement should result in the user being prompted for a value from the keyboard by the Moon program and assign this value to the parameter passed to the input statement. Execution of a console output statement should print to the Moon console the result of evaluating the expression passed as a parameter to the output statement.  
2.0 
 

Notes : (1) Difficulty rating is provided as green: easy, yellow: medium, red: harder. (2) Marking elements with higher marks indicate constructs that are necessary to have in order to demonstrate that the generated code runs correctly. (3) This is the list of code generation elements due for assignment 5. More code generation elements are going to be added on the grading scheme for the final project requirements.    

 

•   Output of moon code in a file : The Moon code should be output to a file, including comments in the generated code to highlight the structure of the code generated for each syntactical construct. When compiling a file named, for example, originalfilename.src, the code generator should write the Moon code into a file named originalfilename.moon.

•   Test cases : Write a set of source files that enable to test the code generation for all syntactical structures that you can generate code for, including simple cases that test isolated syntactical constructs, and more complex cases that test combinations of syntactical constructs.  

•   Driver : Include a driver that reads your test cases and generates, for each test case file, the corresponding .moon file.  

More products