Intermediate representation

From Wikipedia, the free encyclopedia

This is an old revision of this page, as edited by EmausBot (talk | contribs) at 19:08, 4 May 2012 (r2.7.2+) (Robot: Modifying nl:Interne representatie). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

In computer science, an intermediate language is the language of an abstract machine designed to aid in the analysis of computer programs. The term comes from their use in compilers, where a compiler first translates the source code of a program into a form more suitable for code-improving transformations, as an intermediate step before generating object or machine code for a target machine. The design of an intermediate language typically differs from that of a practical machine language in three fundamental ways:

  • Each instruction represents exactly one fundamental operation; e.g. "shift-add" addressing modes common in microprocessors are not present.
  • Control flow information may not be included in the instruction set.
  • The number of registers available may be large, even limitless.

A popular format for intermediate languages is three address code.

A variation in the meaning of this term is to refer to those languages used as an intermediate language by some high-level programming languages which do not output object or machine code, but output the intermediate language only, to submit to a compiler for such language, which then outputs finished object or machine code. This is usually done to gain optimization much as treated above, or portability by using an intermediate language that has compilers for many processors and operating systems, such as C. Languages used for this fall in complexity between high-level languages and low-level languages, such as assembly languages.

Intermediate representation

An intermediate representation (IR) is a data structure that is constructed from input data to a program, and from which part or all of the output data of the program is constructed in turn. Use of the term usually implies that most of the information present in the input is retained by the intermediate representation, with further annotations or rapid lookup features.

A canonical example is found in most modern compilers, where the linear human-readable text representing a program is transformed into an intermediate graph data structure that allows flow analysis and re-arrangements before starting to create the list of actual CPU instructions that will do the work. Use of an intermediate representation allows compiler systems like LLVM to be targeted by many different source languages, and support generation for many different target architectures.

Languages

Though not explicitly designed as an intermediate language, C's nature as an abstraction of assembly and its ubiquity as the de-facto system language in Unix-like and other operating systems has made it a popular intermediate language: Eiffel, Sather, Esterel, some dialects of Lisp (Lush, Gambit), Haskell (Glasgow Haskell Compiler), Squeak's Smalltalk-subset Slang, Cython, Vala, and others make use of C as an intermediate language. Variants of C have been designed to provide C's features as a portable assembly language, including one of the two languages called C-- and the C Intermediate Language.

Sun Microsystem's Java bytecode is the intermediate language used by all compilers targeting the Java Virtual Machine. The JVM can then do just-in-time compilation to get executable machine code to improve performances. Similarly, Microsoft's Common Intermediate Language is an intermediate language designed to be shared by all compilers for the .NET Framework, before static or dynamic compilation to machine code.

The GNU Compiler Collection (GCC) uses internally several intermediate languages to simplify portability and cross-compilation. Among these languages are

While most intermediate languages are designed to support statically typed languages, the Parrot intermediate representation is designed to support dynamically typed languages—initially Perl and Python.

The ILOC intermediate language[1] is used in classes on compiler design as a simple target language.[2]

References

  1. ^ "An ILOC Simulator" by W. A. Barrett 2007, paraphrasing Keith Cooper and Linda Torczon, "Engineering a Compiler", Morgan Kaufmann, 2004. ISBN 1-55860-698-X.
  2. ^ "CISC 471 Compiler Design" by Uli Kremer

See also

External links