3 ms·
Not 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
by pajko 5y ago
Not 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.