P Code Compiler
P Code Compiler
P-Code compilers (Pseudo code compilers) are very similar in concept to interpreters. In,
both cases, the source program is analyzed and converted into an intermediate form, which is then
executed interpretively. With a P-Code compiler, however, this intermediate form is the machine
language for a hypothetical computer, often called as pseudo-machine or P-Machine. The process
of using such a P-Code compiler is illustrated in the figure. The source program is compiled, with
the resulting object program being in P-Code. This P-Code program is then read and executed
under the control of a P-Code interpreter.
The main advantage of this approach is portability of software. It is not necessary for the
compiler to generate different code for different computers, because the P-Code object programs
can be executed on any machine that has a P-Code interpreter.
SOURCE
PROGRAM
COMPILE P-CODE
COMPILER
OBJECT PROGRAM
(P - CODE)
P-CODE
EXECUTE INTERPRETE
R
The design of a P-Machine and the associated P-Code is often related to the requirements
of the language being compiled. This is particularly useful on machines with severely limited
memory size. Obviously the interpretive execution of a P-Code program may be much slower than
the execution of the equivalent machine code. If execution speed is important, some P-Code
compilers support the use of machine language subroutines. By rewriting a small number of
commonly used routines in machine language, rather than P-Code, it is often possible to achieve
substantial improvements in performance. Of course, this approach sacrifices some of the
portability associated with the use of P-Code compilers.