davidmalcolm / gcc-python-plugin

GCC plugin that embeds CPython inside the compiler
GNU General Public License v3.0
199 stars 58 forks source link

FunctionDecl should have 'initial' attribute #69

Open davidmalcolm opened 7 years ago

davidmalcolm commented 7 years ago

Before there is a CFG, the body of a function is in the function decl's DECL_INITIAL, as a block. This field should be exposed to Python.

This patch adds the attribute, but isn't complete; no tests or docs.

diff --git a/generate-tree-c.py b/generate-tree-c.py index 2829b9e..64efaa7 100644 --- a/generate-tree-c.py +++ b/generate-tree-c.py @@ -497,6 +497,9 @@ def generate_tree_code_classes(): add_simple_getter('callgraph_node', 'gcc_python_make_wrapper_cgraph_node(cgraph_get_n 'The gcc.CallgraphNode for this function declarat

davidmalcolm commented 7 years ago

Imported from trac issue 29. Created by tromey on 2012-01-09T09:43:57, last modified: 2012-01-10T11:40:44

davidmalcolm commented 7 years ago

Trac comment by tromey on 2012-01-09 10:30:43:

Actually, I am not sure this is correct. I think it should be DECL_SAVED_TREE instead, or perhaps in addition to. Apparently my knowledge of gcc is outdated :}

davidmalcolm commented 7 years ago

Trac comment by tromey on 2012-01-10 11:40:44:

Sorry, I was really confused.

After gimplification you want access to the gimple body. So, I think there should be a way to access gimple_body(fndecl).

I just moved my pass to after the CFG is made, and that worked for me. I'm not sure of a specific case where it is useful to run earlier. So another option would be to WONTFIX this bug.