Difference: CS255Part2 (1 vs. 9)

Revision 92008-02-12 - XiaomingGu

Line: 1 to 1
 
META TOPICPARENT name="ProjectHome"
Changed:
<
<
  • 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.
>
>
  • 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. At a function call such as scanf and printf, Gcc copies the arguments to a temporary variable. For the project, you need to move these copy statements with the call.
 
  • 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.

Changed:
<
<
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.)
>
>
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 combination of several goto.)
  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.

Revision 82008-02-10 - XiaomingGu

Line: 1 to 1
 
META TOPICPARENT name="ProjectHome"
  • 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.
Line: 7 to 7
  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.
Changed:
<
<
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.
>
>
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.

Revision 72008-02-07 - XiaomingGu

Line: 1 to 1
 
META TOPICPARENT name="ProjectHome"
  • 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.
Line: 29 to 29
 }
Deleted:
<
<
Gimple tree before cs255 pass

main ()
{
  int b;
  int a;

<bb 2>:
  __builtin_puts (&"Input two integers for comparison"[0]);
  scanf (&"%d"[0], &a);
  scanf (&"%d"[0], &b);
  printf (&"a is %d\n"[0], a);
  printf (&"b is %d\n"[0], b);
  if (a > b) goto <L0>; else goto <L1>;

<L0>:;
  __builtin_puts (&"a is greater than b"[0]);
  goto <bb 5> (<L2>);

<L1>:;
  __builtin_puts (&"a is no greater than b"[0]);

<L2>:;
  return;

}

Gimple tree after cs255 pass

main ()
{
  int b;
  int a;

<bb 2>:
  __builtin_puts (&"Input two integers for comparison"[0]);
  printf (&"b is %d\n"[0], b);
  printf (&"a is %d\n"[0], a);
  scanf (&"%d"[0], &b);
  scanf (&"%d"[0], &a);
  if (a <= b) goto <L1>; else goto <L0>;

<L0>:;
  __builtin_puts (&"a is greater than b"[0]);
  goto <bb 5> (<L2>);

<L1>:;
  __builtin_puts (&"a is no greater than b"[0]);

<L2>:;
  return;

}
  Program 2: loop.c
Line: 101 to 44
 }
Deleted:
<
<
Gimple tree before cs255 pass

main ()
{
  int n;
  int s;
  int i;
  int n.0;

<bb 2>:
  __builtin_puts (&"Input an integer for sum"[0]);
  scanf (&"%d"[0], &n);
  n.0 = n;
  if (n.0 >= 0) goto <L13>; else goto <L14>;

<L14>:;
  s = 0;
  goto <bb 4> (<L2>);

<L13>:;
  i = 0;
  s = 0;

<L0>:;
  s = s + i;
  i = i + 1;
  if (i != (int) ((unsigned int) n.0 + 1)) goto <L0>; else goto <L2>;

<L2>:;
  printf (&"The sum from 1 to %d is %d\n"[0], n.0, s);
  return;

}

Gimple tree after cs255 pass

main ()
{
  int n;
  int s;
  int i;
  int n.0;

<bb 2>:
  __builtin_puts (&"Input an integer for sum"[0]);
  scanf (&"%d"[0], &n);
  n.0 = n;
  if (n.0 < 0) goto <L14>; else goto <L13>;

<L14>:;
  s = 0;
  goto <bb 4> (<L2>);

<L13>:;
  i = 0;
  s = 0;

<L0>:;
  s = s + i;
  i = i - 1;
  if (i == (int) ((unsigned int) n.0 + 1)) goto <L2>; else goto <L0>;

<L2>:;
  printf (&"The sum from 1 to %d is %d\n"[0], n.0, s);
  return;

}
  -- XiaomingGu - 02 Feb 2008

Revision 62008-02-07 - ChenDing

Line: 1 to 1
 
META TOPICPARENT name="ProjectHome"
Changed:
<
<
  • Reverse all the printf and scanf 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. Test your code with all possible cases.
>
>
  • 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.
Changed:
<
<
  • If the statement is a self increment/decrement by 1, change it to opposite. For example, change i=i+1 to i=i-1 and vice versa.
>
>
  • 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.
 
Changed:
<
<
When you are working on this transformation, use the following two tests and results to check your code. The counting instructions should be inserted after the control flow changes.
>
>
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.

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

Revision 52008-02-06 - ChenDing

Line: 1 to 1
 
META TOPICPARENT name="ProjectHome"
  • Reverse all the printf and scanf 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. Test your code with all possible cases.
Changed:
<
<
  • If the statement is a conditional branch in the form of if original_cond goto L1; else goto L2, interchange the two branches to if negated_cond goto L2; else goto L1. You only need to concern original_cond in the following six cases: <, >, >=, <=, ==, <>.
  • If the statement is a self increment/decrement by a constant, change it to opposite. For example, change i=i+1 to i=i-1.
>
>
  • 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/decrement by 1, change it to opposite. For example, change i=i+1 to i=i-1 and vice versa.
 
Changed:
<
<
When you are working on this transformation, use the following two tests and results to check your code. Remember to bypass the transformation you done for part 1.
>
>
When you are working on this transformation, use the following two tests and results to check your code. The counting instructions should be inserted after the control flow changes.
  Program 1: ab.c

Revision 42008-02-06 - XiaomingGu

Line: 1 to 1
 
META TOPICPARENT name="ProjectHome"
Changed:
<
<
  • Reverse all the printf and scanf 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.
  • At a function call such as scanf and printf, Gcc copies the arguments to a temporary variable. For the project, you need to move these copy statements with the call.
  • 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.
>
>
  • Reverse all the printf and scanf 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. Test your code with all possible cases.
  • If the statement is a conditional branch in the form of if original_cond goto L1; else goto L2, interchange the two branches to if negated_cond goto L2; else goto L1. You only need to concern original_cond in the following six cases: <, >, >=, <=, ==, <>.
  • If the statement is a self increment/decrement by a constant, change it to opposite. For example, change i=i+1 to i=i-1.
 
Changed:
<
<
After you have implemented the transformation, re-write the following two tests into two new tests so that after your transformation, they produce the same output as the original tests compiled by the compiler without your transformation.
>
>
When you are working on this transformation, use the following two tests and results to check your code. Remember to bypass the transformation you done for part 1.
  Program 1: ab.c
Line: 24 to 24
 }
Added:
>
>
Gimple tree before cs255 pass

main ()
{
  int b;
  int a;

<bb 2>:
  __builtin_puts (&"Input two integers for comparison"[0]);
  scanf (&"%d"[0], &a);
  scanf (&"%d"[0], &b);
  printf (&"a is %d\n"[0], a);
  printf (&"b is %d\n"[0], b);
  if (a > b) goto <L0>; else goto <L1>;

<L0>:;
  __builtin_puts (&"a is greater than b"[0]);
  goto <bb 5> (<L2>);

<L1>:;
  __builtin_puts (&"a is no greater than b"[0]);

<L2>:;
  return;

}

Gimple tree after cs255 pass

main ()
{
  int b;
  int a;

<bb 2>:
  __builtin_puts (&"Input two integers for comparison"[0]);
  printf (&"b is %d\n"[0], b);
  printf (&"a is %d\n"[0], a);
  scanf (&"%d"[0], &b);
  scanf (&"%d"[0], &a);
  if (a <= b) goto <L1>; else goto <L0>;

<L0>:;
  __builtin_puts (&"a is greater than b"[0]);
  goto <bb 5> (<L2>);

<L1>:;
  __builtin_puts (&"a is no greater than b"[0]);

<L2>:;
  return;

}
 Program 2: loop.c

int main() 
{
   int i, s, n;
Changed:
<
<
printf("Input a integer for sum\n");
>
>
printf("Input an integer for sum\n");
  scanf("%d", &n); for (i=0, s=0; i<=n; i++) s += i;
Line: 38 to 96
 }
Added:
>
>
Gimple tree before cs255 pass

main ()
{
  int n;
  int s;
  int i;
  int n.0;

<bb 2>:
  __builtin_puts (&"Input an integer for sum"[0]);
  scanf (&"%d"[0], &n);
  n.0 = n;
  if (n.0 >= 0) goto <L13>; else goto <L14>;

<L14>:;
  s = 0;
  goto <bb 4> (<L2>);

<L13>:;
  i = 0;
  s = 0;

<L0>:;
  s = s + i;
  i = i + 1;
  if (i != (int) ((unsigned int) n.0 + 1)) goto <L0>; else goto <L2>;

<L2>:;
  printf (&"The sum from 1 to %d is %d\n"[0], n.0, s);
  return;

}

Gimple tree after cs255 pass

main ()
{
  int n;
  int s;
  int i;
  int n.0;

<bb 2>:
  __builtin_puts (&"Input an integer for sum"[0]);
  scanf (&"%d"[0], &n);
  n.0 = n;
  if (n.0 < 0) goto <L14>; else goto <L13>;

<L14>:;
  s = 0;
  goto <bb 4> (<L2>);

<L13>:;
  i = 0;
  s = 0;

<L0>:;
  s = s + i;
  i = i - 1;
  if (i == (int) ((unsigned int) n.0 + 1)) goto <L2>; else goto <L0>;

<L2>:;
  printf (&"The sum from 1 to %d is %d\n"[0], n.0, s);
  return;

}
 -- XiaomingGu - 02 Feb 2008 \ No newline at end of file

Revision 32008-02-05 - XiaomingGu

Line: 1 to 1
 
META TOPICPARENT name="ProjectHome"
Deleted:
<
<
 
  • Reverse all the printf and scanf 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.
  • At a function call such as scanf and printf, Gcc copies the arguments to a temporary variable. For the project, you need to move these copy statements with the call.
  • 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.
Line: 10 to 9
 Program 1: ab.c
Changed:
<
<
int main() {
>
>
int main() {
  int a, b; printf("Input two integers for comparison\n"); scanf("%d", &a);
Line: 27 to 27
 Program 2: loop.c
Changed:
<
<
int main() { int i, s; for (i=0, s=0; i<=10; i++)
>
>
int main() { int i, s, n; printf("Input a integer for sum\n"); scanf("%d", &n); for (i=0, s=0; i<=n; i++)
  s += i;
Changed:
<
<
printf("The sum from 1 to 10 is %d\n", s);
>
>
printf("The sum from 1 to %d is %d\n", n, s);
 }

Revision 22008-02-03 - XiaomingGu

Line: 1 to 1
 
META TOPICPARENT name="ProjectHome"
Deleted:
<
<
 
  • Reverse all the printf and scanf 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.
  • At a function call such as scanf and printf, Gcc copies the arguments to a temporary variable. For the project, you need to move these copy statements with the call.
Changed:
<
<
  • If the statement is a conditional branch in the form of if cond goto ; else goto , interchange the two branches to if cond goto ; else goto .
>
>
  • 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.
  After you have implemented the transformation, re-write the following two tests into two new tests so that after your transformation, they produce the same output as the original tests compiled by the compiler without your transformation.

Revision 12008-02-02 - XiaomingGu

Line: 1 to 1
Added:
>
>
META TOPICPARENT name="ProjectHome"

  • Reverse all the printf and scanf 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.
  • At a function call such as scanf and printf, Gcc copies the arguments to a temporary variable. For the project, you need to move these copy statements with the call.
  • If the statement is a conditional branch in the form of if cond goto ; else goto , interchange the two branches to if cond goto ; else goto .

After you have implemented the transformation, re-write the following two tests into two new tests so that after your transformation, they produce the same output as the original tests compiled by the compiler without your transformation.

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;
   for (i=0, s=0; i<=10; i++)
     s += i;
   printf("The sum from 1 to 10 is %d\n", s);
}

-- XiaomingGu - 02 Feb 2008

 
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