3

LLVM Demo を見てください。定数文字列を作成する公式の方法は次のとおりです。

Constant* 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 のコンストラクターが 1 つしかありません。今、定数文字列を作成する方法がわかりません... :(

どんな助けでも大歓迎です!

ありがとう!

4

1 に答える 1

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);

}
于 2012-11-02T03:36:45.760 に答える