本文介绍了如何使用C ++ API将元数据字符串添加到LLVM模块?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试向我的LLVM模块添加。我试图删除的版本是

  #include< llvm / LLVMContext.h> 
#include< llvm / Module.h>
#include< llvm / Metadata.h>

使用命名空间llvm;

int main(){
Module * module = new Module(test,getGlobalContext());
MDString :: get(module-> getContext(),test);
module-> dump();
}



我可以编译并运行它:

 桌面%g ++ llvm.cc -o llvm`llvm-config --cppflags --ldflags --libs all` 
桌面%./llvm
; ModuleID ='test'

但是可以看到,元数据不会显示。 >

我能以某种方式将字符串添加到模块吗? 本身似乎只提供对已命名元数据的访问权限。现在我不知道在哪里可以看看。任何建议?



补充:我感觉你不能只有一个元数据字符串浮动在你的模块,似乎你必须添加到被命名的元数据节点。是这样吗?

解决方案

尝试:

  #include< llvm / LLVMContext.h> 
#include< llvm / Module.h>
#include< llvm / Metadata.h>

使用命名空间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();
}


$ b $ p

我不知道你是否能够将元数据你说。如果它不附加到你的程序的任何部分,那么它有什么好处?我最近一直在寻找MD ...我在。祝你好运。


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

#include <llvm/LLVMContext.h>
#include <llvm/Module.h>
#include <llvm/Metadata.h>

using namespace llvm;

int main() {
    Module* module = new Module("test", getGlobalContext());
    MDString::get(module->getContext(), "test");
    module->dump();
}

I can compile and run it:

Desktop% g++ llvm.cc -o llvm `llvm-config --cppflags --ldflags --libs all`
Desktop% ./llvm 
; ModuleID = 'test'

But as one can see, the metadata does not show up.

Can I somehow add the string to the module? The module itself only seems to offer access to named metadata. Now I don't know where else I could look. Any suggestions?

Supplement: I got the feeling that you can't just have a metadata string "floating around" in your module, it seems like you have to add it to a named metadata node. Is that right?

解决方案

Try this:

#include <llvm/LLVMContext.h>
#include <llvm/Module.h>
#include <llvm/Metadata.h>

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.

这篇关于如何使用C ++ API将元数据字符串添加到LLVM模块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 01:41