Retrieve GENERIC function body in plugin

2012-10-24 Thread Peter Colberg
Hi,

I am writing a plugin to analyse C code by walking the AST in
GENERIC format, and have trouble getting the body of function
declarations.

The plugin registers a callback to PLUGIN_FINISH_UNIT, and therein
retrieves function_decl nodes of the current translation unit by
iterating over cgraph_nodes. However, getting the function body
using DECL_SAVED_TREE(node) always returns NULL.

I verified the output of -fdump-translation-unit, and there the
function body is available, as output by DECL_SAVED_TREE in
tree-dump.c. Am I hooking into the wrong plugin event, or is
there something else that I am missing?

Thanks,
Peter


Re: Retrieve GENERIC function body in plugin

2012-10-24 Thread Peter Colberg
On Wed, Oct 24, 2012 at 12:55:23PM -0400, Peter Colberg wrote:
> The plugin registers a callback to PLUGIN_FINISH_UNIT, and therein
> retrieves function_decl nodes of the current translation unit by
> iterating over cgraph_nodes. However, getting the function body
> using DECL_SAVED_TREE(node) always returns NULL.

Never mind, I figured out a solution. One may register a callback
for PLUGIN_PRE_GENERICIZE, which receives a function declaration
as the first argument. This declaration contains the body.

Peter


Rename IDENTIFIER_NODE in a plugin

2012-10-30 Thread Peter Colberg
Hello,

I am in the process of writing a plugin that parses the header files
of a C library using GCC, walks the AST in GENERIC format, and
translates to C code for a foreign function interface (for LuaJIT).

Many libraries internally use different C type names than those part
of the API, using the C preprocessor for name mangling. I would like
to rename certain tree nodes back to their known API name, before
generating the C output code.

How does one reassign the IDENTIFIER_POINTER of an IDENTIFIER_NODE?

How is the memory of the identifier string allocated and freed?

I have looked at build_string() in tree.c, but this function seems
to apply only to STRING_CST nodes. There are also the functions
make_node_stat() and build*_stat(), but I cannot find any call
to these functions with tree code IDENTIFIER_NODE.

I would be thankful for any pointers.

Peter


Re: Rename IDENTIFIER_NODE in a plugin

2012-10-30 Thread Peter Colberg
On Tue, Oct 30, 2012 at 01:39:59PM -0400, Peter Colberg wrote:
> How does one reassign the IDENTIFIER_POINTER of an IDENTIFIER_NODE?

My question does not make sense, since identifiers are immutable.

I found an alternative solution used throughout the GCC code:

  DECL_NAME(decl) = get_identifier(name)

get_identifier is mentioned in the documentation as well…

http://gcc.gnu.org/onlinedocs/gccint/Identifiers.html#Identifiers

Peter


[ANN] gcc-lua: Lua plugin for the GNU Compiler Collection

2012-10-31 Thread Peter Colberg
Hi,

It is my pleasure to announce gcc-lua:

gcc‑lua extends the GNU Compiler Collection with the ability to run Lua
scripts. The plugin provides an interface to register callback functions for
plugin events, and inspect the abstract syntax tree of a translation unit. The
plugin is useful for static C code analysis. gcc‑lua supports GCC 4.6 or 4.7,
and, Lua 5.1 or 5.2, or LuaJIT.

http://colberg.org/gcc-lua/

Regards,
Peter