MCS-388 Lab 5: Procedures – The Basics (Spring 2014)

Due: May 5, 2014

Objectives

Remember to test your work frequently. Each paragraph can be tested.

Change the syntax of a program so that there can be any number of procedure definitions.

Because each procedure call still passes in one argument, it would be nice if each procedure were expecting an argument. The syntax of a procedure definition should no longer have an empty pair of parentheses. Instead, include the keyword int and a variable name. Your LLVM code should allocate stack space, just like for any other local variable, and store the argument into that variable. Here is an example of how the LLVM code for a typical procedure definition might start:

define i32 @factorial(i32 %t0) {
    %t1 = alloca i32 ; parameter n
    store i32 %t0, i32* %t1

If you didn't take Lab 2's invitation to add return statements, now would be a good time to do so. With your own procedures, having them always return 0 would be rather boring.

At this point, you can eliminate the library, because the definitions of print and println are now within the language your compiler can process. (For that to be literally true, you need to have taken Lab 2's suggestion of allowing character constants. If you skipped that, you can give your compiler modified definitions of print and println in which each character constant is replaced with the corresponding decimal code number.) If you need help with the build.xml aspects of eliminating the library, I'd be glad to assist. For the moment you'll still need the LibraryDeclarations class to provide a declaration of the standard putchar procedure.

Submission

Upload to moodle a zip file of your project.


Course web site: https://gustavus.edu/+max/courses/S2014/MCS-388/
Instructor: Max Hailperin <max@gustavus.edu>