CSC254 Function Code Generation Assignment

Due by 11:59pm 11/02/2010 11/09/2010

In this assignment, you are required to modify your compiler to generate assembly-like code for entire programs. Following are the requirements:
  • Copy any lines that begin with #include to the output program.
  • Put all original variables including arrays into a single array.
  • The output program uses the same grammar as the input program as in the previous assignment except that a generated program cannot have any function other than main()/printf()/scanf(), and it cannot have any variables other than array mem[N], where N is a constant. However, you can define and use macros such as #define stackTop mem[0].
  • Remember that in the input language, all function parameters are passed by value.
  • In the output code, there are only main()/printf()/scanf() left after the function code generation.
  • You may use a jump table to implement parameterized gotos. See an example at demo_code/5_func/fac.c in the repository.
  • Finish above requirements before implementing this one. Your compiler should insert code into a program to report the maximal stack depth after an execution. The basic idea is to maintain a global counter for stack depth and generate increment/decrement code before/after each active function.
  • As with the previous assignment, the output program should be compilable by a C compiler and have the same behavior as the input program. The only exception is reporting the maximal stack depth.

What/When/Where to Submit

Turn in your code with a report of your design including instructions to run your compiler by 11:59pm 11/02/2010 11/09/2010. It should pass all the provided test cases in project_code/c_tests. In the report, write down the name of passed test cases and the reasons for failure in other test cases. For the requirement of reporting the maximal stack depth, use the provided meaning of the life code at project_code/c_tests/meaning_of_life.c to do the testing. Submit the files in project_code/function/user_id.