public IOpCodeDescriptionDefinition Read(string file) { var doc = XDocument.Load(file); var result = new OpCodeDescriptionDefinition(); var instructionElements = doc.Root.Elements("Instruction"); foreach (var ie in instructionElements) { var opcodes = ie.Attribute("OpCode").Value; var opcodeToAdd = opcodes.Split(','); opcodeToAdd.ForEach(i => result.Instructions.Add(ParseOpCodeDescription(i, ie, result))); } return(result); }
private static OpCodeDescription ParseOpCodeDescription(string opcode, XElement ie, OpCodeDescriptionDefinition definiton) { var i = new OpCodeDescription(); i.OpCode = Enum.GetValues(typeof(PapyrusOpCodes)) .Cast <PapyrusOpCodes>() .FirstOrDefault(op => op.ToString().ToLower() == opcode.ToLower()); i.Definition = definiton; var args = ie.Element("Arguments")?.Elements("Argument"); if (args != null) { foreach (var arg in args) { var constraints = new OpCodeConstraint[0]; var constraintValue = arg.Attribute("Constraint")?.Value; if (constraintValue != null) { constraints = constraintValue.Split(',').Select(ConstraintFromString).ToArray(); } i.Arguments.Add(new OpCodeArgumentDescription { Index = int.Parse(arg.Attribute("Index").Value), Alias = arg.Attribute("Alias")?.Value, Description = arg.Attribute("Description")?.Value, ValueType = ValueTypeFromString(arg.Attribute("ValueType")?.Value), Ref = RefFromString(arg.Attribute("Ref")?.Value), Constraints = constraints }); } } var opargs = ie.Element("OperandArguments")?.Elements("OperandArgument"); if (opargs != null) { foreach (var arg in opargs) { var constraints = new OpCodeConstraint[0]; var constraintValue = arg.Attribute("Constraint")?.Value; if (constraintValue != null) { constraints = constraintValue.Split(',').Select(ConstraintFromString).ToArray(); } i.OperandArguments.Add(new OpCodeArgumentDescription { Index = -1, Alias = arg.Attribute("Alias")?.Value, Description = arg.Attribute("Description")?.Value, ValueType = ValueTypeFromString(arg.Attribute("ValueType")?.Value), Ref = RefFromString(arg.Attribute("Ref")?.Value), Constraints = constraints }); } } return(i); }