20

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.

  • I'd advise you to read the articles on compilers. –  Mar 21 '17 at 12:28
  • 8
    Articles on compilers assume you know this already. It's a reasonable question. – Karl Bielefeldt Mar 21 '17 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. –  Mar 21 '17 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 '17 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. – BadgerBadgerBadgerBadger Mar 22 '17 at 06:44

2 Answers2

28

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.

formatkaka
  • 123
  • 6
Blrfl
  • 20,235
  • 2
  • 49
  • 75
  • 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 '17 at 13:18
  • @BartoszKP I actually thought about including that, but the question was about compilers. – Blrfl Mar 21 '17 at 13:22
  • True, just a pure side note, not necessarily to be included in my opinion also. – BartoszKP Mar 21 '17 at 13:26
  • 2
    compilers are translators, not filters. –  Mar 21 '17 at 19:31
  • @mobileink By that line of reasoning, `tr(1)` isn't a filter, either. – Blrfl Mar 21 '17 at 20:29
  • 1
    @Birfl. obviously. "tr" means translate, not filter. filters are not translators, this is just obvious. –  Mar 21 '17 at 20:32
  • @mobileink If you go by Wikipedia's definition ("a computer program or subroutine to process a stream, producing another stream," same one used in my CS classes), translators are filters. – Blrfl Mar 21 '17 at 21:04
  • 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. –  Mar 21 '17 at 21:09
  • 1
    your account of compilation is fine except for the term "filter". –  Mar 21 '17 at 21:13
  • @mobileink I'm leaving it as it is. The downvote button is above and to the left. – Blrfl Mar 21 '17 at 21:15
  • +1 because the answer is good, but I agree with @mobileink's nitpick: a compiler is a translator, not a filter. It doesn't filter (i.e. include/exclude) anything. Just a nitpick, however :) – Andres F. Mar 21 '17 at 22:20
  • @AndresF.: I read the term filter indicating a program that transforms an input stream into an output stream (e.g. stdin to stdout) before. Maybe it is not that common but I would not consider it wrong, it is just a more general meaning than filtering according to a predicate. On the other hand, since a compiler does not transform a stream into another stream, I would not consider it a filter in this generalized sense. So, I agree with the nitpick. – Giorgio Mar 24 '17 at 21:19
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).

Chris Cirefice
  • 2,984
  • 4
  • 17
  • 37