3 ms·
A compiler compiles something to something. For example, gcc compiles C code to assembly, which is then compiled to machine code by gas. Clang does the same: ht
by pajko 5y ago
A compiler compiles something to something. For example, gcc compiles C code to assembly, which is then compiled to machine code by gas. Clang does the same: https://freecompilercamp.org/clang-basics/ https://freecompilercamp.org/clang-basics/
- user-the-name 5y agoClang definitely does not output assembly code and invoke an assembler. It generates machine code directly. It can optionally also generate assembly code if you want to look at it, but it does not do this during normal compilation.
- misnome 5y agoClang doesn't generate LLVM IR as part of it's normal process?
- user-the-name 5y agoNot in a text file, no. It generates LLVM data structures that can be serialised to a text format, but aren't. The only external binary clang invokes is, optionally, the linker. Otherwise, everything is done in one executable invocation without temporary files.
- aetherspawn 5y agoYes and no. It uses the llvm API rather than pipe to llc
- pajko 5y agoNot saving everything to files and not doing things via multiple executables does not mean that a compiler does things in a single step, generating machine code directly from the source code. Both gcc and clang support the -save-temps switch to keep intermediate files during the compilation process. These files are created even without this argument, except that their names are randomly generated somewhere and the files are deleted afterwards.
- pajko 5y agoWas doing a quick check. Looks like the temporary files are not always generated and could not even see any pipes in Process Monitor. EDIT: clang can tell what's being done: $ clang -ccc-print-phases -x c t.c 0: input, "t.c", c 1: preprocessor, {0}, cpp-output 2: compiler, {1}, ir 3: backend, {2}, assembler 4: assembler, {3}, object 5: linker, {4}, image Reference: https://clang.llvm.org/docs/DriverInternals.html https://clang.llvm.org/docs/DriverInternals.html
- NavinF 5y ago> These files are created even without this argument That used to be the case in the dark ages of autoconf. clang does everything in a single address space which is a lot faster now that you aren't doing a million filesystem calls. btw I remember seeing a talk a few years ago about integrating clang with the build system so that the same compiler process can be reused to compile multiple files. Startup time is significant when you have a lot of source files Past: >1 process and many fs calls per cpp. Present: 1 process and a few fs calls per cpp. Future: <1 process and a few fs calls per cpp (on average)
- user-the-name 5y ago-save-temps is for backwards compatibility. The files are not generated if you do not give that flag. clang goes to the extra effort of generating them for you if you request them using that flag, but they are not part of the compilation process. Machine code is generated "directly from the source code" in the sense that there are no intermediate languages produced. There are multiple stages of compilation, of course, but these all involved in-memory data structures, not textual languages.