decompiler_disassembler.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. #ifndef DEC_DISASSEMBLER_H
  22. #define DEC_DISASSEMBLER_H
  23. #include <iostream>
  24. #include <vector>
  25. #include "../common/BinaryReader.h"
  26. #include "instruction.h"
  27. #include "unknown_opcode_exception.h"
  28. #include "objectFactory.h"
  29. /**
  30. * Base class for disassemblers.
  31. */
  32. class Disassembler {
  33. protected:
  34. std::unique_ptr<BinaryReader> stream_; ///< Used to perform file I/O.
  35. InstVec &insts_; ///< Container for disassembled instructions.
  36. uint32 address_base_; ///< Base address where the script starts.
  37. /**
  38. * Performs disassembly.
  39. *
  40. * @throws UnknownOpcodeException on unknown opcode. May throw std::exception on other failures.
  41. */
  42. virtual void DoDisassemble() = 0;
  43. /**
  44. * Outputs the disassembled code.
  45. *
  46. * @param output The std::ostream to output to.
  47. */
  48. virtual void doDumpDisassembly(std::ostream &output);
  49. public:
  50. /**
  51. * Constructor for Disassembler.
  52. *
  53. * @param insts Reference to the vector in which disassembled instructions should be placed.
  54. */
  55. Disassembler(InstVec &insts);
  56. virtual ~Disassembler() = default;
  57. /**
  58. * Open a file for disassembly.
  59. *
  60. * @param filename The file to disassemble.
  61. */
  62. virtual void Open(const char *filename);
  63. /**
  64. * Request disassembled instructions.
  65. *
  66. * @return An std::vector containing the disassembled instructions.
  67. */
  68. void disassemble();
  69. /**
  70. * Outputs the disassembled code. Disassembles code if this has not already been done.
  71. *
  72. * @param output The std::ostream to output to.
  73. */
  74. void dumpDisassembly(std::ostream &output);
  75. };
  76. #endif