string - LLVM 函数调用
问题描述
我最近开始使用 LLVM,在我的 IR 代码中插入函数时遇到问题。起初我的功能是这样的:
print(){
printf("Hello")
}
我设法用这段代码在每条 CALL 指令之前插入它:
Function *fun;
for (Module::iterator F = M.begin(), E = M.end(); F != E; ++F) {
if (F->getName() == "print") {
fun= cast<Function>(F);
}
for (Function::iterator BB = F->begin(), E = F->end(); BB != E; ++BB) {
for (BasicBlock::iterator BI = BB->begin(), BE = BB->end(); BI != BE; ++BI) {
if (isa<CallInst>(&(*BI))) {
CallInst *CI = dyn_cast<CallInst>(BI);
Instruction *newInst = CallInst::Create(fun, "");
BB->getInstList().insert(BI, newInst);
}
}
}
现在我正在尝试做同样的事情(在每个调用指令之前插入我的打印函数)但我的打印函数必须是这种类型的函数:
void print (string something){
printf ("hello");
do something with "something" string but whatever;
}
我尝试了所有我发现但没有成功的东西......(我不明白 IRBuiler、createGlobalString/Ptr 和 getOrInsertFunction() 是如何工作的,这一定是我的问题......有人可以帮助我吗?谢谢......
解决方案
检测这种函数调用的方法就像
CallInst* callonFree = CallInst::Create(your_print_fun, {CI->getOperand(0)},"",CI);
通常,您可以尝试将字符串转换为 char*,这样更易于检测。
推荐阅读
- c++ - Visual Studio Release Build 生成需要 Microsoft.VC80.DebugCRT 的可执行文件
- linux - tar 退出代码 123 是否总是意味着空存档?
- android-studio - android studio 3.1 仅在对话框中找不到设备
- python - Split() 发出期货警告
- javascript - jQuery将字符串变成跨越多个实例
- r - 将图像背景添加到 ggplot barplot 以便图像仅在条形图内可见
- maps - 使用搜索功能将谷歌地图添加到后台设置
- javascript - 始终突出显示“TabButton” - (自定义样式)
- powershell - PowerShell:如何取消注册孤立的 WMI 事件
- laravel - 如何在 Laravel 中格式化存储(不是数据库)中的预格式化日期