Compiler - Target Platform and Language Classification
Understand the differences between native, cross, and VM target compilers, and how high‑level target languages like C are used and formatted.
Summary
Read Summary
Flashcards
Save Flashcards
Quiz
Take Quiz
Quick Practice
What is the primary difference between a native (hosted) compiler and a cross compiler?
1 of 5
Summary
Compiler Classification
Compilers are often classified in two important ways: by the target platform (where the output code runs) and by the target language (what form the output code takes). Understanding these classifications helps clarify when and why different compiler types are used in software development.
Classification by Target Platform
Native and Hosted Compilers
A native compiler (also called a hosted compiler) is the most straightforward type: it generates executable code that runs on the same computer architecture and operating system where the compiler itself is running.
For example, if you compile a C program on your Windows laptop using a compiler installed on that same Windows laptop, the resulting executable runs on Windows—this is a native compiler. The term "hosted" emphasizes that the compiler runs "hosted" on the target system.
Native compilers are the most common type you'll encounter because they allow you to develop and test software directly on the machine where it will run.
Cross Compilers
A cross compiler produces executable code designed to run on a different platform than the one where the compiler executes.
Cross compilers are essential for embedded systems development. Embedded systems (like microcontrollers in appliances, automotive systems, or IoT devices) often lack the computing power or resources to run a full development environment. Instead, developers use a powerful desktop computer running a cross compiler to generate machine code for the embedded device.
For example, you might run a cross compiler on your Linux desktop computer to generate executable code for an ARM-based microcontroller. The compiler runs on the Linux desktop (the "host" platform) but produces code for the ARM device (the "target" platform).
Virtual-Machine Target Compilers
Some compilers generate code that runs on a virtual machine (a software-based emulation of a computer) rather than directly on physical hardware. These compilers occupy a special category because the distinction between native and cross doesn't apply cleanly to them.
When code is compiled to run on a virtual machine, it may execute on the same platform where the compiler runs, or it may execute on a completely different platform—what matters is that the virtual machine acts as an intermediary. Since the execution environment is virtualized rather than physical, these compilers are typically not classified as either native or cross compilers.
A common example is Java, where compilers generate bytecode that runs on the Java Virtual Machine (JVM). The bytecode can run on any computer with a JVM installed, regardless of the platform where the Java compiler was running.
Classification by Target Language
High-Level Target Languages
Not all compilers produce machine code or bytecode. Some compilers are source-to-source compilers (also called transpilers)—they translate source code from one high-level programming language into another high-level programming language, rather than directly into machine code.
The C programming language is particularly important in this context. Because C is widely supported across different platforms and can be optimized effectively by standard C compilers, many compiler designers use C as a portable assembly language—a convenient intermediate target that can then be compiled to machine code for any platform with a C compiler available.
This creates a flexible compilation pipeline: source code in language A → C code → machine code for platform X. This approach provides both portability and the ability to leverage existing C compiler optimizations.
Characteristics of Generated C Code
When compilers generate C code as an intermediate form, that generated code is not intended for human readability. The compiler optimizes for correctness and efficiency, not for human understanding. As a result, generated C code typically lacks proper formatting, indentation, and meaningful variable names.
This is fundamentally different from hand-written code, where programmers follow style guidelines for readability. Generated code might have all statements on a single line, use cryptic variable names, or have unusual structure—all of which is perfectly fine since the generated code will be processed by another compiler, not read by humans.
<extrainfo>
The image shown illustrates how multiple source languages can feed into a unified compiler architecture. Notice how Language 1 and Language 2 each have their own front-end (lexical analyzer, parser, and intermediate-code generator), but then both produce the same intermediate code format. This intermediate code flows into a shared optimizer, which then feeds into multiple target-specific code generators.
This architecture demonstrates the practical benefit of using intermediate representations: the expensive optimization phase doesn't need to be duplicated for each source language or target platform. Instead, it operates on a language-independent and platform-independent intermediate form.
</extrainfo>
Flashcards
What is the primary difference between a native (hosted) compiler and a cross compiler?
A native compiler runs on and generates code for the same platform, while a cross compiler generates code for a different platform.
On which platform does the output of a native (hosted) compiler run?
The same computer architecture and operating system as the compiler itself.
On which platform does the output of a cross compiler run?
A different platform from the one on which the compiler is executed.
What is the term for a compiler that translates source code into another high-level language instead of machine code?
Source-to-source compiler.
Which high-level language is frequently used as a portable assembly language for other compilers?
The C programming language.
Quiz
Compiler - Target Platform and Language Classification Quiz Question 1: Which type of compiler generates output that runs on the same computer architecture and operating system as the compiler itself?
- Native or hosted compiler (correct)
- Cross compiler
- Virtual‑machine target compiler
- Source‑to‑source compiler
Compiler - Target Platform and Language Classification Quiz Question 2: What is the name of a compiler that translates source code into another high‑level language rather than directly into machine code?
- Source‑to‑source compiler (correct)
- Native compiler
- Cross compiler
- Virtual‑machine target compiler
Compiler - Target Platform and Language Classification Quiz Question 3: What type of output does a cross compiler generate?
- Output designed to run on a different platform than the compiler’s host (correct)
- Output designed to run on the same platform as the compiler’s host
- Source code that must be interpreted at runtime
- Machine code that bypasses any operating system
Which type of compiler generates output that runs on the same computer architecture and operating system as the compiler itself?
1 of 3
Key Concepts
Compiler Types
Native compiler
Cross compiler
Virtual‑machine target compiler
Source‑to‑source compiler
Compiler classification
Output and Development
High‑level target language
Generated C code
Portable assembly language
Embedded system development
Definitions
Native compiler
A compiler that produces executable code for the same architecture and operating system on which it runs.
Cross compiler
A compiler that generates code intended to run on a different platform than the one it executes on.
Virtual‑machine target compiler
A compiler that emits code for a virtual machine, allowing execution on the same or different physical platforms.
Source‑to‑source compiler
A compiler that translates source code from one high‑level language into another high‑level language rather than into machine code.
High‑level target language
A programming language used as the output of a compiler instead of low‑level machine code.
Generated C code
C source produced by a compiler, typically optimized for machine translation rather than human readability.
Embedded system development
The practice of creating software for specialized hardware that often lacks a full development environment.
Portable assembly language
The use of a high‑level language like C as an intermediate, architecture‑neutral representation of low‑level operations.
Compiler classification
The categorization of compilers based on characteristics such as target platform and target language.