⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 algebra.dcf

📁 用Java实现的编译器。把源代码编译成SPARC汇编程序
💻 DCF
字号:
// some tests for algebraic simplificationmclass Program {  // has a side effect  int foo() {    callout("printf", "Hi, I am a side effect.\n");    return 10;  }    void main() {    int a,b,c;    int x,y,z;    callout("printf","A? ");    a = callout("readint");    callout("printf","B? ");    b = callout("readint");    callout("printf","C? ");    c = callout("readint");    x = a - a;  // should go to 0    y = b * 1;  // should go to b    z = c + 0;  // should go to c    callout("printf", "x: %d  ", x);    callout("printf", "y: %d  ", y);    callout("printf", "z: %d\n", z);    x = a + b + c - a; // ideally, should reduce to b + c.    y = 3 * b + 4 * b; // relatively easily converted to 7 * b    z = -2 * c + a * c + 2 * c + 3 * a * c; // convertable to (4 * a * c)    callout("printf", "x: %d  ", x);    callout("printf", "y: %d  ", y);    callout("printf", "z: %d\n", z);    x = a * 0 + 0 * (foo()); // convertable to 0, but foo() still needs                             // to be called, since it has a side effect.    y = b * foo() + c * foo(); // convertable to (b+c)*foo(),                                // but call foo twice.    z = (a - a) * (b); // convertable to 0; make sure that multiple rounds                        // happen.    callout("printf", "x: %d  ", x);    callout("printf", "y: %d  ", y);    callout("printf", "z: %d\n", z);    x = (a + b) * (c + 1); // this is as efficent as it gets.                        // it's bad if it's canonicalized to something worse.        callout("printf", "x: %d\n", x);  }}          

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -