简体   繁体   English

如何为llvm IR调用指令创建struct参数?

[英]How can I create a struct parameter for a llvm IR call instruction?

I want to insert a function call instruction into an IR file. 我想在IR文件中插入函数调用指令。 But there are some problems when I tried to create a struct parameter. 但是,当我尝试创建struct参数时存在一些问题。

function: 功能:

 "__myfun(int addr,struct buginfor struct_var)" 

the struct is: 结构是:

 typedef struct buginfor{
    int line;
    char *str1;
    char *str2;
 };

my code: 我的代码:

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), "");

anyone can tell me the right way to create a struct parameter like buginfor? 任何人都可以告诉我创建像buginfor这样的struct参数的正确方法吗?

ps: I want to get the three parameter and make it a llvm IR constantstruct ps:我想获取三个参数并将其设为llvm IR constantstruct

          DILocation Loc(N);    // DILocation is in DebugInfo.h
          unsigned Line = Loc.getLineNumber();
          StringRef File = Loc.getFilename();
          StringRef Dir = Loc.getDirectory();

It seems like you'll want to create a ConstantStruct or an undef struct and then insert values in to it with insertvalue instructions. 似乎您想创建一个ConstantStruct或undef结构,然后使用insertvalue指令将值插入其中。 Depending on if you have constants or runtime values. 取决于您是否具有常量或运行时值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM