21

I keep hearing the term and all google searches lead me to articles on compilers. I just wanna understand what the term compile target means :|

UPDATE: To give some context: I've heard it said that web assembly is a compile target for for other languages such as C, C++, Rust etc.

4 Answers4

32

Compilers are, in essence, translators that take input in one language and produce output in another. For example, Eiffel Software's compiler takes Eiffel-language input and produces C. GCC for Intel reads C-language input and produces x86 assembly. The GAS assembler for Intel takes x86 assembly and produces x86 object code. All three of these things are technically compilers.

Regardless of format, the input read by a compiler is called the source and the output is called the target. The latter term is taken from one of its definitions, "intended result."

The majority of compilers are designed to produce assembly or object code for a particular processor or architecture. Because of that, target is often used to refer to the architecture itself rather than the output format.

The target of a compiler does not need to be the same as the architecture where it runs, and in instances where that happens, the program is called a cross-compiler. (For example, GCC can be built to run on x86 systems to compile C into ARM assembly.)

Additionally, there are single compilers capable of producing output for different targets depending on input such as switches on the command line. These are called multi-target compilers.

Blrfl
  • 20,525
4

In translation, whether language is a natural language like English, or an artificial one like C, we use the terminology source and target to talk about the input and output of a translation system. In natural language translation, the system is the competent human brain capable of translating between two languages. In programming languages, it is a compiler.

Thus, the source for a compiler is the programming language (C), while the target is the bytecode (machine-level instructions). We often use target in compilation because different systems (CPU architectures) have different instruction sets, e.g. ARM, MIPS, etc. The compiler needs to know which instruction set is the target, so that it can create the correct output (bytecode).

0

A compiler translates, often from some high level language to some assembler language. The language it translates to is the compiler target.

Many compilers can only translate to one specific target, say one assembler language. Others can translate to many assembler languages. For example a macos compiler may support translating to 32 or 64 bit x86, 32 of 64 bit ARM, with or without 64, 128, 256 or 512 bit vector instructions, with variations like cryptographic instructions and so on. So the same compiler can easily have 12 or more compiler targets. Plus it might have Java code or web assembly as additional targets.

gnasher729
  • 49,096
-2

I'm not really sure what a compiler target is in the context of a web assembly, but in your example I would assume it means you have a compiler that translates your C, C++, or Rust code to web assembly.

More generally, compilers are translators that accept an input in the form of one programming language and translate it to produce an output in another form. GCC, either general UNIX or Intel specific, will produce assembly or object code for your specific computer system or architecture. So, as the translator, a compiler accepts an input as the source and produces an output as the target. Usually, compilers produce code for a particular processor or architecture. In an embedded context, compilers produce code for a target processor or architecture. Usually, embedded systems will refer to the target such that the compiler targets a specific CPU architecture.

From the perspective of embedded systems, cross-compiling is also not uncommon. Cross-compiling is a process where a program is compiled on a host system, whose architecture differs from that of the target system. E.g. You can run GCC on Linux with an x86 processor to compile C into ARM C/assembly.

Multi-target compilers also offer compiler switches to support multiple target architectures.

So, a compiler target is simply the output of the compile operation.

Earl
  • 1