internal void PrepareSerialization(ChelaModule module) { // Register types and external members used. InstructionDescription desc = InstructionDescription.GetInstructionTable()[(int)opcode]; InstructionArgumentType[] args = desc.GetArguments(); for (int i = 0, k = 0; i < arguments.Length; i++, k++) { object arg = arguments[i]; switch (args[k]) { case InstructionArgumentType.UInt8V: case InstructionArgumentType.Int8V: case InstructionArgumentType.UInt16V: case InstructionArgumentType.Int16V: case InstructionArgumentType.UInt32V: case InstructionArgumentType.Int32V: case InstructionArgumentType.UInt64V: case InstructionArgumentType.Int64V: case InstructionArgumentType.Fp32V: case InstructionArgumentType.Fp64V: { // Ignore the vector arguments. byte n = (byte)arg; i += n; } break; case InstructionArgumentType.TypeID: { // Prepare serialization of generic instances. IChelaType argType = (IChelaType)arg; if (argType.IsGenericInstance() && (argType.IsStructure() || argType.IsClass() || argType.IsInterface())) { ScopeMember member = (ScopeMember)argType; member.PrepareSerialization(); } // Register types. module.RegisterType(argType); } break; case InstructionArgumentType.GlobalID: case InstructionArgumentType.FieldID: case InstructionArgumentType.FunctionID: { // Register external members. ScopeMember member = (ScopeMember)arg; if (member != null) { if (member.IsGenericInstance()) { member.PrepareSerialization(); } module.RegisterMember(member); } } break; case InstructionArgumentType.JumpTable: { // Ignore the jump table ushort tableLen = (ushort)arg; i += tableLen * 2; } break; default: // Do nothing. break; } } }