优化ir
This commit is contained in:
parent
e6bf9ecd12
commit
de2190c211
@ -31,17 +31,17 @@ public final class ProgramBuilder {
|
|||||||
public IRProgram buildProgram(List<Node> roots) {
|
public IRProgram buildProgram(List<Node> roots) {
|
||||||
IRProgram prog = new IRProgram();
|
IRProgram prog = new IRProgram();
|
||||||
for (Node n : roots) {
|
for (Node n : roots) {
|
||||||
if (n instanceof ModuleNode m) {
|
switch (n) {
|
||||||
// 模块节点:将模块内的所有函数加入程序
|
case ModuleNode m ->
|
||||||
m.functions().forEach(f -> prog.add(buildFunction(f)));
|
// 模块节点:将模块内的所有函数加入程序
|
||||||
} else if (n instanceof FunctionNode f) {
|
m.functions().forEach(f -> prog.add(buildFunction(f)));
|
||||||
// 顶层函数节点
|
case FunctionNode f ->
|
||||||
prog.add(buildFunction(f));
|
// 顶层函数节点
|
||||||
} else if (n instanceof StatementNode s) {
|
prog.add(buildFunction(f));
|
||||||
// 顶层脚本语句,包装为 _start 函数
|
case StatementNode s ->
|
||||||
prog.add(buildFunction(wrapTopLevel(s)));
|
// 顶层脚本语句,包装为 _start 函数
|
||||||
} else {
|
prog.add(buildFunction(wrapTopLevel(s)));
|
||||||
throw new IllegalStateException("Unsupported top-level node: " + n);
|
case null, default -> throw new IllegalStateException("Unsupported top-level node: " + n);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return prog;
|
return prog;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user