2021-08-29 15:13:06 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <optional>
|
|
|
|
#include <string>
|
2022-06-23 03:37:46 +00:00
|
|
|
#include <unordered_map>
|
|
|
|
#include <vector>
|
|
|
|
|
2021-08-29 15:13:06 +00:00
|
|
|
#include "common/link_types.h"
|
|
|
|
#include "common/type_system/TypeSpec.h"
|
2022-06-23 03:37:46 +00:00
|
|
|
|
2021-08-29 15:13:06 +00:00
|
|
|
#include "decompiler/Disasm/DecompilerLabel.h"
|
2022-06-23 03:37:46 +00:00
|
|
|
#include "decompiler/config.h"
|
2021-08-29 15:13:06 +00:00
|
|
|
#include "decompiler/util/DecompilerTypeSystem.h"
|
|
|
|
|
|
|
|
namespace decompiler {
|
|
|
|
struct LabelInfo {
|
|
|
|
std::string name;
|
|
|
|
TypeSpec result_type;
|
|
|
|
int idx = -1;
|
|
|
|
bool known = false;
|
|
|
|
bool is_value = false;
|
|
|
|
bool from_user = false;
|
|
|
|
std::optional<int> array_size;
|
|
|
|
|
|
|
|
std::string print() const;
|
|
|
|
};
|
|
|
|
|
|
|
|
class LabelDB {
|
|
|
|
public:
|
|
|
|
LabelDB(const std::unordered_map<std::string, LabelConfigInfo>& config,
|
|
|
|
const std::vector<DecompilerLabel>& labels,
|
|
|
|
const DecompilerTypeSystem& dts);
|
|
|
|
const LabelInfo& lookup(int idx) const;
|
|
|
|
const LabelInfo& lookup(const std::string& name) const;
|
|
|
|
int get_index_by_offset(int seg, int offset) const;
|
2021-09-03 23:19:51 +00:00
|
|
|
std::optional<int> try_get_index_by_offset(int seg, int offset) const;
|
2021-08-29 15:13:06 +00:00
|
|
|
int get_index_by_name(const std::string& name) const;
|
2023-03-31 21:47:38 +00:00
|
|
|
|
|
|
|
// automatic, or from user
|
|
|
|
bool label_info_known_by_name(const std::string& name) const;
|
2021-08-29 15:13:06 +00:00
|
|
|
|
|
|
|
LabelInfo set_and_get_previous(int idx,
|
|
|
|
const TypeSpec& type,
|
|
|
|
bool is_value,
|
|
|
|
std::optional<int> array_size);
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::vector<LabelInfo> m_info;
|
|
|
|
std::unordered_map<std::string, int> m_labels_by_name;
|
|
|
|
std::vector<std::unordered_map<int, int>> m_labels_by_offset_into_seg; // in bytes.
|
|
|
|
};
|
|
|
|
} // namespace decompiler
|