You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
nudt-compiler-cpp/test_tmp/debug_frame3.py

128 lines
3.8 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

# 重新分析帧槽创建顺序
# 在 LowerFunctionParams 中:
# - 前8个参数创建参数帧槽CreateFrameIndex
# - 第9个及以后的参数创建参数帧槽+ 创建arg_slotCreateCalleeStackArgFrameIndex
num_params = 500
# 模拟帧槽创建
slots = []
for i in range(num_params):
if i < 8:
# 前8个参数只创建参数帧槽
slots.append(('param', i, False, False)) # (type, index, is_stack_arg, is_callee_stack_arg)
else:
# 第9个及以后的参数创建参数帧槽和arg_slot
slots.append(('param', i, False, False)) # 参数帧槽
slots.append(('arg_slot', i, True, True)) # arg_slot
# 然后是alloca帧槽
num_alloca = 500
for i in range(num_alloca):
slots.append(('alloca', num_params + i, False, False))
# 然后是load帧槽
slots.append(('load', num_params + num_alloca, False, False))
print(f"总帧槽数: {len(slots)}")
# 计算偏移量
local_cursor = 0
stack_arg_cursor = 0
for slot_type, index, is_stack_arg, is_callee_stack_arg in slots:
if is_stack_arg:
offset = stack_arg_cursor
stack_arg_cursor += 8
else:
local_cursor = ((local_cursor + 4 - 1) // 4) * 4
local_cursor += 4
offset = -local_cursor
# 计算local_size
local_size = ((local_cursor + 16 - 1) // 16) * 16
print(f"local_cursor = {local_cursor}")
print(f"local_size = {local_size}")
# 计算sp_offset_base
sp_offset_base = local_size + 16
print(f"sp_offset_base = {sp_offset_base}")
# 找到第500个参数的相关帧槽
print("\n第500个参数的相关帧槽:")
param_slot_idx = None
arg_slot_idx = None
for i, (slot_type, index, is_stack_arg, is_callee_stack_arg) in enumerate(slots):
if slot_type == 'param' and index == 499:
param_slot_idx = i
if slot_type == 'arg_slot' and index == 499:
arg_slot_idx = i
print(f" 参数帧槽索引: {param_slot_idx}")
print(f" arg_slot索引: {arg_slot_idx}")
# 计算这些帧槽的偏移量
local_cursor = 0
stack_arg_cursor = 0
for i, (slot_type, index, is_stack_arg, is_callee_stack_arg) in enumerate(slots):
if is_stack_arg:
offset = stack_arg_cursor
stack_arg_cursor += 8
else:
local_cursor = ((local_cursor + 4 - 1) // 4) * 4
local_cursor += 4
offset = -local_cursor
if i == param_slot_idx:
print(f" 参数帧槽: offset = {offset}")
if i == arg_slot_idx:
final_offset = sp_offset_base + offset
print(f" arg_slot: offset = {final_offset} (原offset = {offset})")
# 找到第500个alloca帧槽
print("\n第500个alloca帧槽:")
alloca_slot_idx = None
for i, (slot_type, index, is_stack_arg, is_callee_stack_arg) in enumerate(slots):
if slot_type == 'alloca' and index == num_params + 499:
alloca_slot_idx = i
break
print(f" alloca帧槽索引: {alloca_slot_idx}")
# 计算偏移量
local_cursor = 0
stack_arg_cursor = 0
for i, (slot_type, index, is_stack_arg, is_callee_stack_arg) in enumerate(slots):
if is_stack_arg:
offset = stack_arg_cursor
stack_arg_cursor += 8
else:
local_cursor = ((local_cursor + 4 - 1) // 4) * 4
local_cursor += 4
offset = -local_cursor
if i == alloca_slot_idx:
print(f" alloca帧槽: offset = {offset}")
break
# 找到load帧槽
print("\nload帧槽:")
load_slot_idx = len(slots) - 1
print(f" load帧槽索引: {load_slot_idx}")
# 计算偏移量
local_cursor = 0
stack_arg_cursor = 0
for i, (slot_type, index, is_stack_arg, is_callee_stack_arg) in enumerate(slots):
if is_stack_arg:
offset = stack_arg_cursor
stack_arg_cursor += 8
else:
local_cursor = ((local_cursor + 4 - 1) // 4) * 4
local_cursor += 4
offset = -local_cursor
if i == load_slot_idx:
print(f" load帧槽: offset = {offset}")
break