Intermediate representation
Program execution |
---|
General concepts |
|
Types of code |
|
Compilation strategies |
|
Notable runtimes |
|
Notable compilers & toolchains |
|
An Intermediate representation (IR) is the data structure or code used internally by a compiler or virtual machine to represent source code. An IR is designed to be conducive for further processing, such as optimization and translation.[1] A "good" IR must be accurate – capable of representing the source code without loss of information[2] – and independent of any particular source or target language.[1] An IR may take one of several forms: an in-memory data structure, or a special tuple- or stack-based code readable by the program.[3] In the latter case it is also called an intermediate language.
A canonical example is found in most modern compilers, where the linear human-readable text representing a program is transformed into an intermediate graph structure that allows flow analysis and re-arrangement before creating a sequence of actual CPU instructions. Use of an intermediate representation such as this allows compiler systems like the GNU Compiler Collection and LLVM to be used by many different source languages to generate code for many different target architectures.
Contents
1 Intermediate language
1.1 Languages
2 Other
3 See also
4 References
5 External links
Intermediate language
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 the source code of a program is translated into a form more suitable for code-improving transformations before being used to generate 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 processor registers available may be large, even limitless.
A popular format for intermediate languages is three-address code.
The term is also used to refer to languages used as intermediates by some high-level programming languages which do not output object or machine code themselves, but output the intermediate language only. This intermediate language is submitted to a compiler for such language, which then outputs finished object or machine code. This is usually done to ease the process of optimization or to increase 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.
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, Seed7, SystemTap, 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 C-- and the C Intermediate Language.
Any language targeting a virtual machine or p-code machine can be considered an intermediate language:
- Java bytecode
- 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.
- 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.
TIMI is a high level that targets the IBM System i platform.
O-code for BCPL
MATLAB precompiled code- Microsoft P-Code
The GNU Compiler Collection (GCC) uses several intermediate languages internally to simplify portability and cross-compilation. Among these languages are
- the historical Register Transfer Language (RTL)
- the tree language GENERIC
- the SSA-based GIMPLE.
Standard Portable Intermediate Representation SPIR/SPIR-V- LLVM Intermediate Representation
- HSA Intermediate Layer
The LLVM compiler framework is based on the LLVM IR intermediate language, of which the compact, binary serialized representation is also referred to as "bitcode" and has been productized by Apple.[4][5]
The ILOC intermediate language[6] is used in classes on compiler design as a simple target language.[7]
Other
Static analysis tools often use an intermediate representation. For instance, radare2 is a toolbox for binary files analysis and reverse-engineering. It uses the intermediate languages ESIL[8] et REIL[9] to analyze binary files.
See also
- Interlingual machine translation
- Pivot language
- Abstract syntax tree
Bytecode (Intermediate code)- Symbol table
- Source-to-source compiler
Graph rewriting and term rewriting
References
^ ab Walker, David. "CS320: Compilers: Intermediate Representation" (Lecture slides). Retrieved 2016-02-12..mw-parser-output cite.citation{font-style:inherit}.mw-parser-output .citation q{quotes:"""""""'""'"}.mw-parser-output .citation .cs1-lock-free a{background:url("//upload.wikimedia.org/wikipedia/commons/thumb/6/65/Lock-green.svg/9px-Lock-green.svg.png")no-repeat;background-position:right .1em center}.mw-parser-output .citation .cs1-lock-limited a,.mw-parser-output .citation .cs1-lock-registration a{background:url("//upload.wikimedia.org/wikipedia/commons/thumb/d/d6/Lock-gray-alt-2.svg/9px-Lock-gray-alt-2.svg.png")no-repeat;background-position:right .1em center}.mw-parser-output .citation .cs1-lock-subscription a{background:url("//upload.wikimedia.org/wikipedia/commons/thumb/a/aa/Lock-red-alt-2.svg/9px-Lock-red-alt-2.svg.png")no-repeat;background-position:right .1em center}.mw-parser-output .cs1-subscription,.mw-parser-output .cs1-registration{color:#555}.mw-parser-output .cs1-subscription span,.mw-parser-output .cs1-registration span{border-bottom:1px dotted;cursor:help}.mw-parser-output .cs1-ws-icon a{background:url("//upload.wikimedia.org/wikipedia/commons/thumb/4/4c/Wikisource-logo.svg/12px-Wikisource-logo.svg.png")no-repeat;background-position:right .1em center}.mw-parser-output code.cs1-code{color:inherit;background:inherit;border:inherit;padding:inherit}.mw-parser-output .cs1-hidden-error{display:none;font-size:100%}.mw-parser-output .cs1-visible-error{font-size:100%}.mw-parser-output .cs1-maint{display:none;color:#33aa33;margin-left:0.3em}.mw-parser-output .cs1-subscription,.mw-parser-output .cs1-registration,.mw-parser-output .cs1-format{font-size:95%}.mw-parser-output .cs1-kern-left,.mw-parser-output .cs1-kern-wl-left{padding-left:0.2em}.mw-parser-output .cs1-kern-right,.mw-parser-output .cs1-kern-wl-right{padding-right:0.2em}
^ Chow, Fred (2013-11-22). "The Challenge of Cross-language Interoperability". ACM Queue. 11 (10). Retrieved 2016-02-12.
^ Toal, Ray. "Intermediate Representations". Retrieved 2016-02-12.
^ "Bitcode (iOS, watchOS)". Hacker News. 10 June 2015. Retrieved 17 June 2015.
^ "LLVM Bitcode File Format". llvm.org. Retrieved 17 June 2015.
^
"An ILOC Simulator" Archived 2009-05-07 at the Wayback Machine
by W. A. Barrett 2007, paraphrasing Keith Cooper and Linda Torczon, "Engineering a Compiler", Morgan Kaufmann, 2004.
ISBN 1-55860-698-X.
^ "CISC 471 Compiler Design" by Uli Kremer
^ The radare2 contributors. "ESIL". radare2 project. Retrieved 17 June 2015.
^ Sebastian Porst (7 March 2010). "The REIL language – Part I". zynamics.com. Retrieved 17 June 2015.
External links
- The Stanford SUIF Group
Comments
Post a Comment