LLVM转换单元 [英] LLVM translation unit

查看:120
本文介绍了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?

推荐答案

翻译单元是语言标准中的术语.例如,这是从C(c99 iso草稿)中获得的

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

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

5.1 Conceptual models; 5.1.1 Translation environment; 5.1.1.1 Program structure

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

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.

因此,翻译单元是预处理后的单个源文件(file.c)(实例化所有#include d *.h文件,扩展所有宏,跳过所有注释,并且文件可用于标记化).

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).

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

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

术语模块在语言标准中未定义,但AFAIK在更深的翻译阶段指的是translation unit.

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

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

LLVM describes it as: http://llvm.org/docs/ProgrammersManual.html

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

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.

Module类跟踪功能列表,GlobalVariables列表和SymbolTable.此外,它包含一些有用的成员函数,这些函数试图简化常用操作.

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本身是一个库,可以以多种方式使用.

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

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

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.

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

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

这篇关于LLVM转换单元的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆