WorldDisassembler.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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[in] engine The engine to use to disassemble.
  24. * @param[in] insts The list of instructions.
  25. * @param[in] script_number 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. WorldEngine* engine_;
  38. /**
  39. * Parses an opcode.
  40. *
  41. * Adds properties to an instruction, and adds the instruction to the
  42. * list.
  43. *
  44. * @param[in] opcode The opcode code.
  45. * @param[in] name the opcode name.
  46. * @param[in] instruction A newly created instruction of the type
  47. * the opcode belongs to.
  48. * @param[in] stack_change Indicates how much the instruction changes
  49. * the stack pointer by.
  50. * @param[in] argument_format The opcode argument format.
  51. */
  52. template<typename T> void ParseOpcode(
  53. int opcode, std::string name, T instruction, int stack_change, const char* argument_format
  54. ){
  55. const uint32 full_opcode = static_cast<uint32>(opcode);
  56. this->insts_.push_back(instruction);
  57. this->insts_.back()->SetOpcode(full_opcode);
  58. this->insts_.back()->SetAddress(this->address_);
  59. this->insts_.back()->SetStackChange(0);
  60. this->insts_.back()->SetName(std::string(name));
  61. this->insts_.back()->SetCodeGenData("");
  62. this->ReadParams(this->insts_.back(), argument_format);
  63. }
  64. /**
  65. * The script number.
  66. */
  67. int script_number_ = 0;
  68. };