适用于范围分析器的良好 API

发布于 2024-07-10 05:51:20 字数 333 浏览 5 评论 0 原文

我正在开发一些代码生成工具,很多复杂性来自于范围分析。 我经常发现自己想知道诸如

  1. 函数或块的自由变量是什么?
  2. 这个符号是在哪里声明的?
  3. 该声明掩盖了什么?
  4. 符号的这种使用是否可能发生在初始化之前?
  5. 这个变量有可能逃逸吗?

我认为是时候重新思考我的范围界定问题了。

我可以完成所有这些分析,但我正在尝试找出一种构建 API 的方法,以便它易于使用,并且理想情况下,可以懒惰地完成足够的工作。

人们熟悉哪些类似的工具?他们在 API 中做对了什么、做错了什么?

I'm working on some code generation tools, and a lot of complexity comes from doing scope analysis.
I frequently find myself wanting to know things like

  1. What are the free variables of a function or block?
  2. Where is this symbol declared?
  3. What does this declaration mask?
  4. Does this usage of a symbol potentially occur before initialization?
  5. Does this variable potentially escape?

and I think it's time to rethink my scoping kludge.

I can do all this analysis but am trying to figure out a way to structure APIs so that it's easy to use, and ideally, possible to do enough of this work lazily.

What tools like this are people familiar with, and what did they do right and wrong in their APIs?

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

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

发布评论

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

评论(1

2024-07-17 05:51:20

我对这个问题有点惊讶,因为我已经完成了大量的代码生成,并且范围界定问题很少出现(除了偶尔希望生成唯一名称)。

要回答您的示例问题需要进行远远超出范围的认真的程序分析。 逃逸分析本身就很重要。 初始化前使用可能很简单,也可能很重要,具体取决于目标语言。

根据我的经验,用于程序分析的 API很难设计,而且通常是特定于语言的。 如果您的目标是低级语言,您可能会从 机器 SUIF API。

站在你的立场上,我会忍不住窃取别人的程序分析框架George Necula 和他的学生构建了CIL,这似乎是当前分析C代码的标准。 Laurie Hendren 的小组构建了一些用于分析 Java 的优秀工具。

如果我必须自己推出,我会更少担心 API,而更多地担心抽象语法树的真正良好表示。

在非常有限的数据流分析领域(包括未初始化变量问题),João Dias 和我改编了一些Sorin Lerner、David Grove 和 Craig Chambers 的出色工作。 仅发布我们的初步结果

最后,如果您想生成多种语言的代码,那么这就是一个完整的蠕虫罐头。 我已经做过好几次了,做得很糟糕。 如果您创造了自己喜欢的东西,请发布它!

I'm a bit surprised at at the question, as I've done tons of code generation and the question of scoping rarely comes up (except occasionally the desire to generate unique names).

To answer your example questions requires serious program analysis well beyond scoping. Escape analysis by itself is nontrivial. Use-before-initialization can be trivial or nontrivial depending on the target language.

In my experience, APIs for program analysis are difficult to design and frequently language-specific. If you're targeting a low-level language you might learn something useful from the Machine SUIF APIs.

In your place I would be tempted to steal someone else's framework for program analysis. George Necula and his students built CIL, which seems to be the current standard for analyzing C code. Laurie Hendren's group have built some nice tools for analyzing Java.

If I had to roll my own I'd worry less about APIs and more about a really good representation for abstract-syntax trees.

In the very limited domain of dataflow analysis (which includes the uninitialized-variable question), João Dias and I have adapted some nice work by Sorin Lerner, David Grove, and Craig Chambers. Only our preliminary results are published.

Finally if you want to generate code in multiple languages this is a complete can of worms. I have done it badly several times. If you create something you like, publish it!

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