// Add an instruction definition public void AddInstructionDefinition(int imm, InstructionDefinition definition) { // All variations must have the same length if (_immVariations.Count == 0) { Length = definition.Length; } else { System.Diagnostics.Debug.Assert(Length == definition.Length); } if (!_immVariations.ContainsKey(imm)) { _immVariations.Add(imm, definition); } }
// Add an instruction to the set of available instructions static void AddInstruction(InstructionDefinition instruction) { // Prepare the instruction instruction.Prepare(); // Get it's key, replacing operand placeholders with '?' int? immValue; string key = KeyOfMnemonic(instruction.mnemonic, out immValue); // Get the existing instruction Instruction existing; _opMap.TryGetValue(key, out existing); // Does it need to go into an instruction group? if (immValue.HasValue) { if (existing != null) { // Use existing group var group = existing as InstructionGroup; if (group == null) { throw new InvalidOperationException("Internal error: instruction overloaded with typed imm and bit imm"); } group.AddInstructionDefinition(immValue.Value, instruction); } else { // Create new instruction group var group = new InstructionGroup(); group.mnemonic = key; group.AddInstructionDefinition(immValue.Value, instruction); _opMap.Add(key, group); } } else { if (existing != null) { if (existing is InstructionGroup) { throw new InvalidOperationException("Internal error: instruction overloaded with typed imm and bit imm"); } /* * if (existing.opCode.mnemonic != instruction.opCode.mnemonic) * { * Console.WriteLine("Arg overload: {0}", instruction.opCode.mnemonic); * } * else * { * Console.WriteLine("Duplicate mnemonic: {0}", instruction.opCode.mnemonic); * } */ } else { _opMap.Add(key, instruction); } } }