If clang is the front end of the compiler, then why can it create an executable?

One thing that I really don’t understand is regarding the clang function, if clang is the front end of the compiler, it should just work with the parser for the source code, the rest will be done by LLVM, But clang can also create an executable file. So how to understand this? What is the relationship between clang and llvm?

+8
compiler-construction clang llvm
source share
3 answers

If you are very specific: the clang executable is a compiler driver. It calls all the parts necessary to create an executable file. It calls libclang, which performs front-end jobs: parser / lexer, semantic analysis, AST building, and code generation. When the AST drops to LLVM IR, the foreground assignments are completed and the optimizer and LLVM are launched. After opposing the code, the compiler driver will invoke the LLVM interface specified by the target point, and finally the linker that creates the executable. This is why the clang compiler driver can create executable files.

+14
source share

LLVM is a compiler backend that was written before clang, which originally used the front end of gcc in a tool called llvm-gcc. Clang is the name of the front end code, but clang is also the name of a tool that includes the front end of clang, but will also run the entire compiler for you. Later compilation steps are either built into the clang tool as libraries, or if they are separate executable files, clang knows how to call them. With the right command line arguments you can do clang stop part through thru

  • -emit-ast just parses and creates an abstract syntax tree
  • -emit-llvm makes an intermediate LLVM representation, but does not turn it into code for your computer.

Clang will work as a driver for the entire assembly, because what programmers usually want, a parsed sur, a generated object, an executable. The desire for abstract syntax Tree spun you quite rarely.

Obviously, this is the sum of all things LLVM http://llvm.org

Here's a Chriss Lattner video explaining that LLVM is https://www.youtube.com/watch?v=029YXzHtRy0 . Chandler Carrut has some tips on how you explain the parts of clang that he worked on.

+2
source share

There are 3 values ​​of the Clan:

  • front-end (libclang)
  • Compiler driver (clang executable file)
  • Traditional compiler . This not only includes interfaces, but also makes extensive use of middle and rear servers, as well as built-in assembler, to complete the compilation phase. (the driver mainly consists of compilation and a link).
+2
source share

All Articles