将值*转换为指令*/LoadInst * [英] Value* to Instruction*/LoadInst* casting

查看:245
本文介绍了将值*转换为指令*/LoadInst *的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如在isa<LoadInst>(MyValue)为true的情况下,是否可以在LLVM中将Value*强制转换为Instruction*/LoadInst*?在我的特定代码段中:

Can you please tell me if it is possible in LLVM to cast a Value* to an Instruction*/LoadInst* if for example isa<LoadInst>(MyValue) is true? In my particular piece of code:

Value* V1 = icmpInstrArray[i]->getOperand(0);
Value* V2 = icmpInstrArray[i]->getOperand(1);
if (isa<LoadInst>(V1) || isa<LoadInst>(V2)){
...
if(isa<LoadInst>(icmpInstrArray[i]->getOperand(0)))
    LoadInst *LD100 = cast<LoadInst>(icmpInstrArray[i]->getOperand(0));
        Value *C100 = LD100->getPointerOperand(); //HERE COMPILATION ERROR

此外,我只需要创建C100->getName(),我将获得已加载的变量.

Further, I just need to make C100->getName() and I will get the loaded variable.

编译错误为:error: ‘LD100’ was not declared in this scope.

我认为我不能像这样使用演员表.您能告诉我一种从与我的ICMP指令相对应的Load指令中获取已加载变量的方法吗?或者更好的是我如何从icmpInstrArray[i]->getOperand(0)中提取Load指令?

I don't think that I can use cast like that. Can you tell me a method to obtain the loaded variable from a Load instruction correspondent to my ICMP instructions? Or better how I can extract the Load instruction from icmpInstrArray[i]->getOperand(0)?

推荐答案

您缺少if语句周围的花括号.您的代码当前等于:

You are missing the braces around the if-statement. Your code is currently equal to this:

if(isa<LoadInst>(icmpInstrArray[i]->getOperand(0))) {
    LoadInst *LD100 = cast<LoadInst>(icmpInstrArray[i]->getOperand(0));
}
Value *C100 = LD100->getPointerOperand(); //HERE COMPILATION ERROR

LD100未在if语句范围之外定义.这将起作用:

LD100 is not defined outside the if-statements scope. This would work:

if(isa<LoadInst>(icmpInstrArray[i]->getOperand(0))) {
    LoadInst *LD100 = cast<LoadInst>(icmpInstrArray[i]->getOperand(0));
    Value *C100 = LD100->getPointerOperand(); //HERE COMPILATION ERROR
}

这篇关于将值*转换为指令*/LoadInst *的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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