How can I implement a string data type in LLVM?

后端 未结 5 1900
眼角桃花
眼角桃花 2021-01-31 10:31

I have been looking at LLVM lately, and I find it to be quite an interesting architecture. However, looking through the tutorial and the reference material, I can\'t see any ex

5条回答
  •  长情又很酷
    2021-01-31 11:07

    [To follow up on other answers which explain what strings are, here is some implementation help]

    Using the C interface, the calls you'll want are something like:

    LLVMValueRef llvmGenLocalStringVar(const char* data, int len)
    {
      LLVMValueRef glob = LLVMAddGlobal(mod, LLVMArrayType(LLVMInt8Type(), len), "string");
    
      // set as internal linkage and constant
      LLVMSetLinkage(glob, LLVMInternalLinkage);
      LLVMSetGlobalConstant(glob, TRUE);
    
      // Initialize with string:
      LLVMSetInitializer(glob, LLVMConstString(data, len, TRUE));
    
      return glob;
    }
    

提交回复
热议问题