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.

5
  • I'd advise you to read the articles on compilers.
    – user232573
    Mar 21, 2017 at 12:28
  • 7
    Articles on compilers assume you know this already. It's a reasonable question. Mar 21, 2017 at 12:47
  • I was thinking more about wikipedia-style articles. And I agree the question's reasonable. It was just a suggestion, not a criticism.
    – user232573
    Mar 21, 2017 at 12:56
  • 4
    The question is reasonable, but badly written. The term "target" can have differents meanings, so I would recommend to give a reference or more context where you heard it or read about it.
    – Doc Brown
    Mar 21, 2017 at 13:00
  • 1
    @DocBrown I've heard it in many contexts, but most-recently in the context of web assembly being a compile target for other languages. Mar 22, 2017 at 6:44

2 Answers 2

27

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.

12
  • 3
    As a side note, might be worth mentioning that this term is also used in a more generalized form in the context of build systems - a target is an output from any build step, which doesn't necessarily have to be a compilation action (e.g. creating an installer).
    – BartoszKP
    Mar 21, 2017 at 13:18
  • 2
    compilers are translators, not filters.
    – user223083
    Mar 21, 2017 at 19:31
  • 1
    @Birfl. obviously. "tr" means translate, not filter. filters are not translators, this is just obvious.
    – user223083
    Mar 21, 2017 at 20:32
  • 2
    @Birfl: i do not go by wikipedia. just producing one stream from another ssys nothing . the distinction between filters and translators is very well known. a filter includes/excludes, based on a predicate. it does not transform. filter a list of integers by even? and you get untransformed even integers. translate the same list using inc and you get a transformed version of the original list.
    – user223083
    Mar 21, 2017 at 21:09
  • 1
    your account of compilation is fine except for the term "filter".
    – user223083
    Mar 21, 2017 at 21:13
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).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.