[gimplefe] Patch for recognizing function declarations
Diego Novillo
dnovillo@google.com
Thu Aug 2 17:06:00 GMT 2012
On Tue, Jul 31, 2012 at 11:06 AM, Sandeep Soni <soni.sandeepb@gmail.com> wrote:
> +/* The syntax of a function declaration is as follows:
> +
> + FUNCTION_DECL<Name, Type, Parms>
> + <
> + function body
> + >
> +
> + Here, each of the PARMS in itself is a parameter declaration similar to a
> + variable declaration, TYPE is the type of the variable that this
> + function returns and FUNCTION BODY is the series of statements that define
> + the beahavior of the function.
> +
> + Following are some of the examples for which the syntax of the function
> + declarations are described.
> +
> + 1. C-like function as
> + void foo (int first, float second)
> + {
> + first = second;
> + }
> +
> + The corresponding gimple syntax is:
> + FUNCTION_DECL <foo, VOID_TYPE,
> + PARM_DECL<first, INTEGER_TYPE<4>>,
> + PARM_DECL<second, REAL_TYPE<4>>>
> + <
> + GIMPLE_ASSIGN <PARM_DECL,first, second, NULL>
> + >
> +
> + 2. C-like function as
> + int foo (int first, float second)
> + {
> + int local_first;
> + float local_second;
> +
> + local_first = first;
> + local_second = second;
> +
> + return local_first;
> + }
> +
> + The corresponding gimple syntax is:
> + FUNCTION_DECL <foo, INTEGER_TYPE<4>,
> + PARM_DECL<first, INTEGER_TYPE<4>>,
> + PARM_DECL<second, REAL_TYPE<4>>>
> + <
> + VAR_DECL <local_first, INTEGER_TYPE<4>>
> + VAR_DECL <local_second, REAL_TYPE<4>>
> + VAR_DECL <return_var, INTEGER_TYPE<4>>
> +
> + gimple_assign <parm_decl, local_first, first, NULL>
> + gimple_assign <parm_decl, local_second, second, NULL>
> + gimple_assign <parm_decl, return_var, first, NULL>
> + gimple_return <return_var>
> + >
> +
> + Note: 1) The syntax closely mimics the -fdump-tree-gimple-raw option.
> + 2) The function declaration tuple needs to be checked against the
> + call of the function for order and the number of arguments.
> + 3) A symbol table entry for the function should be made. The
> + variables defined within the function should be made to have
> + function scope. */
Nice. Thanks for this documentation.
> + next_token = gl_consume_token (parser->lexer);
> + while (!gl_at_eof(parser->lexer))
Space before '('.
> + {
> + if (next_token->type == CPP_COMMA)
> + {
> + next_token = gl_consume_token (parser->lexer);
> + if (gl_tree_code_for_token (next_token) == PARM_DECL)
> + gp_parse_parm_decl (parser);
> + else
> + error_at (next_token->location,
> + "Unsupported declaration of parameters");
> + else if (next_token->type == CPP_GREATER)
> + break;
> + }
Could you factor this into its own function? You will likely need to
parse other comma-separated lists.
Also, please add some test cases with the patch.
Diego.
More information about the Gcc-patches
mailing list