gcc-python-plugin icon indicating copy to clipboard operation
gcc-python-plugin copied to clipboard

FunctionDecl should have 'initial' attribute

Open davidmalcolm opened this issue 8 years ago • 3 comments

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

  •        add_simple_getter('initial',
    
  •                          'gcc_python_make_wrapper_tree(DECL_INITIAL(self->
    
  •                          "The body of this function as a gcc.Block, or Non
    
           for attr in ('public', 'private', 'protected', 'static'):
               getsettable.add_simple_getter(cu,
    

davidmalcolm avatar Feb 09 '17 20:02 davidmalcolm

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

davidmalcolm avatar Feb 09 '17 20:02 davidmalcolm

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 avatar Feb 09 '17 20:02 davidmalcolm

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.

davidmalcolm avatar Feb 09 '17 20:02 davidmalcolm