如何为llvm IR调用指令创建结构参数
How can I create a struct parameter for a llvm IR call instruction?
我想在IR文件中插入一条函数调用指令。但是,当我尝试创建一个结构参数时,会出现一些问题。
功能:
"__myfun(int addr,struct buginfor struct_var)"
结构为:
typedef struct buginfor{
int line;
char *str1;
char *str2;
};
我的代码:
Value* args[] = { addr };
// struct parameter create
Value *struct_line = ConstantInt::get(IntegerType::get(M->getContext(), 64), 4);
Value *struct_filename= llvm::PointerType::get(IntegerType::get(M->getContext(), 8),20);//20 bytes
Value *struct_dir= llvm::PointerType::get(IntegerType::get(M->getContext(), 8),100);//100 tytes
Type* struct_Ty[] = { struct_line->getType(),struct_filename->getType(),struct_dir->getType()};
llvm::StructType * struct_var= llvm::StructType::create(M->getContext(),"buginfor");
struct_var->setBody(struct_Ty);
Value* arg2 = struct_var;
Type* argsTy[] = { addr->getType(),arg2->getType()};
FunctionType *funcTy = FunctionType::get(Type::getVoidTy(M->getContext()), ArrayRef<Type*>(argsTy, 2), false);
Function *hook;
hook = cast<Function>( M->getOrInsertFunction("__myfun", funcTy, attribute(M)));
CallInst *newInst = CallInst::Create(hook, ArrayRef<Value *>(args, 1), "");
有人能告诉我创建buginfo这样的结构参数的正确方法吗?
ps:我想得到三个参数,并使其成为llvm IR constantstruct
DILocation Loc(N); // DILocation is in DebugInfo.h
unsigned Line = Loc.getLineNumber();
StringRef File = Loc.getFilename();
StringRef Dir = Loc.getDirectory();
您似乎想要创建一个ConstantStruct或一个undef结构,然后使用insertvalue指令将值插入其中。取决于是否有常量或运行时值。
相关文章:
- 如何创建一个CMake变量,除非显式重写,否则使用默认值
- 使用std::multimap迭代器创建std::list
- 使用C++库在Android项目中修改gradle中的cmake参数,用于插入指令的测试
- 在全局变量中保存类的实例以重新创建类(创建"backup")
- 使用CMake创建QML插件
- 如何在c++中为模板函数实例创建快捷方式
- 在C++中,是否可以基于给定的标识符创建基类的新实例,反之亦然
- 创建一个函数以在输入为负数或零时输出字符串.第一次执行用户定义的函数
- 无法编译 rtmidi 测试 cmidiin.cpp 文件, 非法指令
- OpenCV EqualizeHist()从彩色图像创建黑白图像
- 试图在visual studio上用C++创建一个桌面应用程序
- std::threads可以从Windows DLL中的全局变量创建/销毁吗?
- 如何在C++20中创建模板别名的推导指南
- 如何为模板化对象创建模板向量?VS正在投掷C3203
- 如何创建一个空的全局类并在启动时实例化它
- g++ -O3 为 loop 创建了奇怪的指令 - 两个具有相同 asm 的版本
- xerces_3_1能够在注释和处理指令中创建无效的 xml
- 如何为llvm IR调用指令创建结构参数
- 创建文件名的预处理器指令
- 创建过程没有这样的文件或指令