LLVM 翻译单元

发布于 2024-12-01 01:24:19 字数 136 浏览 1 评论 0原文

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

I try to understand LLVM program high level structure.
I read in the book that "programs are composed of modules ,each of which correspons to tranlation unit".Can someone explain me in more details the above and what is the diffrenece between modules and translation units(if any).
I am also interested to know which part of the code is called when translation unit starts and completes debugging information encoding?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

听,心雨的声音 2024-12-08 01:24:19

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

5.1 概念模型; 5.1.1 翻译环境; 5.1.1.1 程序结构

AC 程序不需要同时翻译。保留程序文本
在本国际标准中,以称为源文件(或预处理文件)的单位。一个
源文件以及通过预处理包含的所有标头和源文件
指令 #include 被称为预处理翻译单元。经过预处理后,
预处理翻译单元称为翻译单元

因此,翻译单元是预处理后的单个源文件(file.c)(所有实例化的#included *.h文件,所有宏已展开,所有注释都会被跳过,并且文件已准备好进行标记化)。

翻译单元是编译单元,因为在链接步骤之前它不依赖于任何外部资源。所有标头都在 TU 内。

术语模块在语言标准中没有定义,但据我所知,它指的是更深层次翻译阶段的翻译单元

LLVM 将其描述为: http://llvm.org/docs/ProgrammersManual.html

Module 类代表 LLVM 程序中存在的顶层结构。 LLVM 模块实际上是原始程序的翻译单元,或者是由链接器合并的多个翻译单元的组合。

Module 类跟踪函数列表、全局变量列表和符号表。此外,它还包含一些有用的成员函数,试图使常见操作变得简单。

关于你的问题的这一部分:

我也有兴趣知道翻译单元启动并完成调试信息编码时调用了哪部分代码?

这取决于 LLVM 的使用方式。 LLVM 本身是一个库,可以通过多种方式使用。

对于 clang/LLVM(基于 libclang 和 LLVM 的 C/C++ 编译器),在预处理阶段后创建的翻译单元。它将被解析为 AST,然后解析为 LLVM 程序集并保存在 Module 中。

对于教程示例,这里是模块的创建 http://llvm.org/ releases/2.6/docs/tutorial/JITTutorial1.html

Translation unit is term from language standard. For example, this is from C (c99 iso draft)

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 kept
in units called source files, (or preprocessing files) in this International Standard. A
source file together with all the headers and source files included via the preprocessing
directive #include is known as a preprocessing translation unit. After preprocessing, a
preprocessing translation unit is called a translation unit.

So, translation unit is the single source file (file.c) after preprocessing (all #included *.h files instantiated, all macro are expanded, all comments are skipped, and file is ready for tokenizing).

Translation unit is a unit of compiling, because it didn't depend on any external resource until linking step. All headers are within TU.

Term module is not defined in the language standard, but it AFAIK refers to translation unit at deeper translation phases.

LLVM describes it as: 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.

About this part of your question:

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

This depends on how LLVM is used. LLVM itself is a library and can be used in various ways.

For clang/LLVM (C/C++ complier build on libclang and LLVM) the translation unit created after preprocessing stage. It will be parsed into AST, then into LLVM assembly and saved in Module.

For tutorial example, here is a creation of Modules http://llvm.org/releases/2.6/docs/tutorial/JITTutorial1.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文