Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Intermediate representation
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
{{Short description|Data structure or code used internally by a compiler or virtual machine to represent source code}} {{redirect|Intermediate form|the use of the term in biology|Transitional fossil}} {{Use dmy dates|date=March 2020}} {{Program execution}} 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 to further processing, such as [[Compiler optimization|optimization]] and [[Program transformation|translation]].<ref name=Walker>{{Cite web| last = Walker| first = David| title = CS320: Compilers: Intermediate Representation | format = Lecture slides | access-date = 2016-02-12 | url = http://www.cs.princeton.edu/courses/archive/spr03/cs320/notes/IR-trans1.pdf}}</ref> A "good" IR must be ''accurate'' – capable of representing the source code without loss of information<ref name=Chow>{{Cite journal| volume = 11| issue = 10| last = Chow| first = Fred| title = The Challenge of Cross-language Interoperability| journal = ACM Queue| access-date = 2016-02-12| date = 2013-11-22| url = https://queue.acm.org/detail.cfm?id=2544374}}</ref> – and ''independent'' of any particular source or target language.<ref name=Walker /> An IR may take one of several forms: an in-memory [[data structure]], or a special [[tuple]]- or [[Stack (abstract data type)|stack]]-based [[bytecode|code]] readable by the program.<ref name=Toal>{{Cite web| last = Toal| first = Ray| title = Intermediate Representations| access-date = 2016-02-12| url = http://cs.lmu.edu/~ray/notes/ir/}}</ref> In the latter case it is also called an ''intermediate language''. A canonical example is found in most modern compilers. For example, the [[CPython|CPython interpreter]] transforms the linear human-readable text representing a program into an intermediate [[graph (data structure)|graph structure]] that allows [[flow analysis]] and re-arrangement before execution. 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 [[Code generation (compiler)|generate code]] for many different target [[Instruction set|architectures]]. == Intermediate language == {{Section citations needed|date=February 2025}} An '''intermediate language''' is the language of an [[abstract machine]] designed to aid in the analysis of [[computer program]]s. The term comes from their use in [[compiler]]s, where the source code of a program is translated into a form more suitable for code-improving transformations before being used to generate [[object file|object]] or [[Machine language|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 mode]]s common in [[microprocessors]] are not present. * [[Control flow]] information may not be included in the instruction set. * The number of [[processor register]]s 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 language]]s 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 (computer science)|optimization]] or to increase [[Porting|portability]] by using an intermediate language that has compilers for many [[Central processing unit|processors]] and [[operating systems]], such as [[C (programming language)|C]]. Languages used for this fall in complexity between high-level languages and [[Low-level programming language|low-level]] languages, such as [[assembly language]]s. === Languages === Though not explicitly designed as an intermediate language, [[C (programming language)|C]]'s nature as an abstraction of [[Assembly language|assembly]] and its ubiquity as the ''de facto'' [[System programming language|system language]] in [[Unix-like]] and other operating systems has made it a popular intermediate language: [[Eiffel (programming language)|Eiffel]], [[Sather]], [[Esterel]], some [[Programming language dialect|dialect]]s of [[Lisp (programming language)|Lisp]] ([[Lush (programming language)|Lush]], [[Gambit (Scheme implementation)|Gambit]]), [[Squeak]]'s Smalltalk-subset Slang, [[Nim (programming language)|Nim]], [[Cython]], [[Seed7]], [[SystemTap]], [[Vala (programming language)|Vala]], V, 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. * [[IBM i#TIMI|TIMI]] is used by compilers on the [[IBM i]] platform. * [[O-code]] for [[BCPL]] * [[MATLAB]] precompiled code * [[Microsoft P-Code]] * [[Pascal (programming language)|Pascal]] [[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 [[GNU Compiler Collection#GENERIC and GIMPLE|GENERIC]] * the [[SSA (computing)|SSA]]-based [[GIMPLE]]. (Lower-level than GENERIC; input for most optimizers; has a compact "bytecode" notation.) GCC supports generating these IRs, as a final target: * [[HSA Intermediate Layer]] * [[LLVM#Intermediate representation|LLVM Intermediate Representation]] (converted from GIMPLE in the now-defunct llvm-gcc which uses LLVM optimizers and codegen) The [[LLVM]] compiler framework is based on the [[LLVM#Intermediate representation|LLVM IR]] intermediate language, of which the compact, binary serialized representation is also referred to as "bitcode" and has been productized by Apple.<ref name="Apple's bitcode">{{cite web | url=https://news.ycombinator.com/item?id=9684223 | title=Bitcode (iOS, watchOS) | publisher=Hacker News | date=10 June 2015 | access-date=17 June 2015}}</ref><ref name="LLVM Bitcode">{{cite web | url=http://llvm.org/docs/BitCodeFormat.html | title=LLVM Bitcode File Format | publisher=llvm.org | access-date=17 June 2015}}</ref> Like GIMPLE Bytecode, LLVM Bitcode is useful in link-time optimization. Like GCC, LLVM also targets some IRs meant for direct distribution, including Google's [[Native Client|PNaCl]] IR and [[Standard Portable Intermediate Representation|SPIR]]. A further development within LLVM is the use of ''Multi-Level Intermediate Representation'' ([[MLIR (software)|MLIR]]) with the potential to generate code for different heterogeneous targets, and to combine the outputs of different compilers.<ref>{{cite web |url=https://mlir.llvm.org/ |title = MLIR}}</ref> The ILOC intermediate language<ref> [http://www.engr.sjsu.edu/wbarrett/Parser/simManual.htm "An ILOC Simulator"] {{webarchive|url=https://web.archive.org/web/20090507084132/http://www.engr.sjsu.edu/wbarrett/Parser/simManual.htm |date=2009-05-07 }} by W. A. Barrett 2007, paraphrasing Keith Cooper and Linda Torczon, "Engineering a Compiler", [[Morgan Kaufmann]], 2004. {{ISBN|1-55860-698-X}}.</ref> is used in classes on compiler design as a simple target language.<ref>[http://www.cis.udel.edu/~pollock/471/project2spec.pdf "CISC 471 Compiler Design"] by Uli Kremer</ref> == Other == [[Static program analysis|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<ref name="ESIL">{{cite web | url=https://radare.gitbooks.io/radare2book/content/esil.html | title=ESIL | publisher=Radare2 Project | access-date=17 June 2015 | author=((Radare2 Contributors)) | archive-url=https://web.archive.org/web/20150818235122/http://radare.gitbooks.io/radare2book/content/esil.html | archive-date=18 August 2015 | url-status=dead }}</ref> and REIL<ref name="REIL">{{cite web | url=http://blog.zynamics.com/2010/03/07/the-reil-language-part-i/ | title=The REIL language – Part I | publisher=zynamics.com | date=7 March 2010 | access-date=17 June 2015 | author=Sebastian Porst}}</ref> to analyze binary files. == See also == * [[BURS]] * [[Interlingual machine translation]] * [[Pivot language]] * [[Abstract syntax tree]] * [[Bytecode]] (Intermediate code) * [[Symbol table]] * [[Source-to-source compiler]] * [[Graph rewriting]] and [[term rewriting]] * [[UNCOL]] ==References== {{reflist}} ==External links== * The Stanford SUIF Group {{Authority control}} {{DEFAULTSORT:Intermediate language}} [[Category:Compiler construction]] [[Category:Programming language classification]]
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)
Pages transcluded onto the current version of this page
(
help
)
:
Template:Authority control
(
edit
)
Template:Cite journal
(
edit
)
Template:Cite web
(
edit
)
Template:ISBN
(
edit
)
Template:Program execution
(
edit
)
Template:Redirect
(
edit
)
Template:Reflist
(
edit
)
Template:Section citations needed
(
edit
)
Template:Short description
(
edit
)
Template:Use dmy dates
(
edit
)
Template:Webarchive
(
edit
)