[SOLVED] XML 20191030 Assignment 3 optimiserr: Computer Systems 20007081 Combined

$25

File Name: XML_20191030_Assignment_3__optimiserr:_Computer_Systems_20007081_Combined.zip
File Size: 687.66 KB

5/5 - (1 vote)

20191030 Assignment 3optimiserr: Computer Systems 20007081 Combined
Assignment 3optimiserr
Description
You must complete the implementation of the optimiserr program in the file optimiserr.cpp.
The program reads an XML representation of an abstract syntax tree of a Jack class from standard input, using astparsexml and writes an optimised version to standard output, using astprintasxml. The jackoptimiserr function uses the functions described in abstractsyntaxtree.h to traverse the abstract syntax tree and construct an optimised copy that does not include any redundant code.
Compiling and Running optimiserr
When the Makefile attempts to compile the program optimiserr, it will use the file optimiserr.cpp
and any other .cpp files it can find whose names start optimiserr. For example, if we have our own class abc that we want to use when implementing optimiserr, we would have the extra files, optimiser rabc.cpp and optimiserrabc.h.
The program can be compiled using the command:
make optimiserr
The suite of provided tests can be run using the command:
make testoptimiserr
The test scripts do not show the program outputs, just passed or failed, but they do show you the commands being used to run each test. You can copypaste these commands if you want to run a particular test yourself and see all of the output.
jackoptimiserr
One advantage of having a parser produce an abstract syntax tree is that optimisations can be applied to the abstract syntax tree before code generation. The purpose of the jackoptimiserr function is to make a copy of an abstract syntax tree and where possible eliminate redundant code. That is, if part of the abstract syntax tree represents code that can never be executed, it is eliminated.
Since you need to be able to copy a complete abstract syntax tree representing a Jack class, we have provided a skeleton of the tree copying functions required in the optimiserr.cpp file. This should save you a lot of typing. However, you do not need to follow this structure if you do not want to.
The following cases of redundant code must be eliminated by the optimiser while performing a depth first copy of the original abstract syntax tree.
If Statements
An astif node consists of two parts, an astexpr node for the condition and an aststatements node for the iftrue part.
https:myuni.adelaide.edu.aucourses44936pagesassignment37Coptimiserr 12

20191030 Assignment 3optimiserr: Computer Systems 20007081 Combined
If the condition contains a single astterm node containing an astbool node that has value true, the astif node is replaced by the all of the aststatement nodes that are children of the iftrue part.
If the condition contains a single astterm node containing an astbool node that has value false, the astif node is eliminated.
If Else Statements
An astifelse node consists of three parts, an astexpr node for the condition and an aststatements
node for the iftrue part and an aststatements node for the iffalse part.
If the condition contains a single astterm node containing an astbool node that has value true, the
astif node is replaced by the all of the aststatement nodes that are children of the iftrue part.
If the condition contains a single astterm node containing an astbool node that has value false, the
astif node is replaced by the all of the aststatement nodes that are children of the ifelse part. While Statements
An astwhile node consists of two parts, an astexpr node for the condition and an aststatements node for the body part. If the condition contains a single astterm node containing an astbool node that has value false, the astwhile node is eliminated.
Return Statements
When a return statement is executed the current function terminates and the following code in the enclosing statement sequence will never be executed. Therefore, when an astreturn or
an astreturnexpr node is found whilst copying an aststatements node, no more children of that aststatements node are copied.
If both the iftrue and ifelse parts of an astifelse node will both terminate by executing a return statement, then the astifelse node will be considered a return statement.
If the body part of an astwhile node will terminate by executing a return and the condition part contains a single astterm node containing an astbool node that has value true, then the astwhile node is replaced by copying its body part.
Notes:
Do not modify the main function in optimiserr.cpp.
https:myuni.adelaide.edu.aucourses44936pagesassignment37Coptimiserr 22

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[SOLVED] XML 20191030 Assignment 3 optimiserr: Computer Systems 20007081 Combined
$25