Microchip Technology XC8 Standard Compiler (Workstation) SW006021-1 SW006021-1 Manuel D’Utilisation

Codes de produits
SW006021-1
Page de 518
XC8 Command-line Driver
 2012 Microchip Technology Inc.
DS52053B-page 77
FIGURE 4-2:
MULTI-FILE COMPILATION
4.3.2
Single-Step Compilation
Figure 4-1 showed us the files that are generated by each application and the order in 
which these applications are executed. However this does not indicate how these 
applications are executed when there is more than one source file being compiled.
Consider the case when there are two C source files that form a complete project and 
that are to be compiled, as is the case shown in Figure 4-2. If these files are called 
main.c
 and io.c, these could be compiled with a single command, such as:
xc8 --chip=
16F877A
 main.c io.c
This command will compile the two source files all the way to the final output, but 
internally we can consider this compilation as consisting of two stages.
The first stage involves processing of each source file separately, and generating some 
sort of intermediate file for each source file. The second stage involves combining all 
these intermediate files and further processing to form the final output. An intermediate 
file is a particular temporary file that is produced and marks the mid point between the 
first and second stage of compilation.
The intermediate file used by xc8 is the p-code (.p1 extension) file output by the 
parser, so there will be one p-code file produced for each C source file. As indicated in 
the diagram, CPP and then P1 are executed to form this intermediate file. (For clarity 
the CPP and P1 applications have been represented by the same block in the diagram.)
In the second stage, the code generator reads in all the intermediate p-code files and 
produces a single assembly file output, which is then passed to the subsequent 
applications that produce the final output.
The desirable attribute of this method of compilation is that the code generator, which 
is the main application that transforms from the C to the assembly domain, sees the 
entire project source code via the intermediate files.
Traditional compilers have always used intermediate files that are object files output by 
the assembler. These intermediate object files are then combined by the linker and fur-
ther processed to form the final output. This method of compilation is shown in 
Figure 4-3 and shows that the code generator is executed once for each source file. 
Thus the code generator can only analyze that part of the project that is contained in 
the source file currently being compiled. The MPLAB XC16 and XC32 compilers work 
in this fashion.
Using object files as the intermediate file format with MPLAB XC8 C Compiler will 
defeat many features the compiler uses to optimize code. Always use p-code files as 
the intermediate file format if you are using a make system to build projects.
C file
C file
library 
files
preprocess 
&
parse
p-
code
code 
generation
preprocess 
&
parse
p-
code
link
assemble
First stage of compilation
Second stage of compilation
Intermediate files