Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

CS 352 Spring 2023

Compiler Project 4

Due April 19th, 11:59pm

1. Main Tasks in Project 4

Project 4 (P4, in short) extends Project 3 by covering the full set of MiniJavaP2 programs.

As in P3, it is assumed that the test cases have no syntax and type errors, and they will not cause run- time exceptions. Hence no errors are to be reported.

Some of the type checking code developed in Project 2 is still needed for allocating variables in the  memory and for generating address-computing instructions. Additional work is needed for memory allocation, e.g., to determine the stack frame size for each method.

The semantics of a MiniJavaP2 follows that in Java standard. Students should carefully review relevant   Java type rules and execution rules. The authoritative document for type and run-time evaluation rules  for our projects this semester is Java Language Specification (Java SE 7bEdition, abbreviated as JSE7 in    the rest of this document). Chapters 4 and 15 are of the most relevance, although the program features discussed there go well beyond those in P4. Anything that is not allowed according to this document    should not be allowed by the compiler we built for P4, with the caveat that we do not require short-   circuit evaluation of Boolean expressions (since we assume that no run-time exceptions could happen to the test cases.)

The JSE7 document can be found at https://docs.oracle.com/javase/specs/jls/se7/html/index.html

The criteria to determine the correctness of the generated assembly code is to run it through sample inputs. The output produced by the assembly code must agree with the expected result of the              MiniJavaP2 program. (When in doubt, test the MiniJavaP2 program using the standard Java                   compilation/execution tools.)

The target hardware is a Raspberry Pi virtual machine image. Please refer to relevant lecture slides and the posted ARM documents on Brightspace.

The standard library method Integer.parseInt should now be implemented, by calling atoi() standard      library function. You can assume that the argument passed to this method is a properly written string of digits. The command line argument argv[] should be implemented, with no assumption on the number  of command line arguments.

1.1. Simplifications

To simplify the implementation, the following assumptions are made about the test cases:

•    Arrays are of either a single-dimension or two dimensions.

•   The number of arguments passed to any method will be no greater than four.

•    All string literals can be placed in the .text section in the assembly code generated. The code   generator is responsible for creating a symbolic label in the .text section. For example, given a

local declaration String x = Hello”; The string Hello” can be placed in the .text section                 following a label, say _String1. In other words, the code generator does not need to call malloc() and store Hello” on the heap.

•    Static fields are assumed to be read only. They can therefore be placed in the .text section.          However, no such assumptions are made for variables that are local to methods. Also, keep in    mind that a value returned by a method call may be of int, Boolean, or String type. It can also be a reference to an array whose prime type is int, Boolean, or String.

1.2. Importing Command Line Argument

As an example, suppose we have an executable program file, addCMDline, that is generated from an ARM assembly program, addCMDline.s. On a Linux system, we execute addCMDline by issuing the    command addCMDline 3 4”, which is to add those two numbers 3 and 4.

In the assembly program addCMDline.s, we can access the argument count, argc, from register r0 (that   is, the first argument registers on ARM processor) and the base address of the array argv[], from register r1 (the second argument register). The meaning of argc and argv[] is the same as in the C language. In      this example, we have argc equal to 3 (i.e. three strings in the command line) and argv[0] is the pointer   to string “addCMDline”, argv[1] is the pointer to string “3”, and argv[2] is the pointer to string “4” . We     can next pass argv[1] to the standard library routine atoi() to get an integer value 3, and pass argv[2] to   atoi() to get the integer value 4.

It is important to note that any functions we call will likely modify r0 and r1. Hence, in order to be able to be able to make references to argc and argv[] throughout the main() method, we need reserve          offsets in the stack frame of the main() method for argc and the based address of argv[]. The argument registers r0 and r1 should be saved to such stack locations in the beginning of the main() method.

2. Logistics

2.1. Expected Workflow and the Grading Method

Same as P3. The weights of different program features may be announced to the students in an approximate way when a subset of test cases are posted.

2.2. Submission Instruction

Same as P3, except that the turnin command must name p4 as the project instead of p3.