c++ccompiler-constructionsystems-programmingintermediate-code

How does a compiler identify its host machine's hardware? Which component?


My teacher told me that the intermediate code is generic for all systems but a component of the compiler then make it different according the system/environment the code is run on. Can someone please explain it.


Solution

  • Normally a compiler is divided into two parts: A frontend that does the parsing, and which generates intermediate code. Then a backend which takes the intermediate code and generate the assembly or machine code.

    The frontend can be generic, but the backend is built for a specific target. So the compiler doesn't have to "identify" the host, only know the target.

    Note that host and target may be different systems, which is used for cross compilation.