12

LLVM で ConstantInt を作成する方法がわかりません。作成したい数値はわかっていますが、その数値を表す ConstantInt を作成する方法がわかりません。ドキュメントで必要なコンストラクターが見つからないようです。

私はそれがの線に沿っている必要があると考えています

ConstantInt consVal = new ConstantInt(something here).

私はそれをint型にしたいことを知っています、そして私は自分の価値を知っています...私はただ数値を作成したいだけです!

4

4 に答える 4

11

Most things in LLVM are created through a static method call instead of directly using a constructor. One reason is that an existing object can be returned instead of creating a new instance.

The static members of ConstantInt have a number of creation methods. You're probably most interested in get (Type *Ty, uint64_t V, bool isSigned=false) and, if you don't already have an integer type, IntegerType::get (LLVMContext &C, unsigned NumBits).

于 2013-04-27T01:24:47.230 に答える
6

32 ビット整数を作成するには:

llvm::ConstantInt::get(context, llvm::APInt(/*nbits*/32, value, /*bool*/is_signed));
于 2014-03-23T07:10:08.383 に答える
1

32-bit整数定数を作成するには:

llvm::Type *i32_type = llvm::IntegerType::getInt32Ty(llvm_context);
llvm::Constant *i32_val = llvm::ConstantInt::get(i32_type, -1/*value*/, true);
于 2017-06-23T09:57:36.160 に答える
1
ConstantInt* const_int32  = ConstantInt::get( Context , APInt(32, StringRef("10"), 10));

ここで、APInt(32, StringRef("10"), 10); 文字列 "10" から基数 10 の int 値を取得します。

于 2017-06-28T01:52:51.920 に答える