Ejemplo n.º 1
0
        public List <string> Decompile(long[] data)
        {
            List <string>  decompiled = new List <string>();
            IntcodeContext context    = new IntcodeContext(data, IntcodeMode.None, "decompiled");

            while (context.InstructionPointer < data.Length)
            {
                if (Opcodes.ContainsKey(context.CurrentOpcode))
                {
                    Opcode opcode = Opcodes[context.CurrentOpcode];
                    decompiled.Add(opcode.Describe(context));
                    context.InstructionPointer += opcode.Params + 1;
                }
                else
                {
                    decompiled.Add($"{{ {context.Id} }} {context.InstructionPointer:0000}: Raw data [{context.Data[context.InstructionPointer]}]");
                    context.InstructionPointer++;
                }
            }
            return(decompiled);
        }
Ejemplo n.º 2
0
        private List <IntcodeEvent> GenerateEventsBasedOnData(long[] data)
        {
            List <IntcodeEvent> events  = new List <IntcodeEvent>();
            IntcodeContext      context = new IntcodeContext(data, IntcodeMode.None, "decompiled");

            while (context.InstructionPointer < data.Length)
            {
                if (Opcodes.ContainsKey(context.CurrentOpcode))
                {
                    Opcode opcode = Opcodes[context.CurrentOpcode];
                    events.Add(opcode.ToEvent(context));
                    context.InstructionPointer += opcode.Params + 1;
                }
                else
                {
                    events.Add(new DataEvent(context.InstructionPointer, context.Data[context.InstructionPointer]));
                    context.InstructionPointer++;
                }
            }

            return(events);
        }