2021-01-06 20:04:15 -05:00
|
|
|
/*!
|
|
|
|
* The InstructionParser converts a string like "daddu a0, s7, r0" into an Instruction.
|
|
|
|
* It is used to generate test sequences of instructions for decompiler algorithms.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <unordered_map>
|
2022-06-22 23:37:46 -04:00
|
|
|
|
2021-01-06 20:04:15 -05:00
|
|
|
#include "DecompilerLabel.h"
|
2022-06-22 23:37:46 -04:00
|
|
|
#include "Instruction.h"
|
2021-01-06 20:04:15 -05:00
|
|
|
|
|
|
|
namespace decompiler {
|
|
|
|
struct ParsedProgram {
|
|
|
|
std::vector<DecompilerLabel> labels;
|
|
|
|
std::vector<Instruction> instructions;
|
|
|
|
std::string print();
|
|
|
|
};
|
|
|
|
|
|
|
|
class InstructionParser {
|
|
|
|
public:
|
|
|
|
InstructionParser();
|
|
|
|
Instruction parse_single_instruction(std::string str, const std::vector<DecompilerLabel>& labels);
|
2021-02-01 20:41:37 -05:00
|
|
|
ParsedProgram parse_program(const std::string& str,
|
|
|
|
const std::vector<std::string>& predefined_labels = {});
|
2021-01-06 20:04:15 -05:00
|
|
|
|
|
|
|
private:
|
|
|
|
std::unordered_map<std::string, int> m_opcode_name_lookup;
|
2021-07-25 15:30:37 -04:00
|
|
|
std::unordered_map<std::string, int> m_opcode_name_broadcast_lookup;
|
2021-01-06 20:04:15 -05:00
|
|
|
};
|
|
|
|
} // namespace decompiler
|