在万向节中插入函数调用
Inserting function calls in the gimple
我在弄清楚如何做下一件事时遇到了问题。
我有以下代码:
test.cpp
#include <stdio.h>
void
function(void) {printf("Hellow ");}
int main(void) {
printf("Worldn");
return 0;
}
我想把它变成下一个:
#include <stdio.h>
void
function(void) {printf("Hellow ");}
int main(void) {
function();
printf("Worldn");
return 0;
}
使用gcc插件。
在我的插件中不起作用的代码是这样的:
...
tree function_fn;
tree function_fn_type;
function_fn_type=build_function_type_list(void_type_node, void_type_node, NULL_TREE);
function_fn = build_fn_decl ("function", function_fn_type);
gimple call = gimple_build_call (funcion_fn, 0);
gsi_insert_before (&gsi, call, GSI_NEW_STMT);
...
然后,当我用插件编译test.cpp时,我会收到下一条错误消息:
/tmp/cc2VRszt.o:在函数main':
test.cpp:(.text+0x60): Undefined reference to
函数'中
有人能帮我吗?
您正在构建一个函数声明,并根据声明插入对函数的调用,但除非您在链接到的另一个转换单元中定义了该函数,否则它将无法解析。如果你想让一个插件像你的例子一样在同一个翻译单元中插入一个定义,这个前端开发人员指南将是一个很好的开始:
http://www.tldp.org/HOWTO/GCC-Frontend-HOWTO-7.html
相关文章:
- 函数调用中参数的顺序重要吗
- 基于另一个成员参数将函数调用从类传递给它的一个成员
- 变量没有改变?通过向量的函数调用
- 在两个类中共享相同的函数调用,并在不需要时避免空实例化
- 是否有C++编译器选项允许激进地删除所有函数调用,并将参数传递给具有空体的函数
- 我知道函数调用中存在歧义.有没有办法调用foo()函数
- 模板函数调用
- 获取从C++中同一类中的构造函数调用的方法返回的值
- 析构函数调用
- 成员函数调用和C++对象模型
- 使用共享指针的函数调用,其对象应为 const
- C++:编译时检查匹配的函数调用对?
- 函数调用C++中的参数太少
- 来自 DLL 的函数调用 [表观调用的括号前面的表达式必须具有(指向-)函数类型]
- 返回指向对象的指针的函数调用是否为 prvalue?
- 当我尝试在 Main 中调用插入函数时,它不是取数字?
- 为什么我不能在插入的函数调用中直接使用返回的指针作为参数
- 如何在LLVM传递中的模块末尾插入函数调用?
- 在万向节中插入函数调用
- 在向std::unordered_map插入元素时避免不必要的构造函数调用