سؤال

While doing some reading, I came across the terms "Intermediate Language" and "3AC".

IL, as I understand, is the middle "step" in the source code compilation process. More specifically, I'm reading about bytecode (Java) and C.

The way I interpret it (correct me if am wrong) is;

Source Code 1 (ex. Lisp) -> Intermediate Language (C) -> Assembly Language -> Machine Code

Source Code 2 (ex. Java) -> Bytecode -> Java Virtual Machine

So based on that, am struggling to see where does The Three Address Code (TAC/3AC) comes into play, and what for its used.

هل كانت مفيدة؟

المحلول

Three-address code (TAC) is the intermediate representation used in most compilers. It is essentially a generic assembly language that falls in the lower-end of the mid-level IRs. Some variant of 2, 3 or 4 address code is fairly commonly used as an IR, since it maps well to most assembly languages.

A TAC instruction can have at most three operands. The operands could be two operands to a binary arithmetic operator and the third the result location, or an operand to compare to zero and a second location to branch to, and so on. For example, below on the top is an arithmetic expression and on the bottom, is a translation into TAC instructions:

//Expresion
        a = b * c + b * d;
//3AC
        _t1 = b * c;
        _t2 = b * d;
        _t3 = _t1 + _t2;
        a = _t3;

Source: http://web.archive.org/web/20151010192637/http://www.dound.com/courses/cs143/handouts/17-TAC-Examples.pdf

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top