在万向节中插入函数调用

Inserting function calls in the gimple

本文关键字:函数调用 插入 万向节      更新时间:2023-10-16

我在弄清楚如何做下一件事时遇到了问题。

我有以下代码:

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