我需要使用gcc plugins打印被调用的程序函数的名称--为此,我创建了一个pass,它将在ssa pass之后调用,我已经启动了插件,我可以使用gimple_stmt_iterator循环它的语句:
int read_calls(){
unsigned i;
const_tree str, op;
basic_block bb;
gimple stmt;
tree fnt;
FOR_EACH_BB_FN(bb, cfun) {
gimple_stmt_iterator gsi;
for (gsi=gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi))
{
stmt = gsi_stmt(gsi);
if (is_gimple_call(stmt)){
const char* name = THE_FUNCTION_I_NEED(stmt);
cerr << " Function : " << name << " is called \n";
}
}
}
return 0;
}如何使用其gimple节点打印被调用函数的名称??我还可以打印其他信息,比如调用它的行号,调用它的函数的名称等等。?
发布于 2015-03-30 14:00:39
我已经找了好几个小时了,答案其实很简单:get_name(tree node).我尝试了很多功能,因为文档很差.我在这里找到的:GCC Middle and Back End API Reference
如您所见,没有关于函数的注释,它退出了我找到的关于gcc的最好的文档,不管怎样,get_name(..)工作得很好,我还没有找到如何打印源代码行
发布于 2015-06-08 18:58:38
我知道三种方法:
1:
tree current_fn_decl = gimple_call_fndecl(stmt);
const char* name = function_name(DECL_STRUCT_FUNCTION(current_fn_decl);2:
const char* name = IDENTIFIER_POINTER(DECL_NAME(current_fn_decl));3:
tree current_fn_decl = gimple_call_fndecl(stmt);
const char* name = get_name(current_fn_decl);https://stackoverflow.com/questions/29346772
复制相似问题