LLVM 翻译单元
我尝试理解 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
翻译单位是语言标准中的术语。例如,这是来自 C(c99 iso 草案)
因此,翻译单元是预处理后的单个源文件(
file.c
)(所有实例化的#include
d*.h
文件,所有宏已展开,所有注释都会被跳过,并且文件已准备好进行标记化)。翻译单元是编译单元,因为在链接步骤之前它不依赖于任何外部资源。所有标头都在 TU 内。
术语模块在语言标准中没有定义,但据我所知,它指的是更深层次翻译阶段的
翻译单元
。LLVM 将其描述为: http://llvm.org/docs/ProgrammersManual.html
关于你的问题的这一部分:
这取决于 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)
So, translation unit is the single source file (
file.c
) after preprocessing (all#include
d*.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
About this part of your question:
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