jak-project/decompiler/data/LinkedWordReader.h
Tyler Wilding c4a92571b2
Improve ASSERT macro, fix linux file paths in Taskfile and hopefully fix the windows release (#1295)
* ci: fix windows releases (hopefully)

* scripts: fix Taskfile file references for linux

* asserts: add `ASSERT_MSG` macro and ensure `stdout` is flushed before `abort`ing

* asserts: refactor all `assert(false);` with a preceeding message instances

* lint: format

* temp...

* fix compiler errors

* assert: allow for string literals in `ASSERT_MSG`

* lint: formatting

* revert temp change for testing
2022-04-12 18:48:27 -04:00

44 lines
1.1 KiB
C++

#pragma once
#include <cstring>
#include <vector>
#include <string>
#include <stdexcept>
#include "common/common_types.h"
#include "decompiler/ObjectFile/LinkedWord.h"
#include "common/util/Assert.h"
namespace decompiler {
class LinkedWordReader {
public:
explicit LinkedWordReader(const std::vector<LinkedWord>* words) : m_words(words) {}
std::string get_type_tag() {
if (m_words->at(m_offset).kind() == LinkedWord::TYPE_PTR) {
auto result = m_words->at(m_offset).symbol_name();
m_offset++;
return result;
} else {
ASSERT_MSG(false, "LinkedWordReader::get_type_tag failed");
}
}
template <typename T>
T get_word() {
static_assert(sizeof(T) == 4, "size of word in get_word");
T result;
ASSERT(m_words->at(m_offset).kind() == LinkedWord::PLAIN_DATA);
memcpy(&result, &m_words->at(m_offset).data, 4);
m_offset++;
return result;
}
u32 words_left() {
ASSERT(m_words->size() >= m_offset);
return m_words->size() - m_offset;
}
private:
const std::vector<LinkedWord>* m_words = nullptr;
u32 m_offset = 0;
};
} // namespace decompiler