constant在c语言错误中怎么改,c – 设置llvm :: ConstantInt的值

ConstantInt是一家工厂,不是吗?类有

get method构造新的常量:

/* ... return a ConstantInt for the given value. */

00069 static Constant *get(Type *Ty,uint64_t V,bool isSigned = false);

所以,我认为,你无法修改现有的ConstantInt.如果要修改IR,则应尝试将指针更改为参数(更改IR本身,但不更改常量对象).

可能你想要这样的东西(请记住,我对LLVM没有经验;我几乎可以肯定的例子是不正确的).

Instruction *I = /* your argument */;

/* check that instruction is of needed format,e.g: */

if (I->getOpcode() == Instruction::Add) {

/* read the first operand of instruction */

Value *oldvalue = I->getOperand(0);

/* construct new constant; here 0x1234 is used as value */

Value *newvalue = ConstantInt::get(oldValue->getType(),0x1234);

/* replace operand with new value */

I->setOperand(0,newvalue);

}

要“修改”一个常量,就有一个解决方案(增量和减量are illustrated):

/// AddOne - Add one to a ConstantInt.

static Constant *AddOne(Constant *C) {

return ConstantExpr::getAdd(C,ConstantInt::get(C->getType(),1));

}

/// SubOne - Subtract one from a ConstantInt.

static Constant *SubOne(ConstantInt *C) {

return ConstantInt::get(C->getContext(),C->getValue()-1);

}

00035 /// Note that Constants are immutable (once created they never change)

00036 /// and are fully shared by structural equivalence. This means that two

00037 /// structurally equivalent constants will always have the same address.

00038 /// Constants are created on demand as needed and never deleted: thus clients

00039 /// don't have to worry about the lifetime of the objects.

00040 /// @brief LLVM Constant Representation

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值