CS322 Prog Lang & Compilers Prog Assignment #1 Assigned Wednesday April 5, 2007. Due Monday, April 10, 2007 This assignment is to extend the program discussed in class for translating Arithmetic expressions to IR code. The extension is to evaluate binary operators in a manner that decreases the number of registers needed. The rule of thumb is that given a binary operator (exp1 + exp2) we should first translate the sub expression (either exp1 or exp2) that is more demanding. I.e. we should translate first the sub expression that when translated will require the most registers. 1) Download the files "S02code.sml" and "ProgramTypes.sml". Links to these can be found on the notes web page. 2) Create a compiler manager sources file "Prog1.cm" and get the two files to compile (as is) first. Look at the notes from lecture 1, if you need help getting started. 3) Now write and add the function "demand" fun demand x = case node of Var(loc,x) => . . . | Binop(m,x,y) => . . . | Literal(loc,Cint n) => . . . This function returns an int, which is the number of registers needed to translate the expression "x". You will need to study the function "expr" (from file "S02code.sml") to be sure you get the right answer. Even though the type "expression" has many more constructors than "Var", "Binop", and "Literal". You need only handle these three cases. The function "demand" will be recursive. 4) Use the function "demand" to recode the "Binop" case of "expr" so that the sub-expression with greatest demand is translated first. 5) Test your programs by using the function "trans" (in file "S02code.sml"). Consult the text book (Section 7.3.1 pp 315-318) for ideas about how to construct good tests. WHAT TO HAND IN A) Print out the code of S02code.sml. Circle in colored ink the additions you made to the code. B) Also hand in a copy your compile-manager sources file. C) Run your tests, and print and hand in a transcript of the testing. EXPECTATIONS and EVALUATION A) I expect you to be able to write "demand" (30%) B) I expect you to be able to modify "expr" (30%) C) I expect a good set of tests. (20%) D) I expect you to use the compile-manager (10%) E) I expect neat well designed and elegant (10%) code that is well documented. I expect you to document the code I wrote as well as the code you wrote.