feat: IR函数参数增加类型显示
This commit is contained in:
parent
00f73ecb47
commit
92bd94a563
@ -57,7 +57,7 @@ public class FunctionBuilder {
|
||||
for (ParameterNode p : functionNode.parameters()) {
|
||||
IRVirtualRegister reg = irFunction.newRegister(); // 新寄存器
|
||||
irContext.getScope().declare(p.name(), p.type(), reg); // 变量名→寄存器绑定
|
||||
irFunction.addParameter(reg); // 添加到函数参数列表
|
||||
irFunction.addParameter(reg, p.type()); // 添加到函数参数列表
|
||||
}
|
||||
|
||||
// 3) 生成函数体 IR: 遍历每条语句,逐一转化
|
||||
|
||||
@ -35,6 +35,11 @@ public class IRFunction {
|
||||
*/
|
||||
private final List<IRVirtualRegister> parameters = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* 正式参数所对应的类型,按声明顺序排列。
|
||||
*/
|
||||
private final List<String> parametersType = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* 构造一个具有指定名称的 IRFunction 实例。
|
||||
*
|
||||
@ -61,13 +66,15 @@ public class IRFunction {
|
||||
* </p>
|
||||
*
|
||||
* @param vr 表示函数某个参数的虚拟寄存器
|
||||
* @param type 表示函数某个参数的类型
|
||||
*/
|
||||
public void addParameter(IRVirtualRegister vr) {
|
||||
public void addParameter(IRVirtualRegister vr, String type) {
|
||||
parameters.add(vr);
|
||||
parametersType.add(type);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取函数正式参数的只读列表。
|
||||
* 获取函数正式参数的虚拟寄存器只读列表。
|
||||
*
|
||||
* @return 按声明顺序排列的虚拟寄存器列表
|
||||
*/
|
||||
@ -75,6 +82,15 @@ public class IRFunction {
|
||||
return List.copyOf(parameters);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取函数正式参数的类型只读列表。
|
||||
*
|
||||
* @return 按声明顺序排列的类型列表
|
||||
*/
|
||||
public List<String> parametersType() {
|
||||
return List.copyOf(parametersType);
|
||||
}
|
||||
|
||||
/**
|
||||
* 向函数体末尾追加一条 IR 指令。
|
||||
*
|
||||
@ -130,6 +146,7 @@ public class IRFunction {
|
||||
.append('(');
|
||||
for (int i = 0; i < parameters.size(); i++) {
|
||||
sb.append(parameters.get(i));
|
||||
sb.append(": ").append(parametersType.get(i));
|
||||
if (i < parameters.size() - 1) {
|
||||
sb.append(", ");
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user