forked from NUDT-compiler/nudt-compiler-cpp
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.
49 lines
2.0 KiB
49 lines
2.0 KiB
# 计算 callee_stack_arg 帧槽的正确偏移
|
|
|
|
num_params = 390
|
|
num_reg_params = 8
|
|
|
|
# 模拟帧槽分配
|
|
frame_slots = []
|
|
for param_idx in range(num_params):
|
|
# 创建参数帧槽
|
|
frame_slots.append({"type": "param", "param_idx": param_idx, "is_stack_arg": False})
|
|
|
|
# 如果参数在栈上,创建 callee_stack_arg 帧槽
|
|
if param_idx >= num_reg_params:
|
|
frame_slots.append({"type": "callee_stack_arg", "param_idx": param_idx, "is_stack_arg": True})
|
|
|
|
# 计算 callee_stack_arg 帧槽的初始偏移
|
|
stack_arg_cursor = 0
|
|
for i, slot in enumerate(frame_slots):
|
|
if slot["is_stack_arg"]:
|
|
slot["initial_offset"] = stack_arg_cursor
|
|
stack_arg_cursor += 8
|
|
|
|
# 找到第 222 个参数的 callee_stack_arg 帧槽
|
|
param_idx_222 = 221 # 从 0 开始
|
|
for i, slot in enumerate(frame_slots):
|
|
if slot["type"] == "callee_stack_arg" and slot["param_idx"] == param_idx_222:
|
|
print(f"第 222 个参数的 callee_stack_arg 帧槽索引: {i}")
|
|
print(f"初始偏移: {slot['initial_offset']}")
|
|
print(f"main 函数中第 222 个参数的栈上偏移量: {(222-8-1) * 8}")
|
|
break
|
|
|
|
# 检查第 9 个参数的 callee_stack_arg 帧槽
|
|
param_idx_9 = 8 # 从 0 开始
|
|
for i, slot in enumerate(frame_slots):
|
|
if slot["type"] == "callee_stack_arg" and slot["param_idx"] == param_idx_9:
|
|
print(f"\n第 9 个参数的 callee_stack_arg 帧槽索引: {i}")
|
|
print(f"初始偏移: {slot['initial_offset']}")
|
|
print(f"main 函数中第 9 个参数的栈上偏移量: {(9-8-1) * 8}")
|
|
break
|
|
|
|
# 检查第 10 个参数的 callee_stack_arg 帧槽
|
|
param_idx_10 = 9 # 从 0 开始
|
|
for i, slot in enumerate(frame_slots):
|
|
if slot["type"] == "callee_stack_arg" and slot["param_idx"] == param_idx_10:
|
|
print(f"\n第 10 个参数的 callee_stack_arg 帧槽索引: {i}")
|
|
print(f"初始偏移: {slot['initial_offset']}")
|
|
print(f"main 函数中第 10 个参数的栈上偏移量: {(10-8-1) * 8}")
|
|
break
|