Esempio n. 1
0
        public string ToString(UndertaleCode code, IList <UndertaleVariable> vars)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append(Address.ToString("D5") + ": ");
            sb.Append(Kind.ToString().ToLower());

            switch (GetInstructionType(Kind))
            {
            case InstructionType.SingleTypeInstruction:
                sb.Append("." + Type1.ToOpcodeParam());

                if (Kind == Opcode.Dup)
                {
                    sb.Append(" ");
                    sb.Append(DupExtra.ToString());
                }
                break;

            case InstructionType.DoubleTypeInstruction:
                sb.Append("." + Type1.ToOpcodeParam());
                sb.Append("." + Type2.ToOpcodeParam());
                break;

            case InstructionType.ComparisonInstruction:
                sb.Append("." + Type1.ToOpcodeParam());
                sb.Append("." + Type2.ToOpcodeParam());
                sb.Append(" ");
                sb.Append(ComparisonKind.ToString());
                break;

            case InstructionType.GotoInstruction:
                sb.Append(" ");
                string tgt = (Address + JumpOffset).ToString("D5");
                if (code != null && Address + JumpOffset == code.Length / 4)
                {
                    tgt = "func_end";
                }
                sb.Append(tgt);
                break;

            case InstructionType.PopInstruction:
                sb.Append("." + Type1.ToOpcodeParam());
                sb.Append("." + Type2.ToOpcodeParam());
                sb.Append(" ");
                if (Type1 == DataType.Variable && TypeInst != InstanceType.Undefined)
                {
                    sb.Append(TypeInst.ToString().ToLower());
                    sb.Append(".");
                }
                sb.Append(Destination.ToString());
                break;

            case InstructionType.PushInstruction:
                sb.Append("." + Type1.ToOpcodeParam());
                sb.Append(" ");
                if (Type1 == DataType.Variable && TypeInst != InstanceType.Undefined)
                {
                    sb.Append(TypeInst.ToString().ToLower());
                    sb.Append(".");
                }
                sb.Append((Value as IFormattable)?.ToString(null, CultureInfo.InvariantCulture) ?? Value.ToString());
                break;

            case InstructionType.CallInstruction:
                sb.Append("." + Type1.ToOpcodeParam());
                sb.Append(" ");
                sb.Append(Function.ToString());
                sb.Append("(argc=");
                sb.Append(ArgumentsCount.ToString());
                sb.Append(")");
                break;

            case InstructionType.BreakInstruction:
                sb.Append("." + Type1.ToOpcodeParam());
                sb.Append(" ");
                sb.Append(Value.ToString());
                break;
            }
            return(sb.ToString());
        }