public InstructionGroup[] GetGroups() { var groups = new Dictionary <InstructionOperand[], InstructionGroup>(new OpComparer()); foreach (var def in genTypes.GetObject <InstructionDefs>(TypeIds.InstructionDefs).Defs) { if (ignoredCodes.Contains(def.Code)) { continue; } foreach (var ops in GetOperands(def.OpKindDefs)) { if (!groups.TryGetValue(ops, out var group)) { groups.Add(ops, group = new InstructionGroup(ops)); } group.Defs.Add(def); } } var result = groups.Values.ToArray(); Array.Sort(result, (a, b) => { int c = a.Operands.Length - b.Operands.Length; if (c != 0) { return(c); } for (int i = 0; i < a.Operands.Length; i++) { c = GetOrder(a.Operands[i]) - GetOrder(b.Operands[i]); if (c != 0) { return(c); } } return(0); }); return(result);
static CreateMethod GetMethod(InstructionGroup group, bool unsigned) { var(regCount, immCount, memCount) = GetOpKindCount(group); int regId = 1, immId = 1, memId = 1; string doc = group.Operands.Length switch { 0 => "Creates an instruction with no operands", 1 => "Creates an instruction with 1 operand", _ => $"Creates an instruction with {group.Operands.Length} operands", }; var method = new CreateMethod(doc); AddCodeArg(method); int opNum = -1; foreach (var op in group.Operands) { opNum++; switch (op) { case InstructionOperand.Register: method.Args.Add(new MethodArg($"op{opNum}: Register", MethodArgType.Register, GetArgName("register", regCount, regId++))); break; case InstructionOperand.Memory: method.Args.Add(new MethodArg($"op{opNum}: Memory operand", MethodArgType.Memory, GetArgName("memory", memCount, memId++))); break; case InstructionOperand.Imm32: method.Args.Add(new MethodArg($"op{opNum}: Immediate value", unsigned ? MethodArgType.UInt32 : MethodArgType.Int32, GetArgName("immediate", immCount, immId++))); break; case InstructionOperand.Imm64: method.Args.Add(new MethodArg($"op{opNum}: Immediate value", unsigned ? MethodArgType.UInt64 : MethodArgType.Int64, GetArgName("immediate", immCount, immId++))); break; default: throw new InvalidOperationException(); } } return(method);
protected abstract void GenCreate(FileWriter writer, CreateMethod method, InstructionGroup group);