gcc源代码分析,在expand_call ()函数 和expand_expr_stmt ()函数的开始处加入debug_tree ()函数

对于expand_call函数来说最主要的参数就是exp这个tree树,

打印出来之后我们终于看到了printf和Hello,world!

expand_call

<call_expr 840f0

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>

volatile

arg 0 <addr_expr 84090

type <pointer_type 98f48 type <function_type 956e8>

permanent unsigned SI size <integer_cst 8254c 4>

align 32 size_unit 8 sep_unit 32 symtab 0

arg 0 <function_decl 95740 printf type <function_type 956e8>

external public permanent used QI file /usr/include/stdio.h line 214

align 1 size_unit 1 offset 0 chain <function_decl 954d8 ungetc>

arg 1 <tree_list 83270

value <nop_expr 840d8 type <pointer_type 9117c>

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!

"(nil)

下面是在 函数开始处加入debug_tree ()函数的结果

expand_expr_stmt

<call_expr 840f0

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>

volatile

arg 0 <addr_expr 84090

type <pointer_type 98f48 type <function_type 956e8>

permanent unsigned SI size <integer_cst 8254c 4>

align 32 size_unit 8 sep_unit 32 symtab 0

arg 0 <function_decl 95740 printf type <function_type 956e8>

external public permanent used QI file /usr/include/stdio.h line 214

align 1 size_unit 1 offset 0 chain <function_decl 954d8 ungetc>

arg 1 <tree_list 83270

value <nop_expr 840d8 type <pointer_type 9117c>

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!

"(nil)

在c-parse.tab.c文件里面的stmt的定义出有对expand_expr_stmt()的调用,调用关系终于明朗了!

stmt:

compstmt    {}

| expr ‘;‘

{ emit_line_note (input_filename, lineno);

/* Do default conversion if safe and possibly important,

in case within ({...}).  */

if ((TREE_CODE (TREE_TYPE ($1)) == ARRAY_TYPE

&& lvalue_p ($1))

|| TREE_CODE (TREE_TYPE ($1)) == FUNCTION_TYPE)

$1 = default_conversion ($1);

expand_expr_stmt ($1);

clear_momentary (); }

时间: 2024-08-28 11:56:33

gcc源代码分析,在expand_call ()函数 和expand_expr_stmt ()函数的开始处加入debug_tree ()函数的相关文章

gcc源代码分析,expand_call()函数和printf(&quot;Hello, world!\n&quot;);的关系

expand_call()函数在expr.c文件中. 下面是expand_call()函数的主要调试结果,记录之. 主要是加入了debug_tree()函数和debug_rtx()函数. debug_tree()函数加入到了expand_expr()函数的开始. debug_rtx()函数加入到了gen_rtx()函数的结束处. emit_call_1()函数是何时调用的也能看出.emit_call_insn()是何时调用的也能看出. 主要的调试目的是expand_call()函数是如何生成rt

gcc源代码分析,expand_call ()函数分析第五部分,store_one_arg ()函数

本文主要是分析store_one_arg ()函数和expand_expr ()的关系来说明如何处理 函数的参数.printf("Hello, world!\n");中的"Hello, world!\n"这个字符串常量的! expand_call () 函数中的相关代码: if (args[i].reg == 0 && TYPE_SIZE (TREE_TYPE (args[i].tree_value)) != 0) { fprintf(stderr,

gcc源代码分析,expand_call()函数第三部分

(insn_list 6 (nil)) (insn_list 2 (insn_list 6 (nil))) (sequence[ ] ) (reg:SI 0) (const_int 4) 这次是解释这5条rtx的产生过程 相关的代码片段: /* Mark all register-parms as living through the call.  */ start_sequence (); for (i = 0; i < num_actuals; i++) if (args[i].reg !=

gcc源代码分析,expand_call ()函数第四部分,emit_call_1 ()函数

本文是为了解释下面这4个rtx是如何产生的,和emit_call_1 ()函数有关. (const_int 4) (mem:QI (symbol_ref/v:SI ("printf"))) (call (mem:QI (symbol_ref/v:SI ("printf"))) (const_int 4)) (set (reg:SI 0) (call (mem:QI (symbol_ref/v:SI ("printf"))) (const_int

gcc源代码分析,debug_tree()函数,又一利器啊

gcc源代码分析,debug_rtx()函数,利器啊 print-tree.c #include "config.h" #include "tree.h" #include <stdio.h> /* Names of tree components. Used for printing out the tree and error messages.  */ #define DEFTREECODE(SYM, NAME, TYPE, LEN) NAME,

gcc源代码分析的方法【总结】

看gcc-1.40有段时间了,14年左右看了一段时间,15年左右看了一段时间. 现在可以说基本上明白了gcc的大部分代码. 如果说能快速的明白其中的原理,总结我看代码的方法捷径我列举以下几条. 第一,gcc版本低,这是成功的前提,也是一条捷径. 第二,分析最基本的hello.c文件,就一条函数调用,但是已经足够. 第三,发现了debug_rtx ()函数和debug_tree ()函数.这两个函数可以说是看懂gcc的唯一的两把钥匙! 第四,思路正确,expand_call()如何产生各种rtx的

gcc源代码分析,debug_tree()函数的利用

tree.def 中第0x3d个元素是 DEFTREECODE (CALL_EXPR, "call_expr", "e", 3) 下面是debug_tree()函数的结果,可以看出expand_expr()函数到gen_rtx()函数的调用过程! expand_expr code = 3d <call_expr 840f0 type <integer_type 824d0 int permanent SI size <integer_cst 825

gcc源代码分析gen_push_operand ()函数和emit_move_insn ()函数

如何生成下面红色的3个指令? 和gen_push_operand ()函数和emit_move_insn ()函数有关,他们都在expand_call()函数中被调用. 具体位置: rtx addr; #ifdef PUSH_ROUNDING if (args_addr == 0) addr = gen_push_operand (); else #endif if (GET_CODE (args_so_far) == CONST_INT) addr = memory_address (mode

gcc源代码分析,finish_decl ()函数和push_parm_decl ()函数分析

parms: parm { push_parm_decl ($1); } /* This is what appears inside the parens in a function declarator. Is value is represented in the format that grokdeclarator expects.  */ parmlist_2:  /* empty */ { $$ = get_parm_info (0); } | parms { $$ = get_pa