gpt4 book ai didi

debugging - LLVM 翻译单元

转载 作者:行者123 更新时间:2023-12-02 02:23:12 24 4
gpt4 key购买 nike

我尝试了解 LLVM 程序的高级结构。
我在书中读到“程序由模块组成,每个模块都对应于翻译单元”。有人可以更详细地解释我上面的内容以及模块和翻译单元(如果有的话)之间的区别。
我也有兴趣知道翻译单元启动并完成调试信息编码时调用了哪部分代码?

最佳答案

翻译单位是语言标准中的术语。例如,这是来自 C(c99 iso 草案)

5.1 Conceptual models; 5.1.1 Translation environment; 5.1.1.1 Program structure

A C program need not all be translated at the same time. The text of the program is keptin units called source files, (or preprocessing files) in this International Standard. Asource file together with all the headers and source files included via the preprocessingdirective #include is known as a preprocessing translation unit. After preprocessing, apreprocessing translation unit is called a translation unit.


因此,翻译单元是预处理后的单个源文件( file.c )(所有 #include d *.h 文件实例化,所有宏都被扩展,所有注释都被跳过,文件准备好进行标记化)。
翻译单元是一个编译单元,因为它在链接步骤之前不依赖任何外部资源。所有标题都在 TU 内。
术语模块未在语言标准中定义,但 AFAIK 指的是 translation unit在更深层次的翻译阶段。
LLVM 将其描述为: http://llvm.org/docs/ProgrammersManual.html

The Module class represents the top level structure present in LLVM programs. An LLVM module is effectively either a translation unit of the original program or a combination of several translation units merged by the linker.

The Module class keeps track of a list of Functions, a list of GlobalVariables, and a SymbolTable. Additionally, it contains a few helpful member functions that try to make common operations easy.


关于您问题的这一部分:

I am also interested to know which part of the code is called when translation unit starts and completes debugging information encoding?


这取决于如何使用 LLVM。 LLVM 本身是一个库,可以以多种方式使用。
对于 clang/LLVM(基于 libclang 和 LLVM 构建的 C/C++ 编译器),在预处理阶段之后创建的翻译单元。它将被解析为 AST,然后被解析为 LLVM 程序集并保存在模块中。
以教程为例,这里是创建模块 http://llvm.org/releases/2.6/docs/tutorial/JITTutorial1.html

关于debugging - LLVM 翻译单元,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7146425/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com