本文主要是分析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,"before store_one_arg \n");
store_one_arg (&args[i], argblock, may_be_alloca);
fprintf(stderr,"after store_one_arg \n ");
}
下面是 store_one_arg ()函数中的相关代码:
static void
store_one_arg (arg, argblock, may_be_alloca)
struct arg_data *arg;
rtx argblock;
int may_be_alloca;
{
register tree pval = arg->tree_value;
int used = 0;
if (TREE_CODE (pval) == ERROR_MARK)
return;
fprintf(stderr,"in store_one_arg debug_tree pval \n");
debug_tree(pval);
...
else if (TYPE_MODE (TREE_TYPE (pval)) != BLKmode)
{
register int size;
rtx tem;
fprintf(stderr,"else if type_mode 1 \n");
/* Argument is a scalar, not entirely passed in registers.
(If part is passed in registers, arg->partial says how much
and emit_push_insn will take care of putting it there.)
Push it, and if its size is less than the
amount of space allocated to it,
also bump stack pointer by the additional space.
Note that in C the default argument promotions
will prevent such mismatches. */
size = GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (pval)));
/* Compute how much space the push instruction will push.
On many machines, pushing a byte will advance the stack
pointer by a halfword. */
#ifdef PUSH_ROUNDING
size = PUSH_ROUNDING (size);
#endif
used = size;
/* Compute how much space the argument should get:
round up to a multiple of the alignment for arguments. */
if (none != FUNCTION_ARG_PADDING (TYPE_MODE (TREE_TYPE (pval)), const0_rtx))
used = (((size + PARM_BOUNDARY / BITS_PER_UNIT - 1)
/ (PARM_BOUNDARY / BITS_PER_UNIT))
* (PARM_BOUNDARY / BITS_PER_UNIT));
tem = arg->value;
if (tem == 0)
{
fprintf(stderr,"else if type_mode 2\n");
tem = expand_expr (pval, 0, VOIDmode, 0);
/* ANSI doesn‘t require a sequence point here,
but PCC has one, so this will avoid some problems. */
fprintf(stderr,"else if type_mode 3\n");
emit_queue ();
}
/* Don‘t allow anything left on stack from computation
of argument to alloca. */
if (may_be_alloca)
do_pending_stack_adjust ();
fprintf(stderr,"else if type_mode 4 \n");
emit_push_insn (tem, TYPE_MODE (TREE_TYPE (pval)), 0, 0,
arg->partial, arg->reg, used - size,
argblock, ARGS_SIZE_RTX (arg->offset));
}
下面是调试结果:
before store_one_arg
in store_one_arg debug_tree pval
<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!
"
else if type_mode 1
else if type_mode 2
expand_expr code = 71
<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!
"
expand_expr code = 71
<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!
"
expand_expr code = 74
<addr_expr 840a8
type <pointer_type 94f58
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>
pointer_to_this <pointer_type 94f58> chain <pointer_type 94f58>
unsigned SI
size <integer_cst 8254c literal permanent 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!
"
expand_expr code = 26
<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
pointer_to_this <pointer_type 94f58> chain <pointer_type 94f58>
static literal "Hello, world!
"
output_constant_def
(symbol_ref:SI ("*LC0"))
(mem:BLK (symbol_ref:SI ("*LC0")))
this this
addr_expr
force_operand 27
end addr_expr
else if type_mode 3
else if type_mode 4
begin emit_push_insn
gen_push_operand
(pre_dec:SI (reg:SI 7))
end gen_push_operand
before emit_move_insn
(mem:SI (pre_dec:SI (reg:SI 7)))
before return emit_insn icode= 14
(set (mem:SI (pre_dec:SI (reg:SI 7)))
(symbol_ref:SI ("*LC0")))
emit_insn
after emit_move_insn
after store_one_arg