Compiler construction LLVM中编译器和编译器驱动程序的区别?

Compiler construction LLVM中编译器和编译器驱动程序的区别?,compiler-construction,llvm,Compiler Construction,Llvm,有人能解释一下LLVM中编译器和编译器驱动程序的区别吗 非常感谢您的帮助。我想,编译器指的是整个编译器,而编译器驱动程序对应于驱动编译管道的逻辑。驱动程序的任务是为各种文件调用正确的工具(例如,为C/C++源调用clangcc1,为目标文件调用ld,等等),并为它们设置适当的标志。在llvm中,我们总是使用clang。我将以叮当声为例解释你的问题 当您向命令行输入“铿锵”时,它就是编译器驱动程序。编译器驱动程序有许多选项,这些选项将决定调用哪个编译器组件。例如:clang-cc1是前端,clan

有人能解释一下LLVM中编译器和编译器驱动程序的区别吗


非常感谢您的帮助。

我想,编译器指的是整个编译器,而编译器驱动程序对应于驱动编译管道的逻辑。驱动程序的任务是为各种文件调用正确的工具(例如,为C/C++源调用
clang
cc1,为目标文件调用
ld
,等等),并为它们设置适当的标志。

在llvm中,我们总是使用clang。我将以叮当声为例解释你的问题

当您向命令行输入“铿锵”时,它就是编译器驱动程序。编译器驱动程序有许多选项,这些选项将决定调用哪个编译器组件。例如:clang-cc1是前端,clang是驱动程序。驱动程序使用适合您的系统的选项调用前端

因此,我认为编译器驱动程序驱动编译器组件,使它们协同工作。

简单地说
编译器
是整体编译过程的一部分;
编译器驱动程序是编译过程的串联和管理器

但我们通常混淆这两个概念,称之为编译器

事实上 编译器由多个部分组成,当一个程序源被编译成一个可执行文件时,它会经历许多不同的步骤。
源代码->预处理->编译->汇编->链接

不同的编译器组件负责不同的阶段

例如,编译负责
编译器
cc1
用于c,
cc1plus
用于cxx,
cc1obj
用于Objective-c等)(其中,
cc1
cc1plus
cc1obj
等实际上是
编译器
编译器
使用源代码作为输入,输出作为汇编代码)。

as
负责将汇编代码转换为二进制代码,
ld
负责链接

为了方便这个过程,我们通常只使用
clanghello.c-o hello

完成c源代码到最终可执行文件的构造。
但事实上,在这个过程中,
clang
编译器驱动程序
,它以自动化的方式连接整个编译过程。它做了大量的工作,用适当的参数和顺序调用编译器中的每个工具,最终生成一个可执行文件

明确地
clang hello.c-o hello
命令的详细参数可以通过command
clang hello.c-o hello-v

在我的终端上,它显示:

clang version 8.0.0 (tags/RELEASE_800/final)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/huangshaomang/research/LLVM/ollvmsimon/build/bin

 "/home/huangshaomang/research/LLVM/build/bin/clang-8" "-cc1" "-triple" "x86_64-unknown-linux-gnu" "-emit-obj" "-mrelax-all" "-disable-free" "-main-file-name" "hello.c" "-mrelocation-model" "static" "-mthread-model" "posix" "-mdisable-fp-elim" "-fmath-errno" "-masm-verbose" "-mconstructor-aliases" "-munwind-tables" "-fuse-init-array" "-target-cpu" "x86-64" "-dwarf-column-info" "-debugger-tuning=gdb" "-resource-dir" "/home/huangshaomang/research/LLVM/build/lib/clang/8.0.0" "-internal-isystem" "/usr/local/include" "-internal-isystem" "/home/huangshaomang/research/LLVM/build/lib/clang/8.0.0/include" "-internal-externc-isystem" "/usr/include/x86_64-linux-gnu" "-internal-externc-isystem" "/include" "-internal-externc-isystem" "/usr/include" "-fdebug-compilation-dir" "/home/huangshaomang/research/linker_loader/test_constructor" "-ferror-limit" "19" "-fmessage-length" "233" "-fobjc-runtime=gcc" "-fdiagnostics-show-option" "-fcolor-diagnostics" "-o" "/tmp/hello-5168fe.o" "-x" "c" "hello.c" "-faddrsig"

 "/usr/bin/ld" "-z" "relro" "--hash-style=gnu" "--eh-frame-hdr" "-m" "elf_x86_64" "-dynamic-linker" "/lib64/ld-linux-x86-64.so.2" "-o" "hello" "/usr/lib/gcc/x86_64-linux-gnu/5.4.0/../../../x86_64-linux-gnu/crt1.o" "/usr/lib/gcc/x86_64-linux-gnu/5.4.0/../../../x86_64-linux-gnu/crti.o" "/usr/lib/gcc/x86_64-linux-gnu/5.4.0/crtbegin.o" "-L/usr/lib/gcc/x86_64-linux-gnu/5.4.0" "-L/usr/lib/gcc/x86_64-linux-gnu/5.4.0/../../../x86_64-linux-gnu" "-L/lib/x86_64-linux-gnu" "-L/lib/../lib64" "-L/usr/lib/x86_64-linux-gnu" "-L/usr/lib/gcc/x86_64-linux-gnu/5.4.0/../../.." "-L/home/huangshaomang/research/LLVM/build/bin/../lib" "-L/lib" "-L/usr/lib" "/tmp/hello-5168fe.o" "-lgcc" "--as-needed" "-lgcc_s" "--no-as-needed" "-lc" "-lgcc" "--as-needed" "-lgcc_s" "--no-as-needed" "/usr/lib/gcc/x86_64-linux-gnu/5.4.0/crtend.o" "/usr/lib/gcc/x86_64-linux-gnu/5.4.0/../../../x86_64-linux-gnu/crtn.o"
很明显,
clang
(编译器驱动程序
)依次调用了两个工具(
cc1
(编译器
)和
ld
(链接器
参数非常复杂)

此外,在以下链接中,llvm项目使用了术语“编译器驱动程序”,这可能有助于您更好地理解它