正在加载图片...
Decaf TAc instruction formats The convention followed in the examples below is that tl, t2, and so on refer to variables(either from source program or temporaries)and Ll, L2, etc are used for labels Labels are attached to the instruction that serve as targets for goto/branch instructions and are used to identify function/method definitions and vtables Assignment Function definitions: tl ="abcdefg" EndFunci Return t1 (rvalue can be variable, or string/int Return constant) Memory references Arithmetic (t2 t3=t2+t1 t1=*(t2+8); t3=t2-t1; t3=t2*t1; (t1+-4) t3=t2/t (optional offset must be integer constant, t3=t28t1 can be positive or negative (not all arithmetic operators are present, must synthesize others using the primitives Array indexi available) To access arr5], add offset multiplied by elem size to base and deref Relational/equality/logical: Object fields, method dispatch To access ivars. add offset to base deref t3=t2&&t1; To call method. retrieve function address t3=t2 (must synthesize other ops as necessary) from vtable, invoke using ACall Data specification: Labels and branches VTable ClassName Ll, L2,...i Goto L1: (take branch if value of tl is zer Function/method calls (before call, params are individually pushed right to left) LCall L1 1=Lca11L1; ACall tli to= ACall t1 (LCall used for a function label known at compile-time, ACall for a computed function address most likely from vtable Each has two forms that differ in void vs non-void return value) The built-in functions from Decaf standard library(Alloc, ReadLine, PrintInt, Halt, etc )are invoked via LCal2 Decaf TAC instruction formats The convention followed in the examples below is that t1, t2, and so on refer to variables (either from source program or temporaries) and L1, L2, etc. are used for labels. Labels are attached to the instruction that serve as targets for goto/branch instructions and are used to identify function/method definitions and vtables. Assignment: t2 = t1; t1 = "abcdefg"; t1 = 8; (rvalue can be variable, or string/int constant) Arithmetic: t3 = t2 + t1; t3 = t2 - t1; t3 = t2 * t1; t3 = t2 / t1; t3 = t2 % t1; (not all arithmetic operators are present, must synthesize others using the primitives available) Relational/equality/logical: t3 = t2 == t1; t3 = t2 < t1; t3 = t2 && t1; t3 = t2 || t1; (must synthesize other ops as necessary) Labels and branches: L1: Goto L1; IfZ t1 Goto L1; (take branch if value of t1 is zero) Function/method calls: PushParam t1; (before call, params are individually pushed right to left) LCall L1; t1 = LCall L1; ACall t1; t0 = ACall t1; (LCall used for a function label known at compile-time, ACall for a computed function address, most likely from vtable. Each has two forms that differ in void vs non-void return value) The built-in functions from Decaf standard library (Alloc, ReadLine, PrintInt, Halt, etc.) are invoked via LCall Function definitions: BeginFunc; EndFunc; Return t1; Return; Memory references: t1 = *(t2); t1 = *(t2 + 8); *(t1) = t2; *(t1 + -4) = t2; (optional offset must be integer constant, can be positive or negative) Array indexing: To access arr[5], add offset multiplied by elem size to base and deref Object fields, method dispatch: To access ivars, add offset to base, deref To call method, retrieve function address from vtable, invoke using ACall Data specification: VTable ClassName = L1, L2, ...;
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有