Java Reference
In-Depth Information
C++ program
cpp preprocessor
cfront
C compiler
target code
Figure 10.1: Use of cfront to translate C++ to C.
10.1.1 Examples
The early C
compilers did not produce machine code directly [Str94, Str07].
As shown in Figure 10.1, the C
++
language was initially translated from
source to standard C, with the resulting C program compiled to machine code.
In fact, since C
++
programs could use the standard C preprocessor, source
programs were first translated by C's preprocessor (cpp) and then translated
into standard C by cfront.Thus,inthetrekfromC
++
++
to machine code, there
are two articulated intermediate points and ILss:
From the perspective of the C and C
programming languages, which
include preprocessor directives, the output of cpp is an intermediate
language. Although no name is formally given to this language, it is the
subset of C or C
++
obtained after processing all preprocessor directives.
This simplifies construction of the rest of the compiler, which need not
worry about any preprocessor directives.
++
From the perspective of cfront, standardC is an ILs, interposed between
C
++
and machine code.
The cfront approach served nicely to prototype C
, but it was soon sup-
planted by a more integrated approach that processed C
++
directly. Such
compilers could better diagnose and report compile-time errors.
++
As another example, consider the steps by which LaTeX [Lam95]—the
language in which this topic was authored—is translated into print, as shown
in Figure 10.2. The LaTeX document-preparation system does not produce
printable pages directly. Instead, LaTeX is translated into a more basic ILs
called TeX, which is in turn translated into a device-independent intermediate
 
 
Search WWH ::




Custom Search