WorldDisassembler.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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 "decompiler/Disassembler.h"
  17. class WorldEngine;
  18. class WorldDisassembler : public Disassembler{
  19. public:
  20. /**
  21. * CConstructor.
  22. *
  23. * @param engine[in] The engine to use to disassemble.
  24. * @param insts[in] The list of instructions.
  25. * @param script_number[in] The script number to process.
  26. */
  27. WorldDisassembler(WorldEngine* engine, InstVec& insts, int script_number);
  28. /**
  29. * Destructor.
  30. */
  31. ~WorldDisassembler();
  32. /**
  33. * Disassembles the instructions.
  34. */
  35. void DoDisassemble() override;
  36. private:
  37. /**
  38. * Parses an opcode.
  39. *
  40. * Adds properties to an instruction, and adds the instruction to the
  41. * list.
  42. *
  43. * @param opcode[in] The opcode code.
  44. * @param name[in] the opcode name.
  45. * @param instruction[in][out] A newly created instruction of the type
  46. * the opcode belongs to.
  47. * @param stack_change[in] Indicates how much the instruction changes
  48. * the stack pointer by.
  49. * @param argument_format[in] The opcode argument format.
  50. */
  51. template<typename T> void ParseOpcode(
  52. int opcode, std::string name, T instruction, int stack_change, const char* argument_format
  53. ){
  54. uint32 full_opcode = (full_opcode << 8) + opcode;
  55. this->insts_.push_back(instruction);
  56. this->insts_.back()->SetOpcode(full_opcode);
  57. this->insts_.back()->SetAddress(this->address_);
  58. this->insts_.back()->SetStackChange(0);
  59. this->insts_.back()->SetName(std::string(name));
  60. this->insts_.back()->SetCodeGenData("");
  61. this->ReadParams(this->insts_.back(), argument_format);
  62. }
  63. /**
  64. * The script number.
  65. */
  66. int script_number_ = 0;
  67. };