Constant Propagation Transformation: Difference between revisions

Jump to navigation Jump to search
no edit summary
No edit summary
No edit summary
Line 9: Line 9:
===Example===
===Example===
{| class="wikitable"
{| class="wikitable"
! Input Code
!Result
|-
|The following code tests ConstPropagation applied to main function.
In the given example, variables a, b and c are known.
They are propagated to the rest of the body of main.
|The following code is the generated code after the transformation has been applied.
|-
|-
|<syntaxhighlight lang="c">
|<syntaxhighlight lang="c">
Line 22: Line 14:
// In the given example, variables a, b and c are known.  
// In the given example, variables a, b and c are known.  
// They are propagated to the rest of the body of main.
// They are propagated to the rest of the body of main.
#pragma EMX_TRANSFORMATION ConstPropagation
#pragma EMX_TRANSFORMATION ConstPropagation
int main(void) {
int main(void) {
Line 35: Line 28:
</syntaxhighlight>
</syntaxhighlight>
|<syntaxhighlight lang="c">
|<syntaxhighlight lang="c">
//
// The following code is the generated code after the transformation has been applied.
// The following code is the generated code after the transformation has been applied.
//


int main(void) {
int a = 2;
int b = a;
int c;
int d;
c = 4;
d = 6;
return 0;
}
</syntaxhighlight>
|-
|
|
|}The following code tests ConstPropagation applied to main function. In the given example, variables a, b and c are known. They are propagated to the rest of the body of


main. <syntaxhighlight lang="c">
#pragma EMX_TRANSFORMATION ConstPropagation
int main(void) {
int main(void) {
     int a = 2;
     int a = 2;
     int b = a;
     int b = a;
    int c;
    int d;
      
      
    int c, d;
     c = 4;
     c = 2 + 2;
     d = 6;
     d = b + c;
 
   
    return 0;
}
</syntaxhighlight>The following code is the generated code after the transformation has been applied.<syntaxhighlight lang="c">
int main(void) {
int a = 2;
int b = a;
int c;
int d;
c = 4;
d = 6;
return 0;
return 0;
}
}
</syntaxhighlight>
</syntaxhighlight>
|}
Cookies help us deliver our services. By using our services, you agree to our use of cookies.

Navigation menu