----------------------------------------------------------------------

CSE 401 Fall 1997 (Henry): Compilers

[Home] [Admin] [Details] [Help] [Other]

Assignments / #7 (Reading and Exploration)

----------------------------------------------------------------------

Do by Wednesday, November 12, 1997

There will be no turn in needed for this assignment, although you will be expected to have done the work!

  • Read ASU 6.1 through 6.4 on type checking; 6.5 is optional.

  • Read ASU 8.1 through 8.7 (eg, all of chapter 8) on intermediate code generation and control flow translation schemes.

  • Lower priority (you'll eventually have to read this): Read ASU 7.1 through 7.5 on run time environments data storage, and procedure calling.

  • Read this high level description of floating point numbers, as encoded using the IEEE-754 Floating point standard. This is what the "double" precision data type in C uses, as you were experimenting with in the last assignment involving lex and yacc. Read the discussion of the special values of floating point numbers, as well as the a table that describes the algebra of special floating point numbers.

  • As a group, read and comprehend Henry's solution to the Set data type assignment. (This will be made available on Monday Nov 10.) If your implementation of Set data type differed drastically from his, or if you went completely astray (and hence got a poor grade), then you should plan on using his implementation for the run time implementation of the PL/0 set data type.

  • As a group, compile the core of the Set data type assignment (eg, everything but the main function and any test scaffolding) on the instructional alphas using the mips c++ cross compiler. Here's how to do this ....

    Write all your C++ Set class code in a file called setlib.cc
    Compile this C++ code, on the alphas, using :
    /cse/courses/misc_lang/axp/mips-gcc-cross/bin/mips-dec-ultrix4.2-c++
    Use -S option to get setlib.s as output
    The setlib.s thus obtained contained the MIPS assembly code for your Set data type.

    Examine the mips assembly code that was generated and find the function entry points. Your PL/0 compiler will have to call these functions using the naming (and calling convention) that the C++ cross compiler assumes.

    The function entry points will be named with seemingly gibberish names. The gibberish names are called "mangled names", and are produced by the C++ compiler in the process of "function name encoding". The names encode the class name, the name of the member function, and the types of the arguments to the member function (the return type is not used). The names are mangled to encode unique functions uniquely, using C conventions for identifiers.

    For example, the definition:

    void Set::add(const Set *rv1, const Set *rv2) { ... }
    
    would be turned into a function with the mangled name
        add__3SetPC3SetT1
    
    This name can be parsed as:
    • member function add;
    • from a class whose name is 3 character long and is named "Set";
    • that takes as a first argument a pointer (P) to a constant (C) class whose name is 3 characters long and is named "Set";
    • that takes as a second argument a type that is the same as the type of the first argument (T1).

  • As a group, read, contemplate (if not understand!) and discuss Alan Perlis' epigrams of programming . These epigrams are short sayings that encapsulate a lot of wisdom about computing and computer science. Perlis was involved in computing since the mid 1950's, and was a faculty member at Yale University. He was involved in the design of several programming languages, the implementation of many more, and was a champion of the language APL.

  • As a group, experiment with simple aspects of the unix program dc. dc is a simple postfix desk calculator. dc's arithmetic is based on scaled arbitrary precision integers.
    • Read the manual page for dc (do a "man dc"). The command interface is cryptic, to say the least!
    • Invoke dc from the shell, and try typing postfix expressions to it. The operator 'p' prints out the top item of the stack. For example, "2 3 + p" will print 5; "2 16 ^ p" will print 65536; "2 100 ^ p" will print many digits, and so forth for integers. Set the scale factor using the unary 'k' operator; this will determine where the decimal point goes. Thus, "3 k 1.234 1.234 + p" will print 2.468, and so on.

----------------------------------------------------------------------

401admin@cs.washington.edu (Last modified: 11/05/97)