gcc源代码分析,actualparameterlist ()函数分析

int    printf            (const char *     , ... ) ; 

   printf("Hello, world!\n");

本文是解释实参和形参如何对应的?并且是可变参数的。

hello.c中printf函数就一个参数。下面的 <tree_list 83258

经过actualparameterlist函数形成了第二个tree:<tree_list 83270。

why,本文主要是解决这个问题。


/* Build a function call to function FUNCTION with parameters PARAMS.
   PARAMS is a list--a chain of TREE_LIST nodes--in which the
   TREE_VALUE of each node is a parameter-expression.
   FUNCTION's data type may be a function type or a pointer-to-function.  */

tree
build_function_call (function, params)
     tree function, params;
{
  register tree fntype;
  register tree value_type;
  register tree coerced_params;
  tree name = NULL_TREE;
  tree actualparameterlist ();

/*  debug_tree(params);

 <tree_list 83258

    value <string_cst 84014
        type <array_type 94ef4 type <integer_type 825bc* char>
            BLK
            size <integer_cst 94f40 literal 15
            align 8 size_unit 8 sep_unit 8 symtab 0
            sep <integer_cst 82638 literal permanent 1 domain <integer_type 94ea8>
        static literal "Hello, world!

"

*/


...

  coerced_params = actualparameterlist (TYPE_ARG_TYPES (fntype), params, name);

/* debug_tree(coerced_params);

<tree_list 83270
    value <nop_expr 840d8
        type <pointer_type 9117c type <integer_type 91130* char>
            permanent unsigned SI
            size <integer_cst 8254c literal permanent 4
            align 32 size_unit 8 sep_unit 32 symtab 0
            chain <function_type 912c0>
        literal
        arg 0 <nop_expr 840c0 type <pointer_type 88a44>
            literal
            arg 0 <addr_expr 840a8 type <pointer_type 94f58>
                literal
                arg 0 <string_cst 84014 type <array_type 94ef4>
                    static literal "Hello, world!
"

*/

第一步:

    val = TREE_OPERAND (val, 0);之后

 <string_cst 84014
    type <array_type 94ef4
        type <integer_type 825bc char permanent QI
            size <integer_cst 82638 literal permanent 1
            align 8 size_unit 8 sep_unit 8 symtab 0
            sep <integer_cst 82608 literal permanent -128 precision 8 min <integer_cst 82608 -128>
            max <integer_cst 82620 literal permanent 127
            pointer_to_this <pointer_type 88a44> chain <integer_type 826a8* long int>
        BLK
        size <integer_cst 94f40 literal 15
        align 8 size_unit 8 sep_unit 8 symtab 0 sep <integer_cst 82638 1>
        domain <integer_type 94ea8 SI
            size <integer_cst 8254c literal permanent 4
            align 32 size_unit 8 sep_unit 32 symtab 0
            sep <integer_cst 84048 literal 0 precision 32 min <integer_cst 84048 0>
            max <integer_cst 84078 literal 14
    static literal "Hello, world!
"

第二步:

      val = default_conversion (val);之后
 <nop_expr 840c0
    type <pointer_type 88a44
        type <integer_type 825bc char permanent QI
            size <integer_cst 82638 literal permanent 1
            align 8 size_unit 8 sep_unit 8 symtab 0
            sep <integer_cst 82608 literal permanent -128 precision 8 min <integer_cst 82608 -128>
            max <integer_cst 82620 literal permanent 127
            pointer_to_this <pointer_type 88a44> chain <integer_type 826a8* long int>
        permanent unsigned SI
        size <integer_cst 8254c literal permanent 4
        align 32 size_unit 8 sep_unit 32 symtab 0
        chain <array_type 88a90>
    literal
    arg 0 <addr_expr 840a8
        type <pointer_type 94f58 type <array_type 94ef4>
            unsigned SI size <integer_cst 8254c 4>
            align 32 size_unit 8 sep_unit 32 symtab 0
        literal
        arg 0 <string_cst 84014 type <array_type 94ef4>
            static literal "Hello, world!
"

第三步:

          parmval = convert_for_assignment (type, val, "argument passing");之后:

 <nop_expr 840d8
    type <pointer_type 9117c
        type <integer_type 91130 char readonly permanent QI
            size <integer_cst 82638 literal permanent 1
            align 8 size_unit 8 sep_unit 8 symtab 0
            sep <integer_cst 82608 literal permanent -128 precision 8 min <integer_cst 82608 -128>
            max <integer_cst 82620 literal permanent 127
            pointer_to_this <pointer_type 9117c>
        permanent unsigned SI
        size <integer_cst 8254c literal permanent 4
        align 32 size_unit 8 sep_unit 32 symtab 0
        chain <function_type 912c0>
    literal
    arg 0 <nop_expr 840c0
        type <pointer_type 88a44 type <integer_type 825bc* char>
            permanent unsigned SI size <integer_cst 8254c 4>
            align 32 size_unit 8 sep_unit 32 symtab 0
            chain <array_type 88a90>
        literal
        arg 0 <addr_expr 840a8 type <pointer_type 94f58>
            literal
            arg 0 <string_cst 84014 type <array_type 94ef4>
                static literal "Hello, world!
"

第四步:
      parm = build_tree_list (0, parmval); 之后

 <tree_list 83270
    value <nop_expr 840d8
        type <pointer_type 9117c type <integer_type 91130* char>
            permanent unsigned SI
            size <integer_cst 8254c literal permanent 4
            align 32 size_unit 8 sep_unit 32 symtab 0
            chain <function_type 912c0>
        literal
        arg 0 <nop_expr 840c0 type <pointer_type 88a44>
            literal
            arg 0 <addr_expr 840a8 type <pointer_type 94f58>
                literal
                arg 0 <string_cst 84014 type <array_type 94ef4>
                    static literal "Hello, world!


你可能感兴趣的:(gcc,源代码,分析)