简体   繁体   English

如何检测LLVM中的const修饰符?

[英]How to detect const modifier in LLVM?

I realized that Constant in LLVM is not the same as variable with c/c++'s const modifier.我意识到 LLVM 中的 Constant 与带有 c/c++ 的 const 修饰符的变量不同。

Is there any way for me to differentiate C/C++ variables with const modifier in LLVM from those that do not have it?有什么方法可以让我将 LLVM 中带有 const 修饰符的 C/C++ 变量与没有它的变量区分开来? (all variables including globals) (包括全局变量在内的所有变量)

LLVM IR isn't intended to represent the source type system, it's an intermediate representation and contains the type information that's useful for compiling, which will resemble the source types but need not capture all aspects. LLVM IR 不打算表示源类型系统,它是一种中间表示,包含对编译有用的类型信息,它将类似于源类型但不需要捕获所有方面。 If you want the source type system, you have to look at the debug information, which need not be present, but if it is present it is at least intended to contain the data you want.如果您想要类型系统,则必须查看调试信息,该信息不需要存在,但如果存在,则至少旨在包含您想要的数据。

You can start looking at DIType .您可以开始查看DIType Be warned that this code isn't awfully well documented.请注意,这段代码没有很好的文档记录。

Global variables have a convenient method, though, isConstant() .不过,全局变量有一个方便的方法isConstant()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM