gui效果图,gui代码太长了就不贴了

编译结果
LD,test3
NOT,
STORE,TMP1
LD,test1
OR,
LD,TMP1
OUT,test2
LD,TMP1
RST,test
LD,TMP1
OUT,test22
LD,TMP1
OUT,test4
LD,TMP1
CALL,放料
编译器代码
using System.Collections.Generic;
using System.Linq;
namespace LDEdit
{
public class LadderCompiler
{
private readonly ConnectionManager _connManager;
private readonly Dictionary<CellState, CellState> _cellStateMap;
private Dictionary<CellState, string> _commonNodes = new Dictionary<CellState, string>();
private int _tempCounter = 0;
private Dictionary<CellState, List<List<CellState>>> _coilPathCache = new Dictionary<CellState, List<List<CellState>>>();
public LadderCompiler(ConnectionManager connManager, List<CellState> cells)
{
_connManager = connManager;
_cellStateMap = cells.ToDictionary(c => c);
}
public List<Instruction> Compile()
{
var instructions = new List<Instruction>();
var allPaths = new List<List<CellState>>();
// 第一阶段:收集所有线圈路径
var outputCoils = _cellStateMap.Values
.Where(c => IsOutputType(c.cellType))
.OrderBy(c => c.row)
.ToList();
foreach (var coil in outputCoils)
{
var branches = FindAllBranches(coil);
_coilPathCache[coil] = branches;
allPaths.AddRange(branches);
}
// 第二阶段:分析公共节点
var commonNodes = AnalyzeCommonNodes(allPaths);
GenerateCommonLogic(commonNodes, instructions);
// 第三阶段:生成优化后的指令
foreach (var coil in outputCoils)
{
CompileOptimizedCoil(coil, instructions);
}
return instructions;
}
private Dictionary<CellState, int> AnalyzeCommonNodes(List<List<CellState>> allPaths)
{
var nodeFrequency = new Dictionary<CellState, int>();
var visited = new HashSet<CellState>();
foreach (var path in allPaths)
{
var reversed = Enumerable.Reve