• Reverse all printf, scanf, and __builtin_puts statements in a basic block. If there are k such statements in a basic block, the first statement will be switched with the last statement, the second statement will be switched with the (k-1)th statement, and so on.
  • If the statement is a conditional branch in the form of if cond goto L1; else goto L2, interchange the two branches to if cond goto L2; else goto L1. Alternatively, you can change it to if (not cond) goto L1; else goto L2.
  • If the statement is a self increment (or decrement) by 1, change it to the opposite, that is, to decrement (or increment) by 1. For example, change i=i+1 to i=i-1 and vice versa.
  • Try all our test cases to make sure that your compiler generates code with no error, even though the generated code may not run correctly.

When you are working on this transformation, use the following two tests to check your compiler. The counting instructions should be inserted after the control flow changes.

As part of the documentation, submit two programs that would look bizarre but when compiled by your compiler, will produce the same output as the following two normal looking programs when they are compiled by regular Gcc. (You may break for loop statement into a goto combination.)

Bonus point We offer additional 5% of the project grade as bonus to students who use their compiler, using both of the bizarre examples or their equivalents, to baffle someone outside the class and document his or her reactions in the submitted report. The deadline for the bonus is the same as the project deadline.

Program 1: ab.c

int main() 
{
   int a, b;
   printf("Input two integers for comparison\n");
   scanf("%d", &a);
   scanf("%d", &b);
   printf("a is %d\n", a);
   printf("b is %d\n", b);
   if (a > b)
     printf("a is greater than b\n");
   else
     printf("a is no greater than b\n");
}

Program 2: loop.c

int main() 
{
   int i, s, n;
   printf("Input an integer for sum\n");
   scanf("%d", &n);
   for (i=0, s=0; i<=n; i++)
     s += i;
   printf("The sum from 1 to %d is %d\n", n, s);
}

-- XiaomingGu - 02 Feb 2008

Edit | Attach | Watch | Print version | History: r9 < r8 < r7 < r6 < r5 | Backlinks | Raw View | Raw edit | More topic actions...
Topic revision: r8 - 2008-02-10 - XiaomingGu
 
  • Edit
  • Attach
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2017 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding URCS? Send feedback