DecompilerException.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. /*
  2. * Copyright (C) 2022 The V-Gears Team
  3. *
  4. * This file is part of V-Gears
  5. *
  6. * V-Gears is free software: you can redistribute it and/or modify it under
  7. * terms of the GNU General Public License as published by the Free Software
  8. * Foundation, version 3.0 (GPLv3) of the License.
  9. *
  10. * V-Gears is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. */
  15. #pragma once
  16. #include <exception>
  17. #include <string>
  18. class DecompilerException : public std::exception{};
  19. /**
  20. * Wrong type exception.
  21. *
  22. * Signals that an operation was performed on a Value that doesn't support the
  23. * operation.
  24. */
  25. class WrongTypeException : public DecompilerException{};
  26. /**
  27. * Not implemented exception.
  28. *
  29. * Signals that a function is not implemented in the decompiler.
  30. */
  31. class NotImplementedException : public DecompilerException{
  32. public:
  33. /**
  34. * Constructor.
  35. */
  36. NotImplementedException() = default;
  37. };
  38. /**
  39. * Invalid header exception.
  40. *
  41. * Signals that a script has an invalid header.
  42. */
  43. class ScriptHeaderInvalidException : public DecompilerException{
  44. public:
  45. /**
  46. * Constructor.
  47. */
  48. ScriptHeaderInvalidException() = default;
  49. };
  50. /**
  51. * Unknown bank exception.
  52. *
  53. * Signals that an unknown bank has been tried to access.
  54. */
  55. class UnknownBankException : public DecompilerException{
  56. public:
  57. /**
  58. * Constructor.
  59. */
  60. UnknownBankException() = default;
  61. };
  62. /**
  63. * Unknown opcode parameter exception.
  64. *
  65. * Signals that an opcode has an invalid parameter in a script.
  66. */
  67. class UnknownOpcodeParameterException : public DecompilerException{
  68. public:
  69. /**
  70. * Constructor.
  71. *
  72. * @param[in] param The unknown parameter.
  73. */
  74. explicit UnknownOpcodeParameterException(std::string param);
  75. /**
  76. * Produces an error message.
  77. *
  78. * @return The error message.
  79. */
  80. virtual const char *what() const noexcept override;
  81. private:
  82. /**
  83. * The error message.
  84. */
  85. std::string what_;
  86. };
  87. /**
  88. * Unknown conditional operator exception.
  89. *
  90. * Signals that an unknown conditional operator has been found in a script.
  91. */
  92. class UnknownConditionalOperatorException : public DecompilerException{
  93. public:
  94. /**
  95. * Constructor.
  96. *
  97. * @param[in] address Address at which the operator has been found.
  98. * @param[in] op The unknown operator.
  99. */
  100. UnknownConditionalOperatorException(unsigned int address, unsigned int op);
  101. /**
  102. * Produces an error message.
  103. *
  104. * @return The error message.
  105. */
  106. virtual const char *what() const noexcept override;
  107. private:
  108. /**
  109. * The error message.
  110. */
  111. std::string what_;
  112. };
  113. /**
  114. * Unknown opcode exception.
  115. *
  116. * Signals that an unknown opcode has been found in a script.
  117. */
  118. class UnknownOpcodeException : public DecompilerException{
  119. public:
  120. /**
  121. * Constructor.
  122. *
  123. * @param[in] address Address where the invalid opcode was found.
  124. * @param[in] opcode The value of the invalid opcode.
  125. */
  126. UnknownOpcodeException(unsigned int address, unsigned int opcode);
  127. /**
  128. * Produces an error message.
  129. *
  130. * @return The error message.
  131. */
  132. virtual const char* what() const noexcept override;
  133. private:
  134. /**
  135. * Retrieves an exception identifier.
  136. *
  137. * @return "Opcode".
  138. */
  139. virtual const char* Type() const;
  140. /**
  141. * Address where the invalid opcode was found.
  142. */
  143. unsigned int address_;
  144. /**
  145. * The value of the invalid opcode.
  146. */
  147. unsigned int opcode_;
  148. /**
  149. * Buffer for formatting the error message.
  150. */
  151. mutable char buffer_[255];
  152. };
  153. /**
  154. * Unknown jump type exception.
  155. *
  156. * Signals that a jump is not a conditional jump neither an unconditional
  157. * jump.
  158. */
  159. class UnknownJumpTypeException : public DecompilerException{
  160. public:
  161. /**
  162. * Constructor.
  163. *
  164. * @param[in] address Address where the jump opcode was found.
  165. * @param[in] opcode The value of the jump opcode.
  166. */
  167. UnknownJumpTypeException(unsigned int address, unsigned int opcode);
  168. /**
  169. * Produces an error message.
  170. *
  171. * @return The error message.
  172. */
  173. virtual const char* what() const noexcept override;
  174. private:
  175. /**
  176. * The error message.
  177. */
  178. std::string what_;
  179. };
  180. /**
  181. * Unknown subopcode exception.
  182. *
  183. * Signals that an unknown subopcode has been found in a script.
  184. */
  185. class UnknownSubOpcodeException : public UnknownOpcodeException{
  186. public:
  187. /**
  188. * Constructor.
  189. *
  190. * @param[in] address Address where the invalid subopcode was found.
  191. * @param[in] opcode The value of the invalid subopcode.
  192. */
  193. UnknownSubOpcodeException(unsigned int address, unsigned int opcode);
  194. private:
  195. /**
  196. * Retrieves an exception identifier.
  197. *
  198. * @return "Subopcode".
  199. */
  200. virtual const char* Type() const override;
  201. };