正在加载图片...
What additional processing would need to be added for a program with a complex expression like void main()( Beginfunc nt a b=3 a=(b+2)-(a*3)/6 = b+ t2 t6=6 t7=t5 Endfunci let's consider what needs to be done to deal with arrays(note the TAC code below doesn't do ay bounds checking, that will be your job to implement void Binky (int[] arr)i Binl axr[1]=arr[0]*2; BeginFunc; rr t2 t8 ⊥t9=2 t10=t8*t9 Endfunc Before we deal with classes, we should look at how function calls are implemented. This will facilitate our study of methods as they are used in classes. a program with a simple function call int foo (int a, int b)t eturn a bi void main(t eturn int c Endfunc t d main Beginfunc PushParam ci t1 lCall fooi Endfunc;5 What additional processing would need to be added for a program with a complex expression like: void main() { int b; int a; b = 3; a = 12; a = (b + 2)-(a*3)/6; } main: BeginFunc; _t0 = 3; b = _t0; _t1 = 12; a = _t1; _t2 = 2; _t3 = b + _t2; _t4 = 3; _t5 = a * _t4; _t6 = 6; _t7 = _t5 / _t6; _t8 = _t3 - _t7; a = _t8; EndFunc; Now let’s consider what needs to be done to deal with arrays (note the TAC code below doesn't do array bounds checking, that will be your job to implement!) void Binky(int[] arr) { arr[1] = arr[0] * 2; } _Binky: BeginFunc; _t0 = 1; _t1 = 4; _t2 = _t1 * _t0; _t3 = arr + _t2; _t4 = 0; _t5 = 4; _t6 = _t5 * _t4; _t7 = arr + _t6; _t8 = *(_t7); _t9 = 2; _t10 = _t8 * _t9; *(_t3) = _t10; EndFunc; Before we deal with classes, we should look at how function calls are implemented. This will facilitate our study of methods as they are used in classes. A program with a simple function call: int foo(int a, int b) { return a + b; } void main() { int c; int d; foo(c, d); } _foo: BeginFunc; _t0 = a + b; Return _t0; EndFunc; main: BeginFunc; PushParam d; PushParam c; _t1 = LCall _foo; EndFunc;
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有