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

40 篇文章 3 订阅
16 篇文章 5 订阅


      function = build (ADDR_EXPR, build_pointer_type (TREE_TYPE (function)),
            function);

继续分析上篇文章的这句。



/* Constructors for pointer, array and function types.
   (RECORD_TYPE, UNION_TYPE and ENUMERAL_TYPE nodes are
   constructed by language-dependent code, not here.)  */

/* Construct, lay out and return the type of pointers to TO_TYPE.
   If such a type has already been constructed, reuse it.  */

tree
build_pointer_type (to_type)
     tree to_type;
{
  register tree t = TYPE_POINTER_TO (to_type);

/* 下面是debug_tree(to_type);的结果

 <function_type 956e8
    type <integer_type 824d0 int permanent SI
        size <integer_cst 8254c literal permanent 4
        align 32 size_unit 8 sep_unit 32 symtab 0
        sep <integer_cst 8251c literal permanent -2147483648 precision 32 min <integer_cst 8251c -2147483648>
        max <integer_cst 82534 literal permanent 2147483647
        pointer_to_this <pointer_type 88b4c> chain <integer_type 825bc* char>
    permanent EP
    size <integer_cst 82dd8 type <integer_type 82848* unsigned int> literal permanent 8
    align 32 size_unit 8 sep_unit 0 symtab 0
    arg-types <tree_list 95698 permanent
        value <pointer_type 9117c type <integer_type 91130* char>
            permanent unsigned SI size <integer_cst 8254c 4>
            align 32 size_unit 8 sep_unit 32 symtab 0
            chain <function_type 912c0>
    chain <function_type 959b0>
*/


  register struct obstack *ambient_obstack = current_obstack;
  register struct obstack *ambient_saveable_obstack = saveable_obstack;

  /* First, if we already have a type for pointers to TO_TYPE, use it.  */

  if (t)
    return t;

  /* We need a new one.  If TO_TYPE is permanent, make this permanent too.  */
  if (TREE_PERMANENT (to_type))
    {
      current_obstack = &permanent_obstack;
      saveable_obstack = &permanent_obstack;
    }

  t = make_node (POINTER_TYPE);

/*下面是debug_tree(t);的结果

 <pointer_type 98f48 permanent VOID
    align 1 size_unit 1 sep_unit 0 symtab 0
*/

  TREE_TYPE (t) = to_type;

/*下面是debug_tree(t);的结果

 <pointer_type 98f48
    type <function_type 956e8
        type <integer_type 824d0 int permanent SI
            size <integer_cst 8254c literal permanent 4
            align 32 size_unit 8 sep_unit 32 symtab 0
            sep <integer_cst 8251c literal permanent -2147483648 precision 32 min <integer_cst 8251c -2147483648>
            max <integer_cst 82534 literal permanent 2147483647
            pointer_to_this <pointer_type 88b4c> chain <integer_type 825bc* char>
        permanent EP
        size <integer_cst 82dd8 literal permanent 8
        align 32 size_unit 8 sep_unit 0 symtab 0
        arg-types <tree_list 95698 permanent value <pointer_type 9117c>
        chain <function_type 959b0>

    permanent VOID
    align 1 size_unit 1 sep_unit 0 symtab 0


*/
  /* Record this type as the pointer to TO_TYPE.  */
  TYPE_POINTER_TO (to_type) = t;

/*

 <function_type 956e8
    type <integer_type 824d0 int permanent SI
        size <integer_cst 8254c literal permanent 4
        align 32 size_unit 8 sep_unit 32 symtab 0
        sep <integer_cst 8251c literal permanent -2147483648 precision 32 min <integer_cst 8251c -2147483648>
        max <integer_cst 82534 literal permanent 2147483647
        pointer_to_this <pointer_type 88b4c> chain <integer_type 825bc* char>
    permanent EP
    size <integer_cst 82dd8 type <integer_type 82848* unsigned int> literal permanent 8
    align 32 size_unit 8 sep_unit 0 symtab 0
    arg-types <tree_list 95698 permanent
        value <pointer_type 9117c type <integer_type 91130* char>
            permanent unsigned SI size <integer_cst 8254c 4>
            align 32 size_unit 8 sep_unit 32 symtab 0
            chain <function_type 912c0>
    pointer_to_this <pointer_type 98f48> chain <function_type 959b0>

*/



  /* Lay out the type.  This function has many callers that are concerned
     with expression-construction, and this simplifies them all.
     Also, it guarantees the TYPE_SIZE is permanent if the type is.  */
  layout_type (t);

  current_obstack = ambient_obstack;
  saveable_obstack = ambient_saveable_obstack;
  return t;

}


  layout_type ()函数部分代码:

    case POINTER_TYPE:
    case REFERENCE_TYPE:
      TYPE_MODE (type) = Pmode;
      TYPE_SIZE (type) = build_int (POINTER_SIZE / BITS_PER_UNIT);
      TYPE_SIZE_UNIT (type) = BITS_PER_UNIT;
      TYPE_ALIGN (type) = POINTER_BOUNDARY;
      TREE_UNSIGNED (type) = 1;
      TYPE_PRECISION (type) = POINTER_SIZE;
      break;

 下面是 layout_type ()函数之后debug_tree(t);之后的结果:

 <pointer_type 98f48
    type <function_type 956e8
        type <integer_type 824d0 int permanent SI
            size <integer_cst 8254c literal permanent 4
            align 32 size_unit 8 sep_unit 32 symtab 0
            sep <integer_cst 8251c literal permanent -2147483648 precision 32 min <integer_cst 8251c -2147483648>
            max <integer_cst 82534 literal permanent 2147483647
            pointer_to_this <pointer_type 88b4c> chain <integer_type 825bc* char>
        permanent EP
        size <integer_cst 82dd8 literal permanent 8
        align 32 size_unit 8 sep_unit 0 symtab 0
        arg-types <tree_list 95698 permanent value <pointer_type 9117c>
        pointer_to_this <pointer_type 98f48> chain <function_type 959b0>
    permanent unsigned SI size <integer_cst 8254c 4>
    align 32 size_unit 8 sep_unit 32 symtab 0



  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值