How to add a Metadata String to an LLVM module with the C++ API?

前端 未结 1 1839
北恋
北恋 2021-01-13 07:47

I\'m trying to add a metadata string to my LLVM module. The stripped down version of what I\'m trying is

#include 
#include 

        
1条回答
  •  梦谈多话
    2021-01-13 08:44

    Try this:

    #include 
    #include 
    #include 
    
    using namespace llvm;
    
    int main() {
      Module* module = new Module("test", getGlobalContext());
    
      Value *Elts[] = {
        MDString::get(module->getContext(), "test1")
      };
      MDNode *Node = MDNode::get(getGlobalContext(), Elts);
    
      NamedMDNode *NMD = module->getOrInsertNamedMetadata("test2");
      NMD->addOperand(Node);
    
      module->dump();
    }
    

    I am not sure if you are able to have metadata "floating around" as you say. If it's not attached to any part of your program then what good is it doing? I've been looking into MD a bit lately... I found similar code in lib/Analysis/DIBuilder.cpp. Good luck.

    0 讨论(0)
提交回复
热议问题