查看LLVM Demo,创建常量字符串的正式方法是:
常量* consStr = ConstantArray :: get(mod-> getContext(),“hello”,true);
然而,它不起作用!我远离编译错误:
test.cc:860:78: error: no matching function for call to llvm::ConstantArray::get(llvm::LLVMContext&, char*&, bool)’
/remote/vgrnd66/wli/Tools/llvm-3.1/include/llvm/Constants.h:354:20: note: candidate is: static llvm::Constant* llvm::ConstantArray::get(llvm::ArrayType*, llvm::ArrayRef<llvm::Constant*>)
查看llvm源代码,没有支持
的成员函数llvm::ConstantArray::get(llvm::LLVMContext&, char*&, bool)
我正在使用llvm3.1。
我的代码有什么问题,或者在新的源代码中删除了这个构造函数吗?
这是LLVM源代码差异。
LLVM2.8
class ConstantArray : public Constant {
// ConstantArray accessors
static Constant *get(const ArrayType *T, const std::vector<Constant*> &V);
static Constant *get(const ArrayType *T, Constant *const *Vals,
unsigned NumVals);
/// This method constructs a ConstantArray and initializes it with a text
/// string. The default behavior (AddNull==true) causes a null terminator to
/// be placed at the end of the array. This effectively increases the length
/// of the array by one (you've been warned). However, in some situations
/// this is not desired so if AddNull==false then the string is copied without
/// null termination.
static Constant *get(LLVMContext &Context, StringRef Initializer,
bool AddNull = true);
}
LLVM3.1
class ConstantArray : public Constant {
public:
// ConstantArray accessors
static Constant *get(ArrayType *T, ArrayRef<Constant*> V);
}
显然,2.8中有3个构造函数,但3.1中只有一个构造函数用于ConstantArray。现在我不知道如何创建一个常量字符串...... :(
任何帮助都是有用的!
谢谢!
答案 0 :(得分:4)
行。我发现它已被移动到ConstantDataArray。 LLVM演示cgi似乎已经过时了:)。
class ConstantDataArray : public ConstantDataSequential {
/// getString - This method constructs a CDS and initializes it with a text
/// string. The default behavior (AddNull==true) causes a null terminator to
/// be placed at the end of the array (increasing the length of the string by
/// one more than the StringRef would normally indicate. Pass AddNull=false
/// to disable this behavior.
static Constant *getString(LLVMContext &Context, StringRef Initializer,
bool AddNull = true);
}