diff --git a/lab3-4/README.md b/lab3-4/README.md index fbb110a2aa7e65c4491ca01917d4d07f4c855deb..f26ba1bfa1f1f34491c5a453105fc0fec2416a50 100644 --- a/lab3-4/README.md +++ b/lab3-4/README.md @@ -71,9 +71,58 @@ diff -y my_output.txt ../traces/trace-lab3.txt ## Lab 4 -In lab 4 you will work in file `codegen.cc` search for `/* --- Your code here --- */`' +In Lab 4 you will work in file `codegen.cc` search for `/* --- Your code here --- */`' to see where you need to introduce your changes. +A good place to start is the function `BinaryGenerateCode` + +```C++ +/* + * + * This function is used to generate code for all kinds of binary + * operators and relations. The arguments to the function are the + * following: + * + * q The QuadsList onto which the generated code is placed. + * realop The quad to generate for the operator if the arguments + * are of type real. + * intop The quad to generate for the operator if the arguments + * are of type integer. + * left The AST for the left-hand side of the operator. The + * value type of this AST must be the same as that of the + * AST for the right-hand side. + * right The AST for the right-hand side of the operator. The + * value type of this AST must be the same as that of the + * AST for the left-hand side. + * node The operator node itself. You probably won't need this + * unless you want to print an error message. + * type If not NULL, this is the type of the result. This is + * used for relations, where the type of the result is + * always integer, even if the operands are real. If this + * parameter is NULL, then the type of the result is the + * same as the type of the operands (the parser needs to + * make sure that the operands have the same type.) + * + * See the GenerateCode methods for the binary operators for + * examples of how this function is used. + * + */ + +static VariableInformation *BinaryGenerateCode(QuadsList& q, + tQuadType realop, + tQuadType intop, + ASTNode *left, + ASTNode *right, + ASTNode *node, + TypeInformation *type = NULL) +{ + /* --- Your code here --- */ + return NULL; + /* --- End your code --- */ +} +``` + + ### Testing Lab 4 In order to test Lab 4, there exists a test script. For more details see the README in the test folder.