从uint8_t *转换为StringRef

时间:2018-01-06 18:25:47

标签: llvm llvm-clang llvm-ir llvm-3.0

我使用的是ExecutionEngine.cpp。我想通过以下代码从找到的地址中获取StringRef:

const APInt &IntVal;

uint8_t *y2 = reinterpret_cast<uint8_t *>(const_cast<uint64_t *>(IntVal.getRawData()));

int v2 = *reinterpret_cast<int *>(y2);

StringRef* Src1V=cast<StringRef>(y2);

我收到了这个错误:

home/rasha/llvm/llvm/include/llvm/Support/Casting.h:236:3: required from ‘typename llvm::cast_retty<X, Y*>::ret_type llvm::cast(Y*) [with X = llvm::StringRef; Y = unsigned char; typename llvm::cast_retty<X, Y*>::ret_type = llvm::StringRef*]’

/home/rasha/llvm/llvm/lib/ExecutionEngine/Interpreter/Execution.cpp:1291:38: required from here

/home/rasha/llvm/llvm/include/llvm/Support/Casting.h:56:28: error: ‘classof’ is not a member of ‘llvm::StringRef’

return To::classof(&Val);

请您向我解释错误吗? 请注意,我在Execution.cpp中使用了相同类型的转换,没有错误。

1 个答案:

答案 0 :(得分:0)

字符串在LLVM IR中都表示为library(lubridate) ymd(as.character(Sys.Date())) ,是Constant的子类。如果你想要stringref,你必须通过调用myVector<-c("a string", Sys.Date()) as.Date(as.numeric(myVector[2]),origin="1970-01-01") 的相应API明确告诉LLVM为你做这件事 具体而言,您需要在转换指针后调用以下一个或多个LLVM API:

  • ConstantDataSequential
  • ConstantDataSequential
  • isString (unsigned CharSize=8)
  • isCString ()