<s>
In	O
computing	O
,	O
code	B-Application
generation	I-Application
is	O
part	O
of	O
the	O
process	O
chain	O
of	O
a	O
compiler	B-Language
and	O
converts	O
intermediate	B-Application
representation	I-Application
of	O
source	O
code	O
into	O
a	O
form	O
(	O
e.g.	O
,	O
machine	B-Language
code	I-Language
)	O
that	O
can	O
be	O
readily	O
executed	O
by	O
the	O
target	O
system	O
.	O
</s>
<s>
Sophisticated	O
compilers	B-Language
typically	O
perform	O
multiple	B-Application
passes	I-Application
over	O
various	O
intermediate	B-Application
forms	I-Application
.	O
</s>
<s>
This	O
organization	O
also	O
facilitates	O
the	O
creation	O
of	O
a	O
single	O
compiler	B-Language
that	O
can	O
target	O
multiple	O
architectures	O
,	O
as	O
only	O
the	O
last	O
of	O
the	O
code	B-Application
generation	I-Application
stages	O
(	O
the	O
backend	O
)	O
needs	O
to	O
change	O
from	O
target	O
to	O
target	O
.	O
</s>
<s>
(	O
For	O
more	O
information	O
on	O
compiler	B-Language
design	O
,	O
see	O
Compiler	B-Language
.	O
)	O
</s>
<s>
The	O
input	O
to	O
the	O
code	O
generator	O
typically	O
consists	O
of	O
a	O
parse	O
tree	O
or	O
an	O
abstract	B-Data_Structure
syntax	I-Data_Structure
tree	I-Data_Structure
.	O
</s>
<s>
The	O
tree	O
is	O
converted	O
into	O
a	O
linear	O
sequence	O
of	O
instructions	O
,	O
usually	O
in	O
an	O
intermediate	O
language	O
such	O
as	O
three-address	B-Application
code	I-Application
.	O
</s>
<s>
Further	O
stages	O
of	O
compilation	B-Language
may	O
or	O
may	O
not	O
be	O
referred	O
to	O
as	O
"	O
code	B-Application
generation	I-Application
"	O
,	O
depending	O
on	O
whether	O
they	O
involve	O
a	O
significant	O
change	O
in	O
the	O
representation	O
of	O
the	O
program	O
.	O
</s>
<s>
(	O
For	O
example	O
,	O
a	O
peephole	O
optimization	O
pass	O
would	O
not	O
likely	O
be	O
called	O
"	O
code	B-Application
generation	I-Application
"	O
,	O
although	O
a	O
code	O
generator	O
might	O
incorporate	O
a	O
peephole	O
optimization	O
pass	O
.	O
)	O
</s>
<s>
In	O
addition	O
to	O
the	O
basic	O
conversion	O
from	O
an	O
intermediate	B-Application
representation	I-Application
into	O
a	O
linear	O
sequence	O
of	O
machine	B-Language
instructions	I-Language
,	O
a	O
typical	O
code	O
generator	O
tries	O
to	O
optimize	O
the	O
generated	O
code	O
in	O
some	O
way	O
.	O
</s>
<s>
Tasks	O
which	O
are	O
typically	O
part	O
of	O
a	O
sophisticated	O
compiler	B-Language
's	O
"	O
code	B-Application
generation	I-Application
"	O
phase	O
include	O
:	O
</s>
<s>
Debug	B-General_Concept
data	I-General_Concept
generation	O
if	O
required	O
so	O
the	O
code	O
can	O
be	O
debugged	O
.	O
</s>
<s>
Instruction	O
selection	O
is	O
typically	O
carried	O
out	O
by	O
doing	O
a	O
recursive	O
postorder	B-Algorithm
traversal	I-Algorithm
on	O
the	O
abstract	B-Data_Structure
syntax	I-Data_Structure
tree	I-Data_Structure
,	O
matching	O
particular	O
tree	O
configurations	O
against	O
templates	O
;	O
for	O
example	O
,	O
the	O
tree	O
W	O
:=	O
ADD( X	O
,	O
MUL(Y,Z )	O
)	O
might	O
be	O
transformed	O
into	O
a	O
linear	O
sequence	O
of	O
instructions	O
by	O
recursively	O
generating	O
the	O
sequences	O
for	O
t1	O
:=	O
X	O
and	O
t2	O
:=	O
MUL(Y,Z )	O
,	O
and	O
then	O
emitting	O
the	O
instruction	O
ADD	O
W	O
,	O
t1	O
,	O
t2	O
.	O
</s>
<s>
In	O
a	O
compiler	B-Language
that	O
uses	O
an	O
intermediate	O
language	O
,	O
there	O
may	O
be	O
two	O
instruction	O
selection	O
stagesone	O
to	O
convert	O
the	O
parse	O
tree	O
into	O
intermediate	O
code	O
,	O
and	O
a	O
second	O
phase	O
much	O
later	O
to	O
convert	O
the	O
intermediate	O
code	O
into	O
instructions	O
from	O
the	O
instruction	B-General_Concept
set	I-General_Concept
of	O
the	O
target	O
machine	O
.	O
</s>
<s>
This	O
second	O
phase	O
does	O
not	O
require	O
a	O
tree	B-Algorithm
traversal	I-Algorithm
;	O
it	O
can	O
be	O
done	O
linearly	O
,	O
and	O
typically	O
involves	O
a	O
simple	O
replacement	O
of	O
intermediate-language	O
operations	O
with	O
their	O
corresponding	O
opcodes	B-Language
.	O
</s>
<s>
However	O
,	O
if	O
the	O
compiler	B-Language
is	O
actually	O
a	O
language	B-Language
translator	I-Language
(	O
for	O
example	O
,	O
one	O
that	O
converts	O
Java	B-Language
to	O
C++	B-Language
)	O
,	O
then	O
the	O
second	O
code-generation	O
phase	O
may	O
involve	O
building	O
a	O
tree	O
from	O
the	O
linear	O
intermediate	O
code	O
.	O
</s>
<s>
When	O
code	B-Application
generation	I-Application
occurs	O
at	B-Library
runtime	I-Library
,	O
as	O
in	O
just-in-time	O
compilation	B-Language
(	O
JIT	O
)	O
,	O
it	O
is	O
important	O
that	O
the	O
entire	O
process	O
be	O
efficient	B-General_Concept
with	O
respect	O
to	O
space	O
and	O
time	O
.	O
</s>
<s>
For	O
example	O
,	O
when	O
regular	B-Language
expressions	I-Language
are	O
interpreted	O
and	O
used	O
to	O
generate	O
code	O
at	B-Library
runtime	I-Library
,	O
a	O
non-deterministic	O
finite	B-Architecture
state	I-Architecture
machine	I-Architecture
is	O
often	O
generated	O
instead	O
of	O
a	O
deterministic	O
one	O
,	O
because	O
usually	O
the	O
former	O
can	O
be	O
created	O
more	O
quickly	O
and	O
occupies	O
less	O
memory	O
space	O
than	O
the	O
latter	O
.	O
</s>
<s>
Despite	O
its	O
generally	O
generating	O
less	O
efficient	B-General_Concept
code	O
,	O
JIT	O
code	B-Application
generation	I-Application
can	O
take	O
advantage	O
of	O
profiling	O
information	O
that	O
is	O
available	O
only	O
at	B-Library
runtime	I-Library
.	O
</s>
<s>
Consequently	O
,	O
some	O
techniques	O
that	O
were	O
originally	O
developed	O
for	O
use	O
in	O
compilers	B-Language
have	O
come	O
to	O
be	O
employed	O
in	O
other	O
ways	O
as	O
well	O
.	O
</s>
<s>
For	O
example	O
,	O
YACC	B-Application
(	O
Yet	O
Another	O
Compiler-Compiler	B-Language
)	O
takes	O
input	O
in	O
Backus	O
–	O
Naur	O
form	O
and	O
converts	O
it	O
to	O
a	O
parser	O
in	O
C	B-Language
.	O
Though	O
it	O
was	O
originally	O
created	O
for	O
automatic	O
generation	O
of	O
a	O
parser	O
for	O
a	O
compiler	B-Language
,	O
yacc	B-Application
is	O
also	O
often	O
used	O
to	O
automate	O
writing	O
code	O
that	O
needs	O
to	O
be	O
modified	O
each	O
time	O
specifications	O
are	O
changed	O
.	O
</s>
<s>
Many	O
integrated	B-Application
development	I-Application
environments	I-Application
(	O
IDEs	O
)	O
support	O
some	O
form	O
of	O
automatic	O
source-code	O
generation	O
,	O
often	O
using	O
algorithms	O
in	O
common	O
with	O
compiler	B-Language
code	O
generators	O
,	O
although	O
commonly	O
less	O
complicated	O
.	O
</s>
<s>
(	O
See	O
also	O
:	O
Program	B-Application
transformation	I-Application
,	O
Data	B-General_Concept
transformation	I-General_Concept
.	O
)	O
</s>
<s>
One	O
consequence	O
of	O
this	O
information	O
loss	O
is	O
that	O
reflection	B-Language
becomes	O
difficult	O
or	O
even	O
impossible	O
.	O
</s>
