插入全局变量声明whit一个gcc插件 [英] Insert global variable declaration whit a gcc plugin

查看:183
本文介绍了插入全局变量声明whit一个gcc插件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道是否可以用gcc插件插入一个全局变量声明。例如,如果我有以下代码:

I would know if it's possible to insert a global variable declaration with a gcc plugin. For example if I got de following code:

test.c:

int main(void) {
  return 0;
}

,我想将其转换为:

int fake_var;

int main(void) {
  return 0;
}

这是可能吗?
如果可能,通过我怎么办?

Is that possible? If it's possible, in wich pass a how can I do it?

推荐答案

我想你会想看看varpool.c中的varpool_add_new_variable()。你应该能够传递一个类型为VAR_DECL的声明。同样,看看add_new_static_var(),但我认为前者是你想要的,因为它是专门允许在中间/后端声明全局变量。

I think you'll want to take a look at varpool_add_new_variable() in varpool.c. You should be able to pass a declaration built with type VAR_DECL to it. Similarly, take a look at add_new_static_var(), but I think the former is what you want, as it was added specifically to allow declaring globals in the middle/back end.

这篇关于插入全局变量声明whit一个gcc插件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆