用gcc插件插入全局变量声明 [英] Insert global variable declaration with a gcc plugin

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

问题描述

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

I would like to know if it's possible to insert a global variable declaration with a gcc plugin. For example if I have the 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 which pass and 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.

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

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