Homework 8
- Due Nov 10, 2016 by 1:59pm
- Points 12
- Submitting a file upload
This assignment continues your adventures in compiling calc to LLVM as started in homeworks 6 and 7:
https://utah.instructure.com/courses/377698/assignments/3420338
https://utah.instructure.com/courses/377698/assignments/3426197
Augment your calc compiler to take a single (optional) command line argument "-check" that turns on overflow checking. If this option is not supplied, code generation should be as for HW7. If anything different than a single "-check" option is supplied on the command line, it is a compile time error like any other.
In checking mode, instead of generating an add instruction, generate a call to the sadd.with.overflow intrinsic. Parse the resulting struct, using the 64-bit part as the answer if the 1-bit part is 0. If the 1-bit part is 1, your generated code must call the overflow_fail() function that has been added to the driver. The pos argument is the offset of the offending operator, in bytes, from the start of the file.
Subtract and multiply should also call their equivalent signed overflow intrinsics. Divide should trap on division by zero and also if LONG_MIN is divided by -1. The modulus operator should trap for mod by zero.
Also submit at least one test to the auto-tests-hw8 directory that triggers an overflow. Each such test should have a line "# RESULT OVERFLOW N" in it somewhere, where N is the character position, instead of one of the other results. It should also have another line "# CHECK" to tell the test driver to compile the test case in checking mode.