llvm:是否可以在单个阶段合并验证和编译? [英] llvm: is it possible to merge validation and compilation in a single stage?

查看:123
本文介绍了llvm:是否可以在单个阶段合并验证和编译?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通常来说,编写llvm前端时,将使用AST并首先检查其语义是否定义明确.此后,将进行AST并执行IR构建阶段. 我想知道,直接在AST上执行IR构建阶段是否现实,并且如果在构建过程中发现错误,将部分更改恢复到模块对象?

Generally speaking, when writing a llvm frontend, one will take an AST and first check that its semantics is well-defined. After this, one will take the AST and perform the IR build phase. I was wondering, how realistic is to perform directly the IR build phase onto the AST, and if errors are found during the build process, revert any partial changes to the module object?

我认为这是必需的:

  • 删除定义的类型
  • 删除已定义的全局变量
  • 我想念的还有什么吗?

对此有何想法?在失败的构建阶段之后,干净恢复模块更改需要做什么的一般准则是什么?

Any ideas about this? what are the general guidelines of what needs to done for a clean revert of module changes after a failed build phase?

现在,这是从乐观编译的角度考虑的,而从容地失败则出了点问题.在当前的LLVM模型下,完全有可能或完全不建议这样做.在这方面有一个清晰且有据可查的答案也是完全可以接受的

Now, this is thinking in terms of optimistically compiling, and failing gracefully it somethings goes wrong. It might very well be that this is completely impossible or discouraged under the current LLVM model. A clear and well-documented answer in this regard is also completely acceptable

编辑最后,我只想以合理的方式递增地添加函数,但是如果函数构建失败,则可以正常地恢复到模块的先前状态和/或LLVMContext.无论哪种首选方法都将完全令人满意.

Edit In the end, I just want a reasonable way to add functions incrementally but revert gracefully to previous state of module and/or LLVMContext if a function build fails. Whatever is the preferred approach for that will be entirely satisfactory.

谢谢!

推荐答案

许多编译器(不一定与LLVM相关)将语义分析与代码生成混合在一起,因此可以肯定地做到这一点.但是,我对您的引用将对模块对象的任何部分更改还原"感到困惑.当您开始构建IR模块并在AST中遇到语义错误时,您的计划是什么?您是否要吐出不完整的模块?为什么?考虑任何常规编译器的工作方式,如果代码中存在语义错误(即引用未定义的变量),则不会创建任何输出.您想要其他东西吗?

Many compilers (not necessarily LLVM-related) mix semantic analysis with code generation, so it can definitely be done. However, I'm puzzled by your reference to "revert any partial changes to the module object". When you start building an IR module and encounter a semantic error in the AST, what is your plan? Do you want to spit an incomplete module? Why? Thinking about the way any regular compiler works, if there are semantic errors in the code (i.e. reference to an undefined variable), no output is created. Would you like something different?

这篇关于llvm:是否可以在单个阶段合并验证和编译?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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