优化ir
This commit is contained in:
parent
de2190c211
commit
2884159f3e
@ -1,6 +1,9 @@
|
||||
package org.jcnc.snow.compiler.cli;
|
||||
|
||||
import org.jcnc.snow.compiler.backend.RegisterAllocator;
|
||||
import org.jcnc.snow.compiler.backend.VMCodeGenerator;
|
||||
import org.jcnc.snow.compiler.ir.builder.ProgramBuilder;
|
||||
import org.jcnc.snow.compiler.ir.core.IRFunction;
|
||||
import org.jcnc.snow.compiler.ir.core.IRProgram;
|
||||
import org.jcnc.snow.compiler.lexer.core.LexerEngine;
|
||||
import org.jcnc.snow.compiler.lexer.token.Token;
|
||||
@ -9,6 +12,8 @@ import org.jcnc.snow.compiler.parser.context.ParserContext;
|
||||
import org.jcnc.snow.compiler.parser.core.ParserEngine;
|
||||
import org.jcnc.snow.compiler.parser.function.ASTPrinter;
|
||||
import org.jcnc.snow.compiler.semantic.core.SemanticAnalyzerRunner;
|
||||
import org.jcnc.snow.vm.engine.VMMode;
|
||||
import org.jcnc.snow.vm.engine.VirtualMachineEngine;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
@ -56,27 +61,27 @@ public class SnowCompiler {
|
||||
|
||||
|
||||
/* 5. 后端:寄存器分配 & 代码生成 + VM 执行 */
|
||||
// for (IRFunction fn : program.functions()) {
|
||||
// var alloc = new RegisterAllocator();
|
||||
// var slotM = alloc.allocate(fn);
|
||||
//
|
||||
// var gen = new VMCodeGenerator(slotM);
|
||||
// var code = gen.generate(fn);
|
||||
//
|
||||
// System.out.println("== VM code for " + fn.name() + " ==");
|
||||
// code.forEach(System.out::println);
|
||||
//
|
||||
//
|
||||
// /* 只执行 main 函数 */
|
||||
// if ("main".equals(fn.name())) {
|
||||
// VirtualMachineEngine vm = new VirtualMachineEngine(VMMode.RUN);
|
||||
//
|
||||
// vm.execute(code); // 运行指令
|
||||
// vm.printStack(); // 打印 Operand-/Call-Stack
|
||||
// vm.printLocalVariables(); // 打印局部变量槽
|
||||
//
|
||||
// System.out.println("Process has ended");
|
||||
// }
|
||||
// }
|
||||
for (IRFunction fn : program.functions()) {
|
||||
var alloc = new RegisterAllocator();
|
||||
var slotM = alloc.allocate(fn);
|
||||
|
||||
var gen = new VMCodeGenerator(slotM);
|
||||
var code = gen.generate(fn);
|
||||
|
||||
System.out.println("== VM code for " + fn.name() + " ==");
|
||||
code.forEach(System.out::println);
|
||||
|
||||
|
||||
/* 只执行 main 函数 */
|
||||
if ("main".equals(fn.name())) {
|
||||
VirtualMachineEngine vm = new VirtualMachineEngine(VMMode.RUN);
|
||||
|
||||
vm.execute(code); // 运行指令
|
||||
vm.printStack(); // 打印 Operand-/Call-Stack
|
||||
vm.printLocalVariables(); // 打印局部变量槽
|
||||
|
||||
System.out.println("Process has ended");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user