unknown_opcode_exception.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /* ScummVM Tools
  2. *
  3. * ScummVM Tools is the legal property of its developers, whose
  4. * names are too numerous to list here. Please refer to the
  5. * COPYRIGHT file distributed with this source distribution.
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License
  9. * as published by the Free Software Foundation; either version 2
  10. * of the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  20. */
  21. #pragma once
  22. #include <exception>
  23. #include <string>
  24. class InternalDecompilerError : public std::exception
  25. {
  26. public:
  27. };
  28. class NotImplementedException : public InternalDecompilerError
  29. {
  30. public:
  31. NotImplementedException() = default;
  32. };
  33. class FF7ScriptHeaderInvalidException : public InternalDecompilerError
  34. {
  35. public:
  36. FF7ScriptHeaderInvalidException() = default;
  37. };
  38. class UnknownBankException : public InternalDecompilerError
  39. {
  40. public:
  41. UnknownBankException() = default;
  42. };
  43. class UnknownOpcodeParameterException : public InternalDecompilerError
  44. {
  45. public:
  46. UnknownOpcodeParameterException(std::string param)
  47. {
  48. mWhat = "unknown opcode parameter string: " + param;
  49. }
  50. virtual const char *what() const noexcept override
  51. {
  52. return mWhat.c_str();
  53. }
  54. private:
  55. std::string mWhat = "Unknonw opcode";
  56. };
  57. class UnknownConditionalOperatorException : public InternalDecompilerError
  58. {
  59. public:
  60. UnknownConditionalOperatorException(unsigned int address, unsigned int op)
  61. {
  62. mWhat = "unknown conditional operator: " + std::to_string(op) + " at address " + std::to_string(address);
  63. }
  64. virtual const char *what() const noexcept override
  65. {
  66. return mWhat.c_str();
  67. }
  68. private:
  69. std::string mWhat = "Unknown condicional operator";
  70. };
  71. /**
  72. * Exception representing an unknown opcode.
  73. */
  74. class UnknownOpcodeException : public InternalDecompilerError
  75. {
  76. unsigned int _address; ///< Address where the invalid opcode was found.
  77. unsigned int _opcode; ///< The value of the invalid opcode.
  78. mutable char _buf[255]; ///< Buffer for formatting the error message.
  79. public:
  80. /**
  81. * Constructor for UnknownOpcodeException.
  82. *
  83. * @param address Address where the invalid opcode was found.
  84. * @param opcode The value of the invalid opcode.
  85. */
  86. UnknownOpcodeException(unsigned int address, unsigned int opcode);
  87. /**
  88. * Description of the exception.
  89. */
  90. virtual const char *what() const noexcept override;
  91. private:
  92. virtual const char* Type() const { return "Opcode"; }
  93. };
  94. class UnknownJumpTypeException : public InternalDecompilerError
  95. {
  96. public:
  97. UnknownJumpTypeException(unsigned int address, unsigned int opcode)
  98. {
  99. mWhat = "unknown jump type: " + std::to_string(opcode) + " at address " + std::to_string(address);
  100. }
  101. virtual const char *what() const noexcept override
  102. {
  103. return mWhat.c_str();
  104. }
  105. private:
  106. std::string mWhat = "Unknonw Jump type";
  107. };
  108. class UnknownSubOpcodeException : public UnknownOpcodeException
  109. {
  110. public:
  111. UnknownSubOpcodeException(unsigned int address, unsigned int opcode)
  112. : UnknownOpcodeException(address, opcode)
  113. {
  114. }
  115. private:
  116. virtual const char* Type() const override { return "SubOpcode"; }
  117. };