type of output code from compiler
when a compiler compile a high-level language into the target language that are executable , what form is the target language in ?
Is it a lower-l开发者_C百科evel language like machine code ? Or the compiler just translate it to the OS's functions from the OS's API and the OS do all the work under the hood?
Compilers can have a number of different outputs:
- Machine code that runs directly on the computer
- Intermediate code that is translated to machine code on the fly, and
- Source code for an assembler
The advantage of option 2 is that it allows the output to be portable to different computers, as long as you have available an appropriate intermediate-code to native machine code translator available for the target machine. This is how Java is able to "write once, run anywhere."
A compiler is any program that transforms a program from one representation into another representation. That target representation can be anything, provided that it is at least as computationally powerful as the source representation. In particular, this means that if the source representation is Turing-complete, the target representation must also be Turing-complete.
A compiler can compile from a high-level language to another high-level language (e.g. GWT, which compiles Java to ECMAScript), from a high-level language to a low-level language (e.g. Gambit, which compiles Scheme to C), from a high-level language to machine code (e.g. GCJ, which compiles Java to native code), from a low-level language to a high-level language (e.g. Clue, which compiles C to Java, Lua, Perl, ECMAScript and Common Lisp), from a low-level language to another low-level language (e.g. the Android SDK, which compiles JVML bytecode to Dalvik bytecode), from a low-level language to machine code (e.g. the C1X compiler which is part of HotSpot, which compiles JVML bytecode to machine code), machine code to a high-level language (any so-called "decompiler"), machine code to low-level language (e.g. the JIT compiler in JPC, which compiles x86 native code to JVML bytecode) and native code to native code (e.g. the JIT compiler in PearPC, which compiles PowerPC native code to x86 native code).
精彩评论