diff --git a/.github/workflows/linux-workflow.yaml b/.github/workflows/linux-workflow.yaml index 958ffcb349..515204e5e6 100644 --- a/.github/workflows/linux-workflow.yaml +++ b/.github/workflows/linux-workflow.yaml @@ -25,7 +25,7 @@ jobs: runs-on: ${{ matrix.os }} continue-on-error: ${{ matrix.experimental }} # Set some sort of timeout in the event of run-away builds. We are limited on concurrent jobs so, get rid of them. - timeout-minutes: 20 + timeout-minutes: 45 env: # overrides: https://github.com/mbitsnbites/buildcache/blob/master/doc/configuration.md BUILDCACHE_MAX_CACHE_SIZE: 1000000000 # 1gb diff --git a/.github/workflows/windows-workflow.yaml b/.github/workflows/windows-workflow.yaml index 6a8266f9df..b278e4c535 100644 --- a/.github/workflows/windows-workflow.yaml +++ b/.github/workflows/windows-workflow.yaml @@ -25,7 +25,7 @@ jobs: runs-on: ${{ matrix.os }} continue-on-error: ${{ matrix.experimental }} # Set some sort of timeout in the event of run-away builds. We are limited on concurrent jobs so, get rid of them. - timeout-minutes: 25 # 5 more minutes than linux + timeout-minutes: 45 env: # overrides: https://github.com/mbitsnbites/buildcache/blob/master/doc/configuration.md BUILDCACHE_MAX_CACHE_SIZE: 1000000000 # 1gb diff --git a/README.md b/README.md index 39e8df598f..ad124b2e06 100644 --- a/README.md +++ b/README.md @@ -78,7 +78,7 @@ We don't save any assets from the game - you must bring your own copy of the gam Install packages and init repository: ```sh -sudo apt install gcc make cmake build-essential g++ nasm clang-format +sudo apt install gcc make cmake build-essential g++ nasm clang-format libxrandr-dev libxinerama-dev libxcursor-dev libxi-dev git submodule update --init --recursive ``` diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index 7e8584e2f8..138b4460ae 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -26,6 +26,7 @@ add_library(common type_system/TypeFieldLookup.cpp type_system/TypeSpec.cpp type_system/TypeSystem.cpp + util/Assert.cpp util/BitUtils.cpp util/compress.cpp util/dgo_util.cpp diff --git a/common/audio/audio_formats.cpp b/common/audio/audio_formats.cpp index 231c69079d..db2a104104 100644 --- a/common/audio/audio_formats.cpp +++ b/common/audio/audio_formats.cpp @@ -53,11 +53,11 @@ std::vector decode_adpcm(BinaryReader& reader) { u8 filter = shift_filter >> 4; if (shift > 12) { - assert(false); + ASSERT(false); } if (filter > 4) { - assert(false); + ASSERT(false); } if (flags == 7) { @@ -143,7 +143,7 @@ int get_shift_error(int shift, const s32* samples, bool /*debug*/) { for (int sample_idx = 0; sample_idx < SAMPLES_PER_BLOCK; sample_idx++) { int left_shift = 32 - (12 + 4 - shift); - assert(left_shift >= 0); + ASSERT(left_shift >= 0); s32 sample_left = samples[sample_idx] << left_shift; s32 sample_right = sample_left >> (32 - 4); s32 sample_compressed = sample_right << (12 - shift); @@ -290,7 +290,7 @@ void test_encode_adpcm(const std::vector& samples, fmt::print(" [{}] {} {}\n", i, filter_errors[i], filter_shifts[i]); } fmt::print("prev: {} {}\n", prev_block_samples[0], prev_block_samples[1]); - assert(false); + ASSERT(false); } prev_block_samples[0] = samples.at(block_idx * 28 + 27); diff --git a/common/cross_os_debug/xdbg.cpp b/common/cross_os_debug/xdbg.cpp index 05116f19e9..c3179cad15 100644 --- a/common/cross_os_debug/xdbg.cpp +++ b/common/cross_os_debug/xdbg.cpp @@ -103,7 +103,7 @@ bool check_stopped(const ThreadID& tid, SignalInfo* out) { return true; } printf("[Debugger] Failed to waitpid: %s.\n", strerror(errno)); - // assert(false); // todo, temp because I think we should never hit this. + // ASSERT(false); // todo, temp because I think we should never hit this. return false; } diff --git a/common/custom_data/TFrag3Data.cpp b/common/custom_data/TFrag3Data.cpp index b7f004021f..96ce2a3f69 100644 --- a/common/custom_data/TFrag3Data.cpp +++ b/common/custom_data/TFrag3Data.cpp @@ -1,5 +1,5 @@ #include "Tfrag3Data.h" -#include "common/util/assert.h" +#include "common/util/Assert.h" namespace tfrag3 { @@ -97,7 +97,7 @@ void Level::serialize(Serializer& ser) { if (ser.is_loading() && version != TFRAG3_VERSION) { fmt::print("version mismatch when loading tfrag3 data. Got {}, expected {}\n", version, TFRAG3_VERSION); - assert(false); + ASSERT(false); } ser.from_str(&level_name); @@ -133,7 +133,7 @@ void Level::serialize(Serializer& ser) { if (ser.is_loading() && version2 != TFRAG3_VERSION) { fmt::print("version mismatch when loading tfrag3 data (at end). Got {}, expected {}\n", version2, TFRAG3_VERSION); - assert(false); + ASSERT(false); } } diff --git a/common/custom_data/Tfrag3Data.h b/common/custom_data/Tfrag3Data.h index d1d3cea58f..5e4c5847dc 100644 --- a/common/custom_data/Tfrag3Data.h +++ b/common/custom_data/Tfrag3Data.h @@ -7,7 +7,7 @@ #include "common/dma/gs.h" #include "common/util/Serializer.h" #include "common/math/Vector.h" -#include "common/util/assert.h" +#include "common/util/Assert.h" namespace tfrag3 { diff --git a/common/dma/dma.cpp b/common/dma/dma.cpp index 71e652be68..d2d52b2719 100644 --- a/common/dma/dma.cpp +++ b/common/dma/dma.cpp @@ -1,7 +1,7 @@ #include "dma.h" #include "third-party/fmt/core.h" -#include "common/util/assert.h" +#include "common/util/Assert.h" std::string DmaTag::print() { std::string result; @@ -111,7 +111,7 @@ std::string VifCode::print() { fmt::print("Unhandled vif code {}\n", (int)kind); result = "???"; - assert(false); + ASSERT(false); break; } // TODO: the rest of the VIF code. diff --git a/common/dma/dma.h b/common/dma/dma.h index 8d58285cd9..128f86d401 100644 --- a/common/dma/dma.h +++ b/common/dma/dma.h @@ -8,7 +8,7 @@ #include #include #include "common/common_types.h" -#include "common/util/assert.h" +#include "common/util/Assert.h" struct DmaStats { double sync_time_ms = 0; @@ -89,7 +89,7 @@ inline void emulate_dma(const void* source_base, void* dest_base, u32 tadr, u32 } break; default: printf("bad tag: %d\n", (int)tag.kind); - assert(false); + ASSERT(false); } } } diff --git a/common/dma/dma_chain_read.h b/common/dma/dma_chain_read.h index 7b6856fd89..34e4585458 100644 --- a/common/dma/dma_chain_read.h +++ b/common/dma/dma_chain_read.h @@ -2,7 +2,7 @@ #include #include "common/dma/dma.h" -#include "common/util/assert.h" +#include "common/util/Assert.h" /*! * @file dma_chain_read.h @@ -59,12 +59,12 @@ class DmaFollower { DmaTransfer result; result.transferred_tag = read_val(m_tag_offset + 8); result.size_bytes = (u32)tag.qwc * 16; - assert(!tag.spr); - assert(!m_ended); + ASSERT(!tag.spr); + ASSERT(!m_ended); switch (tag.kind) { case DmaTag::Kind::CNT: // data, then next tag. doesn't read address. - assert(tag.addr == 0); + ASSERT(tag.addr == 0); result.data_offset = m_tag_offset + 16; m_tag_offset = result.data_offset + result.size_bytes; break; @@ -84,12 +84,12 @@ class DmaFollower { break; case DmaTag::Kind::CALL: result.data_offset = m_tag_offset + 16; - assert(m_sp <= 1); + ASSERT(m_sp <= 1); m_tag_offset = tag.addr; m_stack[m_sp++] = result.data_offset + tag.qwc * 16; break; case DmaTag::Kind::RET: - assert(m_sp > 0); + ASSERT(m_sp > 0); result.data_offset = m_tag_offset + 16; m_tag_offset = m_stack[--m_sp]; break; @@ -99,7 +99,7 @@ class DmaFollower { break; default: - assert(false); + ASSERT(false); } result.data = (const u8*)m_base + result.data_offset; return result; diff --git a/common/dma/dma_copy.cpp b/common/dma/dma_copy.cpp index 6853735d2a..e1049b3ec2 100644 --- a/common/dma/dma_copy.cpp +++ b/common/dma/dma_copy.cpp @@ -69,8 +69,8 @@ void FixedChunkDmaCopier::serialize_last_result(Serializer& serializer) { FixedChunkDmaCopier::FixedChunkDmaCopier(u32 main_memory_size) : m_main_memory_size(main_memory_size), m_chunk_count(main_memory_size / chunk_size) { - assert(chunk_size * m_chunk_count == m_main_memory_size); // make sure the memory size is valid. - assert(chunk_size >= 16); + ASSERT(chunk_size * m_chunk_count == m_main_memory_size); // make sure the memory size is valid. + ASSERT(chunk_size >= 16); m_chunk_mask.resize(m_chunk_count); } @@ -96,7 +96,7 @@ const DmaData& FixedChunkDmaCopier::run(const void* memory, u32 offset, bool ver m_chunk_mask.at(tag_chunk_idx) = true; if (tag.addr) { - assert(tag.addr > EE_MAIN_MEM_LOW_PROTECT); + ASSERT(tag.addr > EE_MAIN_MEM_LOW_PROTECT); u32 addr_chunk_idx = tag.addr / chunk_size; u32 addr_offset_in_chunk = tag.addr % chunk_size; // next, make sure that we get the address (if applicable) @@ -175,7 +175,7 @@ const DmaData& FixedChunkDmaCopier::run(const void* memory, u32 offset, bool ver } diff_dma_chains(DmaFollower(memory, offset), DmaFollower(m_result.data.data(), m_result.start_offset)); - assert(false); + ASSERT(false); } else { fmt::print("verification ok: {} bytes\n", ref.size()); } diff --git a/common/dma/gs.cpp b/common/dma/gs.cpp index c7f3220667..a320caa32a 100644 --- a/common/dma/gs.cpp +++ b/common/dma/gs.cpp @@ -1,7 +1,7 @@ #include "gs.h" #include "third-party/fmt/core.h" -#include "common/util/assert.h" +#include "common/util/Assert.h" std::string reg_descriptor_name(GifTag::RegisterDescriptor reg) { switch (reg) { @@ -37,7 +37,7 @@ std::string reg_descriptor_name(GifTag::RegisterDescriptor reg) { return "NOP"; default: - assert(false); + ASSERT(false); } } @@ -57,7 +57,7 @@ std::string GifTag::print() const { result += "disable "; return result; default: - assert(false); + ASSERT(false); } result += fmt::format("nloop: {} ", nloop()); @@ -196,7 +196,7 @@ std::string register_address_name(GsRegisterAddress reg) { case GsRegisterAddress::LABEL: return "LABEL"; default: - assert(false); + ASSERT(false); } } @@ -230,7 +230,7 @@ std::string GsTest::print() const { result += "NOTEQUAL "; break; default: - assert(false); + ASSERT(false); } result += fmt::format("ref: 0x{:x} alpha-fail: ", aref()); switch (afail()) { @@ -247,7 +247,7 @@ std::string GsTest::print() const { result += "RGB_ONLY "; break; default: - assert(false); + ASSERT(false); } } @@ -271,7 +271,7 @@ std::string GsTest::print() const { result += "GREATER"; break; default: - assert(false); + ASSERT(false); } } return result; @@ -290,7 +290,7 @@ std::string GsAlpha::print() const { result += "0 "; break; default: - assert(false); + ASSERT(false); } switch (b_mode()) { @@ -304,7 +304,7 @@ std::string GsAlpha::print() const { result += "- 0) * "; break; default: - assert(false); + ASSERT(false); } switch (c_mode()) { @@ -320,7 +320,7 @@ std::string GsAlpha::print() const { result += fmt::format("{:.4f}", div); } break; default: - assert(false); + ASSERT(false); } switch (d_mode()) { @@ -333,7 +333,7 @@ std::string GsAlpha::print() const { case BlendMode::ZERO_OR_FIXED: break; default: - assert(false); + ASSERT(false); } return result; @@ -376,7 +376,7 @@ std::string DrawMode::to_string() const { result += "greater\n"; break; default: - assert(false); + ASSERT(false); } result += fmt::format(" alpha: "); switch (get_alpha_blend()) { @@ -390,7 +390,7 @@ std::string DrawMode::to_string() const { result += "disabled\n"; break; default: - assert(false); + ASSERT(false); } result += fmt::format(" clamp: s {} t {}\n", get_clamp_s_enable(), get_clamp_t_enable()); result += fmt::format(" filt: {}\n", get_filt_enable()); @@ -409,7 +409,7 @@ std::string DrawMode::to_string() const { result += "never\n"; break; default: - assert(false); + ASSERT(false); } result += fmt::format(" zte: {}\n", get_zt_enable()); result += fmt::format(" abe: {}\n", get_ab_enable()); @@ -428,7 +428,7 @@ std::string DrawMode::to_string() const { result += "zb-only\n"; break; default: - assert(false); + ASSERT(false); } return result; } \ No newline at end of file diff --git a/common/dma/gs.h b/common/dma/gs.h index 00468774fa..75a2fd1cdd 100644 --- a/common/dma/gs.h +++ b/common/dma/gs.h @@ -140,7 +140,7 @@ struct GsZbuf { case 0b1010: return TextureFormat::PSMZ16S; default: - assert(false); + ASSERT(false); } } diff --git a/common/goos/Interpreter.cpp b/common/goos/Interpreter.cpp index 46886bc253..407b952207 100644 --- a/common/goos/Interpreter.cpp +++ b/common/goos/Interpreter.cpp @@ -305,7 +305,7 @@ Arguments Interpreter::get_args(const Object& form, const Object& rest, const Ar if (args.unnamed.size() < spec.unnamed.size()) { throw_eval_error(form, "didn't get enough arguments"); } - assert(args.unnamed.size() == spec.unnamed.size()); + ASSERT(args.unnamed.size() == spec.unnamed.size()); if (!args.rest.empty() && spec.rest.empty()) { throw_eval_error(form, "got too many arguments"); diff --git a/common/goos/Object.cpp b/common/goos/Object.cpp index 60cd1a2e2d..986281c511 100644 --- a/common/goos/Object.cpp +++ b/common/goos/Object.cpp @@ -84,7 +84,7 @@ std::string object_type_to_string(ObjectType type) { template <> std::string fixed_to_string(FloatType x) { auto result = float_to_string(x); - assert((float)x == (float)std::stod(result)); + ASSERT((float)x == (float)std::stod(result)); return result; } diff --git a/common/goos/Object.h b/common/goos/Object.h index e799629005..e0c94c3338 100644 --- a/common/goos/Object.h +++ b/common/goos/Object.h @@ -49,7 +49,7 @@ #include #include #include "common/common_types.h" -#include "common/util/assert.h" +#include "common/util/Assert.h" namespace goos { diff --git a/common/goos/ParseHelpers.cpp b/common/goos/ParseHelpers.cpp index 0951cfd126..9c2f794527 100644 --- a/common/goos/ParseHelpers.cpp +++ b/common/goos/ParseHelpers.cpp @@ -42,7 +42,7 @@ bool va_check( const std::vector>& unnamed, const std::unordered_map>>& named, std::string* err_string) { - assert(args.rest.empty()); + ASSERT(args.rest.empty()); if (unnamed.size() != args.unnamed.size()) { *err_string = "Got " + std::to_string(args.unnamed.size()) + " arguments, but expected " + std::to_string(unnamed.size()); diff --git a/common/goos/ParseHelpers.h b/common/goos/ParseHelpers.h index bb3771363c..47df3575d2 100644 --- a/common/goos/ParseHelpers.h +++ b/common/goos/ParseHelpers.h @@ -23,7 +23,7 @@ void for_each_in_list(const goos::Object& list, T f) { iter = &lap->cdr; } - assert(iter->is_empty_list()); + ASSERT(iter->is_empty_list()); } int list_length(const goos::Object& list); diff --git a/common/goos/PrettyPrinter.cpp b/common/goos/PrettyPrinter.cpp index 8933b24da7..947e1b5255 100644 --- a/common/goos/PrettyPrinter.cpp +++ b/common/goos/PrettyPrinter.cpp @@ -13,7 +13,7 @@ #include "common/log/log.h" #include "common/goos/PrettyPrinter2.h" -#include "common/util/assert.h" +#include "common/util/Assert.h" namespace pretty_print { @@ -141,7 +141,7 @@ void add_to_token_list(const goos::Object& obj, std::vector* tokens) case goos::ObjectType::ENVIRONMENT: throw std::runtime_error("tried to pretty print a goos object kind which is not supported."); default: - assert(false); + ASSERT(false); } } @@ -248,19 +248,19 @@ void insertNewlineBefore(NodePool& pool, PrettyPrinterNode* node, int specialInd * After this has been called, the entire selection should be reformatted with propagate_pretty */ void breakList(NodePool& pool, PrettyPrinterNode* leftParen) { - assert(!leftParen->is_line_separator); - assert(leftParen->tok->kind == FormToken::TokenKind::OPEN_PAREN); + ASSERT(!leftParen->is_line_separator); + ASSERT(leftParen->tok->kind == FormToken::TokenKind::OPEN_PAREN); auto* rp = leftParen->paren; - assert(rp->tok->kind == FormToken::TokenKind::CLOSE_PAREN); + ASSERT(rp->tok->kind == FormToken::TokenKind::CLOSE_PAREN); for (auto* n = leftParen->next; n && n != rp; n = n->next) { if (!n->is_line_separator) { if (n->tok->kind == FormToken::TokenKind::OPEN_PAREN) { n = n->paren; - assert(n->tok->kind == FormToken::TokenKind::CLOSE_PAREN); + ASSERT(n->tok->kind == FormToken::TokenKind::CLOSE_PAREN); insertNewlineAfter(pool, n, 0); } else if (n->tok->kind != FormToken::TokenKind::WHITESPACE) { - assert(n->tok->kind != FormToken::TokenKind::CLOSE_PAREN); + ASSERT(n->tok->kind != FormToken::TokenKind::CLOSE_PAREN); insertNewlineAfter(pool, n, 0); } } @@ -338,7 +338,7 @@ static PrettyPrinterNode* propagatePretty(NodePool& pool, * Get the token on the start of the next line. nullptr if we're the last line. */ PrettyPrinterNode* getNextLine(PrettyPrinterNode* start) { - assert(!start->is_line_separator); + ASSERT(!start->is_line_separator); int line = start->line; for (;;) { if (start->is_line_separator || start->line == line) { @@ -359,7 +359,7 @@ PrettyPrinterNode* getNextLine(PrettyPrinterNode* start) { */ PrettyPrinterNode* getNextListOnLine(PrettyPrinterNode* start) { int line = start->line; - assert(!start->is_line_separator); + ASSERT(!start->is_line_separator); if (!start->next || start->next->is_line_separator) { return nullptr; } @@ -380,7 +380,7 @@ PrettyPrinterNode* getNextListOnLine(PrettyPrinterNode* start) { PrettyPrinterNode* getNextOfKindOrStringOnLine(PrettyPrinterNode* start, FormToken::TokenKind kind) { int line = start->line; - assert(!start->is_line_separator); + ASSERT(!start->is_line_separator); if (!start->next || start->next->is_line_separator) { return nullptr; } @@ -400,7 +400,7 @@ PrettyPrinterNode* getNextOfKindOrStringOnLine(PrettyPrinterNode* start, PrettyPrinterNode* getNextListOrEmptyListOnLine(PrettyPrinterNode* start) { int line = start->line; - assert(!start->is_line_separator); + ASSERT(!start->is_line_separator); if (!start->next || start->next->is_line_separator) { return nullptr; } @@ -454,7 +454,7 @@ loop_end: */ PrettyPrinterNode* getFirstListOnLine(PrettyPrinterNode* start) { int line = start->line; - assert(!start->is_line_separator); + ASSERT(!start->is_line_separator); while (!start->is_line_separator && start->line == line) { if (start->tok->kind == FormToken::TokenKind::OPEN_PAREN) return start; @@ -469,12 +469,12 @@ PrettyPrinterNode* getFirstListOnLine(PrettyPrinterNode* start) { * Get the first token on the first line which exceeds the max length */ PrettyPrinterNode* getFirstBadLine(PrettyPrinterNode* start, int line_length) { - assert(!start->is_line_separator); + ASSERT(!start->is_line_separator); int currentLine = start->line; auto* currentLineNode = start; for (;;) { if (start->is_line_separator) { - assert(start->next); + ASSERT(start->next); start = start->next; } else { if (start->line != currentLine) { @@ -518,7 +518,7 @@ void insertBreaksAsNeeded(NodePool& pool, PrettyPrinterNode* head, int line_leng break; // okay, we have a line which needs fixing. - assert(!candidate_line->prev || candidate_line->prev->is_line_separator); + ASSERT(!candidate_line->prev || candidate_line->prev->is_line_separator); PrettyPrinterNode* form_to_start = getFirstListOnLine(candidate_line); for (;;) { if (!form_to_start) { @@ -547,10 +547,10 @@ void insertBreaksAsNeeded(NodePool& pool, PrettyPrinterNode* head, int line_leng * After this has been called, the entire selection should be reformatted with propagate_pretty */ void breakList(NodePool& pool, PrettyPrinterNode* leftParen, PrettyPrinterNode* first_elt) { - assert(!leftParen->is_line_separator); - assert(leftParen->tok->kind == FormToken::TokenKind::OPEN_PAREN); + ASSERT(!leftParen->is_line_separator); + ASSERT(leftParen->tok->kind == FormToken::TokenKind::OPEN_PAREN); auto* rp = leftParen->paren; - assert(rp->tok->kind == FormToken::TokenKind::CLOSE_PAREN); + ASSERT(rp->tok->kind == FormToken::TokenKind::CLOSE_PAREN); bool breaking = false; for (auto* n = leftParen->next; n && n != rp; n = n->next) { @@ -560,13 +560,13 @@ void breakList(NodePool& pool, PrettyPrinterNode* leftParen, PrettyPrinterNode* if (!n->is_line_separator) { if (n->tok->kind == FormToken::TokenKind::OPEN_PAREN) { n = n->paren; - assert(n->tok->kind == FormToken::TokenKind::CLOSE_PAREN); + ASSERT(n->tok->kind == FormToken::TokenKind::CLOSE_PAREN); if (breaking) { insertNewlineAfter(pool, n, 0); } } else if (n->tok->kind != FormToken::TokenKind::WHITESPACE) { - assert(n->tok->kind != FormToken::TokenKind::CLOSE_PAREN); + ASSERT(n->tok->kind != FormToken::TokenKind::CLOSE_PAREN); if (breaking) { insertNewlineAfter(pool, n, 0); } @@ -694,9 +694,9 @@ void insertSpecialBreaks(NodePool& pool, PrettyPrinterNode* node) { while (true) { // let's break this case: - assert(start_of_case->tok->kind == FormToken::TokenKind::OPEN_PAREN); + ASSERT(start_of_case->tok->kind == FormToken::TokenKind::OPEN_PAREN); auto end_of_case = start_of_case->paren; - assert(end_of_case->tok->kind == FormToken::TokenKind::CLOSE_PAREN); + ASSERT(end_of_case->tok->kind == FormToken::TokenKind::CLOSE_PAREN); // get the first thing in the case // and break there. @@ -746,7 +746,7 @@ std::string to_string_v1(const goos::Object& obj, int line_length) { NodePool pool; std::vector tokens; add_to_token_list(obj, &tokens); - assert(!tokens.empty()); + ASSERT(!tokens.empty()); std::string pretty; // build linked list of nodes @@ -780,8 +780,8 @@ std::string to_string_v1(const goos::Object& obj, int line_length) { n->paren = parenStack.back(); } } - assert(parenStack.size() == 1); - assert(!parenStack.back()); + ASSERT(parenStack.size() == 1); + ASSERT(!parenStack.back()); insertSpecialBreaks(pool, head); propagatePretty(pool, head, line_length); diff --git a/common/goos/PrettyPrinter2.cpp b/common/goos/PrettyPrinter2.cpp index 5a6b6f9ccd..e0f64641f7 100644 --- a/common/goos/PrettyPrinter2.cpp +++ b/common/goos/PrettyPrinter2.cpp @@ -1,7 +1,7 @@ #include "PrettyPrinter2.h" #include "common/common_types.h" #include "third-party/fmt/core.h" -#include "common/util/assert.h" +#include "common/util/Assert.h" namespace pretty_print { @@ -46,13 +46,13 @@ struct Node { break; case Kind::LIST: case Kind::IMPROPER_LIST: - assert(!child_nodes.empty()); + ASSERT(!child_nodes.empty()); for (auto& child : child_nodes) { child.link(this, bfs_order, depth + 1); } break; default: - assert(false); + ASSERT(false); } } @@ -77,7 +77,7 @@ struct Node { case Kind::IMPROPER_LIST: return "[improper list]"; default: - assert(false); + ASSERT(false); } } @@ -141,7 +141,7 @@ Node to_node(const goos::Object& obj) { case goos::ObjectType::ENVIRONMENT: throw std::runtime_error("tried to pretty print a goos object kind which is not supported."); default: - assert(false); + ASSERT(false); } } @@ -186,7 +186,7 @@ void recompute_lengths(const std::vector& bfs_order) { } } break; default: - assert(false); + ASSERT(false); } } } @@ -197,7 +197,7 @@ void recompute_lengths(const std::vector& bfs_order) { * If you want to force a form to always be broken up, see insert_required_breaks */ void break_list(Node* node) { - assert(!node->break_list); + ASSERT(!node->break_list); node->break_list = true; node->sub_elt_indent = 2; node->top_line_count = 1; @@ -306,7 +306,7 @@ int run_algorithm(const std::vector& bfs_order, int line_length) { } int compute_extra_offset(const std::string& str, int s0, int ei) { - assert(!str.empty()); + ASSERT(!str.empty()); for (size_t i = str.length(); i-- > 0;) { if ((int)i == s0) { return ei + str.length() - s0; @@ -381,7 +381,7 @@ void append_node_to_string(const Node* node, str.push_back(')'); } else { str.push_back('('); - assert(!node->child_nodes.empty()); + ASSERT(!node->child_nodes.empty()); int listing_indent = next_indent_level + node->quoted; int extra_indent = 1; int c0 = 0; @@ -413,7 +413,7 @@ void append_node_to_string(const Node* node, } break; default: - assert(false); + ASSERT(false); } } diff --git a/common/goos/Printer.cpp b/common/goos/Printer.cpp index 7804affbee..51466d6c10 100644 --- a/common/goos/Printer.cpp +++ b/common/goos/Printer.cpp @@ -63,7 +63,7 @@ goos::Object build_list(const std::vector& objects) { // build a list out of an array of forms goos::Object build_list(const goos::Object* objects, int count) { - assert(count); + ASSERT(count); auto car = objects[0]; goos::Object cdr; if (count - 1) { @@ -94,7 +94,7 @@ void append(goos::Object& _in, const goos::Object& add) { } if (!in->is_pair()) { - assert(false); // invalid list + ASSERT(false); // invalid list } in->as_pair()->cdr = add; } diff --git a/common/goos/Reader.cpp b/common/goos/Reader.cpp index 31eb0267f6..2ff07bc453 100644 --- a/common/goos/Reader.cpp +++ b/common/goos/Reader.cpp @@ -77,8 +77,8 @@ void TextStream::seek_past_whitespace_and_comments() { case '#': if (text_remains(1) && peek(1) == '|') { - assert(read() == '#'); // # - assert(read() == '|'); // | + ASSERT(read() == '#'); // # + ASSERT(read() == '|'); // | bool found_end = false; // find |# @@ -311,7 +311,7 @@ bool Reader::check_string_is_valid(const std::string& str) const { * whitespace at the end and leaves the stream on the first character after the token. */ Token Reader::get_next_token(TextStream& stream) { - assert(stream.text_remains()); + ASSERT(stream.text_remains()); Token t; t.source_line = stream.line_count; t.source_offset = stream.seek; @@ -389,7 +389,7 @@ bool Reader::read_object(Token& tok, TextStream& ts, Object& obj) { // try as string if (tok.text[0] == '"') { // it's a string. - assert(tok.text.length() == 1); + ASSERT(tok.text.length() == 1); if (read_string(ts, obj)) { return true; } else { @@ -420,22 +420,22 @@ bool Reader::read_object(Token& tok, TextStream& ts, Object& obj) { } bool Reader::read_array(TextStream& stream, Object& o) { - // assert(stream.read() == '('); + // ASSERT(stream.read() == '('); stream.seek_past_whitespace_and_comments(); std::vector objects; bool got_close_paren = false; while (stream.text_remains()) { auto tok = get_next_token(stream); - assert(!tok.text.empty()); + ASSERT(!tok.text.empty()); if (tok.text[0] == '(') { - assert(tok.text.length() == 1); + ASSERT(tok.text.length() == 1); objects.push_back(read_list(stream, true)); stream.seek_past_whitespace_and_comments(); continue; } else if (tok.text[0] == ')') { - assert(tok.text.length() == 1); + ASSERT(tok.text.length() == 1); got_close_paren = true; break; } else { @@ -531,19 +531,19 @@ Object Reader::read_list(TextStream& ts, bool expect_close_paren) { }; if (tok.text.empty()) { - assert(false); + ASSERT(false); // empty list break; } else if (tok.text[0] == '(') { // nested list - assert(tok.text.length() == 1); + ASSERT(tok.text.length() == 1); insert_object(read_list(ts, true)); ts.seek_past_whitespace_and_comments(); continue; } else if (tok.text[0] == ')') { // end of this list got_close_paren = true; - assert(tok.text.length() == 1); + ASSERT(tok.text.length() == 1); break; } else { // try to get an object @@ -604,7 +604,7 @@ Object Reader::read_list(TextStream& ts, bool expect_close_paren) { */ bool Reader::try_token_as_symbol(const Token& tok, Object& obj) { // check start character is valid: - assert(!tok.text.empty()); + ASSERT(!tok.text.empty()); char start = tok.text[0]; if (m_valid_symbols_chars[(int)start]) { obj = SymbolObject::make_new(symbolTable, tok.text); @@ -663,7 +663,7 @@ bool Reader::read_string(TextStream& stream, Object& obj) { if (end != 2) { throw_reader_error(stream, "invalid character escape", -2); } - assert(value < 256); + ASSERT(value < 256); str.push_back(char(value)); } else { throw_reader_error(stream, "unknown string escape code", -1); diff --git a/common/goos/Reader.h b/common/goos/Reader.h index 7beed321e5..efe29b676d 100644 --- a/common/goos/Reader.h +++ b/common/goos/Reader.h @@ -21,7 +21,7 @@ #include "ReplUtils.h" -#include "common/util/assert.h" +#include "common/util/Assert.h" namespace goos { @@ -36,17 +36,17 @@ struct TextStream { int line_count = 0; char peek() { - assert(seek < text->get_size()); + ASSERT(seek < text->get_size()); return text->get_text()[seek]; } char peek(int i) { - assert(seek + i < text->get_size()); + ASSERT(seek + i < text->get_size()); return text->get_text()[seek + i]; } char read() { - assert(seek < text->get_size()); + ASSERT(seek < text->get_size()); char c = text->get_text()[seek++]; if (c == '\n') line_count++; diff --git a/common/goos/TextDB.cpp b/common/goos/TextDB.cpp index 4a1d4090a5..38dda75ffc 100644 --- a/common/goos/TextDB.cpp +++ b/common/goos/TextDB.cpp @@ -104,7 +104,7 @@ void TextDb::insert(const std::shared_ptr& frag) { void TextDb::link(const Object& o, std::shared_ptr frag, int offset) { if (o.is_empty_list()) return; - assert(o.is_pair()); + ASSERT(o.is_pair()); TextRef ref; ref.offset = offset; ref.frag = std::move(frag); diff --git a/common/log/log.cpp b/common/log/log.cpp index 5845efb98f..3d6b95b0f2 100644 --- a/common/log/log.cpp +++ b/common/log/log.cpp @@ -6,7 +6,7 @@ #ifdef _WIN32 // see lg::initialize #include #endif -#include "common/util/assert.h" +#include "common/util/Assert.h" namespace lg { struct Logger { @@ -76,9 +76,9 @@ void log_message(level log_level, LogTime& now, const char* message) { } // namespace internal void set_file(const std::string& filename) { - assert(!gLogger.fp); + ASSERT(!gLogger.fp); gLogger.fp = fopen(filename.c_str(), "w"); - assert(gLogger.fp); + ASSERT(gLogger.fp); } void set_flush_level(level log_level) { @@ -100,7 +100,7 @@ void set_max_debug_levels() { } void initialize() { - assert(!gLogger.initialized); + ASSERT(!gLogger.initialized); #ifdef _WIN32 // Enable some console terminal flags. Some of these may not be enabled by default, unless diff --git a/common/texture/texture_conversion.h b/common/texture/texture_conversion.h index 727985c095..6127781db6 100644 --- a/common/texture/texture_conversion.h +++ b/common/texture/texture_conversion.h @@ -156,8 +156,8 @@ inline u32 psmt4_addr_half_byte(u32 x, u32 y, u32 width) { const u32 psm4_table[8][4] = {{0, 2, 8, 10}, {1, 3, 9, 11}, {4, 6, 12, 14}, {5, 7, 13, 15}, {16, 18, 24, 26}, {17, 19, 25, 27}, {20, 22, 28, 30}, {21, 23, 29, 31}}; - assert(block_row < 8); - assert(block_col < 4); + ASSERT(block_row < 8); + ASSERT(block_col < 4); u32 block = psm4_table[block_row][block_col]; // it's the same table!!! // both columns and pixels within columns. @@ -196,8 +196,8 @@ inline u32 psmt4_addr_half_byte(u32 x, u32 y, u32 width) { 405, 413, 437, 445, 469, 477, 501, 509, 407, 415, 439, 447, 471, 479, 503, 511}, }; - assert(block_y < 16); - assert(block_x < 32); + ASSERT(block_y < 16); + ASSERT(block_x < 32); u32 pixel = pix_table[block_y][block_x]; return (page * 128 * 128) + (block * 32 * 16) + pixel; } diff --git a/common/type_system/Type.cpp b/common/type_system/Type.cpp index 6b395a3be7..d7e0366040 100644 --- a/common/type_system/Type.cpp +++ b/common/type_system/Type.cpp @@ -6,7 +6,7 @@ #include #include "third-party/fmt/core.h" #include "Type.h" -#include "common/util/assert.h" +#include "common/util/Assert.h" namespace { std::string reg_kind_to_string(RegClass kind) { @@ -326,7 +326,7 @@ bool Type::get_my_method(const std::string& name, MethodInfo* out) const { * Get a method that is defined specifically in this type by id. Returns if it was found or not. */ bool Type::get_my_method(int id, MethodInfo* out) const { - assert(id > 0); // 0 is new, should use explicit new method functions instead. + ASSERT(id > 0); // 0 is new, should use explicit new method functions instead. for (auto& x : m_methods) { if (x.id == id) { *out = x; @@ -369,7 +369,7 @@ bool Type::get_my_new_method(MethodInfo* out) const { const MethodInfo& Type::add_method(const MethodInfo& info) { for (auto it = m_methods.rbegin(); it != m_methods.rend(); it++) { if (!it->overrides_method_type_of_parent) { - assert(it->id + 1 == info.id); + ASSERT(it->id + 1 == info.id); break; } } @@ -383,7 +383,7 @@ const MethodInfo& Type::add_method(const MethodInfo& info) { * this is specific to the method named NEW. */ const MethodInfo& Type::add_new_method(const MethodInfo& info) { - assert(info.name == "new"); + ASSERT(info.name == "new"); m_new_method_info_defined = true; m_new_method_info = info; return m_new_method_info; @@ -553,7 +553,7 @@ bool ValueType::get_load_signed() const { void ValueType::set_offset(int offset) { if (offset) { - assert(m_is_boxed); + ASSERT(m_is_boxed); } m_offset = offset; } diff --git a/common/type_system/Type.h b/common/type_system/Type.h index 364c11ae9c..cb101a5bb5 100644 --- a/common/type_system/Type.h +++ b/common/type_system/Type.h @@ -10,7 +10,7 @@ #include #include "common/goal_constants.h" #include "TypeSpec.h" -#include "common/util/assert.h" +#include "common/util/Assert.h" class TypeSystem; @@ -219,12 +219,12 @@ class Field { std::string diff(const Field& other) const; int alignment() const { - assert(m_alignment != -1); + ASSERT(m_alignment != -1); return m_alignment; } int array_size() const { - assert(is_array() && !is_dynamic()); + ASSERT(is_array() && !is_dynamic()); return m_array_size; } diff --git a/common/type_system/TypeFieldLookup.cpp b/common/type_system/TypeFieldLookup.cpp index 18723f0ecf..4733c7266e 100644 --- a/common/type_system/TypeFieldLookup.cpp +++ b/common/type_system/TypeFieldLookup.cpp @@ -18,8 +18,8 @@ bool deref_matches(const DerefInfo& expected, const DerefKind& actual, bool is_integer, bool is_basic) { - assert(expected.mem_deref); - assert(expected.can_deref); + ASSERT(expected.mem_deref); + ASSERT(expected.can_deref); if (actual.is_store || actual.size >= 8 || !is_integer) { // don't check sign extension return expected.load_size == actual.size; @@ -62,7 +62,7 @@ std::string FieldReverseLookupOutput::Token::print() const { case Kind::VAR_IDX: return "__VAR__"; default: - assert(false); + ASSERT(false); return {}; } } @@ -132,7 +132,7 @@ void try_reverse_lookup_array_like(const FieldReverseLookupInput& input, auto di = ts.get_deref_info(array_data_type); bool is_integer = ts.tc(TypeSpec("integer"), input.base_type.get_single_arg()); bool is_basic = ts.tc(TypeSpec("basic"), input.base_type.get_single_arg()); - assert(di.mem_deref); // it's accessing a pointer. + ASSERT(di.mem_deref); // it's accessing a pointer. auto elt_type = di.result_type; if (input.stride) { @@ -243,8 +243,8 @@ void try_reverse_lookup_inline_array(const FieldReverseLookupInput& input, return; } auto di = ts.get_deref_info(input.base_type); - assert(di.can_deref); - assert(!di.mem_deref); + ASSERT(di.can_deref); + ASSERT(!di.mem_deref); if (input.stride && input.stride == di.stride && input.offset < di.stride) { // variable lookup. diff --git a/common/type_system/TypeSpec.h b/common/type_system/TypeSpec.h index 7b2edbad44..defbc1be1d 100644 --- a/common/type_system/TypeSpec.h +++ b/common/type_system/TypeSpec.h @@ -9,7 +9,7 @@ #include #include #include "common/util/SmallVector.h" -#include "common/util/assert.h" +#include "common/util/Assert.h" /*! * A :name value modifier to apply to a type. @@ -103,8 +103,8 @@ class TypeSpec { } const TypeSpec& get_single_arg() const { - assert(m_arguments); - assert(m_arguments->size() == 1); + ASSERT(m_arguments); + ASSERT(m_arguments->size() == 1); return m_arguments->front(); } @@ -118,16 +118,16 @@ class TypeSpec { } const TypeSpec& get_arg(int idx) const { - assert(m_arguments); + ASSERT(m_arguments); return m_arguments->at(idx); } TypeSpec& get_arg(int idx) { - assert(m_arguments); + ASSERT(m_arguments); return m_arguments->at(idx); } const TypeSpec& last_arg() const { - assert(m_arguments); - assert(!m_arguments->empty()); + ASSERT(m_arguments); + ASSERT(!m_arguments->empty()); return m_arguments->back(); } diff --git a/common/type_system/TypeSystem.cpp b/common/type_system/TypeSystem.cpp index bdb8a5fc0d..351da707a7 100644 --- a/common/type_system/TypeSystem.cpp +++ b/common/type_system/TypeSystem.cpp @@ -10,7 +10,7 @@ #include #include "TypeSystem.h" #include "common/util/math_util.h" -#include "common/util/assert.h" +#include "common/util/Assert.h" namespace { template @@ -283,7 +283,7 @@ DerefInfo TypeSystem::get_deref_info(const TypeSpec& ts) const { result_type->get_inline_array_stride_alignment()); } else { // can't have an inline array of value types! - assert(false); + ASSERT(false); } } else if (ts.base_type() == "pointer") { info.can_deref = true; @@ -300,7 +300,7 @@ DerefInfo TypeSystem::get_deref_info(const TypeSpec& ts) const { info.sign_extend = result_type->get_load_signed(); info.reg = result_type->get_preferred_reg_class(); info.load_size = result_type->get_load_size(); - assert(result_type->get_size_in_memory() == result_type->get_load_size()); + ASSERT(result_type->get_size_in_memory() == result_type->get_load_size()); } } else { info.can_deref = false; @@ -474,7 +474,7 @@ int TypeSystem::get_load_size_allow_partial_def(const TypeSpec& ts) const { throw_typesystem_error("Cannot perform a load or store from partially defined type {}", ts.print()); } - assert(partial_def->get_load_size() == 4); + ASSERT(partial_def->get_load_size() == 4); return partial_def->get_load_size(); } @@ -1212,7 +1212,7 @@ int TypeSystem::get_size_in_type(const Field& field) const { "Attempted to use `{}` inline, this probably isn't what you wanted.\n", field_type->get_name()); } - assert(field_type->is_reference()); + ASSERT(field_type->is_reference()); return field.array_size() * align(field_type->get_size_in_memory(), field_type->get_inline_array_stride_alignment()); } else { @@ -1236,7 +1236,7 @@ int TypeSystem::get_size_in_type(const Field& field) const { "may not be defined fully.\n", field_type->get_name()); } - assert(field_type->is_reference()); + ASSERT(field_type->is_reference()); // return align(field_type->get_size_in_memory(), field_type->get_in_memory_alignment()); // looking at dead-pool-heap we tightly pack in this case return field_type->get_size_in_memory(); @@ -1475,7 +1475,7 @@ std::string TypeSystem::lca_base(const std::string& a, const std::string& b) con bi--; } - assert(result); + ASSERT(result); return *result; } @@ -1508,7 +1508,7 @@ TypeSpec TypeSystem::lowest_common_ancestor_reg(const TypeSpec& a, const TypeSpe * Lowest common ancestor of multiple (or at least one) type. */ TypeSpec TypeSystem::lowest_common_ancestor(const std::vector& types) const { - assert(!types.empty()); + ASSERT(!types.empty()); if (types.size() == 1) { return types.front(); } diff --git a/common/type_system/deftype.cpp b/common/type_system/deftype.cpp index 6b19d30d41..9a0bcd5116 100644 --- a/common/type_system/deftype.cpp +++ b/common/type_system/deftype.cpp @@ -526,7 +526,7 @@ TypeSpec parse_typespec(const TypeSystem* type_system, const goos::Object& src) } else { throw std::runtime_error("invalid typespec: " + src.print()); } - assert(false); + ASSERT(false); return {}; } @@ -553,7 +553,7 @@ DeftypeResult parse_deftype(const goos::Object& deftype, TypeSystem* ts) { if (is_type("basic", parent_type, ts)) { auto new_type = std::make_unique(parent_type_name, name, false, 0); auto pto = dynamic_cast(ts->lookup_type(parent_type)); - assert(pto); + ASSERT(pto); if (pto->final()) { throw std::runtime_error( fmt::format("[TypeSystem] Cannot make a child type {} of final basic type {}", name, @@ -589,7 +589,7 @@ DeftypeResult parse_deftype(const goos::Object& deftype, TypeSystem* ts) { } else if (is_type("structure", parent_type, ts)) { auto new_type = std::make_unique(parent_type_name, name, false, false, false, 0); auto pto = dynamic_cast(ts->lookup_type(parent_type)); - assert(pto); + ASSERT(pto); new_type->inherit(pto); ts->forward_declare_type_as(name, "structure"); auto sr = parse_structure_def(new_type.get(), ts, field_list_obj, options_obj); @@ -612,11 +612,11 @@ DeftypeResult parse_deftype(const goos::Object& deftype, TypeSystem* ts) { ts->add_type(name, std::move(new_type)); } else if (is_type("integer", parent_type, ts)) { auto pto = ts->lookup_type(parent_type); - assert(pto); + ASSERT(pto); auto new_type = std::make_unique( parent_type_name, name, pto->get_size_in_memory(), pto->get_load_signed()); auto parent_value = dynamic_cast(pto); - assert(parent_value); + ASSERT(parent_value); new_type->inherit(parent_value); new_type->set_runtime_type(pto->get_runtime_name()); auto sr = parse_bitfield_type_def(new_type.get(), ts, field_list_obj, options_obj); diff --git a/common/type_system/state.cpp b/common/type_system/state.cpp index 373fa6b599..64d32ad7c9 100644 --- a/common/type_system/state.cpp +++ b/common/type_system/state.cpp @@ -5,7 +5,7 @@ * Convert a (state ...) to the function required to go. Must be state. */ TypeSpec state_to_go_function(const TypeSpec& state_type, const TypeSpec& return_type) { - assert(state_type.base_type() == "state"); + ASSERT(state_type.base_type() == "state"); std::vector arg_types; for (int i = 0; i < (int)state_type.arg_count() - 1; i++) { arg_types.push_back(state_type.get_arg(i)); @@ -31,7 +31,7 @@ StateHandler handler_name_to_kind(const std::string& name) { } else if (name == "post") { return StateHandler::POST; } else { - assert(false); + ASSERT(false); } } @@ -50,7 +50,7 @@ std::string handler_kind_to_name(StateHandler kind) { case StateHandler::POST: return "post"; default: - assert(false); + ASSERT(false); } } @@ -80,7 +80,7 @@ TypeSpec get_state_handler_type(StateHandler kind, const TypeSpec& state_type) { break; default: - assert(false); + ASSERT(false); } result.add_or_modify_tag("behavior", state_type.last_arg().base_type()); return result; diff --git a/common/util/Assert.cpp b/common/util/Assert.cpp new file mode 100644 index 0000000000..3d923e9be1 --- /dev/null +++ b/common/util/Assert.cpp @@ -0,0 +1,9 @@ +#include +#include + +#include "Assert.h" + +void private_assert_failed(const char* expr, const char* file, int line, const char* function) { + fprintf(stderr, "%s:%d: Assertion failed: %s\nFunction: %s\n", file, line, expr, function); + abort(); +} diff --git a/common/util/Assert.h b/common/util/Assert.h new file mode 100644 index 0000000000..40f6750dda --- /dev/null +++ b/common/util/Assert.h @@ -0,0 +1,18 @@ +/*! + * @file assert.h + * Custom ASSERT macro + */ + +#pragma once + +[[noreturn]] void private_assert_failed(const char* expr, + const char* file, + int line, + const char* function); + +#ifdef _WIN32 +#define __PRETTY_FUNCTION__ __FUNCSIG__ +#endif + +#define ASSERT(EX) \ + (void)((EX) || (private_assert_failed(#EX, __FILE__, __LINE__, __PRETTY_FUNCTION__), 0)) diff --git a/common/util/BinaryReader.h b/common/util/BinaryReader.h index 18ce2be386..066ba37df5 100644 --- a/common/util/BinaryReader.h +++ b/common/util/BinaryReader.h @@ -9,7 +9,7 @@ #include #include #include "common/common_types.h" -#include "common/util/assert.h" +#include "common/util/Assert.h" class BinaryReader { public: @@ -17,7 +17,7 @@ class BinaryReader { template T read() { - assert(m_seek + sizeof(T) <= m_buffer.size()); + ASSERT(m_seek + sizeof(T) <= m_buffer.size()); T obj; memcpy(&obj, m_buffer.data() + m_seek, sizeof(T)); m_seek += sizeof(T); @@ -26,7 +26,7 @@ class BinaryReader { void ffwd(int amount) { m_seek += amount; - assert(m_seek <= m_buffer.size()); + ASSERT(m_seek <= m_buffer.size()); } uint32_t bytes_left() const { return m_buffer.size() - m_seek; } diff --git a/common/util/BinaryWriter.h b/common/util/BinaryWriter.h index 498aaec9bc..5232f62cc9 100644 --- a/common/util/BinaryWriter.h +++ b/common/util/BinaryWriter.h @@ -9,7 +9,7 @@ #include #include #include -#include "common/util/assert.h" +#include "common/util/Assert.h" struct BinaryWriterRef { size_t offset; @@ -30,8 +30,8 @@ class BinaryWriter { template void add_at_ref(const T& obj, const BinaryWriterRef& ref) { - assert(ref.write_size == sizeof(T)); - assert(ref.offset + ref.write_size < get_size()); + ASSERT(ref.write_size == sizeof(T)); + ASSERT(ref.offset + ref.write_size < get_size()); memcpy(data.data() + ref.offset, &obj, sizeof(T)); } diff --git a/common/util/BitUtils.cpp b/common/util/BitUtils.cpp index 5e212180ec..9c07813251 100644 --- a/common/util/BitUtils.cpp +++ b/common/util/BitUtils.cpp @@ -25,7 +25,7 @@ bool integer_fits(s64 in, int size, bool is_signed) { case 8: return true; default: - assert(false); + ASSERT(false); return false; } } diff --git a/common/util/BitUtils.h b/common/util/BitUtils.h index 88eb015d45..e57a94ee23 100644 --- a/common/util/BitUtils.h +++ b/common/util/BitUtils.h @@ -3,7 +3,7 @@ #include #include "common/util/Range.h" #include "common/common_types.h" -#include "common/util/assert.h" +#include "common/util/Assert.h" constexpr int BITS_PER_BYTE = 8; template @@ -56,7 +56,7 @@ std::optional get_power_of_two(T in) { return i; } } - assert(false); + ASSERT(false); } else { return std::nullopt; } diff --git a/common/util/CopyOnWrite.h b/common/util/CopyOnWrite.h index e758ce43d1..3916e47a5a 100644 --- a/common/util/CopyOnWrite.h +++ b/common/util/CopyOnWrite.h @@ -1,5 +1,5 @@ #include -#include "common/util/assert.h" +#include "common/util/Assert.h" /* template @@ -90,9 +90,9 @@ class CopyOnWrite { } if (!m_data->unique()) { - assert(!m_data->dead()); + ASSERT(!m_data->dead()); m_data->remove_ref(); // don't need to check for dead here, there's another ref somewhere. - assert(!m_data->dead()); + ASSERT(!m_data->dead()); m_data = new ObjectAndCount(m_data->object); m_data->add_ref(); } @@ -111,7 +111,7 @@ class CopyOnWrite { } void acquire_object(ObjectAndCount* obj) { - assert(!m_data); + ASSERT(!m_data); m_data = obj; if (obj) { m_data->add_ref(); diff --git a/common/util/DgoReader.cpp b/common/util/DgoReader.cpp index f6fecd2183..0d360b0f9d 100644 --- a/common/util/DgoReader.cpp +++ b/common/util/DgoReader.cpp @@ -28,7 +28,7 @@ DgoReader::DgoReader(std::string file_name, const std::vector& data) (int)reader.bytes_left()); obj_header.size = reader.bytes_left(); } - assert(reader.bytes_left() >= obj_header.size); + ASSERT(reader.bytes_left() >= obj_header.size); assert_string_empty_after(obj_header.name, 60); DgoDataEntry entry; @@ -44,7 +44,7 @@ DgoReader::DgoReader(std::string file_name, const std::vector& data) all_unique_names.insert(entry.unique_name); entry.data.resize(obj_header.size); - assert((reader.get_seek() % 16) == 0); + ASSERT((reader.get_seek() % 16) == 0); memcpy(entry.data.data(), reader.here(), obj_header.size); m_entries.push_back(entry); @@ -52,8 +52,8 @@ DgoReader::DgoReader(std::string file_name, const std::vector& data) } // check we're at the end - assert(0 == reader.bytes_left()); - assert(all_unique_names.size() == m_entries.size()); + ASSERT(0 == reader.bytes_left()); + ASSERT(all_unique_names.size() == m_entries.size()); } std::string DgoReader::description_as_json() const { diff --git a/common/util/FileUtil.cpp b/common/util/FileUtil.cpp index 5a3004cad3..98cadbc16c 100644 --- a/common/util/FileUtil.cpp +++ b/common/util/FileUtil.cpp @@ -23,7 +23,7 @@ #include #include #endif -#include "common/util/assert.h" +#include "common/util/Assert.h" namespace file_util { std::filesystem::path get_user_home_dir() { @@ -176,7 +176,7 @@ std::string combine_path(const std::string& parent, const std::string& child) { std::string base_name(const std::string& filename) { size_t pos = 0; - assert(!filename.empty()); + ASSERT(!filename.empty()); for (size_t i = filename.size() - 1; i-- > 0;) { if (filename.at(i) == '/' || filename.at(i) == '\\') { pos = (i + 1); @@ -201,7 +201,7 @@ void init_crc() { } uint32_t crc32(const uint8_t* data, size_t size) { - assert(sInitCrc); + ASSERT(sInitCrc); uint32_t crc = 0; for (size_t i = size; i != 0; i--, data++) { crc = crc_table[crc >> 24u] ^ ((crc << 8u) | *data); @@ -343,7 +343,7 @@ void MakeISOName(char* dst, const char* src) { void assert_file_exists(const char* path, const char* error_message) { if (!std::filesystem::exists(path)) { fprintf(stderr, "File %s was not found: %s\n", path, error_message); - assert(false); + ASSERT(false); } } @@ -385,12 +385,12 @@ std::vector decompress_dgo(const std::vector& data_in) { lzokay::EResult ok = lzokay::decompress( compressed_reader.here(), chunk_size, decompressed_data.data() + output_offset, decompressed_data.size() - output_offset, bytes_written); - assert(ok == lzokay::EResult::Success); + ASSERT(ok == lzokay::EResult::Success); compressed_reader.ffwd(chunk_size); output_offset += bytes_written; } else { // nope - sometimes chunk_size is bigger than MAX, but we should still use max. - // assert(chunk_size == MAX_CHUNK_SIZE); + // ASSERT(chunk_size == MAX_CHUNK_SIZE); memcpy(decompressed_data.data() + output_offset, compressed_reader.here(), MAX_CHUNK_SIZE); compressed_reader.ffwd(MAX_CHUNK_SIZE); output_offset += MAX_CHUNK_SIZE; diff --git a/common/util/FontUtils.cpp b/common/util/FontUtils.cpp index 822775a653..c63a1be7b3 100644 --- a/common/util/FontUtils.cpp +++ b/common/util/FontUtils.cpp @@ -60,7 +60,7 @@ const EncodeInfo* GameTextFontBank::find_encode_to_game(const std::string& in, i continue; bool found = true; - for (int i = 0; found && i < (int)info.chars.length() && i + off < in.size(); ++i) { + for (int i = 0; found && i < (int)info.chars.length() && i + off < (int)in.size(); ++i) { if (in.at(i + off) != info.chars.at(i)) { found = false; } @@ -101,7 +101,7 @@ std::string GameTextFontBank::replace_to_game(std::string& str) const { std::string GameTextFontBank::encode_utf8_to_game(std::string& str) const { std::string new_str; - for (int i = 0; i < str.length();) { + for (int i = 0; i < (int)str.length();) { auto remap = find_encode_to_game(str, i); if (!remap) { new_str.push_back(str.at(i)); diff --git a/common/util/Serializer.h b/common/util/Serializer.h index 6c72bf848f..f49076dfc6 100644 --- a/common/util/Serializer.h +++ b/common/util/Serializer.h @@ -3,7 +3,7 @@ #include #include #include -#include "common/util/assert.h" +#include "common/util/Assert.h" /*! * The Serializer is a tool to load or save data from a buffer. @@ -93,7 +93,7 @@ class Serializer { */ template T load() { - assert(!m_writing); + ASSERT(!m_writing); T result; read_or_write(&result, sizeof(T)); return result; @@ -104,7 +104,7 @@ class Serializer { */ template void save(const T& thing) { - assert(m_writing); + ASSERT(m_writing); read_or_write(const_cast(&thing), sizeof(T)); } @@ -126,7 +126,7 @@ class Serializer { * const_cast. */ void save_str(const std::string* str) { - assert(is_saving()); + ASSERT(is_saving()); // safe, we're saving, so from_str will only read. from_str(const_cast(str)); } @@ -135,7 +135,7 @@ class Serializer { * Load a std::string and return it. */ std::string load_string() { - assert(is_loading()); + ASSERT(is_loading()); std::string s; from_str(&s); return s; @@ -168,7 +168,7 @@ class Serializer { * Reset a load back to the beginning. */ void reset_load() { - assert(is_loading()); + ASSERT(is_loading()); m_offset = 0; } @@ -176,7 +176,7 @@ class Serializer { * Get the result of the save. This is a view of the buffer owned by the Serializer. */ std::pair get_save_result() { - assert(m_writing); + ASSERT(m_writing); return {m_data, m_offset}; } @@ -184,7 +184,7 @@ class Serializer { * Have we reached the end of the load? */ bool get_load_finished() const { - assert(!m_writing); + ASSERT(!m_writing); return m_offset == m_size; } @@ -206,7 +206,7 @@ class Serializer { memcpy(m_data + m_offset, data, size); } else { // if we would overflow, it's an error. - assert(m_offset + size <= m_size); + ASSERT(m_offset + size <= m_size); memcpy(data, m_data + m_offset, size); } m_offset += size; diff --git a/common/util/SmallVector.h b/common/util/SmallVector.h index ab18cfa89e..9dfe4c4828 100644 --- a/common/util/SmallVector.h +++ b/common/util/SmallVector.h @@ -5,7 +5,7 @@ #include #include #include -#include "assert.h" +#include "common/util/Assert.h" namespace cu { // This might seem stupid, but compiling an empty file with #include takes 0.5 seconds. @@ -346,7 +346,7 @@ class SmallVector { * Get the element at the index. Assert the index is valid. */ T& at(std::size_t idx) { - assert(idx < m_size); + ASSERT(idx < m_size); return m_storage_begin[idx]; } @@ -354,7 +354,7 @@ class SmallVector { * Get the element at the index. Assert the index is valid. */ const T& at(std::size_t idx) const { - assert(idx < m_size); + ASSERT(idx < m_size); return m_storage_begin[idx]; } diff --git a/common/util/Timer.h b/common/util/Timer.h index 62fa58d7e0..9f4f21a714 100644 --- a/common/util/Timer.h +++ b/common/util/Timer.h @@ -2,7 +2,7 @@ #include #include -#include "common/util/assert.h" +#include "common/util/Assert.h" /*! * Timer for measuring time elapsed with clock_monotonic diff --git a/common/util/Trie.h b/common/util/Trie.h index a2002258a3..34f03c5725 100644 --- a/common/util/Trie.h +++ b/common/util/Trie.h @@ -2,7 +2,7 @@ #include #include -#include "common/util/assert.h" +#include "common/util/Assert.h" /*! * A simple prefix tree. It works similarly to a map, but also supports fast lookups by prefix with diff --git a/common/util/assert.h b/common/util/assert.h deleted file mode 100644 index 684234a032..0000000000 --- a/common/util/assert.h +++ /dev/null @@ -1,19 +0,0 @@ -/*! - * @file assert.h - * Wrapper around . - * Make sure this file is always the last one included. - */ - -#if defined NDEBUG - -#undef NDEBUG -#undef assert -#include - -#define NDEBUG 1 - -#else - -#include - -#endif diff --git a/common/util/compress.cpp b/common/util/compress.cpp index fde9d39f47..a31a19f47f 100644 --- a/common/util/compress.cpp +++ b/common/util/compress.cpp @@ -3,7 +3,7 @@ #include "compress.h" #include "third-party/zstd/lib/zstd.h" -#include "common/util/assert.h" +#include "common/util/Assert.h" namespace compression { @@ -18,7 +18,7 @@ std::vector compress_zstd(const void* data, size_t size) { ZSTD_compress(result.data() + sizeof(size_t), max_compressed, data, size, 1); if (ZSTD_isError(compressed_size)) { printf("ZSTD error: %s\n", ZSTD_getErrorName(compressed_size)); - assert(false); + ASSERT(false); } result.resize(sizeof(size_t) + compressed_size); return result; @@ -29,7 +29,7 @@ std::vector compress_zstd(const void* data, size_t size) { * decompressed data's size. */ std::vector decompress_zstd(const void* data, size_t size) { - assert(size >= sizeof(size_t)); + ASSERT(size >= sizeof(size_t)); size_t decompressed_size; memcpy(&decompressed_size, data, sizeof(size_t)); size_t compressed_size = size - sizeof(size_t); @@ -39,10 +39,10 @@ std::vector decompress_zstd(const void* data, size_t size) { (const u8*)data + sizeof(size_t), compressed_size); if (ZSTD_isError(decomp_size)) { printf("ZSTD error: %s\n", ZSTD_getErrorName(compressed_size)); - assert(false); + ASSERT(false); } - assert(decomp_size == decompressed_size); + ASSERT(decomp_size == decompressed_size); return result; } } // namespace compression diff --git a/common/util/dgo_util.cpp b/common/util/dgo_util.cpp index ab68bd5bda..4a7635239e 100644 --- a/common/util/dgo_util.cpp +++ b/common/util/dgo_util.cpp @@ -2,7 +2,7 @@ #include "dgo_util.h" #include "common/versions.h" #include "third-party/fmt/core.h" -#include "common/util/assert.h" +#include "common/util/Assert.h" /*! * Assert false if the char[] has non-null data after the null terminated string. @@ -13,7 +13,7 @@ void assert_string_empty_after(const char* str, int size) { while (*ptr) ptr++; while (ptr - str < size) { - assert(!*ptr); + ASSERT(!*ptr); ptr++; } } @@ -37,12 +37,12 @@ std::string get_object_file_name(const std::string& original_name, u8* data, int if (!failed) { for (int i = 0; i < int(original_name.length()); i++) { if (start + len + i >= size || data[start + len + i] != original_name[i]) { - assert(false); + ASSERT(false); } } - assert(int(suffix.length()) + start + len + int(original_name.length()) < size); - assert( + ASSERT(int(suffix.length()) + start + len + int(original_name.length()) < size); + ASSERT( !memcmp(data + start + len + original_name.length(), suffix.data(), suffix.length() + 1)); return original_name + "-ag"; diff --git a/common/util/json_util.cpp b/common/util/json_util.cpp index d5eae65c7a..428a0c4b7c 100644 --- a/common/util/json_util.cpp +++ b/common/util/json_util.cpp @@ -1,6 +1,6 @@ #include "common/log/log.h" #include "json_util.h" -#include "common/util/assert.h" +#include "common/util/Assert.h" /*! * Strip out // and / * comments @@ -57,7 +57,7 @@ std::string strip_cpp_style_comments(const std::string& input) { output.push_back(c); break; default: - assert(false); + ASSERT(false); } } diff --git a/common/util/print_float.cpp b/common/util/print_float.cpp index 579ba81e64..6d211fcec7 100644 --- a/common/util/print_float.cpp +++ b/common/util/print_float.cpp @@ -4,7 +4,7 @@ #include "common/goal_constants.h" #include "third-party/dragonbox.h" #include "print_float.h" -#include "common/util/assert.h" +#include "common/util/Assert.h" /*! * Convert a float to a string. The string is _always_ in this format: @@ -28,7 +28,7 @@ std::string meters_to_string(float value, bool append_trailing_decimal) { } int float_to_cstr(float value, char* buffer, bool append_trailing_decimal) { - assert(std::isfinite(value)); + ASSERT(std::isfinite(value)); // dragonbox gives us: // - an integer, representing the decimal value // - sign diff --git a/decompiler/Disasm/Instruction.cpp b/decompiler/Disasm/Instruction.cpp index 2d0f7891ad..a433838634 100644 --- a/decompiler/Disasm/Instruction.cpp +++ b/decompiler/Disasm/Instruction.cpp @@ -7,7 +7,7 @@ #include "Instruction.h" #include "decompiler/ObjectFile/LinkedObjectFile.h" #include "third-party/fmt/core.h" -#include "common/util/assert.h" +#include "common/util/Assert.h" namespace decompiler { /*! @@ -28,7 +28,7 @@ std::string InstructionAtom::to_string(const std::vector& label case IMM_SYM: return sym; case VF_FIELD: - assert(imm >= 0 && imm < 4); + ASSERT(imm >= 0 && imm < 4); return fmt::format(".{}", "xyzw"[imm]); default: throw std::runtime_error("Unsupported InstructionAtom"); @@ -87,14 +87,14 @@ void InstructionAtom::set_sym(std::string _sym) { void InstructionAtom::set_vf_field(uint32_t value) { kind = VF_FIELD; imm = value; - assert(value < 4); + ASSERT(value < 4); } /*! * Get as register, or error if not a register. */ Register InstructionAtom::get_reg() const { - assert(kind == REGISTER); + ASSERT(kind == REGISTER); return reg; } @@ -102,7 +102,7 @@ Register InstructionAtom::get_reg() const { * Get as integer immediate, or error if not an integer immediate. */ int32_t InstructionAtom::get_imm() const { - assert(kind == IMM); + ASSERT(kind == IMM); return imm; } @@ -110,7 +110,7 @@ int32_t InstructionAtom::get_imm() const { * Get the VF_FIELD as an integer immediate, or error if not applicable. */ int32_t InstructionAtom::get_vf_field() const { - assert(kind == VF_FIELD); + ASSERT(kind == VF_FIELD); return imm; } @@ -118,7 +118,7 @@ int32_t InstructionAtom::get_vf_field() const { * Get as label index, or error if not a label. */ int InstructionAtom::get_label() const { - assert(kind == LABEL); + ASSERT(kind == LABEL); return label_id; } @@ -126,7 +126,7 @@ int InstructionAtom::get_label() const { * Get as symbol, or error if not a symbol. */ std::string InstructionAtom::get_sym() const { - assert(kind == IMM_SYM); + ASSERT(kind == IMM_SYM); return sym; } @@ -152,7 +152,7 @@ bool InstructionAtom::operator==(const InstructionAtom& other) const { case VU_Q: return true; default: - assert(false); + ASSERT(false); return false; } } @@ -231,8 +231,8 @@ std::string Instruction::to_string(const std::vector& labels) c // relative store and load instructions have a special syntax in MIPS if (info.is_store) { - assert(n_dst == 0); - assert(n_src == 3); + ASSERT(n_dst == 0); + ASSERT(n_src == 3); result += " "; result += src[0].to_string(labels); result += ", "; @@ -241,8 +241,8 @@ std::string Instruction::to_string(const std::vector& labels) c result += src[2].to_string(labels); result += ")"; } else if (info.is_load) { - assert(n_dst == 1); - assert(n_src == 2); + ASSERT(n_dst == 1); + ASSERT(n_src == 2); result += " "; result += dst[0].to_string(labels); result += ", "; @@ -290,7 +290,7 @@ bool Instruction::is_valid() const { * Add a destination atom to this Instruction */ void Instruction::add_dst(InstructionAtom& a) { - assert(n_dst < MAX_INTRUCTION_DEST); + ASSERT(n_dst < MAX_INTRUCTION_DEST); dst[n_dst++] = a; } @@ -298,7 +298,7 @@ void Instruction::add_dst(InstructionAtom& a) { * Add a source atom to this Instruction */ void Instruction::add_src(InstructionAtom& a) { - assert(n_src < MAX_INSTRUCTION_SOURCE); + ASSERT(n_src < MAX_INSTRUCTION_SOURCE); src[n_src++] = a; } @@ -311,7 +311,7 @@ InstructionAtom& Instruction::get_imm_src() { return src[i]; } } - assert(false); + ASSERT(false); return src[0]; } @@ -326,7 +326,7 @@ int32_t Instruction::get_imm_src_int() { * Safe get dst atom */ InstructionAtom& Instruction::get_dst(size_t idx) { - assert(idx < n_dst); + ASSERT(idx < n_dst); return dst[idx]; } @@ -334,7 +334,7 @@ InstructionAtom& Instruction::get_dst(size_t idx) { * Safe get src atom */ InstructionAtom& Instruction::get_src(size_t idx) { - assert(idx < n_src); + ASSERT(idx < n_src); return src[idx]; } @@ -342,7 +342,7 @@ InstructionAtom& Instruction::get_src(size_t idx) { * Safe get dst atom */ const InstructionAtom& Instruction::get_dst(size_t idx) const { - assert(idx < n_dst); + ASSERT(idx < n_dst); return dst[idx]; } @@ -350,7 +350,7 @@ const InstructionAtom& Instruction::get_dst(size_t idx) const { * Safe get src atom */ const InstructionAtom& Instruction::get_src(size_t idx) const { - assert(idx < n_src); + ASSERT(idx < n_src); return src[idx]; } @@ -369,7 +369,7 @@ int Instruction::get_label_target() const { int result = -1; for (int i = 0; i < n_src; i++) { if (src[i].kind == InstructionAtom::AtomKind::LABEL) { - assert(result == -1); + ASSERT(result == -1); result = src[i].get_label(); } } diff --git a/decompiler/Disasm/InstructionDecode.cpp b/decompiler/Disasm/InstructionDecode.cpp index e530bcedd0..3aaa0e1625 100644 --- a/decompiler/Disasm/InstructionDecode.cpp +++ b/decompiler/Disasm/InstructionDecode.cpp @@ -6,7 +6,7 @@ #include "InstructionDecode.h" #include "decompiler/ObjectFile/LinkedObjectFile.h" -#include "common/util/assert.h" +#include "common/util/Assert.h" namespace decompiler { // utility class to extract fields of an opcode. @@ -83,7 +83,7 @@ static InstructionKind decode_cop2(OpcodeFields fields) { return IK::QMFC2; case 0b00101: - assert(((fields.data >> 1) & (0b1111111111)) == 0); + ASSERT(((fields.data >> 1) & (0b1111111111)) == 0); return IK::QMTC2; case 0b00010: @@ -101,139 +101,139 @@ static InstructionKind decode_cop2(OpcodeFields fields) { case 0b00010111101: case 0b00010111110: case 0b00010111111: - assert(fields.data & (1 << 25)); + ASSERT(fields.data & (1 << 25)); return IK::VMADDA_BC; case 0b00000111100: case 0b00000111101: case 0b00000111110: case 0b00000111111: - assert(fields.data & (1 << 25)); + ASSERT(fields.data & (1 << 25)); return IK::VADDA_BC; case 0b00110111100: case 0b00110111101: case 0b00110111110: case 0b00110111111: - assert(fields.data & (1 << 25)); + ASSERT(fields.data & (1 << 25)); return IK::VMULA_BC; case 0b01010111110: - assert(fields.data & (1 << 25)); + ASSERT(fields.data & (1 << 25)); return IK::VMULA; case 0b01010111100: - assert(fields.data & (1 << 25)); + ASSERT(fields.data & (1 << 25)); return IK::VADDA; case 0b01010111101: - assert(fields.data & (1 << 25)); + ASSERT(fields.data & (1 << 25)); return IK::VMADDA; case 0b00011111100: case 0b00011111101: case 0b00011111110: case 0b00011111111: - assert(fields.data & (1 << 25)); + ASSERT(fields.data & (1 << 25)); return IK::VMSUBA_BC; case 0b00101111100: - assert(fields.data & (1 << 25)); + ASSERT(fields.data & (1 << 25)); return IK::VFTOI0; case 0b00101111101: - assert(fields.data & (1 << 25)); + ASSERT(fields.data & (1 << 25)); return IK::VFTOI4; case 0b00101111110: - assert(fields.data & (1 << 25)); + ASSERT(fields.data & (1 << 25)); return IK::VFTOI12; case 0b00100111100: - assert(fields.data & (1 << 25)); + ASSERT(fields.data & (1 << 25)); return IK::VITOF0; case 0b00100111110: - assert(fields.data & (1 << 25)); + ASSERT(fields.data & (1 << 25)); return IK::VITOF12; case 0b00100111111: - assert(fields.data & (1 << 25)); + ASSERT(fields.data & (1 << 25)); return IK::VITOF15; case 0b00111111100: - assert(fields.data & (1 << 25)); - assert(fields.ft() == 0); + ASSERT(fields.data & (1 << 25)); + ASSERT(fields.ft() == 0); return IK::VMULAQ; case 0b00111111101: - assert(fields.data & (1 << 25)); + ASSERT(fields.data & (1 << 25)); return IK::VABS; case 0b00111111111: - assert(fields.data & (1 << 25)); - assert(fields.dest() == 0b1110); + ASSERT(fields.data & (1 << 25)); + ASSERT(fields.dest() == 0b1110); return IK::VCLIP; case 0b01011111111: - assert(fields.dest() == 0); - assert(fields.ft() == 0); - assert(fields.fs() == 0); + ASSERT(fields.dest() == 0); + ASSERT(fields.ft() == 0); + ASSERT(fields.fs() == 0); return IK::VNOP; case 0b01101111101: - assert(fields.data & (1 << 25)); + ASSERT(fields.data & (1 << 25)); return IK::VSQI; case 0b01101111100: - assert(fields.data & (1 << 25)); + ASSERT(fields.data & (1 << 25)); return IK::VLQI; case 0b01110111111: - assert(fields.dest() == 0); - assert(fields.ft() == 0); - assert(fields.fs() == 0); + ASSERT(fields.dest() == 0); + ASSERT(fields.ft() == 0); + ASSERT(fields.fs() == 0); return IK::VWAITQ; case 0b01011111110: - assert(fields.dest() == 0b1110); - assert(fields.data & (1 << 25)); + ASSERT(fields.dest() == 0b1110); + ASSERT(fields.data & (1 << 25)); return IK::VOPMULA; case 0b01100111100: - assert(fields.data & (1 << 25)); + ASSERT(fields.data & (1 << 25)); return IK::VMOVE; case 0b01110111100: - assert(fields.data & (1 << 25)); + ASSERT(fields.data & (1 << 25)); return IK::VDIV; case 0b01110111101: - assert(fields.fs() == 0); - assert(((fields.data >> 21) & 3) == 0); - assert(fields.data & (1 << 25)); + ASSERT(fields.fs() == 0); + ASSERT(((fields.data >> 21) & 3) == 0); + ASSERT(fields.data & (1 << 25)); return IK::VSQRT; case 0b01111111100: - assert(((fields.data >> 23) & 3) == 0); - assert(fields.data & (1 << 25)); + ASSERT(((fields.data >> 23) & 3) == 0); + ASSERT(fields.data & (1 << 25)); return IK::VMTIR; case 0b01110111110: - assert(fields.data & (1 << 25)); + ASSERT(fields.data & (1 << 25)); return IK::VRSQRT; case 0b10000111100: - assert(fields.fs() == 0); - assert(fields.data & (1 << 25)); + ASSERT(fields.fs() == 0); + ASSERT(fields.data & (1 << 25)); return IK::VRNEXT; case 0b10000111101: - assert(fields.fs() == 0); - assert(fields.data & (1 << 25)); + ASSERT(fields.fs() == 0); + ASSERT(fields.data & (1 << 25)); return IK::VRGET; case 0b10000111111: - assert(fields.ft() == 0); - assert(fields.data & (1 << 25)); - assert(((fields.data >> 23) & 3) == 0); + ASSERT(fields.ft() == 0); + ASSERT(fields.data & (1 << 25)); + ASSERT(((fields.data >> 23) & 3) == 0); return IK::VRXOR; default: @@ -242,105 +242,105 @@ static InstructionKind decode_cop2(OpcodeFields fields) { case 0b000001: case 0b000010: case 0b000011: - assert(fields.data & (1 << 25)); + ASSERT(fields.data & (1 << 25)); return IK::VADD_BC; case 0b000100: case 0b000101: case 0b000110: case 0b000111: - assert(fields.data & (1 << 25)); + ASSERT(fields.data & (1 << 25)); return IK::VSUB_BC; case 0b001000: case 0b001001: case 0b001010: case 0b001011: - assert(fields.data & (1 << 25)); + ASSERT(fields.data & (1 << 25)); return IK::VMADD_BC; case 0b001100: case 0b001101: case 0b001110: case 0b001111: - assert(fields.data & (1 << 25)); + ASSERT(fields.data & (1 << 25)); return IK::VMSUB_BC; case 0b010000: case 0b010001: case 0b010010: case 0b010011: - assert(fields.data & (1 << 25)); + ASSERT(fields.data & (1 << 25)); return IK::VMAX_BC; case 0b010100: case 0b010101: case 0b010110: case 0b010111: - assert(fields.data & (1 << 25)); + ASSERT(fields.data & (1 << 25)); return IK::VMINI_BC; case 0b011000: case 0b011001: case 0b011010: case 0b011011: - assert(fields.data & (1 << 25)); + ASSERT(fields.data & (1 << 25)); return IK::VMUL_BC; case 0b011100: - assert(fields.ft() == 0); - assert(fields.data & (1 << 25)); + ASSERT(fields.ft() == 0); + ASSERT(fields.data & (1 << 25)); return IK::VMULQ; case 0b100000: - assert(fields.data & (1 << 25)); + ASSERT(fields.data & (1 << 25)); return IK::VADDQ; case 0b100100: - assert(fields.data & (1 << 25)); + ASSERT(fields.data & (1 << 25)); return IK::VSUBQ; case 0b100101: - assert(fields.ft() == 0); - assert(fields.data & (1 << 25)); + ASSERT(fields.ft() == 0); + ASSERT(fields.data & (1 << 25)); return IK::VMSUBQ; case 0b101000: - assert(fields.data & (1 << 25)); + ASSERT(fields.data & (1 << 25)); return IK::VADD; case 0b101001: - assert(fields.data & (1 << 25)); + ASSERT(fields.data & (1 << 25)); return IK::VMADD; case 0b101010: - assert(fields.data & (1 << 25)); + ASSERT(fields.data & (1 << 25)); return IK::VMUL; case 0b101011: - assert(fields.data & (1 << 25)); + ASSERT(fields.data & (1 << 25)); return IK::VMAX; case 0b101100: - assert(fields.data & (1 << 25)); + ASSERT(fields.data & (1 << 25)); return IK::VSUB; case 0b101101: - assert(fields.data & (1 << 25)); + ASSERT(fields.data & (1 << 25)); return IK::VMSUB; case 0b101110: - assert(fields.data & (1 << 25)); - assert(fields.dest() == 0b1110); + ASSERT(fields.data & (1 << 25)); + ASSERT(fields.dest() == 0b1110); return IK::VOPMSUB; case 0b101111: - assert(fields.data & (1 << 25)); + ASSERT(fields.data & (1 << 25)); return IK::VMINI; case 0b110010: - assert(fields.data & (1 << 25)); - assert(fields.dest() == 0b0); + ASSERT(fields.data & (1 << 25)); + ASSERT(fields.dest() == 0b0); return IK::VIADDI; case 0b110100: - assert(fields.data & (1 << 25)); - assert(fields.dest() == 0b0); + ASSERT(fields.data & (1 << 25)); + ASSERT(fields.dest() == 0b0); return IK::VIAND; case 0b111000: - assert(fields.data & (1 << 25)); - assert(fields.dest() == 0b0); + ASSERT(fields.data & (1 << 25)); + ASSERT(fields.dest() == 0b0); return IK::VCALLMS; default: return IK::UNKNOWN; @@ -352,7 +352,7 @@ static InstructionKind decode_W(OpcodeFields fields) { typedef InstructionKind IK; switch (fields.function()) { case 0b100000: - assert(fields.ft() == 0); + ASSERT(fields.ft() == 0); return IK::CVTSW; default: return IK::UNKNOWN; @@ -373,47 +373,47 @@ static InstructionKind decode_S(OpcodeFields fields) { case 0b000101: return IK::ABSS; case 0b000110: - assert(fields.ft() == 0); + ASSERT(fields.ft() == 0); return IK::MOVS; case 0b000111: - assert(fields.ft() == 0); + ASSERT(fields.ft() == 0); return IK::NEGS; case 0b000100: - assert(fields.fs() == 0); + ASSERT(fields.fs() == 0); return IK::SQRTS; case 0b010110: return IK::RSQRTS; case 0b011000: - assert(fields.fd() == 0); + ASSERT(fields.fd() == 0); return IK::ADDAS; case 0b011010: - assert(fields.fd() == 0); + ASSERT(fields.fd() == 0); return IK::MULAS; case 0b011100: return IK::MADDS; case 0b011101: return IK::MSUBS; case 0b011110: - assert(fields.fd() == 0); + ASSERT(fields.fd() == 0); return IK::MADDAS; case 0b011111: - assert(fields.fd() == 0); + ASSERT(fields.fd() == 0); return IK::MSUBAS; case 0b100100: - assert(fields.ft() == 0); + ASSERT(fields.ft() == 0); return IK::CVTWS; case 0b101000: return IK::MAXS; case 0b101001: return IK::MINS; case 0b110010: - assert(fields.fd() == 0); + ASSERT(fields.fd() == 0); return IK::CEQS; case 0b110100: - assert(fields.fd() == 0); + ASSERT(fields.fd() == 0); return IK::CLTS; case 0b110110: - assert(fields.fd() == 0); + ASSERT(fields.fd() == 0); return IK::CLES; default: return IK::UNKNOWN; @@ -440,12 +440,12 @@ static InstructionKind decode_cop1(OpcodeFields fields) { typedef InstructionKind IK; switch (fields.cop_func()) { case 0b00000: - assert(fields.sa() == 0); - assert(fields.function() == 0); + ASSERT(fields.sa() == 0); + ASSERT(fields.function() == 0); return IK::MFC1; case 0b00100: - assert(fields.sa() == 0); - assert(fields.function() == 0); + ASSERT(fields.sa() == 0); + ASSERT(fields.function() == 0); return IK::MTC1; case 0b01000: return decode_BC1(fields); @@ -464,7 +464,7 @@ static InstructionKind decode_c0(OpcodeFields fields) { case 0b011000: return IK::ERET; case 0b111000: - assert(fields.sa() == 0 && fields.rd() == 0 && fields.rt() == 0); + ASSERT(fields.sa() == 0 && fields.rd() == 0 && fields.rt() == 0); return IK::EI; default: return IK::UNKNOWN; @@ -477,10 +477,10 @@ static InstructionKind decode_mt0(OpcodeFields fields) { case 0b00000000000: return IK::MTC0; case 0b00000000100: - assert(fields.rd() == 0b11000); + ASSERT(fields.rd() == 0b11000); return IK::MTDAB; case 0b00000000101: - assert(fields.rd() == 0b11000); + ASSERT(fields.rd() == 0b11000); return IK::MTDABM; default: if (fields.rd() == 0b11001 && fields.sa() == 0 && (fields.data & 1) == 1) { @@ -530,7 +530,7 @@ static InstructionKind decode_mmi3(OpcodeFields fields) { case 0b10011: return IK::PNOR; case 0b11011: - assert(fields.rs() == 0); + ASSERT(fields.rs() == 0); return IK::PCPYH; default: return IK::UNKNOWN; @@ -619,16 +619,16 @@ static InstructionKind decode_pmfhl(OpcodeFields fields) { typedef InstructionKind IK; switch (fields.sa()) { case 0b00001: - assert(fields.rs() == 0); - assert(fields.rt() == 0); + ASSERT(fields.rs() == 0); + ASSERT(fields.rt() == 0); return IK::PMFHL_UW; case 0b00000: - assert(fields.rs() == 0); - assert(fields.rt() == 0); + ASSERT(fields.rs() == 0); + ASSERT(fields.rt() == 0); return IK::PMFHL_LW; case 0b00011: - assert(fields.rs() == 0); - assert(fields.rt() == 0); + ASSERT(fields.rs() == 0); + ASSERT(fields.rt() == 0); return IK::PMFHL_LH; default: return IK::UNKNOWN; @@ -639,8 +639,8 @@ static InstructionKind decode_mmi(OpcodeFields fields) { typedef InstructionKind IK; switch (fields.function()) { case 0b000100: - assert(fields.sa() == 0); - assert(fields.rt() == 0); + ASSERT(fields.sa() == 0); + ASSERT(fields.rt() == 0); return IK::PLZCW; case 0b001000: return decode_mmi0(fields); @@ -648,14 +648,14 @@ static InstructionKind decode_mmi(OpcodeFields fields) { return decode_mmi2(fields); case 0b010011: - assert(fields.sa() == 0); - assert(fields.rd() == 0); - assert(fields.rt() == 0); + ASSERT(fields.sa() == 0); + ASSERT(fields.rd() == 0); + ASSERT(fields.rt() == 0); return IK::MTLO1; case 0b010010: - assert(fields.sa() == 0); - assert(fields.rs() == 0); - assert(fields.rt() == 0); + ASSERT(fields.sa() == 0); + ASSERT(fields.rs() == 0); + ASSERT(fields.rt() == 0); return IK::MFLO1; case 0b101000: @@ -702,9 +702,9 @@ static InstructionKind decode_sync(OpcodeFields fields) { // to avoid implementing this, we just split SYNC into two separate instructions. typedef InstructionKind IK; auto stype = fields.sa(); - assert(fields.rt() == 0); - assert(fields.rs() == 0); - assert(fields.rd() == 0); + ASSERT(fields.rt() == 0); + ASSERT(fields.rs() == 0); + ASSERT(fields.rd() == 0); if (stype == 0b00000) { return IK::SYNCL; } else if (stype == 0b10000) { @@ -718,35 +718,35 @@ static InstructionKind decode_special(OpcodeFields fields) { typedef InstructionKind IK; switch (fields.function()) { case 0b000000: - assert(fields.rs() == 0); + ASSERT(fields.rs() == 0); return IK::SLL; // RESERVED case 0b000010: - assert(fields.rs() == 0); + ASSERT(fields.rs() == 0); return IK::SRL; case 0b000011: - assert(fields.rs() == 0); + ASSERT(fields.rs() == 0); return IK::SRA; case 0b000100: - assert(fields.sa() == 0); + ASSERT(fields.sa() == 0); return IK::SLLV; // RESERVED // SRLV // SRAV case 0b001000: - assert(fields.sa() == 0); - assert(fields.rd() == 0); - assert(fields.rt() == 0); + ASSERT(fields.sa() == 0); + ASSERT(fields.rd() == 0); + ASSERT(fields.rt() == 0); return IK::JR; case 0b001001: - assert(fields.rt() == 0); - assert(fields.sa() == 0); + ASSERT(fields.rt() == 0); + ASSERT(fields.sa() == 0); return IK::JALR; case 0b001010: - assert(fields.sa() == 0); + ASSERT(fields.sa() == 0); return IK::MOVZ; case 0b001011: - assert(fields.sa() == 0); + ASSERT(fields.sa() == 0); return IK::MOVN; case 0b001100: return IK::SYSCALL; @@ -756,69 +756,69 @@ static InstructionKind decode_special(OpcodeFields fields) { return decode_sync(fields); case 0b010000: - assert(fields.rs() == 0); - assert(fields.rt() == 0); - assert(fields.sa() == 0); + ASSERT(fields.rs() == 0); + ASSERT(fields.rt() == 0); + ASSERT(fields.sa() == 0); return IK::MFHI; // MTHI case 0b010010: - assert(fields.rs() == 0); - assert(fields.rt() == 0); - assert(fields.sa() == 0); + ASSERT(fields.rs() == 0); + ASSERT(fields.rt() == 0); + ASSERT(fields.sa() == 0); return IK::MFLO; // MTLO case 0b010100: - assert(fields.sa() == 0); + ASSERT(fields.sa() == 0); return IK::DSLLV; // RESERVED case 0b010110: - assert(fields.sa() == 0); + ASSERT(fields.sa() == 0); return IK::DSRLV; case 0b010111: - assert(fields.sa() == 0); + ASSERT(fields.sa() == 0); return IK::DSRAV; case 0b011000: - assert(fields.sa() == 0); + ASSERT(fields.sa() == 0); return IK::MULT3; case 0b011001: - assert(fields.sa() == 0); + ASSERT(fields.sa() == 0); return IK::MULTU3; case 0b011010: - assert(fields.sa() == 0); - assert(fields.rd() == 0); + ASSERT(fields.sa() == 0); + ASSERT(fields.rd() == 0); return IK::DIV; case 0b011011: - assert(fields.sa() == 0); - assert(fields.rd() == 0); + ASSERT(fields.sa() == 0); + ASSERT(fields.rd() == 0); return IK::DIVU; // 4x UNSUPPORTED // ADD case 0b100001: - assert(fields.sa() == 0); + ASSERT(fields.sa() == 0); return IK::ADDU; // SUB case 0b100011: - assert(fields.sa() == 0); + ASSERT(fields.sa() == 0); return IK::SUBU; case 0b100100: - assert(fields.sa() == 0); + ASSERT(fields.sa() == 0); return IK::AND; case 0b100101: - assert(fields.sa() == 0); + ASSERT(fields.sa() == 0); return IK::OR; case 0b100110: - assert(fields.sa() == 0); + ASSERT(fields.sa() == 0); return IK::XOR; case 0b100111: - assert(fields.sa() == 0); + ASSERT(fields.sa() == 0); return IK::NOR; // MFSA // MTSA case 0b101010: - assert(fields.sa() == 0); + ASSERT(fields.sa() == 0); return IK::SLT; case 0b101011: - assert(fields.sa() == 0); + ASSERT(fields.sa() == 0); return IK::SLTU; // DADD case 0b101101: @@ -835,24 +835,24 @@ static InstructionKind decode_special(OpcodeFields fields) { // TNE // RESERVED case 0b111000: - assert(fields.rs() == 0); + ASSERT(fields.rs() == 0); return IK::DSLL; // RESERVED case 0b111010: - assert(fields.rs() == 0); + ASSERT(fields.rs() == 0); return IK::DSRL; case 0b111011: - assert(fields.rs() == 0); + ASSERT(fields.rs() == 0); return IK::DSRA; case 0b111100: - assert(fields.rs() == 0); + ASSERT(fields.rs() == 0); return IK::DSLL32; // RESERVED case 0b111110: - assert(fields.rs() == 0); + ASSERT(fields.rs() == 0); return IK::DSRL32; case 0b111111: - assert(fields.rs() == 0); + ASSERT(fields.rs() == 0); return IK::DSRA32; default: return IK::UNKNOWN; @@ -906,7 +906,7 @@ static InstructionKind decode_opcode(uint32_t code) { case 0b001110: return IK::XORI; case 0b001111: - assert(fields.rs() == 0); + ASSERT(fields.rs() == 0); return IK::LUI; case 0b010000: return decode_cop0(fields); @@ -923,7 +923,7 @@ static InstructionKind decode_opcode(uint32_t code) { // 010110 // blezl case 0b010111: - assert(fields.rt() == 0); + ASSERT(fields.rt() == 0); return IK::BGTZL; // 0b011000: // daddi @@ -1070,7 +1070,7 @@ Instruction decode_instruction(LinkedWord& word, LinkedObjectFile& file, int seg value = fields.fs_f(); break; default: - assert(false); + ASSERT(false); } // use the value, to possibly add an atom @@ -1125,7 +1125,7 @@ Instruction decode_instruction(LinkedWord& word, LinkedObjectFile& file, int seg continue; default: - assert(false); + ASSERT(false); } if (step.is_src) { @@ -1143,11 +1143,11 @@ Instruction decode_instruction(LinkedWord& word, LinkedObjectFile& file, int seg i.src[j].set_sym(word.symbol_name()); } } - assert(fixed); + ASSERT(fixed); } if (word.kind() == LinkedWord::HI_PTR) { - assert(i.kind == InstructionKind::LUI); + ASSERT(i.kind == InstructionKind::LUI); bool fixed = false; for (int j = 0; j < i.n_src; j++) { if (i.src[j].kind == InstructionAtom::IMM) { @@ -1155,11 +1155,11 @@ Instruction decode_instruction(LinkedWord& word, LinkedObjectFile& file, int seg i.src[j].set_label(word.label_id()); } } - assert(fixed); + ASSERT(fixed); } if (word.kind() == LinkedWord::LO_PTR) { - assert(i.kind == InstructionKind::ORI); + ASSERT(i.kind == InstructionKind::ORI); bool fixed = false; for (int j = 0; j < i.n_src; j++) { if (i.src[j].kind == InstructionAtom::IMM) { @@ -1167,7 +1167,7 @@ Instruction decode_instruction(LinkedWord& word, LinkedObjectFile& file, int seg i.src[j].set_label(word.label_id()); } } - assert(fixed); + ASSERT(fixed); } return i; diff --git a/decompiler/Disasm/InstructionMatching.cpp b/decompiler/Disasm/InstructionMatching.cpp index c51da30c6b..b8df563cf7 100644 --- a/decompiler/Disasm/InstructionMatching.cpp +++ b/decompiler/Disasm/InstructionMatching.cpp @@ -4,7 +4,7 @@ */ #include "InstructionMatching.h" -#include "common/util/assert.h" +#include "common/util/Assert.h" namespace decompiler { /*! @@ -44,7 +44,7 @@ bool is_no_link_gpr_store(const Instruction& instr, } break; default: - assert(false); + ASSERT(false); } } else { // just make sure it's a gpr store @@ -53,7 +53,7 @@ bool is_no_link_gpr_store(const Instruction& instr, } } - assert(instr.n_src == 3); + ASSERT(instr.n_src == 3); // match other arguments return src == instr.src[0].get_reg() && offset == instr.src[1].get_imm() && @@ -103,7 +103,7 @@ bool is_no_ll_gpr_load(const Instruction& instr, } break; default: - assert(false); + ASSERT(false); } } else { if (is_signed.value) { @@ -134,7 +134,7 @@ bool is_no_ll_gpr_load(const Instruction& instr, } break; default: - assert(false); + ASSERT(false); } } else { switch (size.value) { @@ -164,7 +164,7 @@ bool is_no_ll_gpr_load(const Instruction& instr, } break; default: - assert(false); + ASSERT(false); } } } @@ -261,8 +261,8 @@ bool is_gpr_load(const Instruction& instr, MatchParam is_signed) { * Given a store, get the offset as an integer. */ int32_t get_gpr_store_offset_as_int(const Instruction& instr) { - assert(is_gpr_store(instr)); - assert(instr.n_src == 3); + ASSERT(is_gpr_store(instr)); + ASSERT(instr.n_src == 3); return instr.src[1].get_imm(); } @@ -344,7 +344,7 @@ bool is_always_branch(const Instruction& instr) { if (instr.kind == InstructionKind::BEQL && instr.get_src(0).get_reg() == r0 && instr.get_src(1).get_reg() == r0) { - assert(false); + ASSERT(false); return true; } diff --git a/decompiler/Disasm/InstructionParser.cpp b/decompiler/Disasm/InstructionParser.cpp index 4ef1610408..91d5556631 100644 --- a/decompiler/Disasm/InstructionParser.cpp +++ b/decompiler/Disasm/InstructionParser.cpp @@ -3,7 +3,7 @@ #include #include "common/common_types.h" #include "InstructionParser.h" -#include "common/util/assert.h" +#include "common/util/Assert.h" namespace decompiler { InstructionParser::InstructionParser() { @@ -64,12 +64,12 @@ InstructionParser::InstructionParser() { added++; } } - assert(added == int(m_opcode_name_lookup.size()) + int(m_opcode_name_broadcast_lookup.size())); + ASSERT(added == int(m_opcode_name_lookup.size()) + int(m_opcode_name_broadcast_lookup.size())); } namespace { std::string get_until_space(std::string& instr) { - assert(!instr.empty()); + ASSERT(!instr.empty()); size_t i; for (i = 0; i < instr.length(); i++) { if (instr[i] == ' ') { @@ -86,7 +86,7 @@ std::string get_until_space(std::string& instr) { } std::string get_instr_name(std::string& instr) { - assert(!instr.empty()); + ASSERT(!instr.empty()); size_t i; for (i = 0; i < instr.length(); i++) { if (instr[i] == ' ') { @@ -121,12 +121,12 @@ std::string get_instr_name(std::string& instr) { } std::string get_comma_separated(std::string& instr) { - assert(!instr.empty()); + ASSERT(!instr.empty()); auto arg = get_until_space(instr); if (instr.empty()) { - assert(arg.back() != ','); + ASSERT(arg.back() != ','); } else { - assert(arg.back() == ','); + ASSERT(arg.back() == ','); arg.pop_back(); } return arg; @@ -141,13 +141,13 @@ std::string get_before_paren(std::string& instr) { return result; } } - assert(false); + ASSERT(false); return {}; } std::string get_in_paren(std::string& instr) { - assert(instr.length() > 2); - assert(instr.front() == '('); + ASSERT(instr.length() > 2); + ASSERT(instr.front() == '('); size_t i; for (i = 0; i < instr.length(); i++) { if (instr[i] == ')') { @@ -160,22 +160,22 @@ std::string get_in_paren(std::string& instr) { return result; } } - assert(false); + ASSERT(false); return {}; } bool is_integer(const std::string& str) { - assert(!str.empty()); + ASSERT(!str.empty()); char* end; std::strtol(str.c_str(), &end, 10); return end == str.c_str() + str.length(); } int parse_integer(const std::string& str) { - assert(!str.empty()); + ASSERT(!str.empty()); char* end; int result = std::strtol(str.c_str(), &end, 10); - assert(end == str.c_str() + str.length()); + ASSERT(end == str.c_str() + str.length()); return result; } @@ -233,7 +233,7 @@ u8 cop2_dst(const std::string& str) { } if (*ptr) { - assert(false); + ASSERT(false); } return result; } @@ -283,7 +283,7 @@ Instruction InstructionParser::parse_single_instruction( } Register reg(gpr_name); - assert(reg.get_kind() == Reg::GPR); + ASSERT(reg.get_kind() == Reg::GPR); InstructionAtom atom; atom.set_reg(reg); if (step.is_src) { @@ -296,7 +296,7 @@ Instruction InstructionParser::parse_single_instruction( case DecodeType::FPR: { auto reg_name = get_comma_separated(str); Register reg(reg_name); - assert(reg.get_kind() == Reg::FPR); + ASSERT(reg.get_kind() == Reg::FPR); InstructionAtom atom; atom.set_reg(reg); if (step.is_src) { @@ -309,7 +309,7 @@ Instruction InstructionParser::parse_single_instruction( case DecodeType::VF: { auto reg_name = get_comma_separated(str); Register reg(reg_name); - assert(reg.get_kind() == Reg::VF); + ASSERT(reg.get_kind() == Reg::VF); InstructionAtom atom; atom.set_reg(reg); if (step.is_src) { @@ -359,7 +359,7 @@ Instruction InstructionParser::parse_single_instruction( auto label = get_comma_separated(str); auto f = std::find_if(labels.begin(), labels.end(), [&](const DecompilerLabel& l) { return l.name == label; }); - assert(f != labels.end()); + ASSERT(f != labels.end()); auto idx = f - labels.begin(); InstructionAtom atom; atom.set_label(idx); @@ -384,7 +384,7 @@ Instruction InstructionParser::parse_single_instruction( instr.il = 0; } else { printf("Bad interlock specification. Got %s\n", thing.c_str()); - assert(false); + ASSERT(false); } } break; @@ -400,17 +400,17 @@ Instruction InstructionParser::parse_single_instruction( instr.cop2_bc = 3; } else { printf("Bad broadcast. Got %s\n", thing.c_str()); - assert(false); + ASSERT(false); } } break; default: printf("missing DecodeType: %d\n", (int)step.decode); - assert(false); + ASSERT(false); } } - assert(str.empty()); + ASSERT(str.empty()); return instr; } @@ -446,7 +446,7 @@ ParsedProgram InstructionParser::parse_program(const std::string& str, if (line.back() == ':') { line.pop_back(); } else { - assert(false); + ASSERT(false); } DecompilerLabel label; label.target_segment = 0; diff --git a/decompiler/Disasm/OpcodeInfo.cpp b/decompiler/Disasm/OpcodeInfo.cpp index 9620a2310b..fb3c3c540d 100644 --- a/decompiler/Disasm/OpcodeInfo.cpp +++ b/decompiler/Disasm/OpcodeInfo.cpp @@ -4,7 +4,7 @@ */ #include "OpcodeInfo.h" -#include "common/util/assert.h" +#include "common/util/Assert.h" namespace decompiler { OpcodeInfo gOpcodeInfo[(uint32_t)InstructionKind::EE_OP_MAX]; @@ -462,12 +462,12 @@ void init_opcode_info() { // for the UNKNOWN op which shouldn't be valid. total_count--; - assert(total_count == valid_count); + ASSERT(total_count == valid_count); opcodes_initialized = true; } void OpcodeInfo::step(DecodeStep& s) { - assert(step_count < MAX_DECODE_STEPS); + ASSERT(step_count < MAX_DECODE_STEPS); steps[step_count] = s; step_count++; defined = true; diff --git a/decompiler/Disasm/Register.cpp b/decompiler/Disasm/Register.cpp index fb4df68673..ba25b290b8 100644 --- a/decompiler/Disasm/Register.cpp +++ b/decompiler/Disasm/Register.cpp @@ -6,7 +6,7 @@ #include "Register.h" #include #include "third-party/fmt/core.h" -#include "common/util/assert.h" +#include "common/util/Assert.h" namespace decompiler { namespace Reg { @@ -65,32 +65,32 @@ const static char* special_names[Reg::MAX_SPECIAL] = {"pcr0", "pcr1", "Q", "ACC" namespace { const char* gpr_to_charp(Reg::Gpr gpr) { - assert(gpr < 32); + ASSERT(gpr < 32); return gpr_names[gpr]; } const char* fpr_to_charp(uint32_t fpr) { - assert(fpr < 32); + ASSERT(fpr < 32); return fpr_names[fpr]; } const char* cop0_to_charp(Reg::Cop0 cpr) { - assert(cpr < 32); + ASSERT(cpr < 32); return cop0_names[cpr]; } const char* vf_to_charp(uint32_t vf) { - assert(vf < 32); + ASSERT(vf < 32); return vf_names[vf]; } const char* vi_to_charp(uint32_t vi) { - assert(vi < 32); + ASSERT(vi < 32); return vi_names[vi]; } const char* special_to_charp(uint32_t special) { - assert(special < Reg::MAX_SPECIAL); + ASSERT(special < Reg::MAX_SPECIAL); return special_names[special]; } } // namespace @@ -126,17 +126,17 @@ Register::Register(Reg::RegisterKind kind, uint32_t num) { case Reg::VI: if (num > 32) { fmt::print("RegisterKind: {}, greater than 32: {}\n", kind, num); - assert(false); + ASSERT(false); } break; case Reg::SPECIAL: if (num > 4) { fmt::print("Special RegisterKind: {}, greater than 4: {}\n", kind, num); - assert(false); + ASSERT(false); } break; default: - assert(false); + ASSERT(false); } } @@ -202,7 +202,7 @@ std::string Register::to_string() const { */ Reg::RegisterKind Register::get_kind() const { uint16_t kind = id >> REG_CATEGORY_SHIFT; - assert(kind < Reg::MAX_KIND); + ASSERT(kind < Reg::MAX_KIND); return (Reg::RegisterKind)kind; } @@ -210,9 +210,9 @@ Reg::RegisterKind Register::get_kind() const { * Get the GPR number. Must be a GPR. */ Reg::Gpr Register::get_gpr() const { - assert(get_kind() == Reg::GPR); + ASSERT(get_kind() == Reg::GPR); uint16_t kind = id & REG_IDX_MASK; - assert(kind < Reg::MAX_GPR); + ASSERT(kind < Reg::MAX_GPR); return (Reg::Gpr)(kind); } @@ -220,9 +220,9 @@ Reg::Gpr Register::get_gpr() const { * Get the FPR number. Must be an FPR. */ uint32_t Register::get_fpr() const { - assert(get_kind() == Reg::FPR); + ASSERT(get_kind() == Reg::FPR); uint16_t kind = id & REG_IDX_MASK; - assert(kind < 32); + ASSERT(kind < 32); return kind; } @@ -230,9 +230,9 @@ uint32_t Register::get_fpr() const { * Get the VF number. Must be a VF. */ uint32_t Register::get_vf() const { - assert(get_kind() == Reg::VF); + ASSERT(get_kind() == Reg::VF); uint16_t kind = id & REG_IDX_MASK; - assert(kind < 32); + ASSERT(kind < 32); return kind; } @@ -240,9 +240,9 @@ uint32_t Register::get_vf() const { * Get the VI number. Must be a VI. */ uint32_t Register::get_vi() const { - assert(get_kind() == Reg::VI); + ASSERT(get_kind() == Reg::VI); uint16_t kind = id & REG_IDX_MASK; - assert(kind < 32); + ASSERT(kind < 32); return kind; } @@ -250,9 +250,9 @@ uint32_t Register::get_vi() const { * Get the COP0 number. Must be a COP0. */ Reg::Cop0 Register::get_cop0() const { - assert(get_kind() == Reg::COP0); + ASSERT(get_kind() == Reg::COP0); uint16_t kind = id & REG_IDX_MASK; - assert(kind < Reg::MAX_COP0); + ASSERT(kind < Reg::MAX_COP0); return (Reg::Cop0)(kind); } @@ -260,9 +260,9 @@ Reg::Cop0 Register::get_cop0() const { * Get the PCR number. Must be a PCR. */ uint32_t Register::get_special() const { - assert(get_kind() == Reg::SPECIAL); + ASSERT(get_kind() == Reg::SPECIAL); uint16_t kind = id & REG_IDX_MASK; - assert(kind < Reg::MAX_SPECIAL); + ASSERT(kind < Reg::MAX_SPECIAL); return kind; } diff --git a/decompiler/Disasm/Register.h b/decompiler/Disasm/Register.h index ee8c48a18f..1341cc989b 100644 --- a/decompiler/Disasm/Register.h +++ b/decompiler/Disasm/Register.h @@ -7,7 +7,7 @@ #include #include -#include "common/util/assert.h" +#include "common/util/Assert.h" namespace decompiler { // Namespace for register name constants @@ -147,13 +147,13 @@ class Register { Register() = default; Register(Reg::RegisterKind kind, uint32_t num); explicit Register(int reg_id) { - assert(reg_id < Reg::MAX_REG_ID); + ASSERT(reg_id < Reg::MAX_REG_ID); id = reg_id; } Register(const std::string& name); static Register get_arg_reg(int idx) { - assert(idx >= 0 && idx < 8); + ASSERT(idx >= 0 && idx < 8); return Register(Reg::GPR, Reg::A0 + idx); } diff --git a/decompiler/Function/BasicBlocks.cpp b/decompiler/Function/BasicBlocks.cpp index 9e9095a949..5b50d8927b 100644 --- a/decompiler/Function/BasicBlocks.cpp +++ b/decompiler/Function/BasicBlocks.cpp @@ -2,7 +2,7 @@ #include "BasicBlocks.h" #include "decompiler/ObjectFile/LinkedObjectFile.h" #include "decompiler/Disasm/InstructionMatching.h" -#include "common/util/assert.h" +#include "common/util/Assert.h" namespace decompiler { /*! @@ -25,34 +25,34 @@ std::vector find_blocks_in_function(const LinkedObjectFile& file, if (instr_info.is_branch && !instr_info.is_branch_likely) { // make sure the delay slot of this branch is included in the function - assert(i + func.start_word < func.end_word - 1); + ASSERT(i + func.start_word < func.end_word - 1); // divider after delay slot dividers.push_back(i + 2); auto label_id = instr.get_label_target(); - assert(label_id != -1); + ASSERT(label_id != -1); const auto& label = file.labels.at(label_id); // should only jump to within our own function - assert(label.target_segment == seg); - assert(label.offset / 4 > func.start_word); - assert(label.offset / 4 < func.end_word - 1); + ASSERT(label.target_segment == seg); + ASSERT(label.offset / 4 > func.start_word); + ASSERT(label.offset / 4 < func.end_word - 1); dividers.push_back(label.offset / 4 - func.start_word); } // for branch likely, we treat the likely instruction as a separate block. if (instr_info.is_branch_likely) { - assert(i + func.start_word < func.end_word - 1); + ASSERT(i + func.start_word < func.end_word - 1); // divider after branch instruction dividers.push_back(i + 1); // divider after likely delay slot. dividers.push_back(i + 2); // divider at the destination. auto label_id = instr.get_label_target(); - assert(label_id != -1); + ASSERT(label_id != -1); const auto& label = file.labels.at(label_id); // should only jump to within our own function - assert(label.target_segment == seg); - assert(label.offset / 4 > func.start_word); - assert(label.offset / 4 < func.end_word - 1); + ASSERT(label.target_segment == seg); + ASSERT(label.offset / 4 > func.start_word); + ASSERT(label.offset / 4 < func.end_word - 1); dividers.push_back(label.offset / 4 - func.start_word); } } @@ -62,7 +62,7 @@ std::vector find_blocks_in_function(const LinkedObjectFile& file, for (size_t i = 0; i < dividers.size() - 1; i++) { if (dividers[i] != dividers[i + 1]) { basic_blocks.emplace_back(dividers[i], dividers[i + 1]); - assert(dividers[i] >= 0); + ASSERT(dividers[i] >= 0); } } diff --git a/decompiler/Function/CfgVtx.cpp b/decompiler/Function/CfgVtx.cpp index a9e65ad411..37f84f69e1 100644 --- a/decompiler/Function/CfgVtx.cpp +++ b/decompiler/Function/CfgVtx.cpp @@ -3,7 +3,7 @@ #include "decompiler/ObjectFile/LinkedObjectFile.h" #include "CfgVtx.h" #include "Function.h" -#include "common/util/assert.h" +#include "common/util/Assert.h" namespace decompiler { ///////////////////////////////////////// @@ -32,12 +32,12 @@ void CfgVtx::replace_pred_and_check(CfgVtx* old_pred, CfgVtx* new_pred) { bool replaced = false; for (auto& x : pred) { if (x == old_pred) { - assert(!replaced); + ASSERT(!replaced); x = new_pred; replaced = true; } } - assert(replaced); + ASSERT(replaced); } /*! @@ -56,7 +56,7 @@ void CfgVtx::replace_succ_and_check(CfgVtx* old_succ, CfgVtx* new_succ) { replaced = true; } - assert(replaced); + ASSERT(replaced); } void CfgVtx::remove_pred(CfgVtx* to_remove) { @@ -68,7 +68,7 @@ void CfgVtx::remove_pred(CfgVtx* to_remove) { break; } } - assert(found); + ASSERT(found); } /*! @@ -87,7 +87,7 @@ void CfgVtx::replace_preds_with_and_check(std::vector old_preds, CfgVtx size_t idx = -1; for (size_t i = 0; i < old_preds.size(); i++) { if (existing_pred == old_preds[i]) { - assert(!match); + ASSERT(!match); idx = i; match = true; } @@ -107,7 +107,7 @@ void CfgVtx::replace_preds_with_and_check(std::vector old_preds, CfgVtx pred = new_pred_list; for (auto x : found) { - assert(x); + ASSERT(x); } } @@ -169,7 +169,7 @@ int BlockVtx::get_first_block_id() const { } std::string SequenceVtx::to_string() const { - assert(!seq.empty()); + ASSERT(!seq.empty()); // todo - this is not a great way to print it. Maybe sequences should have an ID or name? std::string result = "Seq " + seq.front()->to_string() + " ... " + seq.back()->to_string() + std::to_string(uid); @@ -198,7 +198,7 @@ goos::Object EntryVtx::to_form() const { } int EntryVtx::get_first_block_id() const { - assert(false); + ASSERT(false); return -1; } @@ -211,7 +211,7 @@ goos::Object ExitVtx::to_form() const { } int ExitVtx::get_first_block_id() const { - assert(false); + ASSERT(false); return -1; } @@ -264,7 +264,7 @@ goos::Object WhileLoop::to_form() const { } int WhileLoop::get_first_block_id() const { - assert(false); + ASSERT(false); return -1; } @@ -293,7 +293,7 @@ goos::Object UntilLoop_single::to_form() const { int UntilLoop_single::get_first_block_id() const { return block->get_first_block_id(); - assert(false); + ASSERT(false); return -1; } @@ -307,7 +307,7 @@ goos::Object InfiniteLoopBlock::to_form() const { } int InfiniteLoopBlock::get_first_block_id() const { - assert(false); + ASSERT(false); return -1; } @@ -377,7 +377,7 @@ goos::Object EmptyVtx::to_form() const { } int EmptyVtx::get_first_block_id() const { - assert(false); + ASSERT(false); return -1; } @@ -448,13 +448,13 @@ int ControlFlowGraph::get_top_level_vertices_count() { * Get the top level vertex. Only safe to call if we are fully resolved. */ CfgVtx* ControlFlowGraph::get_single_top_level() { - assert(get_top_level_vertices_count() == 1); + ASSERT(get_top_level_vertices_count() == 1); for (auto* x : m_node_pool) { if (!x->parent && x != entry() && x != exit()) { return x; } } - assert(false); + ASSERT(false); return nullptr; } @@ -516,8 +516,8 @@ bool ControlFlowGraph::is_while_loop(CfgVtx* b0, CfgVtx* b1, CfgVtx* b2) { return false; if (b0->succ_branch != b2) return false; - assert(b0->end_branch.has_branch); - assert(b0->end_branch.branch_always); + ASSERT(b0->end_branch.has_branch); + ASSERT(b0->end_branch.branch_always); if (b0->end_branch.branch_likely) return false; @@ -526,7 +526,7 @@ bool ControlFlowGraph::is_while_loop(CfgVtx* b0, CfgVtx* b1, CfgVtx* b2) { return false; if (b1->succ_branch) return false; - assert(!b1->end_branch.has_branch); + ASSERT(!b1->end_branch.has_branch); if (!b2->has_pred(b0)) { printf("expect b2 (%s) to have pred b0 (%s)\n", b2->to_string().c_str(), b0->to_string().c_str()); @@ -541,8 +541,8 @@ bool ControlFlowGraph::is_while_loop(CfgVtx* b0, CfgVtx* b1, CfgVtx* b2) { printf("b0's succ_branch: %s\n", b0->succ_branch->to_string().c_str()); } } - assert(b2->has_pred(b0)); - assert(b2->has_pred(b1)); + ASSERT(b2->has_pred(b0)); + ASSERT(b2->has_pred(b1)); if (b2->pred.size() != 2) return false; @@ -577,14 +577,14 @@ bool ControlFlowGraph::is_until_loop(CfgVtx* b1, CfgVtx* b2) { return false; if (b1->succ_branch) return false; - assert(!b1->end_branch.has_branch); + ASSERT(!b1->end_branch.has_branch); if (!b2->has_pred(b1)) { fmt::print("Graph error {} (s {}) should have pred {} (s {})\n", b2->to_string(), b2->get_first_block_id(), b1->to_string(), b1->get_first_block_id()); } - assert(b2->has_pred(b1)); + ASSERT(b2->has_pred(b1)); if (b2->pred.size() != 1) return false; @@ -618,7 +618,7 @@ bool ControlFlowGraph::is_goto_not_end_and_unreachable(CfgVtx* b0, CfgVtx* b1) { return false; } - assert(b1->prev == b0); + ASSERT(b1->prev == b0); // b1 should have no preds and be unreachable. if (!b1->pred.empty()) { @@ -657,7 +657,7 @@ bool ControlFlowGraph::is_goto_end_and_unreachable(CfgVtx* b0, CfgVtx* b1) { // b0 should next to b1 if (b0->next != b1) return false; - assert(b1->prev == b0); + ASSERT(b1->prev == b0); // b1 should have no preds if (!b1->pred.empty()) @@ -699,7 +699,7 @@ bool ControlFlowGraph::find_while_loop_top_level() { b0->replace_succ_and_check(b2, new_vtx); new_vtx->pred = {b0}; - assert(b2->succ_ft); + ASSERT(b2->succ_ft); b2->succ_ft->replace_pred_and_check(b2, new_vtx); new_vtx->succ_ft = b2->succ_ft; // succ_branch is going back into the loop @@ -750,7 +750,7 @@ bool ControlFlowGraph::find_until_loop() { new_vtx->pred = b1->pred; new_vtx->replace_preds_with_and_check({b2}, nullptr); - assert(b2->succ_ft); + ASSERT(b2->succ_ft); b2->succ_ft->replace_pred_and_check(b2, new_vtx); new_vtx->succ_ft = b2->succ_ft; // succ_branch is going back into the loop @@ -962,17 +962,17 @@ bool ControlFlowGraph::find_infinite_continue() { } new_goto->pred = b0->pred; - assert(b0->succs().size() == 1 && b0->succs().front() == b0->succ_branch); + ASSERT(b0->succs().size() == 1 && b0->succs().front() == b0->succ_branch); // patch up next and prev. new_goto->next = b0->next; if (new_goto->next) { - assert(new_goto->next->prev == b0); + ASSERT(new_goto->next->prev == b0); new_goto->next->prev = new_goto; } new_goto->prev = b0->prev; if (new_goto->prev) { - assert(new_goto->prev->next == b0); + ASSERT(new_goto->prev->next == b0); new_goto->prev->next = new_goto; } @@ -980,9 +980,9 @@ bool ControlFlowGraph::find_infinite_continue() { if (new_goto->next) { // now we will fall through new_goto->succ_ft = b0->next; - assert(!new_goto->succ_ft->has_pred(new_goto)); + ASSERT(!new_goto->succ_ft->has_pred(new_goto)); new_goto->succ_ft->pred.push_back(new_goto); - assert(!new_goto->succ_branch); + ASSERT(!new_goto->succ_branch); } // break goto preds. @@ -1082,12 +1082,12 @@ bool ControlFlowGraph::is_sequence(CfgVtx* b0, CfgVtx* b1, bool allow_self_loops return false; if (b0->succ_ft) return false; - assert(b0->end_branch.branch_always); + ASSERT(b0->end_branch.branch_always); } else { // falls through if (b0->succ_branch) return false; - assert(!b0->end_branch.has_branch); + ASSERT(!b0->end_branch.has_branch); } if (b1->prev != b0) @@ -1210,10 +1210,10 @@ bool ControlFlowGraph::clean_up_asm_branches() { replaced = true; m_blocks.at(bds->succ_branch->get_first_block_id())->needs_label = true; auto* seq = dynamic_cast(b0); - assert(seq); + ASSERT(seq); auto* old_seq = dynamic_cast(b1); - assert(old_seq); + ASSERT(old_seq); if (b0->succ_branch) { b0->succ_branch->replace_preds_with_and_check({b0}, nullptr); @@ -1253,7 +1253,7 @@ bool ControlFlowGraph::clean_up_asm_branches() { m_blocks.at(bds->succ_branch->get_first_block_id())->needs_label = true; auto* seq = dynamic_cast(b0); - assert(seq); + ASSERT(seq); if (b0->succ_branch) { b0->succ_branch->replace_preds_with_and_check({b0}, nullptr); @@ -1308,7 +1308,7 @@ bool ControlFlowGraph::clean_up_asm_branches() { replaced = true; if (!b0->succ_branch) { fmt::print("asm missing branch in block {}\n", b0->to_string()); - assert(false); + ASSERT(false); } m_blocks.at(b0->succ_branch->get_first_block_id())->needs_label = true; @@ -1357,7 +1357,7 @@ bool ControlFlowGraph::clean_up_asm_branches() { b1->parent_claim(new_seq); if (new_seq->succ_branch) { - assert(!new_seq->succ_branch->parent); + ASSERT(!new_seq->succ_branch->parent); } new_seq->end_branch = b1->end_branch; @@ -1372,12 +1372,12 @@ bool ControlFlowGraph::clean_up_asm_branches() { if (debug_asm_branch) { fmt::print(" b1 succ_ft is {}\n", b1->succ_ft->to_string()); } - assert(b1->succ_ft->has_pred(b1)); + ASSERT(b1->succ_ft->has_pred(b1)); } replaced = true; m_blocks.at(b0->succ_branch->get_first_block_id())->needs_label = true; auto* seq = dynamic_cast(b0); - assert(seq); + ASSERT(seq); seq->seq.push_back(b1); @@ -1400,11 +1400,11 @@ bool ControlFlowGraph::clean_up_asm_branches() { } if (b1->succ_ft) { - assert(b1->succ_ft->has_pred(b0)); + ASSERT(b1->succ_ft->has_pred(b0)); } if (b1->succ_ft) { - assert(b1->succ_ft->has_pred(b0)); + ASSERT(b1->succ_ft->has_pred(b0)); } // try @@ -1412,7 +1412,7 @@ bool ControlFlowGraph::clean_up_asm_branches() { seq->succ_ft = b1->succ_ft; seq->succ_branch = b1->succ_branch; if (b1->succ_branch) { - assert(!b1->succ_branch->parent); + ASSERT(!b1->succ_branch->parent); } if (seq->succ_branch && debug_asm_branch) { @@ -1425,7 +1425,7 @@ bool ControlFlowGraph::clean_up_asm_branches() { b1->parent_claim(seq); if (seq->succ_branch) { - assert(!seq->succ_branch->parent); + ASSERT(!seq->succ_branch->parent); } seq->end_branch = b1->end_branch; return false; @@ -1439,10 +1439,10 @@ bool ControlFlowGraph::clean_up_asm_branches() { replaced = true; m_blocks.at(b0->succ_branch->get_first_block_id())->needs_label = true; auto* seq = dynamic_cast(b0); - assert(seq); + ASSERT(seq); auto* old_seq = dynamic_cast(b1); - assert(old_seq); + ASSERT(old_seq); if (b0->succ_branch) { if (debug_asm_branch) { @@ -1484,7 +1484,7 @@ bool ControlFlowGraph::clean_up_asm_branches() { } m_blocks.at(b0->succ_branch->get_first_block_id())->needs_label = true; auto* old_seq = dynamic_cast(b1); - assert(old_seq); + ASSERT(old_seq); if (b0->succ_branch) { if (debug_asm_branch) { fmt::print(" sbp: {}\n", !!b0->succ_branch->parent); @@ -1615,7 +1615,7 @@ bool ControlFlowGraph::find_seq_top_level(bool allow_self_loops) { // printf("make seq type 2 %s %s\n", b0->to_string().c_str(), b1->to_string().c_str()); replaced = true; auto* seq = dynamic_cast(b0); - assert(seq); + ASSERT(seq); seq->seq.push_back(b1); @@ -1637,7 +1637,7 @@ bool ControlFlowGraph::find_seq_top_level(bool allow_self_loops) { if (is_sequence_of_non_sequence_and_sequence(b0, b1, allow_self_loops)) { replaced = true; auto* seq = dynamic_cast(b1); - assert(seq); + ASSERT(seq); seq->seq.insert(seq->seq.begin(), b0); for (auto* p : b0->pred) { @@ -1657,10 +1657,10 @@ bool ControlFlowGraph::find_seq_top_level(bool allow_self_loops) { // printf("make seq type 3 %s %s\n", b0->to_string().c_str(), b1->to_string().c_str()); replaced = true; auto* seq = dynamic_cast(b0); - assert(seq); + ASSERT(seq); auto* old_seq = dynamic_cast(b1); - assert(old_seq); + ASSERT(old_seq); for (auto* x : old_seq->seq) { x->parent_claim(seq); @@ -1739,9 +1739,9 @@ bool ControlFlowGraph::find_cond_w_else(const CondWithElseLengthHack& hack) { return true; } - assert(b0->end_branch.has_branch); - assert(b0->end_branch.branch_always); - assert(b0->succ_branch); + ASSERT(b0->end_branch.has_branch); + ASSERT(b0->end_branch.branch_always); + ASSERT(b0->succ_branch); // TODO - check what's in the delay slot! auto* end_block = b0->succ_branch; @@ -1770,7 +1770,7 @@ bool ControlFlowGraph::find_cond_w_else(const CondWithElseLengthHack& hack) { if (else_block->succ_ft != end_block) { return true; } - assert(!else_block->end_branch.has_branch); + ASSERT(!else_block->end_branch.has_branch); std::vector entries = {{c0, b0}}; auto* prev_condition = c0; @@ -1923,9 +1923,9 @@ bool ControlFlowGraph::find_cond_w_empty_else() { return true; } - assert(b0->end_branch.has_branch); - assert(b0->end_branch.branch_always); - assert(b0->succ_branch); + ASSERT(b0->end_branch.has_branch); + ASSERT(b0->end_branch.branch_always); + ASSERT(b0->succ_branch); // TODO - check what's in the delay slot! auto* end_block = b0->succ_branch; @@ -2105,9 +2105,9 @@ bool ControlFlowGraph::find_cond_n_else() { printf("reject 2A\n"); return true; } - assert(b0->end_branch.has_branch); - assert(b0->end_branch.branch_always); - assert(b0->succ_branch); + ASSERT(b0->end_branch.has_branch); + ASSERT(b0->end_branch.branch_always); + ASSERT(b0->succ_branch); } else { single_case = true; } @@ -2467,7 +2467,7 @@ bool ControlFlowGraph::find_short_circuits() { * The returned vector will have blocks in ordered, so the i-th entry is for the i-th block. */ const std::vector& ControlFlowGraph::create_blocks(int count) { - assert(m_blocks.empty()); + ASSERT(m_blocks.empty()); BlockVtx* prev = nullptr; // for linking next/prev for (int i = 0; i < count; i++) { @@ -2492,12 +2492,12 @@ const std::vector& ControlFlowGraph::create_blocks(int count) { void ControlFlowGraph::link_fall_through(BlockVtx* first, BlockVtx* second, std::vector& blocks) { - assert(!first->succ_ft); // don't want to overwrite something by accident. + ASSERT(!first->succ_ft); // don't want to overwrite something by accident. // can only fall through to the next code in memory. - assert(first->next == second); - assert(second->prev == first); + ASSERT(first->next == second); + ASSERT(second->prev == first); first->succ_ft = second; - assert(blocks.at(first->block_id).succ_ft == -1); + ASSERT(blocks.at(first->block_id).succ_ft == -1); blocks.at(first->block_id).succ_ft = second->block_id; if (!second->has_pred(first)) { @@ -2515,9 +2515,9 @@ void ControlFlowGraph::link_fall_through(BlockVtx* first, void ControlFlowGraph::link_branch(BlockVtx* first, BlockVtx* second, std::vector& blocks) { - assert(!first->succ_branch); + ASSERT(!first->succ_branch); first->succ_branch = second; - assert(blocks.at(first->block_id).succ_branch == -1); + ASSERT(blocks.at(first->block_id).succ_branch == -1); blocks.at(first->block_id).succ_branch = second->block_id; if (!second->has_pred(first)) { @@ -2530,12 +2530,12 @@ void ControlFlowGraph::link_branch(BlockVtx* first, void ControlFlowGraph::link_fall_through_likely(BlockVtx* first, BlockVtx* second, std::vector& blocks) { - assert(!first->succ_ft); // don't want to overwrite something by accident. + ASSERT(!first->succ_ft); // don't want to overwrite something by accident. // can only fall through to the next code in memory. - assert(first->next->next == second); - assert(second->prev->prev == first); + ASSERT(first->next->next == second); + ASSERT(second->prev->prev == first); first->succ_ft = second; - assert(blocks.at(first->block_id).succ_ft == -1); + ASSERT(blocks.at(first->block_id).succ_ft == -1); blocks.at(first->block_id).succ_ft = second->block_id; if (!second->has_pred(first)) { @@ -2553,7 +2553,7 @@ void ControlFlowGraph::flag_early_exit(const std::vector& blocks) { if (block.start_word == block.end_word) { b->is_early_exit_block = true; - assert(!b->end_branch.has_branch); + ASSERT(!b->end_branch.has_branch); } } @@ -2643,7 +2643,7 @@ std::shared_ptr build_cfg( } else { // room for at least a likely branch, try that first. int likely_branch_idx = b.end_word - 1; - assert(likely_branch_idx >= b.start_word); + ASSERT(likely_branch_idx >= b.start_word); auto& likely_branch_candidate = func.instructions.at(likely_branch_idx); if (is_branch(likely_branch_candidate, true)) { @@ -2656,12 +2656,12 @@ std::shared_ptr build_cfg( // need to find block target int block_target = -1; int label_target = likely_branch_candidate.get_label_target(); - assert(label_target != -1); + ASSERT(label_target != -1); const auto& label = file.labels.at(label_target); - assert(label.target_segment == seg); - assert((label.offset % 4) == 0); + ASSERT(label.target_segment == seg); + ASSERT((label.offset % 4) == 0); int offset = label.offset / 4 - func.start_word; - assert(offset >= 0); + ASSERT(offset >= 0); for (int j = int(func.basic_blocks.size()); j-- > 0;) { if (func.basic_blocks[j].start_word == offset) { block_target = j; @@ -2669,7 +2669,7 @@ std::shared_ptr build_cfg( } } - assert(block_target != -1); + ASSERT(block_target != -1); // branch to delay slot cfg->link_branch(blocks.at(i), blocks.at(i + 1), func.basic_blocks); @@ -2700,7 +2700,7 @@ std::shared_ptr build_cfg( } else { // try as a normal branch. int idx = b.end_word - 2; - assert(idx >= b.start_word); + ASSERT(idx >= b.start_word); auto& branch_candidate = func.instructions.at(idx); auto& delay_slot_candidate = func.instructions.at(idx + 1); if (is_branch(branch_candidate, false)) { @@ -2712,12 +2712,12 @@ std::shared_ptr build_cfg( // need to find block target int block_target = -1; int label_target = branch_candidate.get_label_target(); - assert(label_target != -1); + ASSERT(label_target != -1); const auto& label = file.labels.at(label_target); - assert(label.target_segment == seg); - assert((label.offset % 4) == 0); + ASSERT(label.target_segment == seg); + ASSERT((label.offset % 4) == 0); int offset = label.offset / 4 - func.start_word; - assert(offset >= 0); + ASSERT(offset >= 0); // the order here matters when there are zero size blocks. Unclear what the best answer // is. @@ -2730,7 +2730,7 @@ std::shared_ptr build_cfg( } } - assert(block_target != -1); + ASSERT(block_target != -1); cfg->link_branch(blocks.at(i), blocks.at(block_target), func.basic_blocks); if (branch_always) { @@ -2771,7 +2771,7 @@ std::shared_ptr build_cfg( // room for at least a likely branch, try that first. int likely_branch_idx = bb.end_word - 1; - assert(likely_branch_idx >= bb.start_word); + ASSERT(likely_branch_idx >= bb.start_word); auto& likely_branch_candidate = func.instructions.at(likely_branch_idx); if (is_branch(likely_branch_candidate, true)) { @@ -2789,7 +2789,7 @@ std::shared_ptr build_cfg( if (bb.end_word - bb.start_word >= 2) { int idx = bb.end_word - 2; - assert(idx >= bb.start_word); + ASSERT(idx >= bb.start_word); auto& branch_candidate = func.instructions.at(idx); auto& delay_slot_candidate = func.instructions.at(idx + 1); if (is_branch(branch_candidate, false)) { diff --git a/decompiler/Function/CfgVtx.h b/decompiler/Function/CfgVtx.h index bc2563e3fd..aaf2fd9584 100644 --- a/decompiler/Function/CfgVtx.h +++ b/decompiler/Function/CfgVtx.h @@ -2,7 +2,7 @@ #include #include -#include "common/util/assert.h" +#include "common/util/Assert.h" namespace goos { class Object; @@ -18,12 +18,12 @@ void replace_exactly_one_in(std::vector& v, T old, T replace) { bool replaced = false; for (auto& x : v) { if (x == old) { - assert(!replaced); + ASSERT(!replaced); x = replace; replaced = true; } } - assert(replaced); + ASSERT(replaced); } /*! diff --git a/decompiler/Function/Function.cpp b/decompiler/Function/Function.cpp index 5c09828924..30ab73b88c 100644 --- a/decompiler/Function/Function.cpp +++ b/decompiler/Function/Function.cpp @@ -8,7 +8,7 @@ #include "decompiler/IR/IR.h" #include "decompiler/IR2/Form.h" #include "common/util/BitUtils.h" -#include "common/util/assert.h" +#include "common/util/Assert.h" namespace decompiler { namespace { @@ -20,14 +20,14 @@ std::vector fpr_backups = {make_fpr(30), make_fpr(28), make_fpr(26), make_fpr(24), make_fpr(22), make_fpr(20)}; Register get_expected_gpr_backup(int n, int total) { - assert(total <= int(gpr_backups.size())); - assert(n < total); + ASSERT(total <= int(gpr_backups.size())); + ASSERT(n < total); return gpr_backups.at((total - 1) - n); } Register get_expected_fpr_backup(int n, int total) { - assert(total <= int(fpr_backups.size())); - assert(n < total); + ASSERT(total <= int(fpr_backups.size())); + ASSERT(n < total); return fpr_backups.at((total - 1) - n); } @@ -79,7 +79,7 @@ void Function::analyze_prologue(const LinkedObjectFile& file) { Register(Reg::GPR, Reg::SP))) { prologue.ra_backed_up = true; prologue.ra_backup_offset = get_gpr_store_offset_as_int(instructions.at(idx)); - assert(prologue.ra_backup_offset == 0); + ASSERT(prologue.ra_backup_offset == 0); idx++; } @@ -107,13 +107,13 @@ void Function::analyze_prologue(const LinkedObjectFile& file) { prologue.fp_backup_offset = get_gpr_store_offset_as_int(instructions.at(idx)); // in Jak 1 like we never backup fp unless ra is also backed up, so the offset is always 8. // but it seems like it could be possible to do one without the other? - assert(prologue.fp_backup_offset == 8); + ASSERT(prologue.fp_backup_offset == 8); idx++; // after backing up fp, we always set it to t9. prologue.fp_set = is_gpr_3(instructions.at(idx), InstructionKind::OR, make_gpr(Reg::FP), make_gpr(Reg::T9), make_gpr(Reg::R0)); - assert(prologue.fp_set); + ASSERT(prologue.fp_set); idx++; } @@ -144,7 +144,7 @@ void Function::analyze_prologue(const LinkedObjectFile& file) { for (int i = 0; i < n_gpr_backups; i++) { int this_offset = get_gpr_store_offset_as_int(instructions.at(idx + i)); auto this_reg = instructions.at(idx + i).get_src(0).get_reg(); - assert(this_offset == prologue.gpr_backup_offset + 16 * i); + ASSERT(this_offset == prologue.gpr_backup_offset + 16 * i); if (this_reg != get_expected_gpr_backup(i, n_gpr_backups)) { suspected_asm = true; lg::warn("Function {} stores on the stack in a strange way ({}), flagging as asm!", @@ -173,7 +173,7 @@ void Function::analyze_prologue(const LinkedObjectFile& file) { for (int i = 0; i < n_fpr_backups; i++) { int this_offset = instructions.at(idx + i).get_src(1).get_imm(); auto this_reg = instructions.at(idx + i).get_src(0).get_reg(); - assert(this_offset == prologue.fpr_backup_offset + 4 * i); + ASSERT(this_offset == prologue.fpr_backup_offset + 4 * i); if (this_reg != get_expected_fpr_backup(i, n_fpr_backups)) { suspected_asm = true; lg::warn("Function {} stores on the stack in a strange way ({}), flagging as asm!", @@ -209,11 +209,11 @@ void Function::analyze_prologue(const LinkedObjectFile& file) { prologue.n_stack_var_bytes = prologue.gpr_backup_offset - prologue.stack_var_offset; } else { // both, use gprs - assert(prologue.fpr_backup_offset > prologue.gpr_backup_offset); + ASSERT(prologue.fpr_backup_offset > prologue.gpr_backup_offset); prologue.n_stack_var_bytes = prologue.gpr_backup_offset - prologue.stack_var_offset; } - assert(prologue.n_stack_var_bytes >= 0); + ASSERT(prologue.n_stack_var_bytes >= 0); // check that the stack lines up by going in order @@ -221,7 +221,7 @@ void Function::analyze_prologue(const LinkedObjectFile& file) { int total_stack = 0; if (prologue.ra_backed_up) { total_stack = align8(total_stack); - assert(prologue.ra_backup_offset == total_stack); + ASSERT(prologue.ra_backup_offset == total_stack); total_stack += 8; } @@ -233,42 +233,42 @@ void Function::analyze_prologue(const LinkedObjectFile& file) { // FP backup if (prologue.fp_backed_up) { total_stack = align8(total_stack); - assert(prologue.fp_backup_offset == total_stack); + ASSERT(prologue.fp_backup_offset == total_stack); total_stack += 8; - assert(prologue.fp_set); + ASSERT(prologue.fp_set); } // Stack Variables if (prologue.n_stack_var_bytes) { // no alignment because we don't know how the stack vars are aligned. // stack var padding counts toward this section. - assert(prologue.stack_var_offset == total_stack); + ASSERT(prologue.stack_var_offset == total_stack); total_stack += prologue.n_stack_var_bytes; } // GPRS if (prologue.n_gpr_backup) { total_stack = align16(total_stack); - assert(prologue.gpr_backup_offset == total_stack); + ASSERT(prologue.gpr_backup_offset == total_stack); total_stack += 16 * prologue.n_gpr_backup; } // FPRS if (prologue.n_fpr_backup) { total_stack = align4(total_stack); - assert(prologue.fpr_backup_offset == total_stack); + ASSERT(prologue.fpr_backup_offset == total_stack); total_stack += 4 * prologue.n_fpr_backup; } total_stack = align16(total_stack); // End! - assert(prologue.total_stack_usage == total_stack); + ASSERT(prologue.total_stack_usage == total_stack); } // it's fine to have the entire first basic block be the prologue - you could loop back to the // first instruction past the prologue. - assert(basic_blocks.at(0).end_word >= prologue_end); + ASSERT(basic_blocks.at(0).end_word >= prologue_end); resize_first_block(prologue_end, file); prologue.decoded = true; @@ -366,24 +366,24 @@ void Function::check_epilogue(const LinkedObjectFile& file) { if (is_gpr_3(instructions.at(idx), InstructionKind::DADDU, make_gpr(Reg::SP), make_gpr(Reg::SP), make_gpr(Reg::R0))) { idx--; - assert(is_jr_ra(instructions.at(idx))); + ASSERT(is_jr_ra(instructions.at(idx))); idx--; lg::warn("Function {} has a double return and is being flagged as asm.", name()); warnings.general_warning("Flagged as asm due to double return"); } // delay slot should be daddiu sp, sp, offset - assert(is_gpr_2_imm_int(instructions.at(idx), InstructionKind::DADDIU, make_gpr(Reg::SP), + ASSERT(is_gpr_2_imm_int(instructions.at(idx), InstructionKind::DADDIU, make_gpr(Reg::SP), make_gpr(Reg::SP), prologue.total_stack_usage)); idx--; } else { // delay slot is always daddu sp, sp, r0... - assert(is_gpr_3(instructions.at(idx), InstructionKind::DADDU, make_gpr(Reg::SP), + ASSERT(is_gpr_3(instructions.at(idx), InstructionKind::DADDU, make_gpr(Reg::SP), make_gpr(Reg::SP), make_gpr(Reg::R0))); idx--; } // jr ra - assert(is_jr_ra(instructions.at(idx))); + ASSERT(is_jr_ra(instructions.at(idx))); idx--; // restore gprs @@ -391,7 +391,7 @@ void Function::check_epilogue(const LinkedObjectFile& file) { int gpr_idx = prologue.n_gpr_backup - (1 + i); const auto& expected_reg = gpr_backups.at(gpr_idx); auto expected_offset = prologue.gpr_backup_offset + 16 * i; - assert(is_no_ll_gpr_load(instructions.at(idx), 16, true, expected_reg, expected_offset, + ASSERT(is_no_ll_gpr_load(instructions.at(idx), 16, true, expected_reg, expected_offset, make_gpr(Reg::SP))); idx--; } @@ -401,27 +401,27 @@ void Function::check_epilogue(const LinkedObjectFile& file) { int fpr_idx = prologue.n_fpr_backup - (1 + i); const auto& expected_reg = fpr_backups.at(fpr_idx); auto expected_offset = prologue.fpr_backup_offset + 4 * i; - assert( + ASSERT( is_no_ll_fpr_load(instructions.at(idx), expected_reg, expected_offset, make_gpr(Reg::SP))); idx--; } // restore fp if (prologue.fp_backed_up) { - assert(is_no_ll_gpr_load(instructions.at(idx), 8, true, make_gpr(Reg::FP), + ASSERT(is_no_ll_gpr_load(instructions.at(idx), 8, true, make_gpr(Reg::FP), prologue.fp_backup_offset, make_gpr(Reg::SP))); idx--; } // restore ra if (prologue.ra_backed_up) { - assert(is_no_ll_gpr_load(instructions.at(idx), 8, true, make_gpr(Reg::RA), + ASSERT(is_no_ll_gpr_load(instructions.at(idx), 8, true, make_gpr(Reg::RA), prologue.ra_backup_offset, make_gpr(Reg::SP))); idx--; } - assert(!basic_blocks.empty()); - assert(idx + 1 >= basic_blocks.back().start_word); + ASSERT(!basic_blocks.empty()); + ASSERT(idx + 1 >= basic_blocks.back().start_word); basic_blocks.back().end_word = idx + 1; prologue.epilogue_ok = true; epilogue_start = idx + 1; @@ -445,7 +445,7 @@ void Function::find_global_function_defs(LinkedObjectFile& file, DecompilerTypeS state = 1; reg = instr.get_dst(0).get_reg(); label_id = instr.get_src(0).get_label(); - assert(label_id != -1); + ASSERT(label_id != -1); continue; } @@ -471,7 +471,7 @@ void Function::find_global_function_defs(LinkedObjectFile& file, DecompilerTypeS // printf("discard as not code: %s\n", name.c_str()); } else { auto& func = file.get_function_at_label(label_id); - assert(func.guessed_name.empty()); + ASSERT(func.guessed_name.empty()); func.guessed_name.set_as_global(name); dts.add_symbol(name, "function"); ; @@ -538,7 +538,7 @@ void Function::find_method_defs(LinkedObjectFile& file, DecompilerTypeSystem& dt state = 4; lui_reg = instr.get_dst(0).get_reg(); label_id = instr.get_src(0).get_label(); - assert(label_id != -1); + ASSERT(label_id != -1); continue; } else { state = 0; @@ -560,7 +560,7 @@ void Function::find_method_defs(LinkedObjectFile& file, DecompilerTypeSystem& dt if (instr.kind == InstructionKind::JALR && instr.get_dst(0).get_reg() == make_gpr(Reg::RA) && instr.get_src(0).get_reg() == make_gpr(Reg::T9)) { auto& func = file.get_function_at_label(label_id); - assert(func.guessed_name.empty()); + ASSERT(func.guessed_name.empty()); func.guessed_name.set_as_method(type_name, method_id); func.method_of_type = type_name; if (method_id == GOAL_INSPECT_METHOD) { @@ -675,7 +675,7 @@ void Function::find_type_defs(LinkedObjectFile& file, DecompilerTypeSystem& dts) void Function::add_basic_op(std::shared_ptr op, int start_instr, int end_instr) { op->is_basic_op = true; - assert(end_instr > start_instr); + ASSERT(end_instr > start_instr); for (int i = start_instr; i < end_instr; i++) { instruction_to_basic_op[i] = basic_ops.size(); @@ -734,7 +734,7 @@ BlockTopologicalSort Function::bb_topo_sort() { std::unordered_set visit_set; std::vector visit_queue; if (basic_blocks.empty()) { - assert(false); + ASSERT(false); } visit_queue.push_back(0); diff --git a/decompiler/Function/Function.h b/decompiler/Function/Function.h index c27aed6a25..e9cc7bb75b 100644 --- a/decompiler/Function/Function.h +++ b/decompiler/Function/Function.h @@ -60,7 +60,7 @@ struct FunctionName { } int get_anon_id() const { - assert(kind == FunctionKind::UNIDENTIFIED); + ASSERT(kind == FunctionKind::UNIDENTIFIED); return id_in_object; } diff --git a/decompiler/Function/TypeInspector.cpp b/decompiler/Function/TypeInspector.cpp index 6e8c6ef7fe..14063623c2 100644 --- a/decompiler/Function/TypeInspector.cpp +++ b/decompiler/Function/TypeInspector.cpp @@ -28,9 +28,9 @@ FieldPrint get_field_print(const std::string& str) { // first is ~T char c0 = next(); - assert(c0 == '~'); + ASSERT(c0 == '~'); char c1 = next(); - assert(c1 == 'T'); + ASSERT(c1 == 'T'); // next the name: char name_char = next(); @@ -50,21 +50,21 @@ FieldPrint get_field_print(const std::string& str) { field_print.has_array = true; field_print.array_size = size; - assert(num_char == ']'); + ASSERT(num_char == ']'); char c = next(); - assert(c == ' '); + ASSERT(c == ' '); c = next(); - assert(c == '@'); + ASSERT(c == '@'); c = next(); - assert(c == ' '); + ASSERT(c == ' '); c = next(); - assert(c == '#'); + ASSERT(c == '#'); c = next(); - assert(c == 'x'); + ASSERT(c == 'x'); } else { // next a space char space_char = next(); - assert(space_char == ' '); + ASSERT(space_char == ' '); } // next the format @@ -73,10 +73,10 @@ FieldPrint get_field_print(const std::string& str) { char fmt_code = next(); field_print.format = fmt_code; char end1 = next(); - assert(end1 == '~'); + ASSERT(end1 == '~'); char end2 = next(); - assert(end2 == '%'); - assert(idx == (int)str.size()); + ASSERT(end2 == '%'); + ASSERT(idx == (int)str.size()); } else if (fmt1 == '#' && peek(0) == '<') { // struct #~% next(); char type_name_c = next(); @@ -88,17 +88,17 @@ FieldPrint get_field_print(const std::string& str) { std::string expect_end = "@ #x~X>~%"; for (char i : expect_end) { char c = next(); - assert(i == c); + ASSERT(i == c); } field_print.format = 'X'; - assert(idx == (int)str.size()); + ASSERT(idx == (int)str.size()); } else if (fmt1 == '#' && peek(0) == 'x') { // #x~X~% next(); std::string expect_end = "~X~%"; for (char i : expect_end) { char c = next(); - assert(i == c); + ASSERT(i == c); } field_print.format = 'X'; } else if (fmt1 == '~' && peek(0) == '`') { // ~`my-type-with-overriden-print`P~% @@ -112,11 +112,11 @@ FieldPrint get_field_print(const std::string& str) { std::string expect_end = "P~%"; for (char i : expect_end) { char c = next(); - assert(i == c); + ASSERT(i == c); } field_print.format = 'P'; - assert(idx == (int)str.size()); + ASSERT(idx == (int)str.size()); } else if (str.substr(idx - 1) == "(meters ~m)~%") { field_print.format = 'm'; } else if (str.substr(idx - 1) == "(deg ~r)~%") { @@ -173,9 +173,9 @@ struct LoadInfo { LoadInfo get_load_info_from_set(IR* load) { auto as_set = dynamic_cast(load); - assert(as_set); + ASSERT(as_set); auto as_load = dynamic_cast(as_set->src.get()); - assert(as_load); + ASSERT(as_load); LoadInfo info; info.kind = as_load->kind; info.size = as_load->size; @@ -185,10 +185,10 @@ LoadInfo get_load_info_from_set(IR* load) { } auto as_math = dynamic_cast(as_load->location.get()); - assert(as_math); - assert(as_math->kind == IR_IntMath2::ADD); + ASSERT(as_math); + ASSERT(as_math->kind == IR_IntMath2::ADD); auto as_int = dynamic_cast(as_math->arg1.get()); - assert(as_int); + ASSERT(as_int); info.offset = as_int->value; return info; } @@ -200,13 +200,13 @@ Register get_base_of_load(IR_Load* load) { } auto as_math = dynamic_cast(load->location.get()); - assert(as_math->kind == IR_IntMath2::ADD); - assert(dynamic_cast(as_math->arg1.get())); + ASSERT(as_math->kind == IR_IntMath2::ADD); + ASSERT(dynamic_cast(as_math->arg1.get())); auto math_reg = dynamic_cast(as_math->arg0.get()); if (math_reg) { return math_reg->reg; } else { - assert(false); + ASSERT(false); } return {}; } @@ -443,8 +443,8 @@ int identify_basic_field(int idx, FieldPrint& print_info) { (void)file; auto load_info = get_load_info_from_set(function.basic_ops.at(idx++).get()); - assert(load_info.size == 4); - assert(load_info.kind == IR_Load::UNSIGNED || load_info.kind == IR_Load::SIGNED); + ASSERT(load_info.size == 4); + ASSERT(load_info.kind == IR_Load::UNSIGNED || load_info.kind == IR_Load::SIGNED); if (load_info.kind == IR_Load::SIGNED) { result->warnings += "field " + print_info.field_name + " is a basic loaded with a signed load "; @@ -467,8 +467,8 @@ int identify_pointer_field(int idx, FieldPrint& print_info) { (void)file; auto load_info = get_load_info_from_set(function.basic_ops.at(idx++).get()); - assert(load_info.size == 4); - assert(load_info.kind == IR_Load::UNSIGNED); + ASSERT(load_info.size == 4); + ASSERT(load_info.kind == IR_Load::UNSIGNED); int offset = load_info.offset; if (result->is_basic) { @@ -489,7 +489,7 @@ int identify_array_field(int idx, int offset = 0; if (!get_ptr_offset(get_op.get(), make_gpr(Reg::A2), make_gpr(Reg::GP), &offset)) { printf("bad get ptr offset %s\n", get_op->print(file).c_str()); - assert(false); + ASSERT(false); } if (result->is_basic) { offset += BASIC_OFFSET; @@ -511,13 +511,13 @@ int identify_float_field(int idx, TypeInspectorResult* result, FieldPrint& print_info) { auto load_info = get_load_info_from_set(function.basic_ops.at(idx++).get()); - assert(load_info.size == 4); - assert(load_info.kind == IR_Load::FLOAT); + ASSERT(load_info.size == 4); + ASSERT(load_info.kind == IR_Load::FLOAT); auto& float_move = function.basic_ops.at(idx++); if (!is_reg_reg_move(float_move.get(), make_gpr(Reg::A2), make_fpr(0))) { printf("bad float move: %s\n", float_move->print(file).c_str()); - assert(false); + ASSERT(false); } std::string type; @@ -536,7 +536,7 @@ int identify_float_field(int idx, result->warnings += "field " + print_info.field_name + " is a float printed as hex? "; break; default: - assert(false); + ASSERT(false); } int offset = load_info.offset; if (result->is_basic) { @@ -578,7 +578,7 @@ int identify_struct_inline_field(int idx, int offset = 0; if (!get_ptr_offset(get_op.get(), make_gpr(Reg::A2), make_gpr(Reg::GP), &offset)) { printf("bad get ptr offset %s\n", get_op->print(file).c_str()); - assert(false); + ASSERT(false); } if (result->is_basic) { offset += BASIC_OFFSET; @@ -602,7 +602,7 @@ int identify_int_field(int idx, if (load_info.kind == IR_Load::UNSIGNED) { field_type_name += "u"; } else if (load_info.kind == IR_Load::FLOAT) { - assert(false); // ... + ASSERT(false); // ... } field_type_name += "int"; @@ -636,9 +636,9 @@ int identify_int_field(int idx, field_type_name = "useconds"; break; default: - assert(false); + ASSERT(false); } - assert(load_info.size == 8); + ASSERT(load_info.size == 8); } int offset = load_info.offset; @@ -656,13 +656,13 @@ int detect(int idx, Function& function, LinkedObjectFile& file, TypeInspectorRes auto& get_format_op = function.basic_ops.at(idx++); if (!is_get_sym_value(get_format_op.get(), make_gpr(Reg::T9), "format")) { printf("bad get format"); - assert(false); + ASSERT(false); } auto& get_true = function.basic_ops.at(idx++); if (!is_get_sym(get_true.get(), make_gpr(Reg::A0), "#t")) { printf("bad get true"); - assert(false); + ASSERT(false); } auto& get_str = function.basic_ops.at(idx++); @@ -717,7 +717,7 @@ int detect(int idx, Function& function, LinkedObjectFile& file, TypeInspectorRes auto& call_op = function.basic_ops.at(idx++); if (!dynamic_cast(call_op.get())) { printf("bad call\n"); - assert(false); + ASSERT(false); } return idx; @@ -739,7 +739,7 @@ TypeInspectorResult inspect_inspect_method(Function& inspect, result.type_size = flags.size; result.type_method_count = flags.methods; result.type_heap_base = flags.heap_base; - assert(flags.pad == 0); + ASSERT(flags.pad == 0); int idx = get_start_idx(inspect, file, &result, result.parent_type_name); if (idx == 0 || skip_fields) { diff --git a/decompiler/Function/Warnings.h b/decompiler/Function/Warnings.h index 8e4b65dbd8..0180c6368c 100644 --- a/decompiler/Function/Warnings.h +++ b/decompiler/Function/Warnings.h @@ -3,7 +3,7 @@ #include #include #include "third-party/fmt/core.h" -#include "common/util/assert.h" +#include "common/util/Assert.h" namespace decompiler { class DecompWarnings { @@ -91,7 +91,7 @@ class DecompWarnings { case Kind::INFO: return fmt::format("INFO: {}\n", message); default: - assert(false); + ASSERT(false); return {}; } } diff --git a/decompiler/IR/BasicOpBuilder.cpp b/decompiler/IR/BasicOpBuilder.cpp index 7f243428d1..3fec5e6f1a 100644 --- a/decompiler/IR/BasicOpBuilder.cpp +++ b/decompiler/IR/BasicOpBuilder.cpp @@ -112,7 +112,7 @@ std::shared_ptr instr_atom_to_ir(const InstructionAtom& ia, int idx) { // not supported by IR1 return std::make_shared(); default: - assert(false); + ASSERT(false); return nullptr; } } @@ -130,8 +130,8 @@ std::shared_ptr to_asm_automatic(const std::string& str, Instruction& // not supported by IR1 return std::make_shared(); } - assert(instr.n_dst < 2); - assert(instr.n_src < 4); + ASSERT(instr.n_dst < 2); + ASSERT(instr.n_src < 4); if (instr.n_dst >= 1) { result->dst = instr_atom_to_ir(instr.get_dst(0), idx); } @@ -609,7 +609,7 @@ std::shared_ptr try_lwu(Instruction& instr, int idx) { std::shared_ptr try_lq(Instruction& instr, int idx) { if (instr.kind == InstructionKind::LQ && instr.get_src(1).is_reg(make_gpr(Reg::S7)) && instr.get_src(0).kind == InstructionAtom::IMM_SYM) { - assert(false); + ASSERT(false); } else if (instr.kind == InstructionKind::LQ && instr.get_dst(0).is_reg() && instr.get_src(0).is_link_or_label() && instr.get_src(1).is_reg(make_gpr(Reg::FP))) { // static @@ -1349,7 +1349,7 @@ BranchDelay get_branch_delay(Instruction& i, int idx) { b.write_regs.push_back(dst); return b; } else { - assert(false); + ASSERT(false); } } else if (i.kind == InstructionKind::DSLLV) { // this is used for ash? @@ -1521,10 +1521,10 @@ std::shared_ptr try_daddiu(Instruction& i0, Instruction& i1, int idx) i0.get_src(0).get_reg() == make_gpr(Reg::S7)) { auto dst_reg = i0.get_dst(0).get_reg(); auto src_reg = i1.get_src(1).get_reg(); - assert(i0.get_src(0).get_reg() == make_gpr(Reg::S7)); - assert(i0.get_src(1).get_imm() == 8); - assert(i1.get_dst(0).get_reg() == dst_reg); - assert(i1.get_src(0).get_reg() == make_gpr(Reg::S7)); + ASSERT(i0.get_src(0).get_reg() == make_gpr(Reg::S7)); + ASSERT(i0.get_src(1).get_imm() == 8); + ASSERT(i1.get_dst(0).get_reg() == dst_reg); + ASSERT(i1.get_src(0).get_reg() == make_gpr(Reg::S7)); auto op = make_set_atomic( IR_Set_Atomic::REG_64, make_reg(dst_reg, idx), std::make_shared( @@ -1537,10 +1537,10 @@ std::shared_ptr try_daddiu(Instruction& i0, Instruction& i1, int idx) i0.get_src(0).get_reg() == make_gpr(Reg::S7)) { auto dst_reg = i0.get_dst(0).get_reg(); auto src_reg = i1.get_src(1).get_reg(); - assert(i0.get_src(0).get_reg() == make_gpr(Reg::S7)); - assert(i0.get_src(1).get_imm() == 8); - assert(i1.get_dst(0).get_reg() == dst_reg); - assert(i1.get_src(0).get_reg() == make_gpr(Reg::S7)); + ASSERT(i0.get_src(0).get_reg() == make_gpr(Reg::S7)); + ASSERT(i0.get_src(1).get_imm() == 8); + ASSERT(i1.get_dst(0).get_reg() == dst_reg); + ASSERT(i1.get_src(0).get_reg() == make_gpr(Reg::S7)); auto op = make_set_atomic( IR_Set_Atomic::REG_64, make_reg(dst_reg, idx), std::make_shared( @@ -1556,8 +1556,8 @@ std::shared_ptr try_daddiu(Instruction& i0, Instruction& i1, int idx) std::shared_ptr try_lui(Instruction& i0, Instruction& i1, int idx) { if (i0.kind == InstructionKind::LUI && i1.kind == InstructionKind::ORI && i0.get_src(0).is_label() && i1.get_src(1).is_label()) { - assert(i0.get_dst(0).get_reg() == i1.get_src(0).get_reg()); - assert(i0.get_src(0).get_label() == i1.get_src(1).get_label()); + ASSERT(i0.get_dst(0).get_reg() == i1.get_src(0).get_reg()); + ASSERT(i0.get_src(0).get_label() == i1.get_src(1).get_label()); auto op = make_set_atomic(IR_Set_Atomic::REG_64, make_reg(i1.get_dst(0).get_reg(), idx), std::make_shared(i0.get_src(0).get_label())); if (i0.get_dst(0).get_reg() != i1.get_dst(0).get_reg()) { @@ -1628,10 +1628,10 @@ std::shared_ptr try_lui(Instruction& i0, Instruction& i1, Instruction if (i0.kind == InstructionKind::LUI && i1.kind == InstructionKind::ORI && i0.get_src(0).is_label() && i1.get_src(1).is_label() && is_gpr_3(i2, InstructionKind::ADDU, {}, make_gpr(Reg::FP), {})) { - assert(i0.get_dst(0).get_reg() == i1.get_src(0).get_reg()); - assert(i0.get_src(0).get_label() == i1.get_src(1).get_label()); - assert(i2.get_dst(0).get_reg() == i2.get_src(1).get_reg()); - assert(i2.get_dst(0).get_reg() == i1.get_dst(0).get_reg()); + ASSERT(i0.get_dst(0).get_reg() == i1.get_src(0).get_reg()); + ASSERT(i0.get_src(0).get_label() == i1.get_src(1).get_label()); + ASSERT(i2.get_dst(0).get_reg() == i2.get_src(1).get_reg()); + ASSERT(i2.get_dst(0).get_reg() == i1.get_dst(0).get_reg()); auto op = make_set_atomic(IR_Set_Atomic::REG_64, make_reg(i1.get_dst(0).get_reg(), idx), std::make_shared(i0.get_src(0).get_label())); if (i0.get_dst(0).get_reg() != i1.get_dst(0).get_reg()) { @@ -1653,11 +1653,11 @@ std::shared_ptr try_dsubu(Instruction& i0, Instruction& i1, Instructi auto src0_reg = i0.get_src(0).get_reg(); auto src1_reg = i0.get_src(1).get_reg(); auto dst_reg = i1.get_dst(0).get_reg(); - assert(i1.get_src(0).get_reg() == make_gpr(Reg::S7)); - assert(i1.get_src(1).get_imm() == 8); - assert(i2.get_dst(0).get_reg() == dst_reg); - assert(i2.get_src(0).get_reg() == make_gpr(Reg::S7)); - assert(i2.get_src(1).get_reg() == clobber_reg); + ASSERT(i1.get_src(0).get_reg() == make_gpr(Reg::S7)); + ASSERT(i1.get_src(1).get_imm() == 8); + ASSERT(i2.get_dst(0).get_reg() == dst_reg); + ASSERT(i2.get_src(0).get_reg() == make_gpr(Reg::S7)); + ASSERT(i2.get_src(1).get_reg() == clobber_reg); auto op = make_set_atomic( IR_Set_Atomic::REG_64, make_reg(dst_reg, idx), std::make_shared(Condition(Condition::EQUAL, make_reg(src0_reg, idx), @@ -1672,10 +1672,10 @@ std::shared_ptr try_dsubu(Instruction& i0, Instruction& i1, Instructi auto src0_reg = i0.get_src(0).get_reg(); auto src1_reg = i0.get_src(1).get_reg(); auto dst_reg = i1.get_dst(0).get_reg(); - assert(i1.get_src(0).get_reg() == make_gpr(Reg::S7)); - assert(i1.get_src(1).get_imm() == 8); - assert(i2.get_dst(0).get_reg() == dst_reg); - assert(i2.get_src(0).get_reg() == make_gpr(Reg::S7)); + ASSERT(i1.get_src(0).get_reg() == make_gpr(Reg::S7)); + ASSERT(i1.get_src(1).get_imm() == 8); + ASSERT(i2.get_dst(0).get_reg() == dst_reg); + ASSERT(i2.get_src(0).get_reg() == make_gpr(Reg::S7)); if (i2.get_src(1).get_reg() != clobber_reg) { return nullptr; // TODO! } @@ -1695,8 +1695,8 @@ std::shared_ptr try_slt(Instruction& i0, Instruction& i1, Instruction auto clobber_reg = i0.get_dst(0).get_reg(); auto src0_reg = i0.get_src(0).get_reg(); auto src1_reg = i0.get_src(1).get_reg(); - assert(i1.get_src(0).get_reg() == clobber_reg); - assert(i1.get_src(1).get_reg() == make_gpr(Reg::R0)); + ASSERT(i1.get_src(0).get_reg() == clobber_reg); + ASSERT(i1.get_src(1).get_reg() == make_gpr(Reg::R0)); auto op = std::make_shared( Condition(Condition::LESS_THAN_SIGNED, make_reg(src0_reg, idx), make_reg(src1_reg, idx), make_reg(clobber_reg, idx)), @@ -1709,10 +1709,10 @@ std::shared_ptr try_slt(Instruction& i0, Instruction& i1, Instruction auto src0_reg = i0.get_src(0).get_reg(); auto src1_reg = i0.get_src(1).get_reg(); auto dst_reg = i1.get_dst(0).get_reg(); - assert(i1.get_src(0).is_reg(make_gpr(Reg::S7))); - assert(i1.get_src(1).get_imm() == 8); - assert(i2.get_dst(0).get_reg() == dst_reg); - assert(i2.get_src(0).get_reg() == make_gpr(Reg::S7)); + ASSERT(i1.get_src(0).is_reg(make_gpr(Reg::S7))); + ASSERT(i1.get_src(1).get_imm() == 8); + ASSERT(i2.get_dst(0).get_reg() == dst_reg); + ASSERT(i2.get_src(0).get_reg() == make_gpr(Reg::S7)); if (i2.get_src(1).get_reg() != clobber_reg) { return nullptr; // TODO! } @@ -1738,8 +1738,8 @@ std::shared_ptr try_slt(Instruction& i0, Instruction& i1, Instruction auto clobber_reg = i0.get_dst(0).get_reg(); auto src0_reg = i0.get_src(0).get_reg(); auto src1_reg = i0.get_src(1).get_reg(); - assert(i1.get_src(0).get_reg() == clobber_reg); - assert(i1.get_src(1).get_reg() == make_gpr(Reg::R0)); + ASSERT(i1.get_src(0).get_reg() == clobber_reg); + ASSERT(i1.get_src(1).get_reg() == make_gpr(Reg::R0)); auto op = std::make_shared( Condition(Condition::GEQ_SIGNED, make_reg(src0_reg, idx), make_reg(src1_reg, idx), make_reg(clobber_reg, idx)), @@ -1752,10 +1752,10 @@ std::shared_ptr try_slt(Instruction& i0, Instruction& i1, Instruction auto src0_reg = i0.get_src(0).get_reg(); auto src1_reg = i0.get_src(1).get_reg(); auto dst_reg = i1.get_dst(0).get_reg(); - assert(i1.get_src(0).is_reg(make_gpr(Reg::S7))); - assert(i1.get_src(1).get_imm() == 8); - assert(i2.get_dst(0).get_reg() == dst_reg); - assert(i2.get_src(0).get_reg() == make_gpr(Reg::S7)); + ASSERT(i1.get_src(0).is_reg(make_gpr(Reg::S7))); + ASSERT(i1.get_src(1).get_imm() == 8); + ASSERT(i2.get_dst(0).get_reg() == dst_reg); + ASSERT(i2.get_src(0).get_reg() == make_gpr(Reg::S7)); if (i2.get_src(1).get_reg() != clobber_reg) { return nullptr; // TODO! } @@ -1785,8 +1785,8 @@ std::shared_ptr try_slti(Instruction& i0, Instruction& i1, Instructio if (i0.kind == InstructionKind::SLTI && i1.kind == InstructionKind::BNE) { auto clobber_reg = i0.get_dst(0).get_reg(); auto src0_reg = i0.get_src(0).get_reg(); - assert(i1.get_src(0).get_reg() == clobber_reg); - assert(i1.get_src(1).get_reg() == make_gpr(Reg::R0)); + ASSERT(i1.get_src(0).get_reg() == clobber_reg); + ASSERT(i1.get_src(1).get_reg() == make_gpr(Reg::R0)); auto op = std::make_shared( Condition(Condition::LESS_THAN_SIGNED, make_reg(src0_reg, idx), src1, make_reg(clobber_reg, idx)), @@ -1798,10 +1798,10 @@ std::shared_ptr try_slti(Instruction& i0, Instruction& i1, Instructio auto clobber_reg = i0.get_dst(0).get_reg(); auto src0_reg = i0.get_src(0).get_reg(); auto dst_reg = i1.get_dst(0).get_reg(); - assert(i1.get_src(0).is_reg(make_gpr(Reg::S7))); - assert(i1.get_src(1).get_imm() == 8); - assert(i2.get_dst(0).get_reg() == dst_reg); - assert(i2.get_src(0).get_reg() == make_gpr(Reg::S7)); + ASSERT(i1.get_src(0).is_reg(make_gpr(Reg::S7))); + ASSERT(i1.get_src(1).get_imm() == 8); + ASSERT(i2.get_dst(0).get_reg() == dst_reg); + ASSERT(i2.get_src(0).get_reg() == make_gpr(Reg::S7)); if (i2.get_src(1).get_reg() != clobber_reg) { return nullptr; // TODO! } @@ -1815,8 +1815,8 @@ std::shared_ptr try_slti(Instruction& i0, Instruction& i1, Instructio } else if (i0.kind == InstructionKind::SLTI && i1.kind == InstructionKind::BEQ) { auto clobber_reg = i0.get_dst(0).get_reg(); auto src0_reg = i0.get_src(0).get_reg(); - assert(i1.get_src(0).get_reg() == clobber_reg); - assert(i1.get_src(1).get_reg() == make_gpr(Reg::R0)); + ASSERT(i1.get_src(0).get_reg() == clobber_reg); + ASSERT(i1.get_src(1).get_reg() == make_gpr(Reg::R0)); auto op = std::make_shared( Condition(Condition::GEQ_SIGNED, make_reg(src0_reg, idx), src1, make_reg(clobber_reg, idx)), i1.get_src(2).get_label(), get_branch_delay(i2, idx), false); @@ -1827,10 +1827,10 @@ std::shared_ptr try_slti(Instruction& i0, Instruction& i1, Instructio auto clobber_reg = i0.get_dst(0).get_reg(); auto src0_reg = i0.get_src(0).get_reg(); auto dst_reg = i1.get_dst(0).get_reg(); - assert(i1.get_src(0).is_reg(make_gpr(Reg::S7))); - assert(i1.get_src(1).get_imm() == 8); - assert(i2.get_dst(0).get_reg() == dst_reg); - assert(i2.get_src(0).get_reg() == make_gpr(Reg::S7)); + ASSERT(i1.get_src(0).is_reg(make_gpr(Reg::S7))); + ASSERT(i1.get_src(1).get_imm() == 8); + ASSERT(i2.get_dst(0).get_reg() == dst_reg); + ASSERT(i2.get_src(0).get_reg() == make_gpr(Reg::S7)); if (i2.get_src(1).get_reg() != clobber_reg) { return nullptr; // TODO! } @@ -1850,8 +1850,8 @@ std::shared_ptr try_sltiu(Instruction& i0, Instruction& i1, Instructi if (i0.kind == InstructionKind::SLTIU && i1.kind == InstructionKind::BNE) { auto clobber_reg = i0.get_dst(0).get_reg(); auto src0_reg = i0.get_src(0).get_reg(); - assert(i1.get_src(0).get_reg() == clobber_reg); - assert(i1.get_src(1).get_reg() == make_gpr(Reg::R0)); + ASSERT(i1.get_src(0).get_reg() == clobber_reg); + ASSERT(i1.get_src(1).get_reg() == make_gpr(Reg::R0)); auto op = std::make_shared( Condition(Condition::LESS_THAN_UNSIGNED, make_reg(src0_reg, idx), src1, make_reg(clobber_reg, idx)), @@ -1863,10 +1863,10 @@ std::shared_ptr try_sltiu(Instruction& i0, Instruction& i1, Instructi auto clobber_reg = i0.get_dst(0).get_reg(); auto src0_reg = i0.get_src(0).get_reg(); auto dst_reg = i1.get_dst(0).get_reg(); - assert(i1.get_src(0).is_reg(make_gpr(Reg::S7))); - assert(i1.get_src(1).get_imm() == 8); - assert(i2.get_dst(0).get_reg() == dst_reg); - assert(i2.get_src(0).get_reg() == make_gpr(Reg::S7)); + ASSERT(i1.get_src(0).is_reg(make_gpr(Reg::S7))); + ASSERT(i1.get_src(1).get_imm() == 8); + ASSERT(i2.get_dst(0).get_reg() == dst_reg); + ASSERT(i2.get_src(0).get_reg() == make_gpr(Reg::S7)); if (i2.get_src(1).get_reg() != clobber_reg) { return nullptr; // TODO! } @@ -1880,8 +1880,8 @@ std::shared_ptr try_sltiu(Instruction& i0, Instruction& i1, Instructi } else if (i0.kind == InstructionKind::SLTIU && i1.kind == InstructionKind::BEQ) { auto clobber_reg = i0.get_dst(0).get_reg(); auto src0_reg = i0.get_src(0).get_reg(); - assert(i1.get_src(0).get_reg() == clobber_reg); - assert(i1.get_src(1).get_reg() == make_gpr(Reg::R0)); + ASSERT(i1.get_src(0).get_reg() == clobber_reg); + ASSERT(i1.get_src(1).get_reg() == make_gpr(Reg::R0)); auto op = std::make_shared( Condition(Condition::GEQ_UNSIGNED, make_reg(src0_reg, idx), src1, make_reg(clobber_reg, idx)), @@ -1893,10 +1893,10 @@ std::shared_ptr try_sltiu(Instruction& i0, Instruction& i1, Instructi auto clobber_reg = i0.get_dst(0).get_reg(); auto src0_reg = i0.get_src(0).get_reg(); auto dst_reg = i1.get_dst(0).get_reg(); - assert(i1.get_src(0).is_reg(make_gpr(Reg::S7))); - assert(i1.get_src(1).get_imm() == 8); - assert(i2.get_dst(0).get_reg() == dst_reg); - assert(i2.get_src(0).get_reg() == make_gpr(Reg::S7)); + ASSERT(i1.get_src(0).is_reg(make_gpr(Reg::S7))); + ASSERT(i1.get_src(1).get_imm() == 8); + ASSERT(i2.get_dst(0).get_reg() == dst_reg); + ASSERT(i2.get_src(0).get_reg() == make_gpr(Reg::S7)); if (i2.get_src(1).get_reg() != clobber_reg) { return nullptr; // TODO! } @@ -1973,8 +1973,8 @@ std::shared_ptr try_sltu(Instruction& i0, Instruction& i1, Instructio auto clobber_reg = i0.get_dst(0).get_reg(); auto src0_reg = i0.get_src(0).get_reg(); auto src1_reg = i0.get_src(1).get_reg(); - assert(i1.get_src(0).get_reg() == clobber_reg); - assert(i1.get_src(1).get_reg() == make_gpr(Reg::R0)); + ASSERT(i1.get_src(0).get_reg() == clobber_reg); + ASSERT(i1.get_src(1).get_reg() == make_gpr(Reg::R0)); auto op = std::make_shared( Condition(Condition::LESS_THAN_UNSIGNED, make_reg(src0_reg, idx), make_reg(src1_reg, idx), make_reg(clobber_reg, idx)), @@ -1987,10 +1987,10 @@ std::shared_ptr try_sltu(Instruction& i0, Instruction& i1, Instructio auto src0_reg = i0.get_src(0).get_reg(); auto src1_reg = i0.get_src(1).get_reg(); auto dst_reg = i1.get_dst(0).get_reg(); - assert(i1.get_src(0).is_reg(make_gpr(Reg::S7))); - assert(i1.get_src(1).get_imm() == 8); - assert(i2.get_dst(0).get_reg() == dst_reg); - assert(i2.get_src(0).get_reg() == make_gpr(Reg::S7)); + ASSERT(i1.get_src(0).is_reg(make_gpr(Reg::S7))); + ASSERT(i1.get_src(1).get_imm() == 8); + ASSERT(i2.get_dst(0).get_reg() == dst_reg); + ASSERT(i2.get_src(0).get_reg() == make_gpr(Reg::S7)); if (i2.get_src(1).get_reg() != clobber_reg) { return nullptr; // TODO! } @@ -2005,8 +2005,8 @@ std::shared_ptr try_sltu(Instruction& i0, Instruction& i1, Instructio auto clobber_reg = i0.get_dst(0).get_reg(); auto src0_reg = i0.get_src(0).get_reg(); auto src1_reg = i0.get_src(1).get_reg(); - assert(i1.get_src(0).get_reg() == clobber_reg); - assert(i1.get_src(1).get_reg() == make_gpr(Reg::R0)); + ASSERT(i1.get_src(0).get_reg() == clobber_reg); + ASSERT(i1.get_src(1).get_reg() == make_gpr(Reg::R0)); auto op = std::make_shared( Condition(Condition::GEQ_UNSIGNED, make_reg(src0_reg, idx), make_reg(src1_reg, idx), make_reg(clobber_reg, idx)), @@ -2019,10 +2019,10 @@ std::shared_ptr try_sltu(Instruction& i0, Instruction& i1, Instructio auto src0_reg = i0.get_src(0).get_reg(); auto src1_reg = i0.get_src(1).get_reg(); auto dst_reg = i1.get_dst(0).get_reg(); - assert(i1.get_src(0).is_reg(make_gpr(Reg::S7))); - assert(i1.get_src(1).get_imm() == 8); - assert(i2.get_dst(0).get_reg() == dst_reg); - assert(i2.get_src(0).get_reg() == make_gpr(Reg::S7)); + ASSERT(i1.get_src(0).is_reg(make_gpr(Reg::S7))); + ASSERT(i1.get_src(1).get_imm() == 8); + ASSERT(i2.get_dst(0).get_reg() == dst_reg); + ASSERT(i2.get_src(0).get_reg() == make_gpr(Reg::S7)); if (i2.get_src(1).get_reg() != clobber_reg) { return nullptr; // TODO! } diff --git a/decompiler/IR/IR.cpp b/decompiler/IR/IR.cpp index 6b6175b8b9..ea53180f71 100644 --- a/decompiler/IR/IR.cpp +++ b/decompiler/IR/IR.cpp @@ -21,7 +21,7 @@ std::vector> IR::get_all_ir(LinkedObjectFile& file) const { auto end_of_check = result.size(); for (size_t i = last_checked; i < end_of_check; i++) { auto it = result.at(i).get(); - assert(it); + ASSERT(it); it->get_children(&result); } last_checked = end_of_check; @@ -87,7 +87,7 @@ void IR_Set_Atomic::update_reginfo_self(int n_dest, int n_src, int } auto src_as = dynamic_cast(src.get()); - assert(src_as); + ASSERT(src_as); for (auto& x : {src_as->arg0, src_as->arg1}) { auto reg = dynamic_cast(x.get()); @@ -96,9 +96,9 @@ void IR_Set_Atomic::update_reginfo_self(int n_dest, int n_src, int } } - assert(int(write_regs.size()) == n_dest); - assert(int(read_regs.size()) == n_src); - assert(int(clobber_regs.size()) == n_clobber); + ASSERT(int(write_regs.size()) == n_dest); + ASSERT(int(read_regs.size()) == n_src); + ASSERT(int(clobber_regs.size()) == n_clobber); reg_info_set = true; } @@ -110,16 +110,16 @@ void IR_Set_Atomic::update_reginfo_self(int n_dest, int n_src, int } auto src_as = dynamic_cast(src.get()); - assert(src_as); + ASSERT(src_as); auto reg = dynamic_cast(src_as->arg.get()); if (reg) { read_regs.push_back(reg->reg); } - assert(int(write_regs.size()) == n_dest); - assert(int(read_regs.size()) == n_src); - assert(int(clobber_regs.size()) == n_clobber); + ASSERT(int(write_regs.size()) == n_dest); + ASSERT(int(read_regs.size()) == n_src); + ASSERT(int(clobber_regs.size()) == n_clobber); reg_info_set = true; } @@ -131,7 +131,7 @@ void IR_Set_Atomic::update_reginfo_self(int n_dest, int n_src, int n_cl } auto src_as = dynamic_cast(src.get()); - assert(src_as); + ASSERT(src_as); // try to get the source as a register auto reg = dynamic_cast(src_as->location.get()); @@ -150,9 +150,9 @@ void IR_Set_Atomic::update_reginfo_self(int n_dest, int n_src, int n_cl } } - assert(int(write_regs.size()) == n_dest); - assert(int(read_regs.size()) == n_src); - assert(int(clobber_regs.size()) == n_clobber); + ASSERT(int(write_regs.size()) == n_dest); + ASSERT(int(read_regs.size()) == n_src); + ASSERT(int(clobber_regs.size()) == n_clobber); reg_info_set = true; } @@ -164,7 +164,7 @@ void IR_Set_Atomic::update_reginfo_self(int n_dest, int n_src, int n } auto src_as_cmp = dynamic_cast(src.get()); - assert(src_as_cmp); + ASSERT(src_as_cmp); for (auto& x : {src_as_cmp->condition.src0, src_as_cmp->condition.src1}) { auto as_reg = dynamic_cast(x.get()); if (as_reg) { @@ -177,9 +177,9 @@ void IR_Set_Atomic::update_reginfo_self(int n_dest, int n_src, int n clobber_regs.push_back(as_reg->reg); } - assert(int(write_regs.size()) == n_dest); - assert(int(read_regs.size()) == n_src); - assert(int(clobber_regs.size()) == n_clobber); + ASSERT(int(write_regs.size()) == n_dest); + ASSERT(int(read_regs.size()) == n_src); + ASSERT(int(clobber_regs.size()) == n_clobber); reg_info_set = true; } @@ -198,9 +198,9 @@ void IR_Set_Atomic::update_reginfo_regreg() { read_regs.push_back(src_as->reg); } - assert(int(write_regs.size()) == 1); - assert(int(read_regs.size()) == 1); - assert(int(clobber_regs.size()) == 0); + ASSERT(int(write_regs.size()) == 1); + ASSERT(int(read_regs.size()) == 1); + ASSERT(int(clobber_regs.size()) == 0); reg_info_set = true; } @@ -228,11 +228,11 @@ goos::Object IR_Store::to_form(const LinkedObjectFile& file) const { store_operator = "s.q"; break; default: - assert(false); + ASSERT(false); } break; default: - assert(false); + ASSERT(false); } return pretty_print::build_list(pretty_print::to_symbol(store_operator), dst->to_form(file), @@ -263,11 +263,11 @@ goos::Object IR_Store_Atomic::to_form(const LinkedObjectFile& file) const { store_operator = "s.q"; break; default: - assert(false); + ASSERT(false); } break; default: - assert(false); + ASSERT(false); } return pretty_print::build_list(pretty_print::to_symbol(store_operator), dst->to_form(file), @@ -296,9 +296,9 @@ void IR_Store_Atomic::update_reginfo_self(int n_dest, int n_src, int n_clobber) } } - assert(int(write_regs.size()) == n_dest); - assert(int(read_regs.size()) == n_src); - assert(int(clobber_regs.size()) == n_clobber); + ASSERT(int(write_regs.size()) == n_dest); + ASSERT(int(read_regs.size()) == n_src); + ASSERT(int(clobber_regs.size()) == n_clobber); reg_info_set = true; } @@ -375,7 +375,7 @@ goos::Object IR_Load::to_form(const LinkedObjectFile& file) const { load_operator = "l.q"; break; default: - assert(false); + ASSERT(false); } break; case SIGNED: @@ -390,11 +390,11 @@ goos::Object IR_Load::to_form(const LinkedObjectFile& file) const { load_operator = "l.ws"; break; default: - assert(false); + ASSERT(false); } break; default: - assert(false); + ASSERT(false); } return pretty_print::build_list(pretty_print::to_symbol(load_operator), location->to_form(file)); } @@ -425,7 +425,7 @@ goos::Object IR_FloatMath2::to_form(const LinkedObjectFile& file) const { math_operator = "max.f"; break; default: - assert(false); + ASSERT(false); } return pretty_print::build_list(pretty_print::to_symbol(math_operator), arg0->to_form(file), @@ -496,7 +496,7 @@ goos::Object IR_IntMath2::to_form(const LinkedObjectFile& file) const { math_operator = "max.si"; break; default: - assert(false); + ASSERT(false); } return pretty_print::build_list(pretty_print::to_symbol(math_operator), arg0->to_form(file), arg1->to_form(file)); @@ -520,7 +520,7 @@ goos::Object IR_IntMath1::to_form(const LinkedObjectFile& file) const { math_operator = "-.i"; break; default: - assert(false); + ASSERT(false); } return pretty_print::build_list(pretty_print::to_symbol(math_operator), arg->to_form(file)); } @@ -548,7 +548,7 @@ goos::Object IR_FloatMath1::to_form(const LinkedObjectFile& file) const { math_operator = "sqrt.f"; break; default: - assert(false); + ASSERT(false); } return pretty_print::build_list(pretty_print::to_symbol(math_operator), arg->to_form(file)); } @@ -613,7 +613,7 @@ goos::Object BranchDelay::to_form(const LinkedObjectFile& file) const { case UNKNOWN: return pretty_print::build_list("unknown-branch-delay"); default: - assert(false); + ASSERT(false); return {}; } } @@ -669,7 +669,7 @@ int Condition::num_args() const { case NEVER: return 0; default: - assert(false); + ASSERT(false); return -1; } } @@ -765,7 +765,7 @@ void Condition::invert() { kind = FLOAT_GREATER_THAN; break; default: - assert(false); + ASSERT(false); } } @@ -852,7 +852,7 @@ goos::Object Condition::to_form(const LinkedObjectFile& file) const { condtion_operator = "<=0.si"; break; default: - assert(false); + ASSERT(false); } if (nargs == 2) { @@ -868,7 +868,7 @@ goos::Object Condition::to_form(const LinkedObjectFile& file) const { } else if (nargs == 0) { return pretty_print::to_symbol(condtion_operator); } else { - assert(false); + ASSERT(false); return {}; } } @@ -897,9 +897,9 @@ void IR_Branch_Atomic::update_reginfo_self(int n_dest, int n_src, int n_clobber) if (as_reg) { clobber_regs.push_back(as_reg->reg); } - assert(int(write_regs.size()) == n_dest); - assert(int(read_regs.size()) == n_src); - assert(int(clobber_regs.size()) == n_clobber); + ASSERT(int(write_regs.size()) == n_dest); + ASSERT(int(read_regs.size()) == n_src); + ASSERT(int(clobber_regs.size()) == n_clobber); // copy from branch delay read_regs.insert(read_regs.end(), branch_delay.read_regs.begin(), branch_delay.read_regs.end()); @@ -994,7 +994,7 @@ goos::Object IR_AsmReg::to_form(const LinkedObjectFile& file) const { case VU_ACC: return pretty_print::to_symbol("ACC"); default: - assert(false); + ASSERT(false); return {}; } } diff --git a/decompiler/IR/IR.h b/decompiler/IR/IR.h index ff6588f06c..a6c30be9d2 100644 --- a/decompiler/IR/IR.h +++ b/decompiler/IR/IR.h @@ -11,7 +11,7 @@ #include "common/type_system/TypeSpec.h" #include "decompiler/util/DecompilerTypeSystem.h" #include "decompiler/util/TP_Type.h" -#include "common/util/assert.h" +#include "common/util/Assert.h" namespace goos { class Object; @@ -234,7 +234,7 @@ class IR_IntMath1 : public virtual IR { IR_IntMath1(Kind _kind, std::shared_ptr _arg) : kind(_kind), arg(std::move(_arg)) {} IR_IntMath1(Kind _kind, std::shared_ptr _arg, std::shared_ptr _abs_op) : kind(_kind), arg(std::move(_arg)), abs_op(std::move(_abs_op)) { - assert(abs_op); + ASSERT(abs_op); } std::shared_ptr arg; std::shared_ptr abs_op = nullptr; @@ -327,11 +327,11 @@ struct Condition { : kind(_kind), src0(std::move(_src0)), src1(std::move(_src1)), clobber(std::move(_clobber)) { int nargs = num_args(); if (nargs == 2) { - assert(src0 && src1); + ASSERT(src0 && src1); } else if (nargs == 1) { - assert(src0 && !src1); + ASSERT(src0 && !src1); } else if (nargs == 0) { - assert(!src0 && !src1); + ASSERT(!src0 && !src1); } } diff --git a/decompiler/IR2/AtomicOp.cpp b/decompiler/IR2/AtomicOp.cpp index f0c0ea12da..ea68a0e026 100644 --- a/decompiler/IR2/AtomicOp.cpp +++ b/decompiler/IR2/AtomicOp.cpp @@ -7,7 +7,7 @@ #include "AtomicOp.h" #include "OpenGoalMapping.h" #include "Form.h" -#include "common/util/assert.h" +#include "common/util/Assert.h" namespace decompiler { ///////////////////////////// @@ -48,7 +48,7 @@ goos::Object RegisterAccess::to_form(const Env& env, Print mode) const { return pretty_print::to_symbol(m_reg.to_string()); } default: - assert(false); + ASSERT(false); return {}; } } @@ -163,7 +163,7 @@ goos::Object SimpleAtom::to_form(const std::vector& labels, con case Kind::STATIC_ADDRESS: return pretty_print::to_symbol(labels.at(m_int).name); default: - assert(false); + ASSERT(false); return {}; } } @@ -200,7 +200,7 @@ bool SimpleAtom::operator==(const SimpleAtom& other) const { case Kind::STATIC_ADDRESS: return m_int == other.m_int; default: - assert(false); + ASSERT(false); return false; } } @@ -310,7 +310,7 @@ std::string get_simple_expression_op_name(SimpleExpression::Kind kind) { case SimpleExpression::Kind::SET_ON_LESS_THAN_IMM: return "set-on-less-than"; default: - assert(false); + ASSERT(false); return {}; } } @@ -374,7 +374,7 @@ int get_simple_expression_arg_count(SimpleExpression::Kind kind) { case SimpleExpression::Kind::SET_ON_LESS_THAN_IMM: return 2; default: - assert(false); + ASSERT(false); return -1; } } @@ -382,7 +382,7 @@ int get_simple_expression_arg_count(SimpleExpression::Kind kind) { SimpleExpression::SimpleExpression(Kind kind, const SimpleAtom& arg0) : n_args(1) { m_args[0] = arg0; m_kind = kind; - assert(get_simple_expression_arg_count(kind) == 1); + ASSERT(get_simple_expression_arg_count(kind) == 1); } SimpleExpression::SimpleExpression(Kind kind, const SimpleAtom& arg0, const SimpleAtom& arg1) @@ -390,7 +390,7 @@ SimpleExpression::SimpleExpression(Kind kind, const SimpleAtom& arg0, const Simp m_args[0] = arg0; m_args[1] = arg1; m_kind = kind; - assert(get_simple_expression_arg_count(kind) == 2); + ASSERT(get_simple_expression_arg_count(kind) == 2); } SimpleExpression::SimpleExpression(Kind kind, @@ -402,7 +402,7 @@ SimpleExpression::SimpleExpression(Kind kind, m_args[1] = arg1; m_args[2] = arg2; m_kind = kind; - assert(get_simple_expression_arg_count(kind) == 3); + ASSERT(get_simple_expression_arg_count(kind) == 3); } goos::Object SimpleExpression::to_form(const std::vector& labels, @@ -410,7 +410,7 @@ goos::Object SimpleExpression::to_form(const std::vector& label std::vector forms; if (m_kind == Kind::IDENTITY) { // we are "identity" so just pass through the atom - assert(args() == 1); + ASSERT(args() == 1); return get_arg(0).to_form(labels, env); } else { forms.push_back(pretty_print::to_symbol(get_simple_expression_op_name(m_kind))); @@ -429,7 +429,7 @@ bool SimpleExpression::operator==(const SimpleExpression& other) const { if (m_kind != other.m_kind) { return false; } - assert(args() == other.args()); + ASSERT(args() == other.args()); for (int i = 0; i < args(); i++) { if (other.get_arg(i) != get_arg(i)) { return false; @@ -464,7 +464,7 @@ bool SetVarOp::operator==(const AtomicOp& other) const { return false; } auto po = dynamic_cast(&other); - assert(po); + ASSERT(po); return m_dst == po->m_dst && m_src == po->m_src; } @@ -501,7 +501,7 @@ void SetVarOp::collect_vars(RegAccessSet& vars) const { ///////////////////////////// AsmOp::AsmOp(Instruction instr, int my_idx) : AtomicOp(my_idx), m_instr(std::move(instr)) { - assert(m_instr.n_dst <= 1); + ASSERT(m_instr.n_dst <= 1); if (m_instr.n_dst == 1) { auto& dst = m_instr.get_dst(0); if (dst.is_reg()) { @@ -512,7 +512,7 @@ AsmOp::AsmOp(Instruction instr, int my_idx) : AtomicOp(my_idx), m_instr(std::mov } } - assert(m_instr.n_src <= 4); + ASSERT(m_instr.n_src <= 4); for (int i = 0; i < m_instr.n_src; i++) { auto& src = m_instr.get_src(i); if (src.is_reg()) { @@ -530,7 +530,7 @@ AsmOp::AsmOp(Instruction instr, int my_idx) : AtomicOp(my_idx), m_instr(std::mov goos::Object AsmOp::to_form(const std::vector& labels, const Env& env) const { std::vector forms; forms.push_back(pretty_print::to_symbol("." + m_instr.op_name_to_string())); - assert(m_instr.n_dst <= 1); + ASSERT(m_instr.n_dst <= 1); if (m_instr.n_dst == 1) { if (m_dst.has_value()) { @@ -542,7 +542,7 @@ goos::Object AsmOp::to_form(const std::vector& labels, const En } } - assert(m_instr.n_src <= 4); + ASSERT(m_instr.n_src <= 4); for (int i = 0; i < m_instr.n_src; i++) { if (m_src[i].has_value()) { forms.push_back(m_src[i].value().to_form(env)); @@ -574,7 +574,7 @@ goos::Object AsmOp::to_open_goal_form(const std::vector& labels OpenGOALAsm goalOp = OpenGOALAsm(m_instr, m_dst, src); forms.push_back(pretty_print::to_symbol(goalOp.full_function_name())); - assert(m_instr.n_dst <= 1); + ASSERT(m_instr.n_dst <= 1); if (m_instr.n_dst == 1) { if (m_dst.has_value()) { // then print it as a variable @@ -585,7 +585,7 @@ goos::Object AsmOp::to_open_goal_form(const std::vector& labels } } - assert(m_instr.n_src <= 4); + ASSERT(m_instr.n_src <= 4); std::vector args = goalOp.get_args(labels, env); forms.insert(forms.end(), args.begin(), args.end()); @@ -598,7 +598,7 @@ bool AsmOp::operator==(const AtomicOp& other) const { } auto po = dynamic_cast(&other); - assert(po); + ASSERT(po); return (m_instr == po->m_instr) && (m_dst == po->m_dst) && (m_src[0] == po->m_src[0]) && (m_src[1] == po->m_src[1]) && (m_src[2] == po->m_src[2]); @@ -719,7 +719,7 @@ void AsmOp::update_register_info() { break; default: - assert(false); + ASSERT(false); break; } } @@ -814,7 +814,7 @@ std::string get_condition_kind_name(IR2_Condition::Kind kind) { case IR2_Condition::Kind::GEQ_ZERO_UNSIGNED: return ">=0.ui"; default: - assert(false); + ASSERT(false); return ""; } } @@ -857,7 +857,7 @@ int get_condition_num_args(IR2_Condition::Kind kind) { case IR2_Condition::Kind::NEVER: return 0; default: - assert(false); + ASSERT(false); return -1; } } @@ -929,7 +929,7 @@ IR2_Condition::Kind get_condition_opposite(IR2_Condition::Kind kind) { case IR2_Condition::Kind::GEQ_ZERO_UNSIGNED: return IR2_Condition::Kind::LESS_THAN_ZERO_UNSIGNED; default: - assert(false); + ASSERT(false); return IR2_Condition::Kind::INVALID; } } @@ -949,19 +949,19 @@ bool condition_uses_float(IR2_Condition::Kind kind) { } IR2_Condition::IR2_Condition(Kind kind) : m_kind(kind) { - assert(get_condition_num_args(m_kind) == 0); + ASSERT(get_condition_num_args(m_kind) == 0); } IR2_Condition::IR2_Condition(Kind kind, const SimpleAtom& src0) : m_kind(kind) { m_src[0] = src0; - assert(get_condition_num_args(m_kind) == 1); + ASSERT(get_condition_num_args(m_kind) == 1); } IR2_Condition::IR2_Condition(Kind kind, const SimpleAtom& src0, const SimpleAtom& src1) : m_kind(kind) { m_src[0] = src0; m_src[1] = src1; - assert(get_condition_num_args(m_kind) == 2); + ASSERT(get_condition_num_args(m_kind) == 2); } void IR2_Condition::invert() { @@ -1027,7 +1027,7 @@ bool SetVarConditionOp::operator==(const AtomicOp& other) const { } auto po = dynamic_cast(&other); - assert(po); + ASSERT(po); return m_dst == po->m_dst && m_condition == po->m_condition; } @@ -1081,19 +1081,19 @@ goos::Object StoreOp::to_form(const std::vector& labels, const store_name = "s.q!"; break; default: - assert(false); + ASSERT(false); } break; case Kind::FLOAT: - assert(m_size == 4); + ASSERT(m_size == 4); store_name = "s.f!"; break; case Kind::VECTOR_FLOAT: - assert(m_size == 16); + ASSERT(m_size == 16); store_name = "s.vf!"; break; default: - assert(false); + ASSERT(false); } return pretty_print::build_list(pretty_print::to_symbol(store_name), m_addr.to_form(labels, env), @@ -1106,7 +1106,7 @@ bool StoreOp::operator==(const AtomicOp& other) const { } auto po = dynamic_cast(&other); - assert(po); + ASSERT(po); return m_addr == po->m_addr && m_value == po->m_value; } @@ -1144,7 +1144,7 @@ std::string load_kind_to_string(LoadVarOp::Kind kind) { case LoadVarOp::Kind::UNSIGNED: return "unsigned"; default: - assert(false); + ASSERT(false); } } @@ -1156,7 +1156,7 @@ goos::Object LoadVarOp::to_form(const std::vector& labels, cons switch (m_kind) { case Kind::FLOAT: - assert(m_size == 4); + ASSERT(m_size == 4); forms.push_back(pretty_print::build_list("l.f", m_src.to_form(labels, env))); break; case Kind::UNSIGNED: @@ -1177,7 +1177,7 @@ goos::Object LoadVarOp::to_form(const std::vector& labels, cons forms.push_back(pretty_print::build_list("l.q", m_src.to_form(labels, env))); break; default: - assert(false); + ASSERT(false); } break; case Kind::SIGNED: @@ -1192,16 +1192,16 @@ goos::Object LoadVarOp::to_form(const std::vector& labels, cons forms.push_back(pretty_print::build_list("l.w", m_src.to_form(labels, env))); break; default: - assert(false); + ASSERT(false); } break; case Kind::VECTOR_FLOAT: - assert(m_size == 16); + ASSERT(m_size == 16); forms.push_back(pretty_print::build_list("l.vf", m_src.to_form(labels, env))); break; default: - assert(false); + ASSERT(false); } return pretty_print::build_list(forms); } @@ -1212,7 +1212,7 @@ bool LoadVarOp::operator==(const AtomicOp& other) const { } auto po = dynamic_cast(&other); - assert(po); + ASSERT(po); return m_dst == po->m_dst && m_src == po->m_src; } @@ -1239,21 +1239,21 @@ void LoadVarOp::collect_vars(RegAccessSet& vars) const { ///////////////////////////// IR2_BranchDelay::IR2_BranchDelay(Kind kind) : m_kind(kind) { - assert(m_kind == Kind::NOP || m_kind == Kind::NO_DELAY || m_kind == Kind::UNKNOWN); + ASSERT(m_kind == Kind::NOP || m_kind == Kind::NO_DELAY || m_kind == Kind::UNKNOWN); } IR2_BranchDelay::IR2_BranchDelay(Kind kind, RegisterAccess var0) : m_kind(kind) { - assert(m_kind == Kind::SET_REG_FALSE || m_kind == Kind::SET_REG_TRUE || + ASSERT(m_kind == Kind::SET_REG_FALSE || m_kind == Kind::SET_REG_TRUE || m_kind == Kind::SET_BINTEGER || m_kind == Kind::SET_PAIR); - assert(var0.mode() == AccessMode::WRITE); + ASSERT(var0.mode() == AccessMode::WRITE); m_var[0] = var0; } IR2_BranchDelay::IR2_BranchDelay(Kind kind, RegisterAccess var0, RegisterAccess var1) : m_kind(kind) { - assert(m_kind == Kind::NEGATE || m_kind == Kind::SET_REG_REG); - assert(var0.mode() == AccessMode::WRITE); - assert(var1.mode() == AccessMode::READ); + ASSERT(m_kind == Kind::NEGATE || m_kind == Kind::SET_REG_REG); + ASSERT(var0.mode() == AccessMode::WRITE); + ASSERT(var1.mode() == AccessMode::READ); m_var[0] = var0; m_var[1] = var1; } @@ -1263,10 +1263,10 @@ IR2_BranchDelay::IR2_BranchDelay(Kind kind, RegisterAccess var1, RegisterAccess var2) : m_kind(kind) { - assert(m_kind == Kind::DSLLV); - assert(var0.mode() == AccessMode::WRITE); - assert(var1.mode() == AccessMode::READ); - assert(var2.mode() == AccessMode::READ); + ASSERT(m_kind == Kind::DSLLV); + ASSERT(var0.mode() == AccessMode::WRITE); + ASSERT(var1.mode() == AccessMode::READ); + ASSERT(var2.mode() == AccessMode::READ); m_var[0] = var0; m_var[1] = var1; m_var[2] = var2; @@ -1281,37 +1281,37 @@ goos::Object IR2_BranchDelay::to_form(const std::vector& labels case Kind::NO_DELAY: return pretty_print::build_list("no-delay!"); case Kind::SET_REG_FALSE: - assert(m_var[0].has_value()); + ASSERT(m_var[0].has_value()); return pretty_print::build_list("set!", m_var[0]->to_form(env), "#f"); case Kind::SET_REG_TRUE: - assert(m_var[0].has_value()); + ASSERT(m_var[0].has_value()); return pretty_print::build_list("set!", m_var[0]->to_form(env), "#t"); case Kind::SET_REG_REG: - assert(m_var[0].has_value()); - assert(m_var[1].has_value()); + ASSERT(m_var[0].has_value()); + ASSERT(m_var[1].has_value()); return pretty_print::build_list("set!", m_var[0]->to_form(env), m_var[1]->to_form(env)); case Kind::SET_BINTEGER: - assert(m_var[0].has_value()); + ASSERT(m_var[0].has_value()); return pretty_print::build_list("set!", m_var[0]->to_form(env), "binteger"); case Kind::SET_PAIR: - assert(m_var[0].has_value()); + ASSERT(m_var[0].has_value()); return pretty_print::build_list("set!", m_var[0]->to_form(env), "pair"); case Kind::DSLLV: - assert(m_var[0].has_value()); - assert(m_var[1].has_value()); - assert(m_var[2].has_value()); + ASSERT(m_var[0].has_value()); + ASSERT(m_var[1].has_value()); + ASSERT(m_var[2].has_value()); return pretty_print::build_list( "set!", m_var[0]->to_form(env), pretty_print::build_list("sll", m_var[1]->to_form(env), m_var[2]->to_form(env))); case Kind::NEGATE: - assert(m_var[0].has_value()); - assert(m_var[1].has_value()); + ASSERT(m_var[0].has_value()); + ASSERT(m_var[1].has_value()); return pretty_print::build_list("set!", m_var[0]->to_form(env), pretty_print::build_list("-", m_var[1]->to_form(env))); case Kind::UNKNOWN: return pretty_print::build_list("unknown-branch-delay!"); default: - assert(false); + ASSERT(false); return {}; } } @@ -1347,7 +1347,7 @@ void IR2_BranchDelay::get_regs(std::vector* write, std::vectorpush_back(m_var[2]->reg()); break; default: - assert(false); + ASSERT(false); } } @@ -1396,7 +1396,7 @@ bool BranchOp::operator==(const AtomicOp& other) const { } auto po = dynamic_cast(&other); - assert(po); + ASSERT(po); return m_likely == po->m_likely && m_condition == po->m_condition && m_label == po->m_label && m_branch_delay == po->m_branch_delay; } @@ -1473,7 +1473,7 @@ bool AsmBranchOp::operator==(const AtomicOp& other) const { } auto po = dynamic_cast(&other); - assert(po); + ASSERT(po); return m_likely == po->m_likely && m_condition == po->m_condition && m_label == po->m_label && m_branch_delay == po->m_branch_delay; } @@ -1531,7 +1531,7 @@ goos::Object SpecialOp::to_form(const std::vector& labels, cons case Kind::SUSPEND: return pretty_print::build_list("suspend"); default: - assert(false); + ASSERT(false); return {}; } } @@ -1542,7 +1542,7 @@ bool SpecialOp::operator==(const AtomicOp& other) const { } auto po = dynamic_cast(&other); - assert(po); + ASSERT(po); return m_kind == po->m_kind; } @@ -1569,7 +1569,7 @@ void SpecialOp::update_register_info() { clobber_temps(); return; default: - assert(false); + ASSERT(false); } } @@ -1601,7 +1601,7 @@ bool CallOp::operator==(const AtomicOp& other) const { } auto po = dynamic_cast(&other); - assert(po); + ASSERT(po); return true; } @@ -1658,7 +1658,7 @@ bool ConditionalMoveFalseOp::operator==(const AtomicOp& other) const { } auto po = dynamic_cast(&other); - assert(po); + ASSERT(po); return m_dst == po->m_dst && m_src == po->m_src && m_on_zero == po->m_on_zero && m_old_value == po->m_old_value; } @@ -1722,7 +1722,7 @@ bool FunctionEndOp::operator==(const AtomicOp& other) const { } auto po = dynamic_cast(&other); - assert(po); + ASSERT(po); return m_function_has_return_value == po->m_function_has_return_value; } @@ -1751,7 +1751,7 @@ void FunctionEndOp::collect_vars(RegAccessSet& vars) const { StackSpillStoreOp::StackSpillStoreOp(const SimpleAtom& value, int size, int offset, int my_idx) : AtomicOp(my_idx), m_value(value), m_size(size), m_offset(offset) { if (m_value.is_var()) { - assert(m_value.var().mode() == AccessMode::READ); + ASSERT(m_value.var().mode() == AccessMode::READ); } } @@ -1766,7 +1766,7 @@ bool StackSpillStoreOp::operator==(const AtomicOp& other) const { } auto po = dynamic_cast(&other); - assert(po); + ASSERT(po); return m_size == po->m_size && m_value == po->m_value && m_offset == po->m_offset; } @@ -1799,7 +1799,7 @@ StackSpillLoadOp::StackSpillLoadOp(RegisterAccess dst, bool is_signed, int my_idx) : AtomicOp(my_idx), m_dst(dst), m_size(size), m_offset(offset), m_is_signed(is_signed) { - assert(m_dst.mode() == AccessMode::WRITE); + ASSERT(m_dst.mode() == AccessMode::WRITE); } goos::Object StackSpillLoadOp::to_form(const std::vector&, const Env& env) const { @@ -1814,7 +1814,7 @@ bool StackSpillLoadOp::operator==(const AtomicOp& other) const { } auto po = dynamic_cast(&other); - assert(po); + ASSERT(po); return m_size == po->m_size && m_dst == po->m_dst && m_offset == po->m_offset && m_is_signed == po->m_is_signed; } diff --git a/decompiler/IR2/AtomicOp.h b/decompiler/IR2/AtomicOp.h index e48e7efece..b2fd838368 100644 --- a/decompiler/IR2/AtomicOp.h +++ b/decompiler/IR2/AtomicOp.h @@ -8,7 +8,7 @@ #include "decompiler/Disasm/Instruction.h" #include "decompiler/IR2/IR2_common.h" #include "Env.h" -#include "common/util/assert.h" +#include "common/util/Assert.h" namespace decompiler { class FormElement; @@ -136,17 +136,17 @@ class SimpleAtom { bool is_var() const { return m_kind == Kind::VARIABLE; } bool is_label() const { return m_kind == Kind::STATIC_ADDRESS; } const RegisterAccess& var() const { - assert(is_var()); + ASSERT(is_var()); return m_variable; } int label() const { - assert(is_label()); + ASSERT(is_label()); return m_int; } s64 get_int() const { - assert(is_int()); + ASSERT(is_int()); return m_int; } bool is_int() const { return m_kind == Kind::INTEGER_CONSTANT; }; @@ -169,7 +169,7 @@ class SimpleAtom { SimpleExpression as_expr() const; TP_Type get_type(const TypeState& input, const Env& env, const DecompilerTypeSystem& dts) const; const std::string& get_str() const { - assert(is_sym_ptr() || is_sym_val()); + ASSERT(is_sym_ptr() || is_sym_val()); return m_string; } @@ -243,7 +243,7 @@ class SimpleExpression { // how many arguments? int args() const { return n_args; } const SimpleAtom& get_arg(int idx) const { - assert(idx < args()); + ASSERT(idx < args()); return m_args[idx]; } Kind kind() const { return m_kind; } @@ -260,7 +260,7 @@ class SimpleExpression { bool is_identity() const { return m_kind == Kind::IDENTITY; } bool is_var() const { return is_identity() && get_arg(0).is_var(); } const RegisterAccess& var() const { - assert(is_var()); + ASSERT(is_var()); return get_arg(0).var(); } void get_regs(std::vector* out) const; @@ -288,7 +288,7 @@ class SetVarOp : public AtomicOp { public: SetVarOp(const RegisterAccess& dst, SimpleExpression src, int my_idx) : AtomicOp(my_idx), m_dst(dst), m_src(std::move(src)) { - assert(my_idx == dst.idx()); + ASSERT(my_idx == dst.idx()); } virtual goos::Object to_form(const std::vector& labels, const Env& env) const override; @@ -334,7 +334,7 @@ class AsmOp : public AtomicOp { const Instruction& instruction() const { return m_instr; } const std::optional dst() const { return m_dst; } const std::optional src(int i) const { - assert(i < 4); + ASSERT(i < 4); return m_src[i]; } @@ -546,8 +546,8 @@ class IR2_BranchDelay { void collect_vars(RegAccessSet& vars) const; Kind kind() const { return m_kind; } const RegisterAccess& var(int idx) const { - assert(idx < 3); - assert(m_var[idx].has_value()); + ASSERT(idx < 3); + ASSERT(m_var[idx].has_value()); return m_var[idx].value(); } @@ -747,7 +747,7 @@ class FunctionEndOp : public AtomicOp { void collect_vars(RegAccessSet& vars) const override; void mark_function_as_no_return_value(); const RegisterAccess& return_var() const { - assert(m_function_has_return_value); + ASSERT(m_function_has_return_value); return m_return_reg; } diff --git a/decompiler/IR2/AtomicOpForm.cpp b/decompiler/IR2/AtomicOpForm.cpp index 89cbe893aa..7c462ea58b 100644 --- a/decompiler/IR2/AtomicOpForm.cpp +++ b/decompiler/IR2/AtomicOpForm.cpp @@ -16,7 +16,7 @@ RegClass get_reg_kind(const Register& r) { case Reg::FPR: return RegClass::FLOAT; default: - assert(false); + ASSERT(false); return RegClass::INVALID; } } @@ -197,7 +197,7 @@ std::optional get_typecast_for_atom(const SimpleAtom& atom, case SimpleAtom::Kind::SYMBOL_PTR: case SimpleAtom::Kind::SYMBOL_VAL: { - assert(atom.get_str() == "#f"); + ASSERT(atom.get_str() == "#f"); if (expected_type != TypeSpec("symbol")) { // explicitly cast if we're not using a reference type, including pointers. @@ -210,14 +210,14 @@ std::optional get_typecast_for_atom(const SimpleAtom& atom, } break; default: - assert(false); + ASSERT(false); } return {}; } } // namespace FormElement* StoreOp::get_vf_store_as_form(FormPool& pool, const Env& env) const { - assert(m_value.is_var() && m_value.var().reg().get_kind() == Reg::VF); + ASSERT(m_value.is_var() && m_value.var().reg().get_kind() == Reg::VF); if (env.has_type_analysis()) { IR2_RegOffset ro; if (get_as_reg_offset(m_addr, &ro)) { @@ -241,7 +241,7 @@ FormElement* StoreOp::get_vf_store_as_form(FormPool& pool, const Env& env) const for (auto& x : rd.tokens) { tokens.push_back(to_token(x)); } - assert(!rd.addr_of); // we'll change this to true because .svf uses an address. + ASSERT(!rd.addr_of); // we'll change this to true because .svf uses an address. auto addr = pool.alloc_single_element_form(nullptr, source, true, tokens); return pool.alloc_element(m_value.var().reg(), addr, false, m_my_idx); @@ -331,7 +331,7 @@ FormElement* StoreOp::get_as_form(FormPool& pool, const Env& env) const { case SimpleAtom::Kind::SYMBOL_PTR: case SimpleAtom::Kind::SYMBOL_VAL: { - assert(m_value.get_str() == "#f"); + ASSERT(m_value.get_str() == "#f"); std::optional cast_for_set, cast_for_define; if (symbol_type != TypeSpec("symbol")) { cast_for_define = symbol_type; @@ -347,7 +347,7 @@ FormElement* StoreOp::get_as_form(FormPool& pool, const Env& env) const { } break; default: - assert(false); + ASSERT(false); } } @@ -379,7 +379,7 @@ FormElement* StoreOp::get_as_form(FormPool& pool, const Env& env) const { if (rd.success) { std::vector tokens; - assert(!rd.tokens.empty()); + ASSERT(!rd.tokens.empty()); for (auto& token : rd.tokens) { tokens.push_back(to_token(token)); } @@ -393,7 +393,7 @@ FormElement* StoreOp::get_as_form(FormPool& pool, const Env& env) const { // auto val = pool.alloc_single_element_form( // nullptr, m_value.as_expr(), m_my_idx); - assert(!rd.addr_of); + ASSERT(!rd.addr_of); return pool.alloc_element( source, m_value.as_expr(), m_my_idx, ro.var, get_typecast_for_atom(m_value, env, coerce_to_reg_type(rd.result_type), m_my_idx)); @@ -418,7 +418,7 @@ FormElement* StoreOp::get_as_form(FormPool& pool, const Env& env) const { for (auto& x : rd.tokens) { tokens.push_back(to_token(x)); } - assert(!rd.addr_of); + ASSERT(!rd.addr_of); auto addr = pool.alloc_element(source, rd.addr_of, tokens); return pool.alloc_element( @@ -448,7 +448,7 @@ FormElement* StoreOp::get_as_form(FormPool& pool, const Env& env) const { cast_type = "int128"; break; default: - assert(false); + ASSERT(false); } if (m_value.is_var()) { @@ -498,19 +498,19 @@ FormElement* make_label_load(int label_idx, if ((load_kind == LoadVarOp::Kind::FLOAT || load_kind == LoadVarOp::Kind::SIGNED) && load_size == 4 && hint.result_type == TypeSpec("float")) { - assert((label.offset % 4) == 0); + ASSERT((label.offset % 4) == 0); auto word = env.file->words_by_seg.at(label.target_segment).at(label.offset / 4); - assert(word.kind() == LinkedWord::PLAIN_DATA); + ASSERT(word.kind() == LinkedWord::PLAIN_DATA); float value; memcpy(&value, &word.data, 4); return pool.alloc_element(value); } else if (hint.result_type == TypeSpec("uint64") && load_kind != LoadVarOp::Kind::FLOAT && load_size == 8) { - assert((label.offset % 8) == 0); + ASSERT((label.offset % 8) == 0); auto word0 = env.file->words_by_seg.at(label.target_segment).at(label.offset / 4); auto word1 = env.file->words_by_seg.at(label.target_segment).at(1 + (label.offset / 4)); - assert(word0.kind() == LinkedWord::PLAIN_DATA); - assert(word1.kind() == LinkedWord::PLAIN_DATA); + ASSERT(word0.kind() == LinkedWord::PLAIN_DATA); + ASSERT(word1.kind() == LinkedWord::PLAIN_DATA); u64 value; memcpy(&value, &word0.data, 4); memcpy(((u8*)&value) + 4, &word1.data, 4); @@ -524,20 +524,20 @@ FormElement* make_label_load(int label_idx, auto as_bitfield = dynamic_cast(ts.lookup_type(hint.result_type)); if (as_bitfield && load_kind != LoadVarOp::Kind::FLOAT && load_size == 8) { // get the data - assert((label.offset % 8) == 0); + ASSERT((label.offset % 8) == 0); auto word0 = env.file->words_by_seg.at(label.target_segment).at(label.offset / 4); auto word1 = env.file->words_by_seg.at(label.target_segment).at(1 + (label.offset / 4)); - assert(word0.kind() == LinkedWord::PLAIN_DATA); - assert(word1.kind() == LinkedWord::PLAIN_DATA); + ASSERT(word0.kind() == LinkedWord::PLAIN_DATA); + ASSERT(word1.kind() == LinkedWord::PLAIN_DATA); u64 value; memcpy(&value, &word0.data, 4); memcpy(((u8*)&value) + 4, &word1.data, 4); // for some reason, GOAL would use a 64-bit constant for all bitfields, even if they are // smaller. We should check that the higher bits are all zero. int bits = as_bitfield->get_size_in_memory() * 8; - assert(bits <= 64); + ASSERT(bits <= 64); if (bits < 64) { - assert((value >> bits) == 0); + ASSERT((value >> bits) == 0); // technically ub if bits == 64. } auto defs = decompile_bitfield_from_int(hint.result_type, ts, value); @@ -546,11 +546,11 @@ FormElement* make_label_load(int label_idx, /* if (load_kind == LoadVarOp::Kind::FLOAT && load_size == 4) { - assert((label.offset % 4) == 0); + ASSERT((label.offset % 4) == 0); const auto& words = env.file->words_by_seg.at(label.target_segment); if ((int)words.size() > label.offset / 4) { auto word = words.at(label.offset / 4); - assert(word.kind == LinkedWord::PLAIN_DATA); + ASSERT(word.kind == LinkedWord::PLAIN_DATA); float value; memcpy(&value, &word.data, 4); return pool.alloc_element(value); @@ -559,11 +559,11 @@ FormElement* make_label_load(int label_idx, if (load_kind != LoadVarOp::Kind::FLOAT && load_size == 8) { if ((int)env.file->words_by_seg.at(label.target_segment).size() > (label.offset / 4) + 1) { - assert((label.offset % 8) == 0); + ASSERT((label.offset % 8) == 0); auto word0 = env.file->words_by_seg.at(label.target_segment).at(label.offset / 4); auto word1 = env.file->words_by_seg.at(label.target_segment).at(1 + (label.offset / 4)); - assert(word0.kind == LinkedWord::PLAIN_DATA); - assert(word1.kind == LinkedWord::PLAIN_DATA); + ASSERT(word0.kind == LinkedWord::PLAIN_DATA); + ASSERT(word1.kind == LinkedWord::PLAIN_DATA); u64 value; memcpy(&value, &word0.data, 4); memcpy(((u8*)&value) + 4, &word1.data, 4); @@ -627,7 +627,7 @@ Form* LoadVarOp::get_load_src(FormPool& pool, const Env& env) const { if (rd.success) { std::vector tokens; - assert(!rd.tokens.empty()); + ASSERT(!rd.tokens.empty()); for (auto& token : rd.tokens) { tokens.push_back(to_token(token)); } @@ -711,7 +711,7 @@ Form* LoadVarOp::get_load_src(FormPool& pool, const Env& env) const { cast_type = "int128"; break; default: - assert(false); + ASSERT(false); } if (m_kind == Kind::UNSIGNED) { cast_type = "u" + cast_type; @@ -743,11 +743,11 @@ Form* LoadVarOp::get_load_src(FormPool& pool, const Env& env) const { FormElement* LoadVarOp::get_as_form(FormPool& pool, const Env& env) const { auto src = get_load_src(pool, env); if (m_kind == Kind::VECTOR_FLOAT) { - assert(m_dst.reg().get_kind() == Reg::VF); + ASSERT(m_dst.reg().get_kind() == Reg::VF); auto src_as_deref = dynamic_cast(src->try_as_single_element()); if (src_as_deref) { - assert(!src_as_deref->is_addr_of()); + ASSERT(!src_as_deref->is_addr_of()); src_as_deref->set_addr_of(true); return pool.alloc_element(m_dst.reg(), src, true, m_my_idx); } @@ -761,7 +761,7 @@ FormElement* LoadVarOp::get_as_form(FormPool& pool, const Env& env) const { throw std::runtime_error("VF unknown load"); } else { - assert(m_dst.reg().get_kind() != Reg::VF); + ASSERT(m_dst.reg().get_kind() != Reg::VF); return pool.alloc_element(m_dst, src, true, m_type.value_or(TypeSpec("object"))); } } diff --git a/decompiler/IR2/AtomicOpTypeAnalysis.cpp b/decompiler/IR2/AtomicOpTypeAnalysis.cpp index 5f525dccb8..7f87aaf584 100644 --- a/decompiler/IR2/AtomicOpTypeAnalysis.cpp +++ b/decompiler/IR2/AtomicOpTypeAnalysis.cpp @@ -30,7 +30,7 @@ RegClass get_reg_kind(const Register& r) { case Reg::FPR: return RegClass::FLOAT; default: - assert(false); + ASSERT(false); return RegClass::INVALID; } } @@ -167,7 +167,7 @@ TP_Type SimpleAtom::get_type(const TypeState& input, } case Kind::INVALID: default: - assert(false); + ASSERT(false); } return {}; } @@ -337,8 +337,8 @@ TP_Type SimpleExpression::get_type_int2(const TypeState& input, case Kind::LEFT_SHIFT: // multiplication by constant power of two, optimized to a shift. if (m_args[1].is_int() && is_int_or_uint(dts, arg0_type)) { - assert(m_args[1].get_int() >= 0); - assert(m_args[1].get_int() < 64); + ASSERT(m_args[1].get_int() >= 0); + ASSERT(m_args[1].get_int() < 64); // this could be a bitfield access or a multiply. // we pick bitfield access if the parent is a bitfield. if (dynamic_cast(dts.ts.lookup_type(arg0_type.typespec()))) { @@ -388,7 +388,7 @@ TP_Type SimpleExpression::get_type_int2(const TypeState& input, auto type = dts.ts.lookup_type(arg0_type.get_bitfield_type()); auto as_bitfield = dynamic_cast(type); - assert(as_bitfield); + ASSERT(as_bitfield); auto field = find_field(dts.ts, as_bitfield, start_bit, size, is_unsigned); return TP_Type::make_from_ts(coerce_to_reg_type(field.type())); } @@ -794,18 +794,18 @@ TypeState AsmOp::propagate_types_internal(const TypeState& input, TypeState result = input; if (m_instr.kind == InstructionKind::QMFC2) { - assert(m_dst); + ASSERT(m_dst); result.get(m_dst->reg()) = TP_Type::make_from_ts("float"); return result; } if (m_instr.kind == InstructionKind::PCPYUD) { if (m_src[1] && m_src[1]->reg() == Register(Reg::GPR, Reg::R0)) { - assert(m_src[0]); + ASSERT(m_src[0]); auto& in_type = result.get(m_src[0]->reg()); auto bf = dynamic_cast(dts.ts.lookup_type(in_type.typespec())); if (bf) { - assert(m_dst); + ASSERT(m_dst); result.get(m_dst->reg()) = TP_Type::make_from_pcpyud_bitfield(in_type.typespec()); return result; } @@ -815,12 +815,12 @@ TypeState AsmOp::propagate_types_internal(const TypeState& input, // pextuw t0, r0, gp if (m_instr.kind == InstructionKind::PEXTUW) { if (m_src[0] && m_src[0]->reg() == Register(Reg::GPR, Reg::R0)) { - assert(m_src[1]); + ASSERT(m_src[1]); auto type = dts.ts.lookup_type(result.get(m_src[1]->reg()).typespec()); auto as_bitfield = dynamic_cast(type); if (as_bitfield) { auto field = find_field(dts.ts, as_bitfield, 64, 32, true); - assert(m_dst); + ASSERT(m_dst); result.get(m_dst->reg()) = TP_Type::make_from_ts(field.type()); return result; } @@ -1007,7 +1007,7 @@ TP_Type LoadVarOp::get_src_type(const TypeState& input, case Kind::FLOAT: return TP_Type::make_from_ts(TypeSpec("float")); default: - assert(false); + ASSERT(false); } } @@ -1117,7 +1117,7 @@ TP_Type LoadVarOp::get_src_type(const TypeState& input, case Kind::FLOAT: return TP_Type::make_from_ts(TypeSpec("float")); default: - assert(false); + ASSERT(false); } } @@ -1183,7 +1183,7 @@ TypeState SpecialOp::propagate_types_internal(const TypeState& input, case Kind::SUSPEND: return input; default: - assert(false); + ASSERT(false); return input; } } diff --git a/decompiler/IR2/Env.cpp b/decompiler/IR2/Env.cpp index 1c6ad9b379..0884636b59 100644 --- a/decompiler/IR2/Env.cpp +++ b/decompiler/IR2/Env.cpp @@ -148,7 +148,7 @@ VariableWithCast Env::get_variable_and_cast(const RegisterAccess& access) const "(var {}) to type {}, but the actual type is {} ({})", access.reg().to_charp(), access.idx(), lookup_name, x.type_name, type_in_reg.print(), type_in_reg.print()); - assert(false); + ASSERT(false); } } @@ -228,7 +228,7 @@ std::optional Env::get_user_cast_for_access(const RegisterAccess& acce "(var {}) to type {}, but the actual type is {} ({})", access.reg().to_charp(), access.idx(), original_name, x.type_name, type_in_reg.print(), type_in_reg.print()); - assert(false); + ASSERT(false); } } @@ -289,7 +289,7 @@ void Env::set_types(const std::vector& block_init_types, } for (auto x : m_op_init_types) { - assert(x); + ASSERT(x); } m_has_types = true; @@ -306,7 +306,7 @@ void Env::set_types(const std::vector& block_init_types, } std::string Env::print_local_var_types(const Form* top_level_form) const { - assert(has_local_vars()); + ASSERT(has_local_vars()); auto var_info = extract_visible_variables(top_level_form); std::vector entries; for (auto x : var_info) { @@ -347,7 +347,7 @@ std::string Env::print_local_var_types(const Form* top_level_form) const { std::vector Env::extract_visible_variables( const Form* top_level_form) const { - assert(has_local_vars()); + ASSERT(has_local_vars()); std::vector entries; if (top_level_form) { RegAccessSet var_set; @@ -381,7 +381,7 @@ std::vector Env::extract_visible_variables( if (info.initialized) { entries.push_back(info); } else { - assert(false); + ASSERT(false); } } } else { @@ -415,7 +415,7 @@ std::vector Env::extract_visible_variables( FunctionVariableDefinitions Env::local_var_type_list(const Form* top_level_form, int nargs_to_ignore) const { - assert(nargs_to_ignore <= 8); + ASSERT(nargs_to_ignore <= 8); auto vars = extract_visible_variables(top_level_form); FunctionVariableDefinitions result; @@ -480,7 +480,7 @@ RegId Env::get_program_var_id(const RegisterAccess& var) const { } const UseDefInfo& Env::get_use_def_info(const RegisterAccess& ra) const { - assert(has_local_vars()); + ASSERT(has_local_vars()); auto var_id = get_program_var_id(ra); return m_var_names.use_def_info.at(var_id); } @@ -559,7 +559,7 @@ void Env::set_stack_structure_hints(const std::vector& hints break; } default: - assert(false); + ASSERT(false); } m_stack_structures.push_back(entry); diff --git a/decompiler/IR2/Env.h b/decompiler/IR2/Env.h index be8d55b5fc..445db5ec52 100644 --- a/decompiler/IR2/Env.h +++ b/decompiler/IR2/Env.h @@ -9,7 +9,7 @@ #include "decompiler/IR2/IR2_common.h" #include "decompiler/analysis/reg_usage.h" #include "decompiler/config.h" -#include "common/util/assert.h" +#include "common/util/Assert.h" namespace decompiler { class LinkedObjectFile; @@ -61,7 +61,7 @@ class Env { bool has_type_analysis() const { return m_has_types; } bool has_reg_use() const { return m_has_reg_use; } const RegUsageInfo& reg_use() const { - assert(m_has_reg_use); + ASSERT(m_has_reg_use); return m_reg_use; } @@ -71,7 +71,7 @@ class Env { } RegUsageInfo& reg_use() { - assert(m_has_reg_use); + ASSERT(m_has_reg_use); return m_reg_use; } @@ -88,12 +88,12 @@ class Env { * Get the types in registers _after_ the given operation has completed. */ const TypeState& get_types_after_op(int atomic_op_id) const { - assert(m_has_types); + ASSERT(m_has_types); return m_op_end_types.at(atomic_op_id); } const TypeState& get_types_before_op(int atomic_op_id) const { - assert(m_has_types); + ASSERT(m_has_types); return *m_op_init_types.at(atomic_op_id); } @@ -110,7 +110,7 @@ class Env { * have occurred. */ const TypeState& get_types_at_block_entry(int block_id) const { - assert(m_has_types); + ASSERT(m_has_types); return m_block_init_types.at(block_id); } @@ -161,7 +161,7 @@ class Env { const std::string& remapped_name(const std::string& name) const; bool op_id_is_eliminated_coloring_move(int op_id) const { - assert(has_local_vars()); + ASSERT(has_local_vars()); return m_var_names.eliminated_move_op_ids.find(op_id) != m_var_names.eliminated_move_op_ids.end(); } diff --git a/decompiler/IR2/ExpressionHelpers.cpp b/decompiler/IR2/ExpressionHelpers.cpp index 48f73a0d0d..4db004b0e5 100644 --- a/decompiler/IR2/ExpressionHelpers.cpp +++ b/decompiler/IR2/ExpressionHelpers.cpp @@ -10,7 +10,7 @@ namespace decompiler { FormElement* handle_get_property_value_float(const std::vector& forms, FormPool& pool, const Env& env) { - assert(forms.size() == 7); + ASSERT(forms.size() == 7); // lump object // name // 'interp diff --git a/decompiler/IR2/Form.cpp b/decompiler/IR2/Form.cpp index 904609bef6..f4559f169c 100644 --- a/decompiler/IR2/Form.cpp +++ b/decompiler/IR2/Form.cpp @@ -60,7 +60,7 @@ goos::Object FormElement::to_form(const Env& env) const { ////////////////// goos::Object Form::to_form(const Env& env) const { - assert(!m_elements.empty()); + ASSERT(!m_elements.empty()); if (m_elements.size() == 1) { return m_elements.front()->to_form(env); } else { @@ -80,7 +80,7 @@ goos::Object Form::to_form(const Env& env) const { } goos::Object Form::to_form_as_condition(const Env& env) const { - assert(!m_elements.empty()); + ASSERT(!m_elements.empty()); if (m_elements.size() == 1) { return m_elements.front()->to_form_as_condition_internal(env); } else { @@ -203,7 +203,7 @@ LoadSourceElement::LoadSourceElement(Form* addr, int size, LoadVarOp::Kind kind) goos::Object LoadSourceElement::to_form_internal(const Env& env) const { switch (m_kind) { case LoadVarOp::Kind::FLOAT: - assert(m_size == 4); + ASSERT(m_size == 4); return pretty_print::build_list("l.f", m_addr->to_form(env)); case LoadVarOp::Kind::UNSIGNED: switch (m_size) { @@ -218,7 +218,7 @@ goos::Object LoadSourceElement::to_form_internal(const Env& env) const { case 16: return pretty_print::build_list("l.q", m_addr->to_form(env)); default: - assert(false); + ASSERT(false); return {}; } break; @@ -231,16 +231,16 @@ goos::Object LoadSourceElement::to_form_internal(const Env& env) const { case 4: return pretty_print::build_list("l.w", m_addr->to_form(env)); default: - assert(false); + ASSERT(false); return {}; } break; case LoadVarOp::Kind::VECTOR_FLOAT: - assert(m_size == 16); + ASSERT(m_size == 16); return pretty_print::build_list("l.vf", m_addr->to_form(env)); break; default: - assert(false); + ASSERT(false); return {}; } } @@ -271,7 +271,7 @@ void LoadSourceElement::get_modified_regs(RegSet& regs) const { SimpleAtomElement::SimpleAtomElement(const SimpleAtom& atom, bool omit_var_cast) : m_atom(atom), m_omit_var_cast(omit_var_cast) { if (m_omit_var_cast) { - assert(atom.is_var()); + ASSERT(atom.is_var()); } } @@ -314,7 +314,7 @@ SetVarElement::SetVarElement(const RegisterAccess& var, } goos::Object SetVarElement::to_form_internal(const Env& env) const { - assert(active()); + ASSERT(active()); auto reg_kind = m_dst.reg().get_kind(); if ((reg_kind == Reg::FPR || reg_kind == Reg::GPR) && env.has_type_analysis() && env.has_local_vars()) { @@ -546,7 +546,7 @@ AsmBranchElement::AsmBranchElement(AsmBranchOp* branch_op, Form* branch_delay, b : m_branch_op(branch_op), m_branch_delay(branch_delay), m_likely(likely) { m_branch_delay->parent_element = this; for (auto& elt : m_branch_delay->elts()) { - assert(elt->parent_form == m_branch_delay); + ASSERT(elt->parent_form == m_branch_delay); } } @@ -622,15 +622,15 @@ goos::Object TranslatedAsmBranch::to_form_internal(const Env& env) const { } } - assert(block_id >= 0); + ASSERT(block_id >= 0); if (m_branch_delay) { if (m_branch_delay->parent_element != this) { fmt::print("bad ptr. Parent is {}\n", m_branch_delay->parent_element->to_string(env)); - assert(false); + ASSERT(false); } - assert(m_branch_delay->parent_element->parent_form); + ASSERT(m_branch_delay->parent_element->parent_form); std::vector list = { pretty_print::to_symbol("b!"), m_branch_condition->to_form(env), pretty_print::to_symbol(fmt::format("cfg-{}", block_id)), @@ -668,11 +668,11 @@ void TranslatedAsmBranch::collect_vars(RegAccessSet& vars, bool recursive) const if (m_branch_delay) { if (m_branch_delay->parent_element != this) { fmt::print("bad ptr. Parent is {}\n", (void*)m_branch_delay->parent_element); - assert(false); + ASSERT(false); } for (auto& elt : m_branch_delay->elts()) { - assert(elt->parent_form == m_branch_delay); + ASSERT(elt->parent_form == m_branch_delay); } m_branch_delay->collect_vars(vars, recursive); @@ -1289,7 +1289,7 @@ goos::Object ShortCircuitElement::to_form_internal(const Env& env) const { forms.push_back(pretty_print::to_symbol("or")); break; default: - assert(false); + ASSERT(false); } for (auto& x : entries) { forms.push_back(x.condition->to_form_as_condition(env)); @@ -1638,7 +1638,7 @@ void GenericOperator::collect_vars(RegAccessSet& vars, bool recursive) const { } return; default: - assert(false); + ASSERT(false); } } @@ -1651,7 +1651,7 @@ goos::Object GenericOperator::to_form(const Env& env) const { case Kind::FUNCTION_EXPR: return m_function->to_form(env); default: - assert(false); + ASSERT(false); return {}; } } @@ -1665,7 +1665,7 @@ void GenericOperator::apply(const std::function& f) { m_function->apply(f); break; default: - assert(false); + ASSERT(false); } } @@ -1678,7 +1678,7 @@ void GenericOperator::apply_form(const std::function& f) { m_function->apply_form(f); break; default: - assert(false); + ASSERT(false); } } @@ -1694,7 +1694,7 @@ bool GenericOperator::operator==(const GenericOperator& other) const { case Kind::FUNCTION_EXPR: return false; default: - assert(false); + ASSERT(false); return false; } } @@ -1712,7 +1712,7 @@ void GenericOperator::get_modified_regs(RegSet& regs) const { m_function->get_modified_regs(regs); break; default: - assert(false); + ASSERT(false); } } @@ -1855,7 +1855,7 @@ std::string fixed_operator_to_string(FixedOperatorKind kind) { case FixedOperatorKind::CPAD_HOLD_P: return "cpad-hold?"; default: - assert(false); + ASSERT(false); return ""; } } @@ -1898,7 +1898,7 @@ GenericElement::GenericElement(GenericOperator op, std::vector forms) goos::Object GenericElement::to_form_internal(const Env& env) const { if (m_head.kind() == GenericOperator::Kind::CONDITION_OPERATOR && m_head.condition_kind() == IR2_Condition::Kind::TRUTHY) { - assert(m_elts.size() == 1); + ASSERT(m_elts.size() == 1); return m_elts.front()->to_form_as_condition(env); } else if (m_head.kind() == GenericOperator::Kind::CONDITION_OPERATOR && m_head.condition_kind() == IR2_Condition::Kind::ALWAYS) { @@ -1907,7 +1907,7 @@ goos::Object GenericElement::to_form_internal(const Env& env) const { std::vector result; result.push_back(m_head.to_form(env)); for (auto x : m_elts) { - assert(x->parent_element); + ASSERT(x->parent_element); result.push_back(x->to_form(env)); } return pretty_print::build_list(result); @@ -1955,7 +1955,7 @@ CastElement::CastElement(TypeSpec type, Form* source, bool numeric) } goos::Object CastElement::to_form_internal(const Env& env) const { - // assert(m_source->parent_element == this); + // ASSERT(m_source->parent_element == this); auto atom = form_as_atom(m_source); if (atom && atom->is_var()) { return pretty_print::build_list( @@ -1967,25 +1967,25 @@ goos::Object CastElement::to_form_internal(const Env& env) const { } void CastElement::apply(const std::function& f) { - // assert(m_source->parent_element == this); + // ASSERT(m_source->parent_element == this); f(this); m_source->apply(f); } void CastElement::apply_form(const std::function& f) { - // assert(m_source->parent_element == this); + // ASSERT(m_source->parent_element == this); m_source->apply_form(f); } void CastElement::collect_vars(RegAccessSet& vars, bool recursive) const { - // assert(m_source->parent_element == this); + // ASSERT(m_source->parent_element == this); if (recursive) { m_source->collect_vars(vars, recursive); } } void CastElement::get_modified_regs(RegSet& regs) const { - assert(m_source->parent_element == this); + ASSERT(m_source->parent_element == this); m_source->get_modified_regs(regs); } @@ -2032,7 +2032,7 @@ void DerefToken::collect_vars(RegAccessSet& vars, bool recursive) const { } break; default: - assert(false); + ASSERT(false); } } @@ -2047,7 +2047,7 @@ goos::Object DerefToken::to_form(const Env& env) const { case Kind::EXPRESSION_PLACEHOLDER: return pretty_print::to_symbol("PLACEHOLDER"); default: - assert(false); + ASSERT(false); return {}; } } @@ -2062,7 +2062,7 @@ void DerefToken::apply(const std::function& f) { m_expr->apply(f); break; default: - assert(false); + ASSERT(false); } } @@ -2076,7 +2076,7 @@ void DerefToken::apply_form(const std::function& f) { m_expr->apply_form(f); break; default: - assert(false); + ASSERT(false); } } @@ -2090,7 +2090,7 @@ void DerefToken::get_modified_regs(RegSet& regs) const { m_expr->get_modified_regs(regs); break; default: - assert(false); + ASSERT(false); } } @@ -2131,7 +2131,7 @@ DerefElement::DerefElement(Form* base, bool is_addr_of, std::vector } goos::Object DerefElement::to_form_internal(const Env& env) const { - assert(m_base->parent_element); + ASSERT(m_base->parent_element); std::vector forms = {pretty_print::to_symbol(m_is_addr_of ? "&->" : "->"), m_base->to_form(env)}; for (auto& tok : m_tokens) { @@ -2561,8 +2561,8 @@ CounterLoopElement::CounterLoopElement(Kind kind, m_kind(kind) { m_body->parent_element = this; m_check_value->parent_element = this; - assert(m_var_inc.reg() == m_var_check.reg()); - assert(m_var_init.reg() == m_var_inc.reg()); + ASSERT(m_var_inc.reg() == m_var_check.reg()); + ASSERT(m_var_init.reg() == m_var_inc.reg()); } goos::Object CounterLoopElement::to_form_internal(const Env& env) const { @@ -2575,7 +2575,7 @@ goos::Object CounterLoopElement::to_form_internal(const Env& env) const { loop_name = "countdown"; break; default: - assert(false); + ASSERT(false); } std::vector outer = { pretty_print::to_symbol(loop_name), @@ -2652,7 +2652,7 @@ goos::Object StackStructureDefElement::to_form_internal(const Env&) const { m_entry.ref_type.get_single_arg().print(), m_entry.hint.container_size)); default: - assert(false); + ASSERT(false); } } @@ -3269,7 +3269,7 @@ goos::Object ResLumpMacroElement::to_form_internal(const Env& env) const { forms.push_back(pretty_print::to_symbol("res-lump-value")); break; default: - assert(false); + ASSERT(false); } forms.push_back(m_lump_object->to_form(env)); diff --git a/decompiler/IR2/Form.h b/decompiler/IR2/Form.h index 308153ef33..6b7ba8feb7 100644 --- a/decompiler/IR2/Form.h +++ b/decompiler/IR2/Form.h @@ -63,7 +63,7 @@ class FormElement { FormElement& operator=(const FormElement& other) = delete; void mark_popped() { - assert(!m_popped); + ASSERT(!m_popped); m_popped = true; } @@ -1016,22 +1016,22 @@ class GenericOperator { void get_modified_regs(RegSet& regs) const; Kind kind() const { return m_kind; } FixedOperatorKind fixed_kind() const { - assert(m_kind == Kind::FIXED_OPERATOR); + ASSERT(m_kind == Kind::FIXED_OPERATOR); return m_fixed_kind; } IR2_Condition::Kind condition_kind() const { - assert(m_kind == Kind::CONDITION_OPERATOR); + ASSERT(m_kind == Kind::CONDITION_OPERATOR); return m_condition_kind; } const Form* func() const { - assert(m_kind == Kind::FUNCTION_EXPR); + ASSERT(m_kind == Kind::FUNCTION_EXPR); return m_function; } Form* func() { - assert(m_kind == Kind::FUNCTION_EXPR); + ASSERT(m_kind == Kind::FUNCTION_EXPR); return m_function; } @@ -1129,14 +1129,14 @@ class DerefToken { Kind kind() const { return m_kind; } const std::string& field_name() const { - assert(m_kind == Kind::FIELD_NAME); + ASSERT(m_kind == Kind::FIELD_NAME); return m_name; } s64 int_constant() const { return m_int_constant; } Form* expr() { - assert(m_kind == Kind::INTEGER_EXPRESSION); + ASSERT(m_kind == Kind::INTEGER_EXPRESSION); return m_expr; } @@ -1862,17 +1862,17 @@ class Form { const FormElement* operator[](int idx) const { return m_elements.at(idx); } int size() const { return int(m_elements.size()); } FormElement* back() const { - assert(!m_elements.empty()); + ASSERT(!m_elements.empty()); return m_elements.back(); } FormElement** back_ref() { - assert(!m_elements.empty()); + ASSERT(!m_elements.empty()); return &m_elements.back(); } void pop_back() { - assert(!m_elements.empty()); + ASSERT(!m_elements.empty()); m_elements.pop_back(); } @@ -1986,7 +1986,7 @@ class FormPool { } void cache_conversion(const CfgVtx* vtx, Form* form) { - assert(m_vtx_to_form_cache.find(vtx) == m_vtx_to_form_cache.end()); + ASSERT(m_vtx_to_form_cache.find(vtx) == m_vtx_to_form_cache.end()); m_vtx_to_form_cache[vtx] = form; } diff --git a/decompiler/IR2/FormExpressionAnalysis.cpp b/decompiler/IR2/FormExpressionAnalysis.cpp index 056e06210f..70da6a3bdb 100644 --- a/decompiler/IR2/FormExpressionAnalysis.cpp +++ b/decompiler/IR2/FormExpressionAnalysis.cpp @@ -408,7 +408,7 @@ std::vector pop_to_forms(const std::vector& vars, } // add casts, if needed. - assert(vars.size() == forms.size()); + ASSERT(vars.size() == forms.size()); for (size_t i = 0; i < vars.size(); i++) { auto atom = form_as_atom(forms[i]); bool is_var = atom && atom->is_var(); @@ -472,7 +472,7 @@ void Form::update_children_from_stack(const Env& env, FormPool& pool, FormStack& stack, bool allow_side_effects) { - assert(!m_elements.empty()); + ASSERT(!m_elements.empty()); std::vector new_elts; @@ -530,7 +530,7 @@ std::vector make_casts_if_needed(const std::vector& in, FormPool& pool, const Env& env) { std::vector out; - assert(in.size() == in_types.size()); + ASSERT(in.size() == in_types.size()); for (size_t i = 0; i < in_types.size(); i++) { out.push_back(make_cast_if_needed(in.at(i), in_types.at(i), out_type, pool, env)); } @@ -641,7 +641,7 @@ void SimpleExpressionElement::update_from_stack_fpr_to_gpr(const Env& env, // set ourself to identity. m_expr = src.as_expr(); // then go again. - assert(m_popped); + ASSERT(m_popped); m_popped = false; update_from_stack(env, pool, stack, result, allow_side_effects); } else { @@ -722,7 +722,7 @@ FormElement* make_and_compact_math_op(Form* arg0, arg0_elts = {arg0}; } - assert(!arg0_elts.empty()); + ASSERT(!arg0_elts.empty()); if (arg0_cast) { arg0_elts.front() = cast_form(arg0_elts.front(), *arg0_cast, pool, env); } @@ -735,7 +735,7 @@ FormElement* make_and_compact_math_op(Form* arg0, arg1_elts = {arg1}; } - assert(!arg1_elts.empty()); + ASSERT(!arg1_elts.empty()); if (arg1_cast) { arg1_elts.front() = cast_form(arg1_elts.front(), *arg1_cast, pool, env); } @@ -884,14 +884,14 @@ void SimpleExpressionElement::update_from_stack_add_i(const Env& env, std::vector tokens; for (auto& tok : out.tokens) { if (tok.kind == FieldReverseLookupOutput::Token::Kind::VAR_IDX) { - assert(!used_index); + ASSERT(!used_index); used_index = true; tokens.push_back(DerefToken::make_int_expr(match_result.maps.forms.at(0))); } else { tokens.push_back(to_token(tok)); } } - assert(used_index); + ASSERT(used_index); result->push_back(pool.alloc_element(args.at(1), out.addr_of, tokens)); return; } else { @@ -922,14 +922,14 @@ void SimpleExpressionElement::update_from_stack_add_i(const Env& env, std::vector tokens; for (auto& tok : out.tokens) { if (tok.kind == FieldReverseLookupOutput::Token::Kind::VAR_IDX) { - assert(!used_index); + ASSERT(!used_index); used_index = true; tokens.push_back(DerefToken::make_int_expr(match_result.maps.forms.at(0))); } else { tokens.push_back(to_token(tok)); } } - assert(used_index); + ASSERT(used_index); result->push_back(pool.alloc_element(args.at(1), out.addr_of, tokens)); return; } else { @@ -951,14 +951,14 @@ void SimpleExpressionElement::update_from_stack_add_i(const Env& env, std::vector tokens; for (auto& tok : out.tokens) { if (tok.kind == FieldReverseLookupOutput::Token::Kind::VAR_IDX) { - assert(!used_index); + ASSERT(!used_index); used_index = true; tokens.push_back(DerefToken::make_int_expr(match_result.maps.forms.at(0))); } else { tokens.push_back(to_token(tok)); } } - assert(used_index); + ASSERT(used_index); result->push_back(pool.alloc_element(args.at(1), out.addr_of, tokens)); return; } else { @@ -1003,14 +1003,14 @@ void SimpleExpressionElement::update_from_stack_add_i(const Env& env, std::vector tokens; for (auto& tok : rd_ok.tokens) { if (tok.kind == FieldReverseLookupOutput::Token::Kind::VAR_IDX) { - assert(!used_index); + ASSERT(!used_index); used_index = true; tokens.push_back(DerefToken::make_int_expr(match_result.maps.forms.at(0))); } else { tokens.push_back(to_token(tok)); } } - assert(used_index); + ASSERT(used_index); result->push_back(pool.alloc_element(args.at(0), rd_ok.addr_of, tokens)); return; } else { @@ -1054,14 +1054,14 @@ void SimpleExpressionElement::update_from_stack_add_i(const Env& env, std::vector tokens; for (auto& tok : rd_ok.tokens) { if (tok.kind == FieldReverseLookupOutput::Token::Kind::VAR_IDX) { - assert(!used_index); + ASSERT(!used_index); used_index = true; tokens.push_back(DerefToken::make_int_expr(match_result.maps.forms.at(0))); } else { tokens.push_back(to_token(tok)); } } - assert(used_index); + ASSERT(used_index); result->push_back(pool.alloc_element(args.at(1), rd_ok.addr_of, tokens)); return; } else { @@ -1160,7 +1160,7 @@ void SimpleExpressionElement::update_from_stack_force_si_2(const Env& env, if (arg1_reg) { arg1_i = is_int_type(env, m_my_idx, m_expr.get_arg(1).var()); } else { - assert(m_expr.get_arg(1).is_int()); + ASSERT(m_expr.get_arg(1).is_int()); } std::vector args; @@ -1206,7 +1206,7 @@ void SimpleExpressionElement::update_from_stack_force_ui_2(const Env& env, if (arg1_reg) { arg1_u = is_uint_type(env, m_my_idx, m_expr.get_arg(1).var()); } else { - assert(m_expr.get_arg(1).is_int()); + ASSERT(m_expr.get_arg(1).is_int()); } std::vector args; @@ -1447,12 +1447,12 @@ FormElement* SimpleExpressionElement::update_from_stack_logor_or_logand_helper( had_pcpyud = true; bitfield_info = dynamic_cast(env.dts->ts.lookup_type(arg0_reg_type.get_bitfield_type())); - assert(bitfield_info); + ASSERT(bitfield_info); } else if (arg0_reg_type.kind == TP_Type::Kind::PCPYUD_BITFIELD_AND) { // already have the pcpyud in the thing. bitfield_info = dynamic_cast(env.dts->ts.lookup_type(arg0_reg_type.get_bitfield_type())); - assert(bitfield_info); + ASSERT(bitfield_info); } } @@ -1462,10 +1462,10 @@ FormElement* SimpleExpressionElement::update_from_stack_logor_or_logand_helper( auto read_elt = dynamic_cast(base->try_as_single_element()); if (!read_elt) { read_elt = pool.alloc_element(base, bitfield_type); - assert(!had_pcpyud); + ASSERT(!had_pcpyud); } else { if (had_pcpyud) { - assert(read_elt->has_pcpyud()); + ASSERT(read_elt->has_pcpyud()); } } @@ -1475,7 +1475,7 @@ FormElement* SimpleExpressionElement::update_from_stack_logor_or_logand_helper( } else if (kind == FixedOperatorKind::LOGIOR) { manip_kind = BitfieldManip::Kind::LOGIOR_WITH_CONSTANT_INT; } else { - assert(false); + ASSERT(false); } BitfieldManip step(manip_kind, m_expr.get_arg(1).get_int()); @@ -1490,7 +1490,7 @@ FormElement* SimpleExpressionElement::update_from_stack_logor_or_logand_helper( // andi, something else (don't think this can happen?) std::vector result; update_from_stack_copy_first_int_2(env, kind, pool, stack, &result, allow_side_effects); - assert(result.size() == 1); + ASSERT(result.size() == 1); return result.at(0); } else { // and, two forms @@ -1512,10 +1512,10 @@ FormElement* SimpleExpressionElement::update_from_stack_logor_or_logand_helper( if (!read_elt) { read_elt = pool.alloc_element(args.at(0), bitfield_type); made_new_read_elt = true; - assert(!had_pcpyud); + ASSERT(!had_pcpyud); } else { if (had_pcpyud) { - assert(read_elt->has_pcpyud()); + ASSERT(read_elt->has_pcpyud()); } } @@ -1529,11 +1529,11 @@ FormElement* SimpleExpressionElement::update_from_stack_logor_or_logand_helper( } else if (kind == FixedOperatorKind::LOGIOR) { manip_kind = BitfieldManip::Kind::LOGIOR_WITH_CONSTANT_INT; } else { - assert(false); + ASSERT(false); } BitfieldManip step(manip_kind, *arg1_as_int); auto other = read_elt->push_step(step, env.dts->ts, pool, env); - // assert(!other); // shouldn't be complete. + // ASSERT(!other); // shouldn't be complete. if (other) { return other; } else { @@ -1546,7 +1546,7 @@ FormElement* SimpleExpressionElement::update_from_stack_logor_or_logand_helper( } else if (kind == FixedOperatorKind::LOGIOR) { manip_kind = BitfieldManip::Kind::LOGIOR_WITH_FORM; } else { - assert(false); + ASSERT(false); } auto step = BitfieldManip::from_form(manip_kind, stripped_arg1); auto other = read_elt->push_step(step, env.dts->ts, pool, env); @@ -1723,7 +1723,7 @@ void SimpleExpressionElement::update_from_stack_left_shift(const Env& env, auto read_elt = pool.alloc_element(base, arg0_type); BitfieldManip step(BitfieldManip::Kind::LEFT_SHIFT, m_expr.get_arg(1).get_int()); auto other = read_elt->push_step(step, env.dts->ts, pool, env); - assert(!other); // shouldn't be complete. + ASSERT(!other); // shouldn't be complete. result->push_back(read_elt); } else { // try to turn this into a multiplication, if possible @@ -1735,7 +1735,7 @@ void SimpleExpressionElement::update_from_stack_left_shift(const Env& env, if (as_ba) { BitfieldManip step(BitfieldManip::Kind::LEFT_SHIFT, m_expr.get_arg(1).get_int()); auto other = as_ba->push_step(step, env.dts->ts, pool, env); - assert(!other); // shouldn't be complete. + ASSERT(!other); // shouldn't be complete. result->push_back(as_ba); return; } @@ -1788,7 +1788,7 @@ void SimpleExpressionElement::update_from_stack_right_shift_logic(const Env& env auto read_elt = pool.alloc_element(base, arg0_type); BitfieldManip step(BitfieldManip::Kind::RIGHT_SHIFT_LOGICAL, m_expr.get_arg(1).get_int()); auto other = read_elt->push_step(step, env.dts->ts, pool, env); - assert(other); // should be a high field. + ASSERT(other); // should be a high field. result->push_back(other); } else { auto arg0_i = is_int_type(env, m_my_idx, m_expr.get_arg(0).var()); @@ -1857,7 +1857,7 @@ void SimpleExpressionElement::update_from_stack_right_shift_arith(const Env& env auto read_elt = pool.alloc_element(base, arg0_type); BitfieldManip step(BitfieldManip::Kind::RIGHT_SHIFT_ARITH, m_expr.get_arg(1).get_int()); auto other = read_elt->push_step(step, env.dts->ts, pool, env); - assert(other); // should be a high field. + ASSERT(other); // should be a high field. result->push_back(other); } else { if (m_expr.get_arg(1).is_int()) { @@ -1888,7 +1888,7 @@ void SimpleExpressionElement::update_from_stack_right_shift_arith(const Env& env if (as_ba) { BitfieldManip step(BitfieldManip::Kind::RIGHT_SHIFT_ARITH, m_expr.get_arg(1).get_int()); auto other = as_ba->push_step(step, env.dts->ts, pool, env); - assert(other); // should be a high field. + ASSERT(other); // should be a high field. result->push_back(other); return; } @@ -2158,9 +2158,9 @@ void SimpleExpressionElement::update_from_stack(const Env& env, void SetVarElement::push_to_stack(const Env& env, FormPool& pool, FormStack& stack) { mark_popped(); for (auto x : m_src->elts()) { - assert(x->parent_form == m_src); + ASSERT(x->parent_form == m_src); } - assert(m_src->parent_element == this); + ASSERT(m_src->parent_element == this); // hack for method stuff if (is_dead_set()) { @@ -2197,7 +2197,7 @@ void SetVarElement::push_to_stack(const Env& env, FormPool& pool, FormStack& sta m_src->update_children_from_stack(env, pool, stack, true); for (auto x : m_src->elts()) { - assert(x->parent_form == m_src); + ASSERT(x->parent_form == m_src); } if (m_src->is_single_element()) { @@ -2226,13 +2226,13 @@ void SetVarElement::push_to_stack(const Env& env, FormPool& pool, FormStack& sta stack.push_value_to_reg(m_dst, m_src, true, m_src_type, m_var_info); for (auto x : m_src->elts()) { - assert(x->parent_form == m_src); + ASSERT(x->parent_form == m_src); } } void SetFormFormElement::push_to_stack(const Env& env, FormPool& pool, FormStack& stack) { - assert(m_popped); - assert(m_real_push_count == 0); + ASSERT(m_popped); + ASSERT(m_real_push_count == 0); m_real_push_count++; // check for bitfield setting: @@ -2795,7 +2795,7 @@ void FunctionCallElement::update_from_stack(const Env& env, auto mr = match(matcher, unstacked.at(0)); if (mr.matched && nargs >= 1) { auto vtable_reg = mr.maps.regs.at(0); - assert(vtable_reg); + ASSERT(vtable_reg); auto vtable_var_name = env.get_variable_name(*vtable_reg); auto arg0_mr = match(Matcher::any_reg(0), unstacked.at(1)); if (arg0_mr.matched && env.get_variable_name(*arg0_mr.maps.regs.at(0)) == vtable_var_name) { @@ -2826,7 +2826,7 @@ void FunctionCallElement::update_from_stack(const Env& env, new_form = pool.alloc_element( GenericOperator::make_function(mr.maps.forms.at(1)), arg_forms); result->push_back(new_form); - assert(!go_next_state); + ASSERT(!go_next_state); return; } } @@ -2862,7 +2862,7 @@ void FunctionCallElement::update_from_stack(const Env& env, // if needed, cast to to correct type. std::vector expected_arg_types = {TypeSpec("symbol"), TypeSpec("type"), TypeSpec("int")}; - assert(new_args.size() >= 3); + ASSERT(new_args.size() >= 3); for (size_t i = 0; i < 3; i++) { auto& var = all_pop_vars.at(i + 1); // 0 is the function itself. auto arg_type = env.get_types_before_op(var.idx()).get(var.reg()).typespec(); @@ -2875,7 +2875,7 @@ void FunctionCallElement::update_from_stack(const Env& env, auto new_op = pool.alloc_element( GenericOperator::make_fixed(FixedOperatorKind::OBJECT_NEW), new_args); result->push_back(new_op); - assert(!go_next_state); + ASSERT(!go_next_state); return; } if (name == "new" && type_1 == "type") { @@ -2883,7 +2883,7 @@ void FunctionCallElement::update_from_stack(const Env& env, auto new_op = pool.alloc_element( GenericOperator::make_fixed(FixedOperatorKind::TYPE_NEW), new_args); result->push_back(new_op); - assert(!go_next_state); + ASSERT(!go_next_state); return; } else if (name == "new") { constexpr int allocation = 2; @@ -2920,7 +2920,7 @@ void FunctionCallElement::update_from_stack(const Env& env, auto cons_op = pool.alloc_element( GenericOperator::make_fixed(FixedOperatorKind::CONS), cons_args); result->push_back(cons_op); - assert(!go_next_state); + ASSERT(!go_next_state); return; } else { // just normal construction on the heap @@ -2930,7 +2930,7 @@ void FunctionCallElement::update_from_stack(const Env& env, auto new_op = pool.alloc_element( GenericOperator::make_fixed(FixedOperatorKind::NEW), new_args); result->push_back(new_op); - assert(!go_next_state); + ASSERT(!go_next_state); return; } } @@ -3006,7 +3006,7 @@ void FunctionCallElement::update_from_stack(const Env& env, auto gop = GenericOperator::make_function(method_op); result->push_back(pool.alloc_element(gop, arg_forms)); - assert(!go_next_state); + ASSERT(!go_next_state); return; } @@ -3044,7 +3044,7 @@ void FunctionCallElement::update_from_stack(const Env& env, } result->push_back(pool.alloc_element( GenericOperator::make_fixed(FixedOperatorKind::NEW), stack_new_args)); - assert(!go_next_state); + ASSERT(!go_next_state); return; } } @@ -3130,7 +3130,7 @@ void UntilElement::push_to_stack(const Env& env, FormPool& pool, FormStack& stac } condition_to_body = condition_temp_stack.rewrite(pool, env); condition->clear(); - assert(!condition_to_body.empty()); + ASSERT(!condition_to_body.empty()); condition->push_back(condition_to_body.back()); condition_to_body.pop_back(); } @@ -3484,7 +3484,7 @@ void CondWithElseElement::push_to_stack(const Env& env, FormPool& pool, FormStac // update register info if (rewrite_as_set && !set_unused) { // might not be the same if a set is eliminated by a coloring move. - // assert(dest_sets.size() == write_output_forms.size()); + // ASSERT(dest_sets.size() == write_output_forms.size()); if (!dest_sets.empty()) { for (size_t i = 0; i < dest_sets.size() - 1; i++) { auto var = dest_sets.at(i)->dst(); @@ -3633,7 +3633,7 @@ void ShortCircuitElement::push_to_stack(const Env& env, FormPool& pool, FormStac to_push = as_handle_get; } - assert(used_as_value.has_value()); + ASSERT(used_as_value.has_value()); stack.push_value_to_reg(final_result, pool.alloc_single_form(nullptr, to_push), true, env.get_variable_type(final_result, false)); already_rewritten = true; @@ -3739,7 +3739,7 @@ FormElement* ConditionElement::make_zero_check_generic(const Env& env, const std::vector& source_forms, const std::vector& source_types) { // (zero? (+ thing small-integer)) -> (= thing (- small-integer)) - assert(source_forms.size() == 1); + ASSERT(source_forms.size() == 1); auto enum_type_info = env.dts->ts.try_enum_lookup(source_types.at(0)); if (enum_type_info && !enum_type_info->is_bitfield()) { @@ -3863,7 +3863,7 @@ FormElement* ConditionElement::make_nonzero_check_generic(const Env& env, const std::vector&) { // for (nonzero? (-> obj bitfield)) FormElement* bitfield_compare = nullptr; - assert(source_forms.size() == 1); + ASSERT(source_forms.size() == 1); auto as_bitfield_op = dynamic_cast(source_forms.at(0)->try_as_single_element()); if (as_bitfield_op) { @@ -3903,7 +3903,7 @@ FormElement* ConditionElement::make_equal_check_generic(const Env& env, FormPool& pool, const std::vector& source_forms, const std::vector& source_types) { - assert(source_forms.size() == 2); + ASSERT(source_forms.size() == 2); // (= thing '()) auto ref = source_forms.at(1); auto ref_atom = form_as_atom(ref); @@ -3932,7 +3932,7 @@ FormElement* ConditionElement::make_not_equal_check_generic( FormPool& pool, const std::vector& source_forms, const std::vector& source_types) { - assert(source_forms.size() == 2); + ASSERT(source_forms.size() == 2); // (!= thing '()) auto ref = source_forms.at(1); auto ref_atom = form_as_atom(ref); @@ -3963,7 +3963,7 @@ FormElement* ConditionElement::make_less_than_zero_signed_check_generic( FormPool& pool, const std::vector& source_forms, const std::vector& types) { - assert(source_forms.size() == 1); + ASSERT(source_forms.size() == 1); // (< (shl (the-as int iter) 62) 0) -> (pair? iter) // match (shl [(the-as int [x]) | [x]] 62) @@ -3994,7 +3994,7 @@ FormElement* ConditionElement::make_geq_zero_signed_check_generic( FormPool& pool, const std::vector& source_forms, const std::vector& types) { - assert(source_forms.size() == 1); + ASSERT(source_forms.size() == 1); // (>= (shl (the-as int iter) 62) 0) -> (not (pair? iter)) // match (shl [(the-as int [x]) | [x]] 62) @@ -4028,7 +4028,7 @@ FormElement* ConditionElement::make_geq_zero_unsigned_check_generic( FormPool& pool, const std::vector& source_forms, const std::vector& types) { - assert(source_forms.size() == 1); + ASSERT(source_forms.size() == 1); // (>= (shl (the-as int iter) 62) 0) -> (not (pair? iter)) // match (shl [(the-as int [x]) | [x]] 62) @@ -4226,8 +4226,8 @@ void ConditionElement::push_to_stack(const Env& env, FormPool& pool, FormStack& source_forms.push_back(pool.alloc_single_element_form(nullptr, *m_src[i])); } } - assert(popped_counter == int(popped_forms.size())); - assert(source_forms.size() == source_types.size()); + ASSERT(popped_counter == int(popped_forms.size())); + ASSERT(source_forms.size() == source_types.size()); stack.push_form_element(make_generic(env, pool, source_forms, source_types), true); } @@ -4279,8 +4279,8 @@ void ConditionElement::update_from_stack(const Env& env, source_forms.push_back(pool.alloc_single_element_form(nullptr, *m_src[i])); } } - assert(popped_counter == int(popped_forms.size())); - assert(source_forms.size() == source_types.size()); + ASSERT(popped_counter == int(popped_forms.size())); + ASSERT(source_forms.size() == source_types.size()); result->push_back(make_generic(env, pool, source_forms, source_types)); } @@ -4296,7 +4296,7 @@ void ReturnElement::push_to_stack(const Env& env, FormPool& pool, FormStack& sta std::optional var; new_entries = rewrite_to_get_var(temp_stack, pool, env.end_var(), env, &var); - assert(!new_entries.empty()); + ASSERT(!new_entries.empty()); return_code->clear(); @@ -4333,13 +4333,13 @@ void push_asm_srl_to_stack(const AsmOp* op, FormStack& stack) { // we will try to convert this into a bitfield operation. If this fails, fall back to assembly. auto var = op->src(0); - assert(var.has_value()); // srl should always have this. + ASSERT(var.has_value()); // srl should always have this. auto dst = op->dst(); - assert(dst.has_value()); + ASSERT(dst.has_value()); auto integer_atom = op->instruction().get_src(1); - assert(integer_atom.is_imm()); + ASSERT(integer_atom.is_imm()); auto integer = integer_atom.get_imm(); auto arg0_type = env.get_variable_type(*var, true); @@ -4350,7 +4350,7 @@ void push_asm_srl_to_stack(const AsmOp* op, auto read_elt = pool.alloc_element(base, arg0_type); BitfieldManip step(BitfieldManip::Kind::RIGHT_SHIFT_LOGICAL_32BIT, integer); auto other = read_elt->push_step(step, env.dts->ts, pool, env); - assert(other); // should be a high field. + ASSERT(other); // should be a high field. stack.push_value_to_reg(*dst, pool.alloc_single_form(nullptr, other), true, env.get_variable_type(*dst, true)); } else { @@ -4360,7 +4360,7 @@ void push_asm_srl_to_stack(const AsmOp* op, if (as_ba) { BitfieldManip step(BitfieldManip::Kind::RIGHT_SHIFT_LOGICAL_32BIT, integer); auto other = as_ba->push_step(step, env.dts->ts, pool, env); - assert(other); // should immediately get a field. + ASSERT(other); // should immediately get a field. stack.push_value_to_reg(*dst, pool.alloc_single_form(nullptr, other), true, env.get_variable_type(*dst, true)); } else { @@ -4377,10 +4377,10 @@ void push_asm_sllv_to_stack(const AsmOp* op, FormPool& pool, FormStack& stack) { auto var = op->src(0); - assert(var.has_value()); + ASSERT(var.has_value()); auto dst = op->dst(); - assert(dst.has_value()); + ASSERT(dst.has_value()); auto arg0_type = env.get_variable_type(*var, true); auto type_info = env.dts->ts.lookup_type(arg0_type); @@ -4391,7 +4391,7 @@ void push_asm_sllv_to_stack(const AsmOp* op, auto read_elt = pool.alloc_element(base, arg0_type); BitfieldManip step(BitfieldManip::Kind::SLLV_SEXT, 0); auto other = read_elt->push_step(step, env.dts->ts, pool, env); - assert(other); // should immediately get a field. + ASSERT(other); // should immediately get a field. stack.push_value_to_reg(*dst, pool.alloc_single_form(nullptr, other), true, env.get_variable_type(*dst, true)); } else { @@ -4401,7 +4401,7 @@ void push_asm_sllv_to_stack(const AsmOp* op, // part of existing chain. BitfieldManip step(BitfieldManip::Kind::SLLV_SEXT, 0); auto other = as_ba->push_step(step, env.dts->ts, pool, env); - assert(other); // should immediately get a field. + ASSERT(other); // should immediately get a field. stack.push_value_to_reg(*dst, pool.alloc_single_form(nullptr, other), true, env.get_variable_type(*dst, true)); } else { @@ -4427,13 +4427,13 @@ void push_asm_pcpyud_to_stack(const AsmOp* op, // pcpyud v1, gp, r0 for example. auto var = op->src(0); - assert(var.has_value()); + ASSERT(var.has_value()); auto dst = op->dst(); - assert(dst.has_value()); + ASSERT(dst.has_value()); auto possible_r0 = op->src(1); - assert(possible_r0.has_value()); + ASSERT(possible_r0.has_value()); auto arg0_type = env.get_variable_type(*var, true); auto type_info = env.dts->ts.lookup_type(arg0_type); @@ -4457,13 +4457,13 @@ void push_asm_pextuw_to_stack(const AsmOp* op, // (.pextuw t0-0 r0-0 obj) auto var = op->src(1); - assert(var.has_value()); + ASSERT(var.has_value()); auto dst = op->dst(); - assert(dst.has_value()); + ASSERT(dst.has_value()); auto possible_r0 = op->src(0); - assert(possible_r0.has_value()); + ASSERT(possible_r0.has_value()); auto arg0_type = env.get_variable_type(*var, true); auto type_info = env.dts->ts.lookup_type(arg0_type); @@ -4473,7 +4473,7 @@ void push_asm_pextuw_to_stack(const AsmOp* op, auto read_elt = pool.alloc_element(base, arg0_type); BitfieldManip step(BitfieldManip::Kind::PEXTUW, 0); auto other = read_elt->push_step(step, env.dts->ts, pool, env); - assert(other); // should immediately get a field. + ASSERT(other); // should immediately get a field. stack.push_value_to_reg(*dst, pool.alloc_single_form(nullptr, other), true, env.get_variable_type(*dst, true)); } else { @@ -4488,13 +4488,13 @@ void push_asm_madds_to_stack(const AsmOp* op, FormPool& pool, FormStack& stack) { auto src0 = op->src(0); - assert(src0.has_value()); + ASSERT(src0.has_value()); auto src1 = op->src(1); - assert(src1.has_value()); + ASSERT(src1.has_value()); auto dst = op->dst(); - assert(dst.has_value()); + ASSERT(dst.has_value()); auto vars = pop_to_forms({*src0, *src1}, env, pool, stack, true); @@ -4566,7 +4566,7 @@ void AtomicOpElement::push_to_stack(const Env& env, FormPool& pool, FormStack& s if (as_branch && !as_branch->is_likely()) { // this is a bit of a hack, but we go AsmBranchOp -> AsmBranchElement -> TranslatedAsmBranch auto delay = as_branch->branch_delay(); - assert(delay); + ASSERT(delay); // this might not be enough - we may need to back up to the cfg builder and do something there. auto del = pool.alloc_single_element_form(nullptr, delay); auto be = pool.alloc_element(as_branch, del, false); @@ -4677,7 +4677,7 @@ void BranchElement::push_to_stack(const Env& env, FormPool& pool, FormStack& sta m_op->to_string(env)); } - assert(!m_op->likely()); + ASSERT(!m_op->likely()); auto op = pool.alloc_element(branch_condition, branch_delay, m_op->label_id(), m_op->likely()); // fmt::print("rewrote (non-asm) as {}\n", op->to_string(env)); @@ -4720,7 +4720,7 @@ void DynamicMethodAccess::update_from_stack(const Env& env, auto idx = match_result.maps.regs.at(0); auto base = match_result.maps.regs.at(1); - assert(idx.has_value() && base.has_value()); + ASSERT(idx.has_value() && base.has_value()); auto deref = pool.alloc_element( var_to_form(base.value(), pool), false, @@ -4761,7 +4761,7 @@ void ArrayFieldAccess::update_with_val(Form* new_val, } auto idx = match_result.maps.forms.at(1); auto base = match_result.maps.forms.at(0); - assert(idx && base); + ASSERT(idx && base); if (m_flipped) { std::swap(idx, base); @@ -4810,7 +4810,7 @@ void ArrayFieldAccess::update_with_val(Form* new_val, auto idx = match_result.maps.forms.at(1); auto base = match_result.maps.forms.at(0); - assert(idx && base); + ASSERT(idx && base); std::vector tokens = m_deref_tokens; for (auto& x : tokens) { @@ -4847,7 +4847,7 @@ void ArrayFieldAccess::update_with_val(Form* new_val, auto base = strip_int_or_uint_cast(mr.maps.forms.at(1)); auto idx = mr.maps.forms.at(0); - assert(idx && base); + ASSERT(idx && base); std::vector tokens = m_deref_tokens; for (auto& x : tokens) { @@ -4877,7 +4877,7 @@ void ArrayFieldAccess::update_with_val(Form* new_val, } auto idx = match_result.maps.forms.at(0); auto base = match_result.maps.forms.at(1); - assert(idx && base); + ASSERT(idx && base); std::vector tokens = m_deref_tokens; for (auto& x : tokens) { @@ -4918,7 +4918,7 @@ void ArrayFieldAccess::update_with_val(Form* new_val, idx = match_result.maps.forms.at(0); base = match_result.maps.forms.at(1); - assert(idx && base); + ASSERT(idx && base); std::vector tokens = m_deref_tokens; for (auto& x : tokens) { @@ -4957,7 +4957,7 @@ void ArrayFieldAccess::update_with_val(Form* new_val, auto base = strip_int_or_uint_cast(mr.maps.forms.at(1)); auto idx = mr.maps.forms.at(0); - assert(idx && base); + ASSERT(idx && base); std::vector tokens = m_deref_tokens; for (auto& x : tokens) { @@ -5445,7 +5445,7 @@ void BreakElement::push_to_stack(const Env& env, FormPool& pool, FormStack& stac std::vector new_entries; new_entries = temp_stack.rewrite(pool, env); - assert(!new_entries.empty()); + ASSERT(!new_entries.empty()); return_code->clear(); for (int i = 0; i < ((int)new_entries.size()); i++) { diff --git a/decompiler/IR2/FormStack.cpp b/decompiler/IR2/FormStack.cpp index c68d19dbcc..154b7b2f5a 100644 --- a/decompiler/IR2/FormStack.cpp +++ b/decompiler/IR2/FormStack.cpp @@ -8,7 +8,7 @@ namespace decompiler { std::string FormStack::StackEntry::print(const Env& env) const { if (destination.has_value()) { - assert(source && !elt); + ASSERT(source && !elt); if (active) { return fmt::format("d: {} s: {} | {} <- {} f: {} w: {}", active, sequence_point, destination.value().reg().to_charp(), source->to_string(env), @@ -20,7 +20,7 @@ std::string FormStack::StackEntry::print(const Env& env) const { } } else { - assert(elt && !source); + ASSERT(elt && !source); if (active) { return fmt::format("d: {} s: {} | {} f: {}", active, sequence_point, elt->to_string(env), non_seq_source.has_value()); @@ -45,7 +45,7 @@ void FormStack::push_value_to_reg(RegisterAccess var, bool sequence_point, TypeSpec type, const SetVarInfo& info) { - assert(value); + ASSERT(value); StackEntry entry; entry.active = true; // by default, we should display everything! entry.sequence_point = sequence_point; @@ -61,7 +61,7 @@ void FormStack::push_value_to_reg_dead(RegisterAccess var, bool sequence_point, TypeSpec type, const SetVarInfo& info) { - assert(value); + ASSERT(value); StackEntry entry; entry.active = false; entry.sequence_point = sequence_point; @@ -77,7 +77,7 @@ void FormStack::push_non_seq_reg_to_reg(const RegisterAccess& dst, Form* src_as_form, TypeSpec type, const SetVarInfo& info) { - assert(src_as_form); + ASSERT(src_as_form); StackEntry entry; entry.active = true; entry.sequence_point = false; @@ -137,7 +137,7 @@ Form* FormStack::pop_reg(Register reg, if (found_orig_out) { *found_orig_out = false; } - assert(allow_side_effects); + ASSERT(allow_side_effects); (void)env; // keep this for easy debugging. RegSet modified; size_t begin = m_stack.size(); @@ -158,9 +158,9 @@ Form* FormStack::pop_reg(Register reg, return nullptr; } entry.active = false; - assert(entry.source); + ASSERT(entry.source); if (entry.non_seq_source.has_value()) { - assert(entry.sequence_point == false); + ASSERT(entry.sequence_point == false); auto result = pop_reg(entry.non_seq_source->reg(), barrier, env, allow_side_effects, i); if (result) { if (found_orig_out) { @@ -184,14 +184,14 @@ Form* FormStack::pop_reg(Register reg, } // no match, and not a sequence: if (entry.source) { - assert(!entry.elt); + ASSERT(!entry.elt); entry.source->get_modified_regs(modified); if (!allow_side_effects) { // shouldn't allow skipping past a set! (may be too conservative?) return nullptr; } } else { - assert(entry.elt); + ASSERT(entry.elt); entry.elt->get_modified_regs(modified); if (!allow_side_effects && entry.elt->has_side_effects()) { // shouldn't allow skipping past something with a set! (also may be too conservative?) @@ -211,12 +211,12 @@ Form* FormStack::pop_reg(Register reg, FormElement* FormStack::pop_back(FormPool& pool) { auto& back = m_stack.back(); - assert(back.active); + ASSERT(back.active); back.active = false; if (back.elt) { return back.elt; } else { - assert(back.destination.has_value()); + ASSERT(back.destination.has_value()); auto elt = pool.alloc_element(*back.destination, back.source, back.sequence_point, back.set_type, back.set_info); back.source->parent_element = elt; @@ -234,7 +234,7 @@ bool is_op_in_place(SetVarElement* elt, auto result = match(matcher, elt->src()); if (result.matched) { auto first = result.maps.regs.at(0); - assert(first.has_value()); + ASSERT(first.has_value()); if (first->reg() != elt->dst().reg()) { return false; diff --git a/decompiler/IR2/FormStack.h b/decompiler/IR2/FormStack.h index 36a8b7ed96..bb5e74200c 100644 --- a/decompiler/IR2/FormStack.h +++ b/decompiler/IR2/FormStack.h @@ -83,12 +83,12 @@ class FormStack { if (!my_entry.destination) { return {}; } - assert(my_entry.source && !my_entry.elt); + ASSERT(my_entry.source && !my_entry.elt); } else { if (my_entry.destination) { return {}; } - assert(my_entry.elt && !my_entry.source); + ASSERT(my_entry.elt && !my_entry.source); } entries.push_back(my_entry); } else { @@ -100,7 +100,7 @@ class FormStack { void pop(int count) { for (int i = 0; i < count; i++) { - assert(!m_stack.empty()); + ASSERT(!m_stack.empty()); m_stack.pop_back(); } } @@ -125,7 +125,7 @@ class FormStack { return; } } - assert(false); + ASSERT(false); } int size() const { return m_stack.size(); } diff --git a/decompiler/IR2/GenericElementMatcher.cpp b/decompiler/IR2/GenericElementMatcher.cpp index 5833871f76..9084c07356 100644 --- a/decompiler/IR2/GenericElementMatcher.cpp +++ b/decompiler/IR2/GenericElementMatcher.cpp @@ -594,7 +594,7 @@ bool Matcher::do_match(Form* input, MatchResult::Maps* maps_out) const { } default: - assert(false); + ASSERT(false); return false; } } @@ -661,7 +661,7 @@ bool DerefTokenMatcher::do_match(const DerefToken& input, MatchResult::Maps* map } return false; default: - assert(false); + ASSERT(false); return false; } } @@ -719,7 +719,7 @@ bool GenericOpMatcher::do_match(GenericOperator& input, MatchResult::Maps* maps_ } return false; default: - assert(false); + ASSERT(false); return false; } } diff --git a/decompiler/IR2/IR2_common.h b/decompiler/IR2/IR2_common.h index 02c496f9d9..e51b063722 100644 --- a/decompiler/IR2/IR2_common.h +++ b/decompiler/IR2/IR2_common.h @@ -264,13 +264,13 @@ struct VariableNames { std::unordered_map use_def_info; void disable_use(const RegisterAccess& access) { - assert(access.mode() == AccessMode::READ); + ASSERT(access.mode() == AccessMode::READ); auto var_id = read_opid_to_varid.at(access.reg()).at(access.idx()); use_def_info.at(RegId(access.reg(), var_id)).disable_use(access.idx(), access.reg()); } void disable_def(const RegisterAccess& access, DecompWarnings& warnings) { - assert(access.mode() == AccessMode::WRITE); + ASSERT(access.mode() == AccessMode::WRITE); auto var_id = write_opid_to_varid.at(access.reg()).at(access.idx()); use_def_info.at(RegId(access.reg(), var_id)).disable_def(access.idx(), warnings); } diff --git a/decompiler/IR2/LabelDB.cpp b/decompiler/IR2/LabelDB.cpp index f6c7cc3c5a..9980f0e880 100644 --- a/decompiler/IR2/LabelDB.cpp +++ b/decompiler/IR2/LabelDB.cpp @@ -47,12 +47,12 @@ LabelDB::LabelDB(const std::unordered_map& config, m_labels_by_offset_into_seg.at(existing_info.target_segment)[existing_info.offset] = (int)i; } - assert(m_labels_by_name.size() == labels.size()); + ASSERT(m_labels_by_name.size() == labels.size()); size_t total_from_offsets = 0; for (int i = 0; i < N_SEG; i++) { total_from_offsets += m_labels_by_offset_into_seg[i].size(); } - assert(total_from_offsets == labels.size()); + ASSERT(total_from_offsets == labels.size()); // now config for (const auto& config_it : config) { diff --git a/decompiler/IR2/OpenGoalMapping.cpp b/decompiler/IR2/OpenGoalMapping.cpp index 21d89f3f60..ae486022a6 100644 --- a/decompiler/IR2/OpenGoalMapping.cpp +++ b/decompiler/IR2/OpenGoalMapping.cpp @@ -216,7 +216,7 @@ std::vector OpenGOALAsm::get_args(const std::vector(type); - assert(as_bitfield); + ASSERT(as_bitfield); auto field = try_find_field(ts, as_bitfield, 64, 64, true); if (field) { auto result = @@ -395,7 +395,7 @@ std::optional BitfieldAccessElement::get_set_field_0(const TypeSystem& u64 mask = step.amount; auto type = ts.lookup_type(m_type); auto as_bitfield = dynamic_cast(type); - assert(as_bitfield); + ASSERT(as_bitfield); // use the mask to figure out the field. auto field = find_field_from_mask(ts, as_bitfield, ~mask, m_got_pcpyud); if (field) { @@ -429,7 +429,7 @@ FormElement* BitfieldAccessElement::push_step(const BitfieldManip step, int start_bit = pcpyud_offset + shift_size - size; auto type = ts.lookup_type(m_type); auto as_bitfield = dynamic_cast(type); - assert(as_bitfield); + ASSERT(as_bitfield); auto field = find_field(ts, as_bitfield, start_bit, size, is_unsigned); auto result = pool.alloc_element(m_base, false, DerefToken::make_field_name(field.name())); @@ -443,7 +443,7 @@ FormElement* BitfieldAccessElement::push_step(const BitfieldManip step, int start_bit = 0 + pcpyud_offset; auto type = ts.lookup_type(m_type); auto as_bitfield = dynamic_cast(type); - assert(as_bitfield); + ASSERT(as_bitfield); auto field = find_field(ts, as_bitfield, start_bit, size, is_unsigned); auto result = pool.alloc_element(m_base, false, DerefToken::make_field_name(field.name())); @@ -460,7 +460,7 @@ FormElement* BitfieldAccessElement::push_step(const BitfieldManip step, int start_bit = 64; auto type = ts.lookup_type(m_type); auto as_bitfield = dynamic_cast(type); - assert(as_bitfield); + ASSERT(as_bitfield); auto field = find_field(ts, as_bitfield, start_bit, size, is_unsigned); auto result = pool.alloc_element(m_base, false, DerefToken::make_field_name(field.name())); @@ -484,7 +484,7 @@ FormElement* BitfieldAccessElement::push_step(const BitfieldManip step, auto type = ts.lookup_type(m_type); auto as_bitfield = dynamic_cast(type); - assert(as_bitfield); + ASSERT(as_bitfield); auto field = find_field(ts, as_bitfield, start_bit, size, is_unsigned); auto result = pool.alloc_element(m_base, false, DerefToken::make_field_name(field.name())); @@ -506,7 +506,7 @@ FormElement* BitfieldAccessElement::push_step(const BitfieldManip step, } auto type = ts.lookup_type(m_type); auto as_bitfield = dynamic_cast(type); - assert(as_bitfield); + ASSERT(as_bitfield); auto field = find_field_from_mask(ts, as_bitfield, m_steps.at(0).amount, false); // todo PCPYUP if (field) { auto get_field = pool.alloc_element(m_base, false, @@ -530,10 +530,10 @@ FormElement* BitfieldAccessElement::push_step(const BitfieldManip step, } auto type = ts.lookup_type(m_type); auto as_bitfield = dynamic_cast(type); - assert(as_bitfield); + ASSERT(as_bitfield); // use the mask to figure out the field. auto field = find_field_from_mask(ts, as_bitfield, ~mask, m_got_pcpyud); - assert(field); + ASSERT(field); bool is_signed = ts.tc(TypeSpec("int"), field->type()) && !ts.tc(TypeSpec("uint"), field->type()); @@ -564,9 +564,9 @@ FormElement* BitfieldAccessElement::push_step(const BitfieldManip step, u64 value = step.amount; auto type = ts.lookup_type(m_type); auto as_bitfield = dynamic_cast(type); - assert(as_bitfield); + ASSERT(as_bitfield); auto field = find_field_from_mask(ts, as_bitfield, value, m_got_pcpyud); - assert(field); + ASSERT(field); bool is_signed = ts.tc(TypeSpec("int"), field->type()) && !ts.tc(TypeSpec("uint"), field->type()); @@ -593,10 +593,10 @@ FormElement* BitfieldAccessElement::push_step(const BitfieldManip step, auto type = ts.lookup_type(m_type); auto as_bitfield = dynamic_cast(type); - assert(as_bitfield); + ASSERT(as_bitfield); // use the mask to figure out the field. auto field = find_field_from_mask(ts, as_bitfield, ~mask, m_got_pcpyud); - assert(field); + ASSERT(field); auto val = get_bitfield_initial_set(step.value, as_bitfield, ts, pcpyud_offset); @@ -634,7 +634,7 @@ std::vector compact_nested_logiors(GenericElement* input, const Env&) { GenericElement* next = input; while (next) { - assert(next->elts().size() == 2); + ASSERT(next->elts().size() == 2); result.push_back(next->elts().at(1)); auto next_next = strip_int_or_uint_cast(next->elts().at(0)); next = next_next->try_as_element(); @@ -808,7 +808,7 @@ std::optional> get_field_defs_from_expr(const BitFieldT BitField field_info; if (!type_info->lookup_field(maybe_field->field_name, &field_info)) { - assert(false); + ASSERT(false); } if (field_info.type() == TypeSpec("symbol") || field_info.type() == TypeSpec("type")) { maybe_field->value = strip_int_or_uint_cast(maybe_field->value); @@ -913,7 +913,7 @@ Form* cast_to_bitfield_enum(const EnumType* type_info, FormPool& pool, const Env& env, Form* in) { - assert(type_info->is_bitfield()); + ASSERT(type_info->is_bitfield()); auto integer = get_goal_integer_constant(strip_int_or_uint_cast(in), env); if (integer) { return cast_to_bitfield_enum(type_info, pool, env, *integer); @@ -928,7 +928,7 @@ Form* cast_to_int_enum(const EnumType* type_info, FormPool& pool, const Env& env, Form* in) { - assert(!type_info->is_bitfield()); + ASSERT(!type_info->is_bitfield()); auto integer = get_goal_integer_constant(strip_int_or_uint_cast(in), env); if (integer) { return cast_to_int_enum(type_info, pool, env, *integer); @@ -939,7 +939,7 @@ Form* cast_to_int_enum(const EnumType* type_info, } Form* cast_to_int_enum(const EnumType* type_info, FormPool& pool, const Env& env, s64 in) { - assert(!type_info->is_bitfield()); + ASSERT(!type_info->is_bitfield()); auto entry = decompile_int_enum_from_int(TypeSpec(type_info->get_name()), env.dts->ts, in); auto oper = GenericOperator::make_function( pool.alloc_single_element_form(nullptr, type_info->get_name())); @@ -948,7 +948,7 @@ Form* cast_to_int_enum(const EnumType* type_info, FormPool& pool, const Env& env } Form* cast_to_bitfield_enum(const EnumType* type_info, FormPool& pool, const Env& env, s64 in) { - assert(type_info->is_bitfield()); + ASSERT(type_info->is_bitfield()); auto elts = decompile_bitfield_enum_from_int(TypeSpec(type_info->get_name()), env.dts->ts, in); auto oper = GenericOperator::make_function( pool.alloc_single_element_form(nullptr, type_info->get_name())); diff --git a/decompiler/IR2/bitfields.h b/decompiler/IR2/bitfields.h index 79fd4015cb..2c92513fce 100644 --- a/decompiler/IR2/bitfields.h +++ b/decompiler/IR2/bitfields.h @@ -3,7 +3,7 @@ #include "common/common_types.h" #include "decompiler/IR2/Form.h" #include "decompiler/util/data_decompile.h" -#include "common/util/assert.h" +#include "common/util/Assert.h" namespace decompiler { struct BitfieldManip { @@ -30,7 +30,7 @@ struct BitfieldManip { } bool right_shift_unsigned() const { - assert(is_right_shift()); + ASSERT(is_right_shift()); return kind == Kind::RIGHT_SHIFT_LOGICAL || kind == Kind::RIGHT_SHIFT_LOGICAL_32BIT; } @@ -79,7 +79,7 @@ struct BitfieldManip { return "pextuw"; case Kind::INVALID: default: - assert(false); + ASSERT(false); } } @@ -173,7 +173,7 @@ class ModifiedCopyBitfieldElement : public FormElement { const std::vector mods() const { return m_field_modifications; } bool from_pcpyud() const { return m_from_pcpyud; } void clear_pcpyud_flag() { - assert(m_from_pcpyud); + ASSERT(m_from_pcpyud); m_from_pcpyud = false; } diff --git a/decompiler/ObjectFile/LinkedObjectFile.cpp b/decompiler/ObjectFile/LinkedObjectFile.cpp index ed935d025c..486fc366a6 100644 --- a/decompiler/ObjectFile/LinkedObjectFile.cpp +++ b/decompiler/ObjectFile/LinkedObjectFile.cpp @@ -14,7 +14,7 @@ #include "third-party/json.hpp" #include "common/log/log.h" #include "common/goos/PrettyPrinter.h" -#include "common/util/assert.h" +#include "common/util/Assert.h" namespace decompiler { /*! @@ -22,7 +22,7 @@ namespace decompiler { * This can only be done once, and must be done before adding any words. */ void LinkedObjectFile::set_segment_count(int n_segs) { - assert(segments == 0); + ASSERT(segments == 0); segments = n_segs; words_by_seg.resize(n_segs); label_per_seg_by_offset.resize(n_segs); @@ -56,8 +56,8 @@ int LinkedObjectFile::get_label_id_for(int seg, int offset) { } else { // return an existing label auto& label = labels.at(kv->second); - assert(label.offset == offset); - assert(label.target_segment == seg); + ASSERT(label.offset == offset); + ASSERT(label.target_segment == seg); return kv->second; } } @@ -96,7 +96,7 @@ Function& LinkedObjectFile::get_function_at_label(int label_id) { } } - assert(false); + ASSERT(false); return functions_by_seg.front().front(); // to avoid error } @@ -147,16 +147,16 @@ bool LinkedObjectFile::pointer_link_word(int source_segment, int source_offset, int dest_segment, int dest_offset) { - assert((source_offset % 4) == 0); + ASSERT((source_offset % 4) == 0); auto& word = words_by_seg.at(source_segment).at(source_offset / 4); - assert(word.kind() == LinkedWord::PLAIN_DATA); + ASSERT(word.kind() == LinkedWord::PLAIN_DATA); if (dest_offset / 4 > (int)words_by_seg.at(dest_segment).size()) { // printf("HACK bad link ignored!\n"); return false; } - assert(dest_offset / 4 <= (int)words_by_seg.at(dest_segment).size()); + ASSERT(dest_offset / 4 <= (int)words_by_seg.at(dest_segment).size()); word.set_to_pointer(LinkedWord::PTR, get_label_id_for(dest_segment, dest_offset)); return true; @@ -169,9 +169,9 @@ void LinkedObjectFile::symbol_link_word(int source_segment, int source_offset, const char* name, LinkedWord::Kind kind) { - assert((source_offset % 4) == 0); + ASSERT((source_offset % 4) == 0); auto& word = words_by_seg.at(source_segment).at(source_offset / 4); - // assert(word.kind == LinkedWord::PLAIN_DATA); + // ASSERT(word.kind == LinkedWord::PLAIN_DATA); if (word.kind() != LinkedWord::PLAIN_DATA) { printf("bad symbol link word\n"); } @@ -183,9 +183,9 @@ void LinkedObjectFile::symbol_link_word(int source_segment, * the symbol table register. */ void LinkedObjectFile::symbol_link_offset(int source_segment, int source_offset, const char* name) { - assert((source_offset % 4) == 0); + ASSERT((source_offset % 4) == 0); auto& word = words_by_seg.at(source_segment).at(source_offset / 4); - assert(word.kind() == LinkedWord::PLAIN_DATA); + ASSERT(word.kind() == LinkedWord::PLAIN_DATA); word.set_to_symbol(LinkedWord::SYM_OFFSET, name); } @@ -197,15 +197,15 @@ void LinkedObjectFile::pointer_link_split_word(int source_segment, int source_lo_offset, int dest_segment, int dest_offset) { - assert((source_hi_offset % 4) == 0); - assert((source_lo_offset % 4) == 0); + ASSERT((source_hi_offset % 4) == 0); + ASSERT((source_lo_offset % 4) == 0); auto& hi_word = words_by_seg.at(source_segment).at(source_hi_offset / 4); auto& lo_word = words_by_seg.at(source_segment).at(source_lo_offset / 4); - // assert(dest_offset / 4 <= (int)words_by_seg.at(dest_segment).size()); - assert(hi_word.kind() == LinkedWord::PLAIN_DATA); - assert(lo_word.kind() == LinkedWord::PLAIN_DATA); + // ASSERT(dest_offset / 4 <= (int)words_by_seg.at(dest_segment).size()); + ASSERT(hi_word.kind() == LinkedWord::PLAIN_DATA); + ASSERT(lo_word.kind() == LinkedWord::PLAIN_DATA); hi_word.set_to_pointer(LinkedWord::HI_PTR, get_label_id_for(dest_segment, dest_offset)); lo_word.set_to_pointer(LinkedWord::LO_PTR, hi_word.label_id()); @@ -244,7 +244,7 @@ static const char* segment_names[] = {"main segment", "debug segment", "top-leve std::string LinkedObjectFile::print_words() { std::string result; - assert(segments <= 3); + ASSERT(segments <= 3); for (int seg = segments; seg-- > 0;) { // segment header result += ";------------------------------------------\n; "; @@ -321,7 +321,7 @@ void LinkedObjectFile::find_code() { auto& seg = words_by_seg.front(); for (auto& word : seg) { if (word.kind() == LinkedWord::TYPE_PTR) { - assert(word.symbol_name() != "function"); + ASSERT(word.symbol_name() != "function"); } } offset_of_data_zone_by_seg.at(0) = 0; @@ -361,8 +361,8 @@ void LinkedObjectFile::find_code() { } } - assert(found_jr_ra); - assert(jr_ra_loc + 1 < words_by_seg.at(i).size()); + ASSERT(found_jr_ra); + ASSERT(jr_ra_loc + 1 < words_by_seg.at(i).size()); offset_of_data_zone_by_seg.at(i) = jr_ra_loc + 2; } else { @@ -380,7 +380,7 @@ void LinkedObjectFile::find_code() { for (size_t j = offset_of_data_zone_by_seg.at(i); j < words_by_seg.at(i).size(); j++) { auto& word = words_by_seg.at(i).at(j); if (word.kind() == LinkedWord::TYPE_PTR && word.symbol_name() == "function") { - assert(false); + ASSERT(false); } } @@ -390,7 +390,7 @@ void LinkedObjectFile::find_code() { } } else { // for files which we couldn't extract link data yet, they will have 0 segments and its ok. - assert(segments == 0); + ASSERT(segments == 0); } } @@ -400,7 +400,7 @@ void LinkedObjectFile::find_code() { void LinkedObjectFile::find_functions() { if (segments == 1) { // it's a v2 file, shouldn't have any functions - assert(offset_of_data_zone_by_seg.at(0) == 0); + ASSERT(offset_of_data_zone_by_seg.at(0) == 0); } else { // we assume functions don't have any data in between them, so we use the "function" type tag to // mark the end of the previous function and the start of the next. This means that some @@ -422,7 +422,7 @@ void LinkedObjectFile::find_functions() { } // mark this as a function, and try again from the current function start - assert(found_function_tag_loc); + ASSERT(found_function_tag_loc); stats.function_count++; functions_by_seg.at(seg).emplace_back(function_tag_loc, function_end); function_end = function_tag_loc; @@ -506,21 +506,21 @@ void LinkedObjectFile::process_fp_relative_links() { // other cases. Also, the position of the fp register is swapped between the two. case InstructionKind::DADDU: case InstructionKind::ADDU: { - assert(prev_instr); + ASSERT(prev_instr); if (prev_instr->kind != InstructionKind::ORI) { lg::error("Failed to process fp relative links for (d)addu preceded by: {}", prev_instr->to_string(labels)); return; } - assert(prev_instr->kind == InstructionKind::ORI); + ASSERT(prev_instr->kind == InstructionKind::ORI); int offset_reg_src_id = instr.kind == InstructionKind::DADDU ? 0 : 1; auto offset_reg = instr.get_src(offset_reg_src_id).get_reg(); - assert(offset_reg == prev_instr->get_dst(0).get_reg()); - assert(offset_reg == prev_instr->get_src(0).get_reg()); + ASSERT(offset_reg == prev_instr->get_dst(0).get_reg()); + ASSERT(offset_reg == prev_instr->get_src(0).get_reg()); auto& atom = prev_instr->get_imm_src(); int additional_offset = 0; if (pprev_instr && pprev_instr->kind == InstructionKind::LUI) { - assert(pprev_instr->get_dst(0).get_reg() == offset_reg); + ASSERT(pprev_instr->get_dst(0).get_reg() == offset_reg); additional_offset = (1 << 16) * pprev_instr->get_imm_src().get_imm(); pprev_instr->get_imm_src().set_label( get_label_id_for(seg, current_fp + atom.get_imm() + additional_offset)); @@ -532,7 +532,7 @@ void LinkedObjectFile::process_fp_relative_links() { default: printf("unknown fp using op: %s\n", instr.to_string(labels).c_str()); - assert(false); + ASSERT(false); } } } @@ -564,11 +564,11 @@ std::string LinkedObjectFile::print_function_disassembly(Function& func, } for (int j = 1; j < 4; j++) { - // assert(get_label_at(seg, (func.start_word + i)*4 + j) == -1); + // ASSERT(get_label_at(seg, (func.start_word + i)*4 + j) == -1); if (get_label_at(seg, (func.start_word + i) * 4 + j) != -1) { result += "BAD OFFSET LABEL: "; result += labels.at(get_label_at(seg, (func.start_word + i) * 4 + j)).name + "\n"; - assert(false); + ASSERT(false); } } @@ -695,7 +695,7 @@ std::string LinkedObjectFile::print_asm_function_disassembly(const std::string& std::string LinkedObjectFile::print_disassembly(bool write_hex) { std::string result; - assert(segments <= 3); + ASSERT(segments <= 3); for (int seg = segments; seg-- > 0;) { // segment header result += ";------------------------------------------\n; "; @@ -819,7 +819,7 @@ std::string LinkedObjectFile::print_scripts() { * Is the object pointed to the empty list? */ bool LinkedObjectFile::is_empty_list(int seg, int byte_idx) { - assert((byte_idx % 4) == 0); + ASSERT((byte_idx % 4) == 0); auto& word = words_by_seg.at(seg).at(byte_idx / 4); return word.kind() == LinkedWord::EMPTY_PTR; } @@ -857,7 +857,7 @@ goos::Object LinkedObjectFile::to_form_script(int seg, int word_idx, std::vector return result; } else { // cdr object should be aligned. - assert((cdr_addr % 4) == 0); + ASSERT((cdr_addr % 4) == 0); auto& cdr_word = words_by_seg.at(seg).at(cdr_addr / 4); // check for proper list if (cdr_word.kind() == LinkedWord::PTR && @@ -875,7 +875,7 @@ goos::Object LinkedObjectFile::to_form_script(int seg, int word_idx, std::vector } } else { // improper list, should be impossible to get here because of earlier checks - assert(false); + ASSERT(false); } } @@ -936,7 +936,7 @@ goos::Object LinkedObjectFile::to_form_script_object(int seg, std::string debug; append_word_to_string(debug, word); printf("don't know how to print %s\n", debug.c_str()); - assert(false); + ASSERT(false); } } break; @@ -944,21 +944,21 @@ goos::Object LinkedObjectFile::to_form_script_object(int seg, default: // pointers should be aligned! printf("align %d\n", byte_idx & 7); - assert(false); + ASSERT(false); } return result; } u32 LinkedObjectFile::read_data_word(const DecompilerLabel& label) { - assert(0 == (label.offset % 4)); + ASSERT(0 == (label.offset % 4)); auto& word = words_by_seg.at(label.target_segment).at(label.offset / 4); - assert(word.kind() == LinkedWord::Kind::PLAIN_DATA); + ASSERT(word.kind() == LinkedWord::Kind::PLAIN_DATA); return word.data; } std::string LinkedObjectFile::get_goal_string_by_label(const DecompilerLabel& label) const { - assert(0 == (label.offset % 4)); + ASSERT(0 == (label.offset % 4)); return get_goal_string(label.target_segment, (label.offset / 4) - 1, false); } diff --git a/decompiler/ObjectFile/LinkedObjectFileCreation.cpp b/decompiler/ObjectFile/LinkedObjectFileCreation.cpp index 58925b0682..6f96eb7bb8 100644 --- a/decompiler/ObjectFile/LinkedObjectFileCreation.cpp +++ b/decompiler/ObjectFile/LinkedObjectFileCreation.cpp @@ -10,7 +10,7 @@ #include "decompiler/util/DecompilerTypeSystem.h" #include "common/link_types.h" #include "common/util/BitUtils.h" -#include "common/util/assert.h" +#include "common/util/Assert.h" namespace decompiler { // There are three link versions: @@ -133,9 +133,9 @@ static uint32_t c_symlink2(LinkedObjectFile& f, } else { // offset link - replace lower 16 bits with symbol table offset. - assert((code_value & 0xffff) == 0 || (code_value & 0xffff) == 0xffff); - assert(kind == SymbolLinkKind::SYMBOL); - // assert(false); // this case does not occur in V2/V4. It does in V3. + ASSERT((code_value & 0xffff) == 0 || (code_value & 0xffff) == 0xffff); + ASSERT(kind == SymbolLinkKind::SYMBOL); + // ASSERT(false); // this case does not occur in V2/V4. It does in V3. f.symbol_link_offset(seg_id, code_ptr_offset - initial_offset, name); } @@ -190,7 +190,7 @@ static uint32_t c_symlink3(LinkedObjectFile& f, f.symbol_link_word(seg, code_ptr - initial_offset, name, word_kind); } else { f.stats.v3_symbol_link_offset++; - assert(kind == SymbolLinkKind::SYMBOL); + ASSERT(kind == SymbolLinkKind::SYMBOL); f.symbol_link_offset(seg, code_ptr - initial_offset, name); } @@ -221,7 +221,7 @@ static void link_v2_or_v4(LinkedObjectFile& f, const std::string& name, DecompilerTypeSystem& dts) { const auto* header = (const LinkHeaderV4*)&data.at(0); - assert(header->version == 4 || header->version == 2); + ASSERT(header->version == 4 || header->version == 2); // these are different depending on the version. uint32_t code_offset, link_data_offset, code_size; @@ -241,7 +241,7 @@ static void link_v2_or_v4(LinkedObjectFile& f, code_offset = header->length; // we have to compute the code size ourself code_size = data.size() - code_offset; - assert(header->type_tag == 0xffffffff); + ASSERT(header->type_tag == 0xffffffff); } f.stats.total_code_bytes += code_size; @@ -251,7 +251,7 @@ static void link_v2_or_v4(LinkedObjectFile& f, const uint8_t* code_start = &data.at(code_offset); const uint8_t* code_end = &data.at(code_offset + code_size - 1) + 1; // get the pointer to one past the end. - assert(((code_end - code_start) % 4) == 0); + ASSERT(((code_end - code_start) % 4) == 0); f.set_segment_count(1); for (auto x = code_start; x < code_end; x += 4) { f.push_back_word_to_segment(*((const uint32_t*)x), 0); @@ -262,9 +262,9 @@ static void link_v2_or_v4(LinkedObjectFile& f, uint32_t link_ptr_offset = link_data_offset; link_ptr_offset += sizeof(LinkHeaderV2); auto* link_header_v2 = (const LinkHeaderV2*)(link_data); - assert(link_header_v2->type_tag == 0xffffffff); - assert(link_header_v2->version == 2); - assert(link_header_v2->length == header->length); + ASSERT(link_header_v2->type_tag == 0xffffffff); + ASSERT(link_header_v2->version == 2); + ASSERT(link_header_v2->length == header->length); f.stats.total_v2_link_bytes += link_header_v2->length; // first "section" of link data is a list of where all the pointer are. @@ -341,7 +341,7 @@ static void link_v2_or_v4(LinkedObjectFile& f, // always happens. link_ptr_offset--; } else { - assert(false); + ASSERT(false); } s_name = (const char*)(&data.at(link_ptr_offset)); @@ -360,12 +360,12 @@ static void link_v2_or_v4(LinkedObjectFile& f, // just be on the safe side. // (see the !symbolValue case in intern_type_from_c) } else { - assert(false); + ASSERT(false); } } if (std::string("_empty_") == s_name) { - assert(kind == SymbolLinkKind::SYMBOL); + ASSERT(kind == SymbolLinkKind::SYMBOL); kind = SymbolLinkKind::EMPTY_LIST; } @@ -378,10 +378,10 @@ static void link_v2_or_v4(LinkedObjectFile& f, } // check length - assert(link_header_v2->length == align64(link_ptr_offset - link_data_offset + 1)); + ASSERT(link_header_v2->length == align64(link_ptr_offset - link_data_offset + 1)); size_t expected_end = header->version == 4 ? data.size() : link_header_v2->length; while (link_ptr_offset < expected_end) { - assert(data.at(link_ptr_offset) == 0); + ASSERT(data.at(link_ptr_offset) == 0); link_ptr_offset++; } } @@ -391,7 +391,7 @@ static void assert_string_empty_after(const char* str, int size) { while (*ptr) ptr++; while (ptr - str < size) { - assert(!*ptr); + ASSERT(!*ptr); ptr++; } } @@ -405,11 +405,11 @@ static void link_v5(LinkedObjectFile& f, printf("abandon %s!\n", name.c_str()); return; } - assert(header->type_tag == 0); - assert(name == header->name); - assert(header->n_segments == 3); - assert(header->pad == 0x50); - assert(header->length_to_get_to_code - header->link_length == 0x50); + ASSERT(header->type_tag == 0); + ASSERT(name == header->name); + ASSERT(header->n_segments == 3); + ASSERT(header->pad == 0x50); + ASSERT(header->length_to_get_to_code - header->link_length == 0x50); f.set_segment_count(3); @@ -433,15 +433,15 @@ static void link_v5(LinkedObjectFile& f, for (int i = 0; i < 3; i++) { segment_data_offsets[i] = data_ptr_offset + header->segment_info[i].data; segment_link_offsets[i] = header->segment_info[i].relocs + 0x50; - assert(header->segment_info[i].magic == 1); + ASSERT(header->segment_info[i].magic == 1); } // check that the data region is filled for (int i = 0; i < 2; i++) { - assert(align16(segment_data_offsets[i] + header->segment_info[i].size) == + ASSERT(align16(segment_data_offsets[i] + header->segment_info[i].size) == segment_data_offsets[i + 1]); } - assert(align16(segment_data_offsets[2] + header->segment_info[2].size) == data.size()); + ASSERT(align16(segment_data_offsets[2] + header->segment_info[2].size) == data.size()); // loop over segments (reverse order for now) for (int seg_id = 3; seg_id-- > 0;) { @@ -471,8 +471,8 @@ static void link_v5(LinkedObjectFile& f, auto data_ptr = base_ptr - 4; auto link_ptr = segment_link_offsets[seg_id]; - assert((data_ptr % 4) == 0); - assert((segment_size % 4) == 0); + ASSERT((data_ptr % 4) == 0); + ASSERT((segment_size % 4) == 0); auto code_start = (const uint32_t*)(&data.at(data_ptr + 4)); auto code_end = ((const uint32_t*)(&data.at(data_ptr + segment_size))) + 1; @@ -503,10 +503,10 @@ static void link_v5(LinkedObjectFile& f, f.stats.v3_split_pointers++; auto dest_seg = (old_code >> 8) & 0xf; auto lo_hi_offset = (old_code >> 12) & 0xf; - assert(lo_hi_offset); - assert(dest_seg < 3); + ASSERT(lo_hi_offset); + ASSERT(dest_seg < 3); auto offset_upper = old_code & 0xff; - // assert(offset_upper == 0); + // ASSERT(offset_upper == 0); uint32_t low_code = *(const uint32_t*)(&data.at(data_ptr + 4 * lo_hi_offset)); uint32_t offset = low_code & 0xffff; if (offset_upper) { @@ -560,7 +560,7 @@ static void link_v5(LinkedObjectFile& f, SymbolLinkKind::SYMBOL, sname, seg_id, dts); } } else if ((reloc & 0x3f) == 0x3f) { - assert(false); // todo, does this ever get hit? + ASSERT(false); // todo, does this ever get hit? } else { int n_methods_base = reloc & 0x3f; int n_methods = n_methods_base * 4; @@ -582,21 +582,21 @@ static void link_v5(LinkedObjectFile& f, segment_link_ends[seg_id] = link_ptr; } - assert(segment_link_offsets[0] == 128); + ASSERT(segment_link_offsets[0] == 128); if (header->segment_info[0].size) { - assert(segment_link_ends[0] + 1 == segment_link_offsets[1]); + ASSERT(segment_link_ends[0] + 1 == segment_link_offsets[1]); } else { - assert(segment_link_offsets[0] + 2 == segment_link_offsets[1]); + ASSERT(segment_link_offsets[0] + 2 == segment_link_offsets[1]); } if (header->segment_info[1].size) { - assert(segment_link_ends[1] + 1 == segment_link_offsets[2]); + ASSERT(segment_link_ends[1] + 1 == segment_link_offsets[2]); } else { - assert(segment_link_offsets[1] + 2 == segment_link_offsets[2]); + ASSERT(segment_link_offsets[1] + 2 == segment_link_offsets[2]); } - assert(align16(segment_link_ends[2] + 2) == segment_data_offsets[0]); + ASSERT(align16(segment_link_ends[2] + 2) == segment_data_offsets[0]); } static void link_v3(LinkedObjectFile& f, @@ -605,14 +605,14 @@ static void link_v3(LinkedObjectFile& f, DecompilerTypeSystem& dts, int game_version) { auto header = (const LinkHeaderV3*)(&data.at(0)); - assert(name == header->name); - assert(header->segments == 3); + ASSERT(name == header->name); + ASSERT(header->segments == 3); f.set_segment_count(3); assert_string_empty_after(header->name, 64); for (int i = 0; i < 3; i++) { - assert(header->segment_info[i].magic == 0); + ASSERT(header->segment_info[i].magic == 0); // printf(" [%d] %d %d %d %d\n", i, header->segment_info[i].size, // header->segment_info[i].data, header->segment_info[i].magic, // header->segment_info[i].relocs); @@ -631,10 +631,10 @@ static void link_v3(LinkedObjectFile& f, // check that the data region is filled for (int i = 0; i < 2; i++) { - assert(align16(segment_data_offsets[i] + header->segment_info[i].size) == + ASSERT(align16(segment_data_offsets[i] + header->segment_info[i].size) == segment_data_offsets[i + 1]); } - assert(align16(segment_data_offsets[2] + header->segment_info[2].size) == data.size()); + ASSERT(align16(segment_data_offsets[2] + header->segment_info[2].size) == data.size()); // todo - check link region is filled. @@ -673,8 +673,8 @@ static void link_v3(LinkedObjectFile& f, auto data_ptr = base_ptr - 4; auto link_ptr = segment_link_offsets[seg_id]; - assert((data_ptr % 4) == 0); - assert((segment_size % 4) == 0); + ASSERT((data_ptr % 4) == 0); + ASSERT((segment_size % 4) == 0); auto code_start = (const uint32_t*)(&data.at(data_ptr + 4)); auto code_end = ((const uint32_t*)(&data.at(data_ptr + segment_size))) + 1; @@ -705,10 +705,10 @@ static void link_v3(LinkedObjectFile& f, f.stats.v3_split_pointers++; auto dest_seg = (old_code >> 8) & 0xf; auto lo_hi_offset = (old_code >> 12) & 0xf; - assert(lo_hi_offset); - assert(dest_seg < 3); + ASSERT(lo_hi_offset); + ASSERT(dest_seg < 3); auto offset_upper = old_code & 0xff; - // assert(offset_upper == 0); + // ASSERT(offset_upper == 0); uint32_t low_code = *(const uint32_t*)(&data.at(data_ptr + 4 * lo_hi_offset)); uint32_t offset = low_code & 0xffff; if (offset_upper) { @@ -759,7 +759,7 @@ static void link_v3(LinkedObjectFile& f, } if (std::string("_empty_") == s_name) { - assert(kind == SymbolLinkKind::SYMBOL); + ASSERT(kind == SymbolLinkKind::SYMBOL); kind = SymbolLinkKind::EMPTY_LIST; } @@ -770,21 +770,21 @@ static void link_v3(LinkedObjectFile& f, segment_link_ends[seg_id] = link_ptr; } - assert(segment_link_offsets[0] == 128); + ASSERT(segment_link_offsets[0] == 128); if (header->segment_info[0].size) { - assert(segment_link_ends[0] + 1 == segment_link_offsets[1]); + ASSERT(segment_link_ends[0] + 1 == segment_link_offsets[1]); } else { - assert(segment_link_offsets[0] + 2 == segment_link_offsets[1]); + ASSERT(segment_link_offsets[0] + 2 == segment_link_offsets[1]); } if (header->segment_info[1].size) { - assert(segment_link_ends[1] + 1 == segment_link_offsets[2]); + ASSERT(segment_link_ends[1] + 1 == segment_link_offsets[2]); } else { - assert(segment_link_offsets[1] + 2 == segment_link_offsets[2]); + ASSERT(segment_link_offsets[1] + 2 == segment_link_offsets[2]); } - assert(align16(segment_link_ends[2] + 2) == segment_data_offsets[0]); + ASSERT(align16(segment_link_ends[2] + 2) == segment_data_offsets[0]); } /*! @@ -799,16 +799,16 @@ LinkedObjectFile to_linked_object_file(const std::vector& data, // use appropriate linker if (header->version == 3) { - assert(header->type_tag == 0); + ASSERT(header->type_tag == 0); link_v3(result, data, name, dts, game_version); } else if (header->version == 4 || header->version == 2) { - assert(header->type_tag == 0xffffffff); + ASSERT(header->type_tag == 0xffffffff); link_v2_or_v4(result, data, name, dts); } else if (header->version == 5) { link_v5(result, data, name, dts); } else { printf("Unsupported version %d\n", header->version); - assert(false); + ASSERT(false); } return result; diff --git a/decompiler/ObjectFile/LinkedWord.h b/decompiler/ObjectFile/LinkedWord.h index 188a99fce8..dc278d7bfc 100644 --- a/decompiler/ObjectFile/LinkedWord.h +++ b/decompiler/ObjectFile/LinkedWord.h @@ -9,7 +9,7 @@ #include #include #include "common/common_types.h" -#include "common/util/assert.h" +#include "common/util/Assert.h" namespace decompiler { class LinkedWord { @@ -114,7 +114,7 @@ class LinkedWord { } u8 get_byte(int idx) const { - assert(kind() == PLAIN_DATA); + ASSERT(kind() == PLAIN_DATA); switch (idx) { case 0: return data & 0xff; @@ -125,7 +125,7 @@ class LinkedWord { case 3: return (data >> 24) & 0xff; default: - assert(false); + ASSERT(false); return 0; } } @@ -134,12 +134,12 @@ class LinkedWord { Kind kind() const { return m_kind; } u32 label_id() const { - assert(m_kind == PTR || m_kind == LO_PTR || m_kind == HI_PTR); + ASSERT(m_kind == PTR || m_kind == LO_PTR || m_kind == HI_PTR); return m_data_ptr; } std::string symbol_name() const { - assert(holds_string()); + ASSERT(holds_string()); return (const char*)(m_data_ptr); } diff --git a/decompiler/ObjectFile/ObjectFileDB.cpp b/decompiler/ObjectFile/ObjectFileDB.cpp index 222680c39d..76a1207950 100644 --- a/decompiler/ObjectFile/ObjectFileDB.cpp +++ b/decompiler/ObjectFile/ObjectFileDB.cpp @@ -65,8 +65,8 @@ std::string obj_filename_to_name(const std::string& x) { } } - assert(last_dot > last_slash + 1); - assert(last_slash + 1 < x.length()); + ASSERT(last_dot > last_slash + 1); + ASSERT(last_slash + 1 < x.length()); return x.substr(last_slash + 1, last_dot - last_slash - 1); } } // namespace @@ -96,13 +96,13 @@ ObjectFileData& ObjectFileDB::lookup_record(const ObjectFileRecord& rec) { for (auto& x : obj_files_by_name[rec.name]) { if (x.record.version == rec.version) { - assert(x.record.hash == rec.hash); - assert(!result); + ASSERT(x.record.hash == rec.hash); + ASSERT(!result); result = &x; } } - assert(result); + ASSERT(result); return *result; } @@ -190,7 +190,7 @@ void ObjectFileDB::load_map_file(const std::string& map_data) { auto kv = dgo_obj_name_map[dgo].find(game_name_with_ag); if (kv != dgo_obj_name_map[dgo].end()) { lg::error("Object {} in dgo {} occurs more than one time.", game_name_with_ag, dgo); - assert(false); + ASSERT(false); } dgo_obj_name_map[dgo][game_name_with_ag] = mapped_name; } @@ -212,7 +212,7 @@ void ObjectFileDB::get_objs_from_dgo(const std::string& filename, const Config& auto header = reader.read(); auto dgo_base_name = file_util::base_name(filename); - assert(header.name == dgo_base_name); + ASSERT(header.name == dgo_base_name); assert_string_empty_after(header.name, 60); // get all obj files... @@ -226,11 +226,11 @@ void ObjectFileDB::get_objs_from_dgo(const std::string& filename, const Config& reader.ffwd(reader.bytes_left()); continue; } else { - assert(false); + ASSERT(false); } } } else { - assert(reader.bytes_left() >= obj_header.object_count); + ASSERT(reader.bytes_left() >= obj_header.object_count); } if (std::string(obj_header.name).find("-ag") != std::string::npos) { @@ -238,7 +238,7 @@ void ObjectFileDB::get_objs_from_dgo(const std::string& filename, const Config& "Object file {} has \"-ag\" in its name. This will break any tools which use this to " "detect an art group", obj_header.name); - assert(false); + ASSERT(false); } auto name = get_object_file_name(obj_header.name, reader.here(), obj_header.object_count); @@ -249,7 +249,7 @@ void ObjectFileDB::get_objs_from_dgo(const std::string& filename, const Config& } // check we're at the end - assert(0 == reader.bytes_left()); + ASSERT(0 == reader.bytes_left()); } /*! @@ -270,7 +270,7 @@ void ObjectFileDB::add_obj_from_dgo(const std::string& obj_name, } } stats.total_obj_files++; - assert(obj_size > 128); + ASSERT(obj_size > 128); uint16_t version = *(const uint16_t*)(obj_data + 8); auto hash = file_util::crc32(obj_data, obj_size); @@ -279,12 +279,12 @@ void ObjectFileDB::add_obj_from_dgo(const std::string& obj_name, for (auto& e : obj_files_by_name[obj_name]) { if (e.data.size() == obj_size && e.record.hash == hash) { // just to make sure we don't have a hash collision. - assert(!memcmp(obj_data, e.data.data(), obj_size)); + ASSERT(!memcmp(obj_data, e.data.data(), obj_size)); // already got it! e.reference_count++; auto& rec = e.record; - assert(name_in_dgo == e.name_in_dgo); + ASSERT(name_in_dgo == e.name_in_dgo); e.dgo_names.push_back(dgo_name); obj_files_by_dgo[dgo_name].push_back(rec); duplicated = true; @@ -316,13 +316,13 @@ void ObjectFileDB::add_obj_from_dgo(const std::string& obj_name, auto dgo_kv = dgo_obj_name_map.find(strip_dgo_extension(dgo_name)); if (dgo_kv == dgo_obj_name_map.end()) { lg::error("Object {} is from DGO {}, but this DGO was not in the map.", obj_name, dgo_name); - assert(false); + ASSERT(false); } auto name_kv = dgo_kv->second.find(obj_name); if (name_kv == dgo_kv->second.end()) { lg::error("Object {} from DGO {} was not found in the name map.", obj_name, dgo_name); - assert(false); + ASSERT(false); } data.name_from_map = name_kv->second; } @@ -384,7 +384,7 @@ std::string ObjectFileDB::generate_obj_listing(const std::unordered_set= 5); + ASSERT(y.length() >= 5); std::string new_str = y == "NO-XGO" ? y : y.substr(0, y.length() - 4); dgos += "\"" + new_str + "\", "; } @@ -603,7 +603,7 @@ std::string ObjectFileDB::process_tpages(TextureDB& tex_db) { } }); - assert(tpage_dir_count <= 1); + ASSERT(tpage_dir_count <= 1); lg::info("Processed {} / {} textures ({} px) {:.2f}% in {:.2f} ms", success, total, total_px, 100.f * float(success) / float(total), timer.getMs()); @@ -631,7 +631,7 @@ std::string ObjectFileDB::process_game_text_files(GameTextVersion version) { string_count += statistics.total_text; char_count += statistics.total_chars; if (text_by_language_by_id.find(statistics.language) != text_by_language_by_id.end()) { - assert(false); + ASSERT(false); } text_by_language_by_id[statistics.language] = std::move(statistics.text); } @@ -653,7 +653,7 @@ std::string ObjectFileDB::process_game_count_file() { for_each_obj([&](ObjectFileData& data) { if (data.name_in_dgo == "game-cnt") { - assert(!found); + ASSERT(!found); found = true; result = write_game_count(process_game_count(data)); } @@ -683,10 +683,10 @@ void ObjectFileDB::analyze_functions_ir1(const Config& config) { for_each_obj([&](ObjectFileData& data) { if (data.linked_data.segments == 3) { // the top level segment should have a single function - assert(data.linked_data.functions_by_seg.at(2).size() == 1); + ASSERT(data.linked_data.functions_by_seg.at(2).size() == 1); auto& func = data.linked_data.functions_by_seg.at(2).front(); - assert(func.guessed_name.empty()); + ASSERT(func.guessed_name.empty()); func.guessed_name.set_as_top_level(data.to_unique_name()); func.find_global_function_defs(data.linked_data, dts); func.find_type_defs(data.linked_data, dts); diff --git a/decompiler/ObjectFile/ObjectFileDB.h b/decompiler/ObjectFile/ObjectFileDB.h index db652bec27..f87012a5f5 100644 --- a/decompiler/ObjectFile/ObjectFileDB.h +++ b/decompiler/ObjectFile/ObjectFileDB.h @@ -15,7 +15,7 @@ #include "common/common_types.h" #include "decompiler/data/TextureDB.h" #include "decompiler/analysis/symbol_def_map.h" -#include "common/util/assert.h" +#include "common/util/Assert.h" namespace decompiler { /*! @@ -125,7 +125,7 @@ class ObjectFileDB { */ template void for_each_obj(Func f) { - assert(obj_files_by_name.size() == obj_file_order.size()); + ASSERT(obj_files_by_name.size() == obj_file_order.size()); for (const auto& name : obj_file_order) { for (auto& obj : obj_files_by_name.at(name)) { // lg::info("{}...", name); diff --git a/decompiler/ObjectFile/ObjectFileDB_IR2.cpp b/decompiler/ObjectFile/ObjectFileDB_IR2.cpp index 09732dd883..a9146364f5 100644 --- a/decompiler/ObjectFile/ObjectFileDB_IR2.cpp +++ b/decompiler/ObjectFile/ObjectFileDB_IR2.cpp @@ -185,10 +185,10 @@ void ObjectFileDB::ir2_top_level_pass(const Config& config) { for_each_obj([&](ObjectFileData& data) { if (data.linked_data.segments == 3) { // the top level segment should have a single function - assert(data.linked_data.functions_by_seg.at(2).size() == 1); + ASSERT(data.linked_data.functions_by_seg.at(2).size() == 1); auto& func = data.linked_data.functions_by_seg.at(2).front(); - assert(func.guessed_name.empty()); + ASSERT(func.guessed_name.empty()); func.guessed_name.set_as_top_level(data.to_unique_name()); func.find_global_function_defs(data.linked_data, dts); func.find_type_defs(data.linked_data, dts); @@ -224,7 +224,7 @@ void ObjectFileDB::ir2_top_level_pass(const Config& config) { total_unknowns++; break; default: - assert(false); + ASSERT(false); } total_functions++; @@ -296,8 +296,8 @@ void ObjectFileDB::ir2_basic_block_pass(int seg, const Config& config, ObjectFil func.analyze_prologue(data.linked_data); } else { // manually exclude the type tag from the basic block. - assert(func.basic_blocks.front().start_word == 0); - assert(func.basic_blocks.front().end_word >= 1); + ASSERT(func.basic_blocks.front().start_word == 0); + ASSERT(func.basic_blocks.front().end_word >= 1); func.basic_blocks.front().start_word = 1; } @@ -629,7 +629,7 @@ std::string ObjectFileDB::ir2_to_file(ObjectFileData& data, const Config& config std::string result; const char* segment_names[] = {"main segment", "debug segment", "top-level segment"}; - assert(data.linked_data.segments <= 3); + ASSERT(data.linked_data.segments <= 3); for (int seg = data.linked_data.segments; seg-- > 0;) { // segment header result += ";------------------------------------------\n; "; @@ -676,7 +676,7 @@ std::string ObjectFileDB::ir2_to_file(ObjectFileData& data, const Config& config } // check for no misaligned labels in code segments. for (int j = 1; j < 4; j++) { - assert(data.linked_data.get_label_at(seg, (func.start_word + instr_idx) * 4 + j) == + ASSERT(data.linked_data.get_label_at(seg, (func.start_word + instr_idx) * 4 + j) == -1); } @@ -791,7 +791,7 @@ std::string ObjectFileDB::ir2_function_to_string(ObjectFileData& data, Function& } // check for no misaligned labels in code segments. for (int j = 1; j < 4; j++) { - assert(data.linked_data.get_label_at(seg, (func.start_word + i) * 4 + j) == -1); + ASSERT(data.linked_data.get_label_at(seg, (func.start_word + i) * 4 + j) == -1); } // print the assembly instruction @@ -815,7 +815,7 @@ std::string ObjectFileDB::ir2_function_to_string(ObjectFileData& data, Function& in_delay_slot = true; } total_instructions_printed++; - assert(last_instr_printed + 1 == i); + ASSERT(last_instr_printed + 1 == i); last_instr_printed = i; }; @@ -909,7 +909,7 @@ std::string ObjectFileDB::ir2_function_to_string(ObjectFileData& data, Function& result += "\n"; - assert(total_instructions_printed == (func.end_word - func.start_word - 1)); + ASSERT(total_instructions_printed == (func.end_word - func.start_word - 1)); return result; } @@ -983,7 +983,7 @@ bool ObjectFileDB::lookup_function_type(const FunctionName& name, mi.type.substitute_for_method_call(name.type_name)); return true; } else { - assert(false); + ASSERT(false); } return false; } @@ -994,7 +994,7 @@ std::string ObjectFileDB::ir2_final_out(ObjectFileData& data, std::string result; result += ";;-*-Lisp-*-\n"; result += "(in-package goal)\n\n"; - assert(data.linked_data.functions_by_seg.at(TOP_LEVEL_SEGMENT).size() == 1); + ASSERT(data.linked_data.functions_by_seg.at(TOP_LEVEL_SEGMENT).size() == 1); auto top_level = data.linked_data.functions_by_seg.at(TOP_LEVEL_SEGMENT).at(0); result += write_from_top_level(top_level, dts, data.linked_data, skip_functions); result += "\n\n"; diff --git a/decompiler/VuDisasm/VuDisassembler.cpp b/decompiler/VuDisasm/VuDisassembler.cpp index 73b969b8d9..e4c2197ba7 100644 --- a/decompiler/VuDisasm/VuDisassembler.cpp +++ b/decompiler/VuDisasm/VuDisassembler.cpp @@ -4,7 +4,7 @@ #include "VuDisassembler.h" #include "third-party/fmt/core.h" #include "common/util/print_float.h" -#include "common/util/assert.h" +#include "common/util/Assert.h" namespace decompiler { @@ -226,7 +226,7 @@ VuDisassembler::VuDisassembler(VuKind kind) : m_kind(kind) { * Add a VU operation to the decode table */ VuDisassembler::OpInfo& VuDisassembler::add_op(VuInstrK kind, const std::string& name) { - assert((int)kind < (int)VuInstrK::INVALID); + ASSERT((int)kind < (int)VuInstrK::INVALID); auto& elt = m_op_info[(int)kind]; elt.name = name; elt.known = true; @@ -291,14 +291,14 @@ VuInstrK VuDisassembler::lower_kind(u32 in) { return VuInstrK::ERLENG; } fmt::print("Unknown lower special: 0b{:b}\n", in); - assert(false); + ASSERT(false); } else { - assert((op & 0b1000000) == 0); - assert(op < 64); + ASSERT((op & 0b1000000) == 0); + ASSERT(op < 64); auto elt = m_lower_op6_table[(int)op]; if (!elt.known) { fmt::print("Invalid lower op6: 0b{:b} 0b{:b} 0x{:x}\n", op, in, in); - assert(false); + ASSERT(false); } return elt.kind; } @@ -354,20 +354,20 @@ VuInstrK VuDisassembler::upper_kind(u32 in) { case 0b01011'1111'10: return VuInstrK::OPMULA; case 0b01011'1111'11: - assert(upper_dest_mask(in) == 0); - assert(upper_fs(in) == 0); - assert(upper_ft(in) == 0); + ASSERT(upper_dest_mask(in) == 0); + ASSERT(upper_fs(in) == 0); + ASSERT(upper_ft(in) == 0); return VuInstrK::NOP; break; default: fmt::print("Invalid op11: 0b{:b}\n", upper_op11(in)); - assert(false); + ASSERT(false); } } if (!upper_info.known) { fmt::print("Invalid upper op6: 0b{:b}\n", upper_op6(in)); - assert(false); + ASSERT(false); } return upper_info.kind; } @@ -382,14 +382,14 @@ s32 VuDisassembler::get_instruction_index_mask() { case VU1: return (16384 / 8) - 1; default: - assert(false); + ASSERT(false); } } VuProgram VuDisassembler::disassemble(void* data, int size_bytes, bool debug_print) { auto bytes = (u8*)data; // should be 8 byte aligned size. - assert((size_bytes & 0x7) == 0); + ASSERT((size_bytes & 0x7) == 0); VuProgram prog; int instruction_count = size_bytes / 8; for (int i = 0; i < instruction_count; i++) { @@ -426,14 +426,14 @@ VuInstruction VuDisassembler::decode(VuInstrK kind, u32 data, int instr_idx) { auto& inst = info(kind); if (!inst.known) { fmt::print("instr idx {} is unknown\n", (int)kind); - assert(false); + ASSERT(false); } for (auto& step : inst.decode) { s64 value = -1; switch (step.field) { case VuDecodeStep::FieldK::IEMDT: value = data >> 25; - assert((value & 3) == 0); + ASSERT((value & 3) == 0); break; case VuDecodeStep::FieldK::DST_MASK: value = upper_dest_mask(data); @@ -485,7 +485,7 @@ VuInstruction VuDisassembler::decode(VuInstrK kind, u32 data, int instr_idx) { break; default: - assert(false); + ASSERT(false); } switch (step.atom) { @@ -496,22 +496,22 @@ VuInstruction VuDisassembler::decode(VuInstrK kind, u32 data, int instr_idx) { instr.mask = value; break; case VuDecodeStep::AtomK::DST_VF: - assert(!instr.dst); + ASSERT(!instr.dst); instr.dst = VuInstructionAtom::make_vf(value); break; case VuDecodeStep::AtomK::DST_VI: - assert(!instr.dst); + ASSERT(!instr.dst); instr.dst = VuInstructionAtom::make_vi(value); break; case VuDecodeStep::AtomK::SRC_VF: instr.src.push_back(VuInstructionAtom::make_vf(value)); break; case VuDecodeStep::AtomK::BC: - assert(!instr.bc); + ASSERT(!instr.bc); instr.bc = value; break; case VuDecodeStep::AtomK::ASSERT_ZERO: - assert(value == 0); + ASSERT(value == 0); break; case VuDecodeStep::AtomK::SRC_VI: instr.src.push_back(VuInstructionAtom::make_vi(value)); @@ -526,15 +526,15 @@ VuInstruction VuDisassembler::decode(VuInstrK kind, u32 data, int instr_idx) { instr.src.push_back(VuInstructionAtom::make_imm(value)); break; case VuDecodeStep::AtomK::DST_ACC: - assert(!instr.dst); + ASSERT(!instr.dst); instr.dst = VuInstructionAtom::make_acc(); break; case VuDecodeStep::AtomK::DST_Q: - assert(!instr.dst); + ASSERT(!instr.dst); instr.dst = VuInstructionAtom::make_q(); break; case VuDecodeStep::AtomK::DST_P: - assert(!instr.dst); + ASSERT(!instr.dst); instr.dst = VuInstructionAtom::make_p(); break; case VuDecodeStep::AtomK::SRC_Q: @@ -553,7 +553,7 @@ VuInstruction VuDisassembler::decode(VuInstrK kind, u32 data, int instr_idx) { instr.first_src_field = value; break; default: - assert(false); + ASSERT(false); } } @@ -862,7 +862,7 @@ std::string VuDisassembler::to_string(const VuInstruction& instr) const { auto& in = info(instr.kind); if (!in.known) { - assert(false); + ASSERT(false); } std::string result; @@ -934,7 +934,7 @@ std::string VuDisassembler::to_string(const VuInstruction& instr) const { idx++; } - assert(!close); + ASSERT(!close); if (comma) { result.pop_back(); @@ -1046,7 +1046,7 @@ std::string get_label_name(const VuInstructionPair& pair, return arg.to_string(label_names); } } - assert(false); + ASSERT(false); } std::string VuDisassembler::to_string_with_cpp(const VuProgram& prog) const { diff --git a/decompiler/VuDisasm/VuDisassembler.h b/decompiler/VuDisasm/VuDisassembler.h index 6e11a590a7..6fd02e0170 100644 --- a/decompiler/VuDisasm/VuDisassembler.h +++ b/decompiler/VuDisasm/VuDisassembler.h @@ -3,7 +3,7 @@ #include #include "decompiler/VuDisasm/VuProgram.h" -#include "common/util/assert.h" +#include "common/util/Assert.h" namespace decompiler { @@ -220,7 +220,7 @@ class VuDisassembler { }; const OpInfo& info(VuInstrK op) const { - assert((int)op < (int)VuInstrK::INVALID); + ASSERT((int)op < (int)VuInstrK::INVALID); return m_op_info[(int)op]; } diff --git a/decompiler/VuDisasm/VuInstruction.cpp b/decompiler/VuDisasm/VuInstruction.cpp index df77afc35b..5da13d4ce2 100644 --- a/decompiler/VuDisasm/VuInstruction.cpp +++ b/decompiler/VuDisasm/VuInstruction.cpp @@ -1,15 +1,15 @@ #include "third-party/fmt/core.h" #include "VuInstruction.h" -#include "common/util/assert.h" +#include "common/util/Assert.h" namespace decompiler { VuInstructionAtom VuInstructionAtom::make_vf(int idx) { - assert(idx >= 0 && idx <= 31); + ASSERT(idx >= 0 && idx <= 31); return {Kind::VF, idx}; } VuInstructionAtom VuInstructionAtom::make_vi(int idx) { - assert(idx >= 0 && idx <= 15); + ASSERT(idx >= 0 && idx <= 15); return {Kind::VI, idx}; } @@ -82,7 +82,7 @@ std::string VuInstructionAtom::to_string(const std::vector& labels) return fmt::format("vi{:02d}", m_value); case Kind::INVALID: default: - assert(false); + ASSERT(false); } } diff --git a/decompiler/analysis/atomic_op_builder.cpp b/decompiler/analysis/atomic_op_builder.cpp index 1c766d3451..f5d8001419 100644 --- a/decompiler/analysis/atomic_op_builder.cpp +++ b/decompiler/analysis/atomic_op_builder.cpp @@ -66,7 +66,7 @@ RegisterAccess make_src_var(Register reg, int idx) { } RegisterAccess make_dst_var(const Instruction& i, int idx) { - assert(i.n_dst == 1); + ASSERT(i.n_dst == 1); return make_dst_var(i.get_dst(0).get_reg(), idx); } @@ -203,10 +203,10 @@ std::unique_ptr make_standard_store(const Instruction& i0, SimpleAtom val; SimpleExpression dst; if (i0.get_src(0).is_reg(rs7())) { - assert(kind == StoreOp::Kind::INTEGER); + ASSERT(kind == StoreOp::Kind::INTEGER); val = SimpleAtom::make_sym_val("#f"); } else if (i0.get_src(0).is_reg(rr0())) { - assert(kind == StoreOp::Kind::INTEGER); + ASSERT(kind == StoreOp::Kind::INTEGER); val = SimpleAtom::make_int_constant(0); } else { val = make_src_atom(i0.get_src(0).get_reg(), idx); @@ -420,7 +420,7 @@ std::unique_ptr make_branch(const IR2_Condition& condition, int dest_label, int my_idx, bool force_asm) { - assert(!likely); + ASSERT(!likely); auto branch_delay = get_branch_delay(delay, my_idx); if (!force_asm && branch_delay.is_known()) { return std::make_unique(likely, condition, dest_label, branch_delay, my_idx); @@ -438,7 +438,7 @@ std::unique_ptr make_asm_branch_no_delay(const IR2_Condition& conditio bool likely, int dest_label, int my_idx) { - assert(likely); + ASSERT(likely); return std::make_unique(likely, condition, dest_label, nullptr, my_idx); } @@ -450,7 +450,7 @@ std::unique_ptr make_branch_no_delay(const IR2_Condition& condition, if (force_asm_branch) { return make_asm_branch_no_delay(condition, likely, dest_label, my_idx); } - assert(likely); + ASSERT(likely); IR2_BranchDelay delay(IR2_BranchDelay::Kind::NO_DELAY); return std::make_unique(likely, condition, dest_label, delay, my_idx); } @@ -460,7 +460,7 @@ std::unique_ptr make_asm_branch(const IR2_Condition& condition, bool likely, int dest_label, int my_idx) { - assert(!likely); + ASSERT(!likely); auto delay_op = std::shared_ptr(convert_1_allow_asm(delay, my_idx)); if (!delay_op) { throw std::runtime_error( @@ -1065,10 +1065,10 @@ std::unique_ptr convert_daddiu_2(const Instruction& i0, const Instruct if (!i0.get_src(0).is_reg(rs7())) { return nullptr; } - assert(i0.get_src(0).is_reg(rs7())); - assert(i0.get_src(1).is_imm(8)); - assert(i1.get_dst(0).is_reg(dest)); - assert(i1.get_src(0).is_reg(rs7())); + ASSERT(i0.get_src(0).is_reg(rs7())); + ASSERT(i0.get_src(1).is_imm(8)); + ASSERT(i1.get_dst(0).is_reg(dest)); + ASSERT(i1.get_src(0).is_reg(rs7())); auto kind = i1.kind == InstructionKind::MOVN ? IR2_Condition::Kind::ZERO : IR2_Condition::Kind::NONZERO; return std::make_unique(make_dst_var(dest, idx), @@ -1094,7 +1094,7 @@ std::unique_ptr convert_lui_2(const Instruction& i0, const Instruction (s64(i0.get_src(0).get_imm()) << 16)); } else if (i0.get_src(0).is_label() && i1.get_src(1).is_label()) { auto label = i0.get_src(0).get_label(); - assert(label == i1.get_src(1).get_label()); + ASSERT(label == i1.get_src(1).get_label()); src = SimpleAtom::make_static_address(label); } @@ -1124,9 +1124,9 @@ std::unique_ptr convert_slt_2(const Instruction& i0, if (temp == left) { return nullptr; } - assert(temp != left); - assert(temp != right); - assert(left != right); + ASSERT(temp != left); + ASSERT(temp != right); + ASSERT(left != right); std::unique_ptr result; SimpleExpression::Kind kind; if (is_gpr_3(i1, InstructionKind::MOVZ, left, right, temp)) { @@ -1226,10 +1226,10 @@ std::unique_ptr convert_lui_3(const Instruction& i0, // lui temp, <> // ori dst, temp, <> // addu dst, fp, dst - assert(i0.get_dst(0).get_reg() == i1.get_src(0).get_reg()); // temp - assert(i0.get_src(0).get_label() == i1.get_src(1).get_label()); // labels - assert(i2.get_dst(0).get_reg() == i2.get_src(1).get_reg()); // dst - assert(i2.get_dst(0).get_reg() == i1.get_dst(0).get_reg()); // dst + ASSERT(i0.get_dst(0).get_reg() == i1.get_src(0).get_reg()); // temp + ASSERT(i0.get_src(0).get_label() == i1.get_src(1).get_label()); // labels + ASSERT(i2.get_dst(0).get_reg() == i2.get_src(1).get_reg()); // dst + ASSERT(i2.get_dst(0).get_reg() == i1.get_dst(0).get_reg()); // dst auto temp = i0.get_dst(0).get_reg(); auto dst = i2.get_dst(0).get_reg(); auto label = i0.get_src(0).get_label(); @@ -1244,10 +1244,10 @@ std::unique_ptr convert_lui_3(const Instruction& i0, // lui temp, <> // ori temp, temp, <> // daddu dst, temp, fp - assert(i0.get_dst(0).get_reg() == i1.get_src(0).get_reg()); // temp - assert(i0.get_src(0).get_label() == i1.get_src(1).get_label()); // labels - assert(i0.get_dst(0).get_reg() == i1.get_dst(0).get_reg()); // temp - assert(i2.get_src(0).get_reg() == i0.get_dst(0).get_reg()); // temp + ASSERT(i0.get_dst(0).get_reg() == i1.get_src(0).get_reg()); // temp + ASSERT(i0.get_src(0).get_label() == i1.get_src(1).get_label()); // labels + ASSERT(i0.get_dst(0).get_reg() == i1.get_dst(0).get_reg()); // temp + ASSERT(i2.get_src(0).get_reg() == i0.get_dst(0).get_reg()); // temp auto temp = i0.get_dst(0).get_reg(); auto dst = i2.get_dst(0).get_reg(); auto label = i0.get_src(0).get_label(); @@ -1274,12 +1274,12 @@ std::unique_ptr convert_dsubu_3(const Instruction& i0, auto a = i0.get_src(0).get_reg(); auto b = i0.get_src(1).get_reg(); auto dest = i1.get_dst(0).get_reg(); - assert(i1.get_src(0).is_reg(rs7())); - assert(i1.get_src(1).is_imm(FIX_SYM_TRUE)); - assert(i2.get_dst(0).get_reg() == dest); - assert(i2.get_src(0).is_reg(rs7())); - assert(i2.get_src(1).get_reg() == temp); - assert(temp != dest); + ASSERT(i1.get_src(0).is_reg(rs7())); + ASSERT(i1.get_src(1).is_imm(FIX_SYM_TRUE)); + ASSERT(i2.get_dst(0).get_reg() == dest); + ASSERT(i2.get_src(0).is_reg(rs7())); + ASSERT(i2.get_src(1).get_reg() == temp); + ASSERT(temp != dest); auto kind = i2.kind == InstructionKind::MOVN ? IR2_Condition::Kind::EQUAL : IR2_Condition::Kind::NOT_EQUAL; std::unique_ptr result; @@ -1332,8 +1332,8 @@ std::unique_ptr convert_slt_3(const Instruction& i0, // delay slot auto temp = i0.get_dst(0).get_reg(); auto dest = i1.get_src(2).get_label(); - assert(i1.get_src(0).get_reg() == temp); - assert(i1.get_src(1).is_reg(rr0())); + ASSERT(i1.get_src(0).get_reg() == temp); + ASSERT(i1.get_src(1).is_reg(rr0())); IR2_Condition condition; if (s1 == rr0()) { @@ -1365,12 +1365,12 @@ std::unique_ptr convert_slt_3(const Instruction& i0, // movz dest, s7, temp auto temp = i0.get_dst(0).get_reg(); auto dest = i1.get_dst(0).get_reg(); - assert(i1.get_src(0).is_reg(rs7())); - assert(i1.get_src(1).is_imm(FIX_SYM_TRUE)); - assert(i2.get_dst(0).get_reg() == dest); - assert(i2.get_src(0).is_reg(rs7())); - assert(i2.get_src(1).get_reg() == temp); - assert(temp != dest); + ASSERT(i1.get_src(0).is_reg(rs7())); + ASSERT(i1.get_src(1).is_imm(FIX_SYM_TRUE)); + ASSERT(i2.get_dst(0).get_reg() == dest); + ASSERT(i2.get_src(0).is_reg(rs7())); + ASSERT(i2.get_src(1).get_reg() == temp); + ASSERT(temp != dest); IR2_Condition condition; if (s1 == rr0()) { auto kind = is_signed ? IR2_Condition::Kind::LESS_THAN_ZERO_SIGNED @@ -1411,8 +1411,8 @@ std::unique_ptr convert_slti_3(const Instruction& i0, // delay slot auto temp = i0.get_dst(0).get_reg(); auto dest = i1.get_src(2).get_label(); - assert(i1.get_src(0).get_reg() == temp); - assert(i1.get_src(1).is_reg(rr0())); + ASSERT(i1.get_src(0).get_reg() == temp); + ASSERT(i1.get_src(1).is_reg(rr0())); auto kind = is_signed ? IR2_Condition::Kind::LESS_THAN_SIGNED : IR2_Condition::Kind::LESS_THAN_UNSIGNED; auto condition = IR2_Condition(kind, make_src_atom(s0, idx), s1); @@ -1430,12 +1430,12 @@ std::unique_ptr convert_slti_3(const Instruction& i0, // movz dest, s7, temp auto temp = i0.get_dst(0).get_reg(); auto dest = i1.get_dst(0).get_reg(); - assert(i1.get_src(0).is_reg(rs7())); - assert(i1.get_src(1).is_imm(FIX_SYM_TRUE)); - assert(i2.get_dst(0).get_reg() == dest); - assert(i2.get_src(0).is_reg(rs7())); - assert(i2.get_src(1).get_reg() == temp); - assert(temp != dest); + ASSERT(i1.get_src(0).is_reg(rs7())); + ASSERT(i1.get_src(1).is_imm(FIX_SYM_TRUE)); + ASSERT(i2.get_dst(0).get_reg() == dest); + ASSERT(i2.get_src(0).is_reg(rs7())); + ASSERT(i2.get_src(1).get_reg() == temp); + ASSERT(temp != dest); IR2_Condition condition; auto kind = @@ -1517,11 +1517,11 @@ std::unique_ptr convert_dsll32_4(const Instruction& i0, if (sa != 30) { return nullptr; } - assert(i1.get_dst(0).get_reg() == temp); - assert(i1.get_src(0).get_reg() == temp); - assert(i1.get_src(1).is_reg(rr0())); - assert(i2.get_src(0).get_reg() == temp); - assert(i2.get_src(1).is_reg(rr0())); + ASSERT(i1.get_dst(0).get_reg() == temp); + ASSERT(i1.get_src(0).get_reg() == temp); + ASSERT(i1.get_src(1).is_reg(rr0())); + ASSERT(i2.get_src(0).get_reg() == temp); + ASSERT(i2.get_src(1).is_reg(rr0())); IR2_Condition condition(IR2_Condition::Kind::IS_NOT_PAIR, make_src_atom(arg, idx)); auto result = make_branch(condition, i3, false, i2.get_src(2).get_label(), idx, false); @@ -2141,7 +2141,7 @@ int convert_block_to_atomic_ops(int begin_idx, // instr->to_string(labels)); } - assert(converted && length && op); + ASSERT(converted && length && op); // add mappings: container->atomic_op_to_instruction[container->ops.size()] = begin_idx; for (int i = 0; i < length; i++) { @@ -2197,8 +2197,8 @@ FunctionAtomicOps convert_function_to_atomic_ops( } } - assert(func.basic_blocks.size() == result.block_id_to_end_atomic_op.size()); - assert(func.basic_blocks.size() == result.block_id_to_first_atomic_op.size()); + ASSERT(func.basic_blocks.size() == result.block_id_to_end_atomic_op.size()); + ASSERT(func.basic_blocks.size() == result.block_id_to_first_atomic_op.size()); return result; } } // namespace decompiler diff --git a/decompiler/analysis/atomic_op_builder.h b/decompiler/analysis/atomic_op_builder.h index cc72770da4..c70bbe0908 100644 --- a/decompiler/analysis/atomic_op_builder.h +++ b/decompiler/analysis/atomic_op_builder.h @@ -17,9 +17,9 @@ struct FunctionAtomicOps { std::vector> ops; FunctionEndOp& end_op() const { - assert(!ops.empty()); + ASSERT(!ops.empty()); auto end = dynamic_cast(ops.back().get()); - assert(end); + ASSERT(end); return *end; } diff --git a/decompiler/analysis/cfg_builder.cpp b/decompiler/analysis/cfg_builder.cpp index d1dcf0ae0c..8dda80df55 100644 --- a/decompiler/analysis/cfg_builder.cpp +++ b/decompiler/analysis/cfg_builder.cpp @@ -25,7 +25,7 @@ std::pair get_condition_branch_as_vector(Form* in) { // If this changes, this can be fixed here, rather than refactoring the whole thing. if (in->size() > 1) { auto irb = dynamic_cast(in->back()); - assert(irb); + ASSERT(irb); return std::make_pair(irb, in); } return std::make_pair(nullptr, nullptr); @@ -64,15 +64,15 @@ std::pair get_condition_branch(Form* in) { */ void clean_up_cond_with_else(FormPool& pool, FormElement* ir, const Env& env) { auto cwe = dynamic_cast(ir); - assert(cwe); + ASSERT(cwe); for (auto& e : cwe->entries) { // don't reclean already cleaned things. if (e.cleaned) { continue; } auto jump_to_next = get_condition_branch(e.condition); - assert(jump_to_next.first); - assert(jump_to_next.first->op()->branch_delay().kind() == IR2_BranchDelay::Kind::NOP); + ASSERT(jump_to_next.first); + ASSERT(jump_to_next.first->op()->branch_delay().kind() == IR2_BranchDelay::Kind::NOP); // patch the branch to next with a condition. auto replacement = jump_to_next.first->op()->get_condition_as_form(pool, env); replacement->invert(); @@ -80,9 +80,9 @@ void clean_up_cond_with_else(FormPool& pool, FormElement* ir, const Env& env) { // check the jump at the end of a block. auto jump_to_end = get_condition_branch(e.body); - assert(jump_to_end.first); - assert(jump_to_end.first->op()->branch_delay().kind() == IR2_BranchDelay::Kind::NOP); - assert(jump_to_end.first->op()->condition().kind() == IR2_Condition::Kind::ALWAYS); + ASSERT(jump_to_end.first); + ASSERT(jump_to_end.first->op()->branch_delay().kind() == IR2_BranchDelay::Kind::NOP); + ASSERT(jump_to_end.first->op()->condition().kind() == IR2_Condition::Kind::ALWAYS); // if possible, we just want to remove this from the sequence its in. // but sometimes there's a case with nothing in it so there is no sequence. @@ -91,7 +91,7 @@ void clean_up_cond_with_else(FormPool& pool, FormElement* ir, const Env& env) { // this happens rarely, as you would expect. auto as_end_of_sequence = get_condition_branch_as_vector(e.body); if (as_end_of_sequence.first) { - assert(as_end_of_sequence.second->size() > 1); + ASSERT(as_end_of_sequence.second->size() > 1); as_end_of_sequence.second->pop_back(); } else { // we need to have _something_ as the body, so we just put an (empty). @@ -106,8 +106,8 @@ void clean_up_cond_with_else(FormPool& pool, FormElement* ir, const Env& env) { */ void clean_up_until_loop(FormPool& pool, UntilElement* ir, const Env& env) { auto condition_branch = get_condition_branch(ir->condition); - assert(condition_branch.first); - assert(condition_branch.first->op()->branch_delay().kind() == IR2_BranchDelay::Kind::NOP); + ASSERT(condition_branch.first); + ASSERT(condition_branch.first->op()->branch_delay().kind() == IR2_BranchDelay::Kind::NOP); auto replacement = condition_branch.first->op()->get_condition_as_form(pool, env); replacement->invert(); *(condition_branch.second) = replacement; @@ -118,13 +118,13 @@ void clean_up_until_loop(FormPool& pool, UntilElement* ir, const Env& env) { */ void clean_up_infinite_while_loop(FormPool& pool, WhileElement* ir) { auto jump = get_condition_branch(ir->body); - assert(jump.first); - assert(jump.first->op()->branch_delay().kind() == IR2_BranchDelay::Kind::NOP); - assert(jump.first->op()->condition().kind() == IR2_Condition::Kind::ALWAYS); + ASSERT(jump.first); + ASSERT(jump.first->op()->branch_delay().kind() == IR2_BranchDelay::Kind::NOP); + ASSERT(jump.first->op()->condition().kind() == IR2_Condition::Kind::ALWAYS); auto as_end_of_sequence = get_condition_branch_as_vector(ir->body); if (as_end_of_sequence.first) { // there's more in the sequence, just remove the last thing. - assert(as_end_of_sequence.second->size() > 1); + ASSERT(as_end_of_sequence.second->size() > 1); as_end_of_sequence.second->pop_back(); } else { // Nothing else in the sequence, just replace the jump with an (empty) @@ -138,12 +138,12 @@ void clean_up_infinite_while_loop(FormPool& pool, WhileElement* ir) { */ void clean_up_return(FormPool& pool, ReturnElement* ir) { auto jump_to_end = get_condition_branch(ir->return_code); - assert(jump_to_end.first); - assert(jump_to_end.first->op()->branch_delay().kind() == IR2_BranchDelay::Kind::NOP); - assert(jump_to_end.first->op()->condition().kind() == IR2_Condition::Kind::ALWAYS); + ASSERT(jump_to_end.first); + ASSERT(jump_to_end.first->op()->branch_delay().kind() == IR2_BranchDelay::Kind::NOP); + ASSERT(jump_to_end.first->op()->condition().kind() == IR2_Condition::Kind::ALWAYS); auto as_end_of_sequence = get_condition_branch_as_vector(ir->return_code); if (as_end_of_sequence.first) { - assert(as_end_of_sequence.second->size() > 1); + ASSERT(as_end_of_sequence.second->size() > 1); as_end_of_sequence.second->pop_back(); } else { *(jump_to_end.second) = pool.alloc_element(); @@ -166,10 +166,10 @@ void clean_up_return_final(const Function& f, ReturnElement* ir) { throw std::runtime_error(fmt::format("failed to recognize dead code after return, got {}", ir->dead_code->to_string(f.ir2.env))); } - assert(dead); + ASSERT(dead); auto src = dynamic_cast(dead->src()->try_as_single_element()); - assert(src); - assert(src->expr().is_identity() && src->expr().get_arg(0).is_int() && + ASSERT(src); + ASSERT(src->expr().is_identity() && src->expr().get_arg(0).is_int() && src->expr().get_arg(0).get_int() == 0); ir->dead_code = nullptr; } @@ -179,12 +179,12 @@ void clean_up_return_final(const Function& f, ReturnElement* ir) { */ void clean_up_break(FormPool& pool, BreakElement* ir, const Env&) { auto jump_to_end = get_condition_branch(ir->return_code); - assert(jump_to_end.first); - assert(jump_to_end.first->op()->branch_delay().kind() == IR2_BranchDelay::Kind::NOP); - assert(jump_to_end.first->op()->condition().kind() == IR2_Condition::Kind::ALWAYS); + ASSERT(jump_to_end.first); + ASSERT(jump_to_end.first->op()->branch_delay().kind() == IR2_BranchDelay::Kind::NOP); + ASSERT(jump_to_end.first->op()->condition().kind() == IR2_Condition::Kind::ALWAYS); auto as_end_of_sequence = get_condition_branch_as_vector(ir->return_code); if (as_end_of_sequence.first) { - assert(as_end_of_sequence.second->size() > 1); + ASSERT(as_end_of_sequence.second->size() > 1); as_end_of_sequence.second->pop_back(); } else { *(jump_to_end.second) = pool.alloc_element(); @@ -220,9 +220,9 @@ void clean_up_break_final(const Function& f, BreakElement* ir, const Env& env) { throw std::runtime_error(fmt::format("failed to recognize dead code after break, got {}", ir->dead_code->to_string(f.ir2.env))); } - assert(dead); + ASSERT(dead); auto src = dynamic_cast(dead->src()->try_as_single_element()); - assert(src); + ASSERT(src); if (src->expr().is_identity() && src->expr().get_arg(0).is_int() && src->expr().get_arg(0).get_int() == 0) { ir->dead_code = nullptr; @@ -235,8 +235,8 @@ void clean_up_break_final(const Function& f, BreakElement* ir, const Env& env) { * GOAL does this on comparisons to false. */ bool delay_slot_sets_false(BranchElement* branch, SetVarOp& delay) { - assert(branch->op()->likely()); - assert(branch->op()->branch_delay().kind() == IR2_BranchDelay::Kind::NO_DELAY); + ASSERT(branch->op()->likely()); + ASSERT(branch->op()->branch_delay().kind() == IR2_BranchDelay::Kind::NO_DELAY); if (delay.src().is_identity() && delay.src().get_arg(0).is_sym_val() && delay.src().get_arg(0).get_str() == "#f") { @@ -276,8 +276,8 @@ bool delay_slot_sets_false(BranchElement* branch, SetVarOp& delay) { * then uses that */ bool delay_slot_sets_truthy(BranchElement* branch, SetVarOp& delay) { - assert(branch->op()->likely()); - assert(branch->op()->branch_delay().kind() == IR2_BranchDelay::Kind::NO_DELAY); + ASSERT(branch->op()->likely()); + ASSERT(branch->op()->branch_delay().kind() == IR2_BranchDelay::Kind::NO_DELAY); if (delay.src().is_identity() && delay.src().get_arg(0).is_sym_ptr() && delay.src().get_arg(0).get_str() == "#t") { @@ -317,8 +317,8 @@ bool try_clean_up_sc_as_and(FormPool& pool, Function& func, ShortCircuitElement* RegisterAccess ir_dest; for (int i = 0; i < int(ir->entries.size()) - 1; i++) { auto branch = get_condition_branch(ir->entries.at(i).condition); - assert(branch.first); - assert(ir->entries.at(i).branch_delay.has_value()); + ASSERT(branch.first); + ASSERT(ir->entries.at(i).branch_delay.has_value()); if (!delay_slot_sets_false(branch.first, *ir->entries.at(i).branch_delay)) { return false; } @@ -343,7 +343,7 @@ bool try_clean_up_sc_as_and(FormPool& pool, Function& func, ShortCircuitElement* // now get rid of the branches for (int i = 0; i < int(ir->entries.size()) - 1; i++) { auto branch = get_condition_branch(ir->entries.at(i).condition); - assert(branch.first); + ASSERT(branch.first); if (func.ir2.env.has_reg_use()) { auto delay_id = ir->entries.at(i).branch_delay->dst().idx(); @@ -357,7 +357,7 @@ bool try_clean_up_sc_as_and(FormPool& pool, Function& func, ShortCircuitElement* auto delay_op = func.ir2.atomic_ops->ops.at(delay_id).get(); auto as_set = dynamic_cast(delay_op); - assert(as_set); + ASSERT(as_set); if (as_set->src().is_var()) { // must be the case where the src should have truthy in it. // lg::warn("Disabling use of {} in or delay slot", as_set->to_string(func.ir2.env)); @@ -396,7 +396,7 @@ bool try_clean_up_sc_as_and(FormPool& pool, Function& func, ShortCircuitElement* lg::error("Bad live out result on {}. At 0 was {} now at {} is {}", func.name(), live_out_result, i, this_live_out); } - assert(live_out_result == this_live_out); + ASSERT(live_out_result == this_live_out); } } @@ -425,8 +425,8 @@ bool try_clean_up_sc_as_or(FormPool& pool, Function& func, ShortCircuitElement* for (int i = 0; i < int(ir->entries.size()) - 1; i++) { // short circuit branch auto branch = get_condition_branch(ir->entries.at(i).condition); - assert(branch.first); - assert(ir->entries.at(i).branch_delay.has_value()); + ASSERT(branch.first); + ASSERT(ir->entries.at(i).branch_delay.has_value()); // the branch should write true (there's two ways this can happen) if (!delay_slot_sets_truthy(branch.first, *ir->entries.at(i).branch_delay)) { return false; @@ -460,7 +460,7 @@ bool try_clean_up_sc_as_or(FormPool& pool, Function& func, ShortCircuitElement* for (int i = 0; i < int(ir->entries.size()) - 1; i++) { auto branch = get_condition_branch(ir->entries.at(i).condition); - assert(branch.first); + ASSERT(branch.first); if (func.ir2.env.has_reg_use()) { auto delay_id = ir->entries.at(i).branch_delay->dst().idx(); @@ -480,7 +480,7 @@ bool try_clean_up_sc_as_or(FormPool& pool, Function& func, ShortCircuitElement* // is inserted by the GOAL compiler, not by putting a var twice in the source code. auto delay_op = func.ir2.atomic_ops->ops.at(delay_id).get(); auto as_set = dynamic_cast(delay_op); - assert(as_set); + ASSERT(as_set); if (as_set->src().is_var()) { // must be the case where the src should have truthy in it. // lg::warn("Disabling use of {} in or delay slot", as_set->to_string(func.ir2.env)); @@ -516,7 +516,7 @@ bool try_clean_up_sc_as_or(FormPool& pool, Function& func, ShortCircuitElement* } else { bool this_live_out = (delay_info.written_and_unused.find(ir_dest.reg()) == delay_info.written_and_unused.end()); - assert(live_out_result == this_live_out); + ASSERT(live_out_result == this_live_out); } } @@ -544,8 +544,8 @@ void clean_up_sc(FormPool& pool, Function& func, ShortCircuitElement* ir); */ bool try_splitting_nested_sc(FormPool& pool, Function& func, ShortCircuitElement* ir) { auto first_branch = get_condition_branch(ir->entries.front().condition); - assert(first_branch.first); - assert(ir->entries.front().branch_delay.has_value()); + ASSERT(first_branch.first); + ASSERT(ir->entries.front().branch_delay.has_value()); bool first_is_and = delay_slot_sets_false(first_branch.first, *ir->entries.front().branch_delay); bool first_is_or = delay_slot_sets_truthy(first_branch.first, *ir->entries.front().branch_delay); @@ -555,17 +555,17 @@ bool try_splitting_nested_sc(FormPool& pool, Function& func, ShortCircuitElement "and/or:\n{}", ir->to_string(func.ir2.env))); } - assert(first_is_and != first_is_or); // one or the other but not both! + ASSERT(first_is_and != first_is_or); // one or the other but not both! int first_different = -1; // the index of the first one that's different. for (int i = 1; i < int(ir->entries.size()) - 1; i++) { auto branch = get_condition_branch(ir->entries.at(i).condition); - assert(branch.first); - assert(ir->entries.at(i).branch_delay.has_value()); + ASSERT(branch.first); + ASSERT(ir->entries.at(i).branch_delay.has_value()); bool is_and = delay_slot_sets_false(branch.first, *ir->entries.at(i).branch_delay); bool is_or = delay_slot_sets_truthy(branch.first, *ir->entries.at(i).branch_delay); - assert(is_and != is_or); + ASSERT(is_and != is_or); if (first_different == -1) { // haven't seen a change yet. @@ -577,7 +577,7 @@ bool try_splitting_nested_sc(FormPool& pool, Function& func, ShortCircuitElement } } - assert(first_different != -1); + ASSERT(first_different != -1); std::vector nested_ir; for (int i = first_different; i < int(ir->entries.size()); i++) { @@ -609,7 +609,7 @@ bool try_splitting_nested_sc(FormPool& pool, Function& func, ShortCircuitElement * if there is a case like (and a (or b c)) */ void clean_up_sc(FormPool& pool, Function& func, ShortCircuitElement* ir) { - assert(ir->entries.size() > 0); + ASSERT(ir->entries.size() > 0); if (ir->entries.size() == 1) { // need to fake the final entry. ShortCircuitElement::Entry empty_final; @@ -620,7 +620,7 @@ void clean_up_sc(FormPool& pool, Function& func, ShortCircuitElement* ir) { if (!try_clean_up_sc_as_and(pool, func, ir)) { if (!try_clean_up_sc_as_or(pool, func, ir)) { if (!try_splitting_nested_sc(pool, func, ir)) { - assert(false); + ASSERT(false); } } } @@ -650,17 +650,17 @@ void convert_cond_no_else_to_compare(FormPool& pool, FormElement** ir_loc, Form* parent_form) { CondNoElseElement* cne = dynamic_cast(*ir_loc); - assert(cne); + ASSERT(cne); auto condition = get_condition_branch(cne->entries.front().condition); - assert(condition.first); + ASSERT(condition.first); auto body = dynamic_cast(cne->entries.front().body->try_as_single_element()); - assert(body); + ASSERT(body); auto dst = body->dst(); auto src_atom = get_atom_src(body->src()); - assert(src_atom); - assert(src_atom->is_sym_val()); - assert(src_atom->get_str() == "#f"); - assert(cne->entries.size() == 1); + ASSERT(src_atom); + ASSERT(src_atom->is_sym_val()); + ASSERT(src_atom->get_str() == "#f"); + ASSERT(cne->entries.size() == 1); // safe to do this here because we never give up on this. f.ir2.env.disable_def(condition.first->op()->branch_delay().var(0), f.warnings); @@ -686,11 +686,11 @@ void convert_cond_no_else_to_compare(FormPool& pool, parent_form->push_back(x); } // auto condition_as_seq = dynamic_cast(cne->entries.front().condition.get()); - // assert(condition_as_seq); + // ASSERT(condition_as_seq); // if (condition_as_seq) { // auto replacement = std::make_shared(); // replacement->forms = condition_as_seq->forms; - // assert(condition.second == &condition_as_seq->forms.back()); + // ASSERT(condition.second == &condition_as_seq->forms.back()); // replacement->forms.pop_back(); // replacement->forms.push_back(std::make_shared( // IR_Set::REG_64, dst, @@ -705,15 +705,15 @@ void clean_up_cond_no_else_final(Function& func, CondNoElseElement* cne) { auto& entry = cne->entries.at(idx); if (entry.false_destination.has_value()) { auto fr = entry.false_destination; - assert(fr.has_value()); + ASSERT(fr.has_value()); cne->final_destination = *fr; } else { - assert(false); + ASSERT(false); } } auto last_branch = dynamic_cast(cne->entries.back().original_condition_branch); - assert(last_branch); + ASSERT(last_branch); if (func.ir2.env.has_reg_use()) { auto& last_branch_info = func.ir2.env.reg_use().op.at(last_branch->op()->op_id()); @@ -727,14 +727,14 @@ void clean_up_cond_no_else_final(Function& func, CondNoElseElement* cne) { auto branch = dynamic_cast(cne->entries.at(i).original_condition_branch); auto& branch_info_i = func.ir2.env.reg_use().op.at(branch->op()->op_id()); auto reg = cne->entries.at(i).false_destination; - assert(reg.has_value()); - assert(branch); + ASSERT(reg.has_value()); + ASSERT(branch); if (branch_info_i.written_and_unused.find(reg->reg()) == branch_info_i.written_and_unused.end()) { lg::error("Branch delay register used improperly: {}", reg->to_string(func.ir2.env)); throw std::runtime_error("Bad delay slot in clean_up_cond_no_else_final"); } - // assert(branch_info_i.written_and_unused.find(reg->reg()) != + // ASSERT(branch_info_i.written_and_unused.find(reg->reg()) != // branch_info_i.written_and_unused.end()); } } @@ -761,7 +761,7 @@ void clean_up_cond_no_else_final(Function& func, CondNoElseElement* cne) { */ void clean_up_cond_no_else(FormPool& pool, Function& f, FormElement** ir_loc, Form* parent_form) { auto cne = dynamic_cast(*ir_loc); - assert(cne); + ASSERT(cne); for (size_t idx = 0; idx < cne->entries.size(); idx++) { auto& e = cne->entries.at(idx); if (e.cleaned) { @@ -769,22 +769,22 @@ void clean_up_cond_no_else(FormPool& pool, Function& f, FormElement** ir_loc, Fo } auto jump_to_next = get_condition_branch(e.condition); - assert(jump_to_next.first); + ASSERT(jump_to_next.first); if (jump_to_next.first->op()->branch_delay().kind() == IR2_BranchDelay::Kind::SET_REG_TRUE && cne->entries.size() == 1) { convert_cond_no_else_to_compare(pool, f, ir_loc, parent_form); return; } else { - assert(jump_to_next.first->op()->branch_delay().kind() == + ASSERT(jump_to_next.first->op()->branch_delay().kind() == IR2_BranchDelay::Kind::SET_REG_FALSE || jump_to_next.first->op()->branch_delay().kind() == IR2_BranchDelay::Kind::NOP); - assert(jump_to_next.first->op()->condition().kind() != IR2_Condition::Kind::ALWAYS); + ASSERT(jump_to_next.first->op()->condition().kind() != IR2_Condition::Kind::ALWAYS); if (jump_to_next.first->op()->branch_delay().kind() == IR2_BranchDelay::Kind::SET_REG_FALSE) { - assert(!e.false_destination); + ASSERT(!e.false_destination); e.false_destination = jump_to_next.first->op()->branch_delay().var(0); - assert(e.false_destination); + ASSERT(e.false_destination); } e.original_condition_branch = *jump_to_next.second; @@ -796,12 +796,12 @@ void clean_up_cond_no_else(FormPool& pool, Function& f, FormElement** ir_loc, Fo if (idx != cne->entries.size() - 1) { auto jump_to_end = get_condition_branch(e.body); - assert(jump_to_end.first); - assert(jump_to_end.first->op()->branch_delay().kind() == IR2_BranchDelay::Kind::NOP); - assert(jump_to_end.first->op()->condition().kind() == IR2_Condition::Kind::ALWAYS); + ASSERT(jump_to_end.first); + ASSERT(jump_to_end.first->op()->branch_delay().kind() == IR2_BranchDelay::Kind::NOP); + ASSERT(jump_to_end.first->op()->condition().kind() == IR2_Condition::Kind::ALWAYS); auto as_end_of_sequence = get_condition_branch_as_vector(e.body); if (as_end_of_sequence.first) { - assert(as_end_of_sequence.second->size() > 1); + ASSERT(as_end_of_sequence.second->size() > 1); as_end_of_sequence.second->pop_back(); } else { *(jump_to_end.second) = pool.alloc_element(); @@ -1041,8 +1041,8 @@ Form* try_sc_as_abs(FormPool& pool, Function& f, const ShortCircuit* vtx) { auto input = branch->op()->condition().src(0); auto output = delay->dst(); - assert(input.is_var()); - assert(input.var().reg() == delay->src().get_arg(0).var().reg()); + ASSERT(input.is_var()); + ASSERT(input.var().reg() == delay->src().get_arg(0).var().reg()); // remove the branch b0_ptr->pop_back(); @@ -1113,11 +1113,11 @@ Form* try_sc_as_ash(FormPool& pool, Function& f, const ShortCircuit* vtx) { */ auto sa_in = branch->op()->condition().src(0); - assert(sa_in.is_var()); + ASSERT(sa_in.is_var()); auto result = delay->dst(); auto value_in = delay->src().get_arg(0).var(); auto sa_in2 = delay->src().get_arg(1).var(); - assert(sa_in.var().reg() == sa_in2.reg()); + ASSERT(sa_in.var().reg() == sa_in2.reg()); auto dsubu_candidate = b1_ptr->at(0); auto dsrav_candidate = b1_ptr->at(1); @@ -1139,7 +1139,7 @@ Form* try_sc_as_ash(FormPool& pool, Function& f, const ShortCircuit* vtx) { std::optional clobber_ir; auto dsubu_set = dynamic_cast(dsubu_candidate); auto dsrav_set = dynamic_cast(dsrav_candidate); - assert(dsubu_set && dsrav_set); + ASSERT(dsubu_set && dsrav_set); if (clobber != result.reg()) { clobber_ir = dsubu_set->dst(); } @@ -1198,7 +1198,7 @@ SetVarOp get_delay_op(const Function& f, const BlockVtx* vtx) { auto delay_start = f.ir2.atomic_ops->block_id_to_first_atomic_op.at(vtx->block_id); auto delay_end = f.ir2.atomic_ops->block_id_to_end_atomic_op.at(vtx->block_id); if (delay_end - delay_start != 1) { - assert(false); + ASSERT(false); } auto& delay_op = f.ir2.atomic_ops->ops.at(delay_start); auto* delay = dynamic_cast(delay_op.get()); @@ -1281,7 +1281,7 @@ Form* try_sc_as_type_of(FormPool& pool, Function& f, const ShortCircuit* vtx) { return nullptr; } auto temp_reg = first_branch->op()->condition().src(0).var(); - assert(temp_reg.reg() == temp_reg0.reg()); + ASSERT(temp_reg.reg() == temp_reg0.reg()); auto dst_reg = b0_delay_op.dst(); auto b1_delay_op = get_delay_op(f, b1_d); @@ -1293,12 +1293,12 @@ Form* try_sc_as_type_of(FormPool& pool, Function& f, const ShortCircuit* vtx) { // check we agree on destination register. auto dst_reg2 = b1_delay_op.dst(); - assert(dst_reg2.reg() == dst_reg.reg()); + ASSERT(dst_reg2.reg() == dst_reg.reg()); // else case is a lwu to grab the type from a basic - assert(else_case); + ASSERT(else_case); auto dst_reg3 = else_case->dst(); - assert(dst_reg3.reg() == dst_reg.reg()); + ASSERT(dst_reg3.reg() == dst_reg.reg()); auto load_op = dynamic_cast(else_case->src()->try_as_single_element()); if (!load_op || load_op->kind() != LoadVarOp::Kind::UNSIGNED || load_op->size() != 4) { return nullptr; @@ -1314,8 +1314,8 @@ Form* try_sc_as_type_of(FormPool& pool, Function& f, const ShortCircuit* vtx) { return nullptr; } - assert(src_reg3.var().reg() == src_reg.reg()); - assert(offset.get_int() == -4); + ASSERT(src_reg3.var().reg() == src_reg.reg()); + ASSERT(offset.get_int() == -4); std::optional clobber; if (temp_reg.reg() != dst_reg.reg()) { @@ -1438,7 +1438,7 @@ void convert_and_inline(FormPool& pool, Function& f, const BlockVtx* as_block, T // add = false; auto consumed_expr = dynamic_cast(op_as_set->src()->try_as_single_element()); - assert(consumed_expr); + ASSERT(consumed_expr); auto& consumed = consumed_expr->expr().get_arg(0).var(); auto& ri_outer = f.ir2.env.reg_use().op.at(consumed.idx()); // meh if (ri_outer.consumes.find(consumed.reg()) != ri_outer.consumes.end()) { @@ -1628,13 +1628,13 @@ Form* cfg_to_ir_helper(FormPool& pool, Function& f, const CfgVtx* vtx) { e.condition = cfg_to_ir(pool, f, x.condition); if (x.likely_delay) { auto delay = dynamic_cast(x.likely_delay); - assert(delay); + ASSERT(delay); auto delay_start = f.ir2.atomic_ops->block_id_to_first_atomic_op.at(delay->block_id); auto delay_end = f.ir2.atomic_ops->block_id_to_end_atomic_op.at(delay->block_id); - assert(delay_end - delay_start == 1); + ASSERT(delay_end - delay_start == 1); auto& op = f.ir2.atomic_ops->ops.at(delay_start); auto op_as_expr = dynamic_cast(op.get()); - assert(op_as_expr); + ASSERT(op_as_expr); e.branch_delay = *op_as_expr; } @@ -1665,10 +1665,10 @@ Form* cfg_to_ir_helper(FormPool& pool, Function& f, const CfgVtx* vtx) { // lg::error("failed to recognize dead code after return, got {}", // dead_code->to_string(f.ir2.env)); // } - // assert(dead); + // ASSERT(dead); // auto src = dynamic_cast(dead->src()->try_as_single_element()); - // assert(src); - // assert(src->expr().is_identity() && src->expr().get_arg(0).is_int() && + // ASSERT(src); + // ASSERT(src->expr().is_identity() && src->expr().get_arg(0).is_int() && // src->expr().get_arg(0).get_int() == 0); auto result = pool.alloc_single_element_form( @@ -1716,22 +1716,22 @@ void clean_up_while_loops(FormPool& pool, Form* sequence, const Env& env) { for (int i = 0; i < sequence->size(); i++) { auto* form_as_while = dynamic_cast(sequence->at(i)); if (form_as_while && !form_as_while->cleaned) { - assert(i != 0); + ASSERT(i != 0); auto prev_as_branch = dynamic_cast(sequence->at(i - 1)); - assert(prev_as_branch); + ASSERT(prev_as_branch); // printf("got while intro branch %s\n", prev_as_branch->print(file).c_str()); // this should be an always jump. We'll assume that the CFG builder successfully checked // the brach destination, but we will check the condition. - assert(prev_as_branch->op()->condition().kind() == IR2_Condition::Kind::ALWAYS); - assert(prev_as_branch->op()->branch_delay().kind() == IR2_BranchDelay::Kind::NOP); + ASSERT(prev_as_branch->op()->condition().kind() == IR2_Condition::Kind::ALWAYS); + ASSERT(prev_as_branch->op()->branch_delay().kind() == IR2_BranchDelay::Kind::NOP); to_remove.push_back(i - 1); // now we should try to find the condition branch: auto condition_branch = get_condition_branch(form_as_while->condition); - assert(condition_branch.first); - assert(condition_branch.first->op()->branch_delay().kind() == IR2_BranchDelay::Kind::NOP); + ASSERT(condition_branch.first); + ASSERT(condition_branch.first->op()->branch_delay().kind() == IR2_BranchDelay::Kind::NOP); // printf("got while condition branch %s\n", condition_branch.first->print(file).c_str()); auto replacement = condition_branch.first->op()->get_condition_as_form(pool, env); @@ -1742,7 +1742,7 @@ void clean_up_while_loops(FormPool& pool, Form* sequence, const Env& env) { // remove the implied forward always branches. for (int i = int(to_remove.size()); i-- > 0;) { auto idx = to_remove.at(i); - assert(dynamic_cast(sequence->at(idx))); + ASSERT(dynamic_cast(sequence->at(idx))); sequence->elts().erase(sequence->elts().begin() + idx); } } diff --git a/decompiler/analysis/expression_build.cpp b/decompiler/analysis/expression_build.cpp index 082b715049..e1ba4b3b29 100644 --- a/decompiler/analysis/expression_build.cpp +++ b/decompiler/analysis/expression_build.cpp @@ -17,7 +17,7 @@ bool convert_to_expressions( const std::vector& arg_names, const std::unordered_map& var_override_map, const DecompilerTypeSystem& dts) { - assert(top_level_form); + ASSERT(top_level_form); // set argument names to some reasonable defaults. these will be used if the user doesn't // give us anything more specific. @@ -141,7 +141,7 @@ bool convert_to_expressions( // and sanity check for tree errors. for (auto x : top_level_form->elts()) { - assert(x->parent_form == top_level_form); + ASSERT(x->parent_form == top_level_form); } // if we were don't return, make sure we didn't find a return form. diff --git a/decompiler/analysis/final_output.cpp b/decompiler/analysis/final_output.cpp index 980ad3d5f9..d7a6bda302 100644 --- a/decompiler/analysis/final_output.cpp +++ b/decompiler/analysis/final_output.cpp @@ -12,7 +12,7 @@ goos::Object get_arg_list_for_function(const Function& func, const Env& env) { if (func.type.arg_count() < 1) { throw std::runtime_error(fmt::format("Function {} has unknown type.\n", func.name())); } - assert(func.type.arg_count() >= 1); + ASSERT(func.type.arg_count() >= 1); for (size_t i = 0; i < func.type.arg_count() - 1; i++) { auto reg = Register(Reg::GPR, Reg::A0 + i); auto name = fmt::format("{}-0", reg.to_charp()); @@ -92,7 +92,7 @@ std::string final_defun_out(const Function& func, if (special_mode == FunctionDefSpecials::DEFUN_DEBUG) { def_name = "defun-debug"; } else { - assert(special_mode == FunctionDefSpecials::NONE); + ASSERT(special_mode == FunctionDefSpecials::NONE); } auto behavior = func.type.try_get_tag("behavior"); @@ -116,7 +116,7 @@ std::string final_defun_out(const Function& func, } if (func.guessed_name.kind == FunctionName::FunctionKind::METHOD) { - assert(special_mode == FunctionDefSpecials::NONE); + ASSERT(special_mode == FunctionDefSpecials::NONE); std::vector top; top.push_back(pretty_print::to_symbol("defmethod")); auto method_info = @@ -131,7 +131,7 @@ std::string final_defun_out(const Function& func, } if (func.guessed_name.kind == FunctionName::FunctionKind::TOP_LEVEL_INIT) { - assert(special_mode == FunctionDefSpecials::NONE); + ASSERT(special_mode == FunctionDefSpecials::NONE); std::vector top; top.push_back(pretty_print::to_symbol("top-level-function")); top.push_back(arguments); @@ -143,7 +143,7 @@ std::string final_defun_out(const Function& func, if (func.guessed_name.kind == FunctionName::FunctionKind::UNIDENTIFIED) { std::string def_name = "defun-anon"; - assert(special_mode == FunctionDefSpecials::NONE); + ASSERT(special_mode == FunctionDefSpecials::NONE); std::vector top; top.push_back(pretty_print::to_symbol(def_name)); top.push_back(pretty_print::to_symbol(func.name())); @@ -229,7 +229,7 @@ std::string write_from_top_level_form(Form* top_form, const std::unordered_set& skip_functions, const Env& env) { std::vector forms = top_form->elts(); - assert(!forms.empty()); + ASSERT(!forms.empty()); // remove a (none) from the end, if it exists. auto back_as_generic_op = dynamic_cast(forms.back()); @@ -406,7 +406,7 @@ std::string write_from_top_level_form(Form* top_form, result += fmt::format(";; definition for symbol {}, type {}\n", sym_name, symbol_type.print()); auto setset = dynamic_cast(f.try_as_single_element()); - assert(setset); + ASSERT(setset); result += pretty_print::to_string(setset->to_form_for_define(env)); result += "\n\n"; } diff --git a/decompiler/analysis/find_defstates.cpp b/decompiler/analysis/find_defstates.cpp index 76c03d39b7..0021e1b71e 100644 --- a/decompiler/analysis/find_defstates.cpp +++ b/decompiler/analysis/find_defstates.cpp @@ -111,7 +111,7 @@ std::vector get_defstate_entries( env.get_variable_name(let_dest_var), env.get_variable_name(*var)); } else { - assert(false); + ASSERT(false); } } @@ -173,7 +173,7 @@ FormElement* rewrite_nonvirtual_defstate( const std::unordered_map>& skip_states = {}) { // first thing in the body should be something like: // (set! teetertotter-idle (the-as (state none) v1-3)) - assert(elt->body()->size() > 0); + ASSERT(elt->body()->size() > 0); int body_index = 0; // the setup @@ -256,7 +256,7 @@ FormElement* rewrite_virtual_defstate( const std::string& expected_state_name, FormPool& pool, const std::unordered_map>& skip_states = {}) { - assert(elt->body()->size() > 1); + ASSERT(elt->body()->size() > 1); // variable at the top of let, contains the static state with name exptected_state_name auto state_var_from_let_def = elt->entries().at(0).dest; // our index into the let body diff --git a/decompiler/analysis/find_skelgroups.cpp b/decompiler/analysis/find_skelgroups.cpp index ad3ce77e86..0447781643 100644 --- a/decompiler/analysis/find_skelgroups.cpp +++ b/decompiler/analysis/find_skelgroups.cpp @@ -142,7 +142,7 @@ DefskelgroupElement::Info get_defskelgroup_entries(Form* body, env.get_variable_name(let_dest_var), env.get_variable_name(*var)); } else { - assert(false); + ASSERT(false); } } @@ -167,7 +167,7 @@ FormElement* rewrite_defskelgroup(LetElement* elt, FormPool& pool) { // last thing in the body should be something like: // (set! *hopper-sg* v1-1) - assert(elt->body()->size() > 0); + ASSERT(elt->body()->size() > 0); int last_lod = (elt->body()->size() - 3) / 2 - 1; if (last_lod > skelgroup_info.max_lod) { diff --git a/decompiler/analysis/inline_asm_rewrite.cpp b/decompiler/analysis/inline_asm_rewrite.cpp index 16f328cff3..6a167212b6 100644 --- a/decompiler/analysis/inline_asm_rewrite.cpp +++ b/decompiler/analysis/inline_asm_rewrite.cpp @@ -14,7 +14,7 @@ bool rewrite_inline_asm_instructions(Form* top_level_form, FormPool& pool, Function& f, const DecompilerTypeSystem&) { - assert(top_level_form); + ASSERT(top_level_form); try { RegSet vf_regs; @@ -63,7 +63,7 @@ bool rewrite_inline_asm_instructions(Form* top_level_form, new_entries.push_back(newElem); } - assert(!new_entries.empty()); + ASSERT(!new_entries.empty()); form->clear(); for (auto x : new_entries) { form->push_back(x); diff --git a/decompiler/analysis/insert_lets.cpp b/decompiler/analysis/insert_lets.cpp index 1651798cf1..0f6d583966 100644 --- a/decompiler/analysis/insert_lets.cpp +++ b/decompiler/analysis/insert_lets.cpp @@ -81,7 +81,7 @@ Form* lca_form(Form* a, Form* b, const Env& env) { if (!result) { fmt::print("{} bad form is {}\n\n{}\n", env.func->name(), a->to_string(env), b->to_string(env)); } - assert(result); + ASSERT(result); // fmt::print("{}\n\n", result->to_string(env)); return result; @@ -133,7 +133,7 @@ FormElement* rewrite_as_dotimes(LetElement* in, const Env& env, FormPool& pool) // check the lt operation: auto lt_var = mr.maps.regs.at(0); - assert(lt_var); + ASSERT(lt_var); if (env.get_variable_name(*lt_var) != var) { return nullptr; // wrong variable checked } @@ -155,7 +155,7 @@ FormElement* rewrite_as_dotimes(LetElement* in, const Env& env, FormPool& pool) } auto inc_var = int_mr.maps.regs.at(0); - assert(inc_var); + ASSERT(inc_var); if (env.get_variable_name(*inc_var) != var) { return nullptr; // wrong variable incremented } @@ -239,7 +239,7 @@ FormElement* rewrite_as_send_event(LetElement* in, const Env& env, FormPool& poo return nullptr; } int param_count = num_params_mr.maps.ints.at(1); - assert(param_count >= 0 && param_count < 7); + ASSERT(param_count >= 0 && param_count < 7); if (body->size() != 4 + param_count) { // fmt::print(" fail: pc3\n"); return nullptr; @@ -360,7 +360,7 @@ FormElement* rewrite_as_countdown(LetElement* in, const Env& env, FormPool& pool // check the zero operation: auto lt_var = mr.maps.regs.at(0); - assert(lt_var); + ASSERT(lt_var); if (env.get_variable_name(*lt_var) != idx_var) { return nullptr; // wrong variable checked } @@ -382,7 +382,7 @@ FormElement* rewrite_as_countdown(LetElement* in, const Env& env, FormPool& pool } auto inc_var = int_mr.maps.regs.at(0); - assert(inc_var); + ASSERT(inc_var); if (env.get_variable_name(*inc_var) != idx_var) { return nullptr; // wrong variable incremented } @@ -422,7 +422,7 @@ FormElement* fix_up_abs(LetElement* in, const Env& env, FormPool& pool) { return nullptr; } - assert(mr.maps.regs.at(0)); + ASSERT(mr.maps.regs.at(0)); auto abs_var_name = env.get_variable_name(*mr.maps.regs.at(0)); if (abs_var_name != temp_name) { return nullptr; @@ -477,7 +477,7 @@ FormElement* fix_up_abs_2(LetElement* in, const Env& env, FormPool& pool) { return nullptr; } - assert(mr.maps.regs.at(0)); + ASSERT(mr.maps.regs.at(0)); auto abs_var_name = env.get_variable_name(*mr.maps.regs.at(0)); if (abs_var_name != temp_name) { @@ -851,7 +851,7 @@ FormElement* rewrite_multi_let_as_vector_dot(LetElement* in, const Env& env, For return nullptr; } for (int j = 0; j < 2; j++) { - assert(as_op->op()->src(j).has_value()); + ASSERT(as_op->op()->src(j).has_value()); vars[i][j] = *as_op->op()->src(j); } } @@ -871,14 +871,14 @@ FormElement* rewrite_multi_let_as_vector_dot(LetElement* in, const Env& env, For return nullptr; } auto this_var = mr.maps.regs.at(0); - assert(this_var.has_value()); + ASSERT(this_var.has_value()); if (in_vars[in_var].has_value()) { // seen it before if (env.get_variable_name(*this_var) != env.get_variable_name(*in_vars[in_var])) { return nullptr; } } else { - assert(axis == 0); + ASSERT(axis == 0); // first time seeing it. in_vars[in_var] = this_var; } @@ -996,7 +996,7 @@ LetStats insert_lets(const Function& func, Env& env, FormPool& pool, Form* top_l // } // } // - // assert(f); + // ASSERT(f); // } // and add it. @@ -1019,7 +1019,7 @@ LetStats insert_lets(const Function& func, Env& env, FormPool& pool, Form* top_l for (auto fe : kv.second.elts_using_var) { lca = lca_form(lca, fe->parent_form, env); } - assert(lca); + ASSERT(lca); var_info[kv.first].lca_form = lca; } @@ -1051,7 +1051,7 @@ LetStats insert_lets(const Function& func, Env& env, FormPool& pool, Form* top_l // kv.second.end_idx, kv.second.lca_form->at(i)->to_string(env)); } } - assert(got_one); + ASSERT(got_one); } // fmt::print("\n"); @@ -1168,14 +1168,14 @@ LetStats insert_lets(const Function& func, Env& env, FormPool& pool, Form* top_l elt_idx++; } else { auto existing_let = lets.at(ownership[elt_idx]); - assert(existing_let); + ASSERT(existing_let); auto& existing_let_info = group.second.at(ownership[elt_idx]); - assert(existing_let_info.start_elt == elt_idx); + ASSERT(existing_let_info.start_elt == elt_idx); body.push_back(existing_let); elt_idx = existing_let_info.end_elt; } } - assert(elt_idx == let_desc.end_elt); + ASSERT(elt_idx == let_desc.end_elt); auto new_let = pool.alloc_element(pool.alloc_sequence_form(nullptr, body)); // insert a cast, if needed. auto casted_src = insert_cast_for_let(let_desc.set_form->dst(), let_desc.set_form->src_type(), @@ -1194,14 +1194,14 @@ LetStats insert_lets(const Function& func, Env& env, FormPool& pool, Form* top_l elt_idx++; } else { auto existing_let = lets.at(ownership[elt_idx]); - assert(existing_let); + ASSERT(existing_let); auto& existing_let_info = group.second.at(ownership[elt_idx]); - assert(existing_let_info.start_elt == elt_idx); + ASSERT(existing_let_info.start_elt == elt_idx); new_body.push_back(existing_let); elt_idx = existing_let_info.end_elt; } } - assert(elt_idx == group.first->size()); + ASSERT(elt_idx == group.first->size()); group.first->elts() = new_body; group.first->claim_all_children(); @@ -1260,7 +1260,7 @@ LetStats insert_lets(const Function& func, Env& env, FormPool& pool, Form* top_l // rewrite: form->at(idx) = rewrite_multi_let(as_let, env, pool); - assert(form->at(idx)->parent_form == form); + ASSERT(form->at(idx)->parent_form == form); changed = true; } }); diff --git a/decompiler/analysis/mips2c.cpp b/decompiler/analysis/mips2c.cpp index 57e61b89fd..ad35ee381e 100644 --- a/decompiler/analysis/mips2c.cpp +++ b/decompiler/analysis/mips2c.cpp @@ -95,7 +95,7 @@ std::string goal_to_c_function_name(const FunctionName& name) { case FunctionName::FunctionKind::METHOD: return fmt::format("method_{}_{}", name.method_id, goal_to_c_name(name.type_name)); default: - assert(false); + ASSERT(false); } } @@ -103,7 +103,7 @@ std::string goal_to_c_function_name(const FunctionName& name) { * Convert a decompiler register into the name of the register constant in mips2c_private.h */ const char* reg_to_name(const InstructionAtom& atom) { - assert(atom.is_reg()); + ASSERT(atom.is_reg()); return atom.get_reg().to_charp(); } @@ -287,9 +287,9 @@ void link_fall_through(int first_idx, int second_idx, std::vector& bl auto& first = blocks.at(first_idx); auto& second = blocks.at(second_idx); - assert(first.succ_ft == -1); // don't want to overwrite something by accident. + ASSERT(first.succ_ft == -1); // don't want to overwrite something by accident. // can only fall through to the next code in memory. - assert(first_idx + 1 == second_idx); + ASSERT(first_idx + 1 == second_idx); first.succ_ft = second_idx; if (!second.has_pred(first_idx)) { @@ -306,7 +306,7 @@ void link_fall_through(int first_idx, int second_idx, std::vector& bl void link_branch(int first_idx, int second_idx, std::vector& blocks) { auto& first = blocks.at(first_idx); auto& second = blocks.at(second_idx); - assert(first.succ_branch == -1); + ASSERT(first.succ_branch == -1); first.succ_branch = second_idx; if (!second.has_pred(first_idx)) { @@ -321,9 +321,9 @@ void link_branch(int first_idx, int second_idx, std::vector& blocks) void link_fall_through_likely(int first_idx, int second_idx, std::vector& blocks) { auto& first = blocks.at(first_idx); auto& second = blocks.at(second_idx); - assert(first.succ_ft == -1); // don't want to overwrite something by accident. + ASSERT(first.succ_ft == -1); // don't want to overwrite something by accident. // can only fall through to the next code in memory. - assert(first_idx + 2 == second_idx); + ASSERT(first_idx + 2 == second_idx); first.succ_ft = second_idx; @@ -361,10 +361,10 @@ std::vector setup_preds_and_succs(const Function& func, auto& b = func.basic_blocks[i]; if (blocks.at(i).branch_always) { // likely branch, already set up. - assert(likely_delay_slot_blocks.count(i)); + ASSERT(likely_delay_slot_blocks.count(i)); continue; } else { - assert(!likely_delay_slot_blocks.count(i)); + ASSERT(!likely_delay_slot_blocks.count(i)); } bool not_last = (i + 1) < int(func.basic_blocks.size()); @@ -376,7 +376,7 @@ std::vector setup_preds_and_succs(const Function& func, } else { // room for at least a likely branch, try that first. int likely_branch_idx = b.end_word - 1; - assert(likely_branch_idx >= b.start_word); + ASSERT(likely_branch_idx >= b.start_word); auto& likely_branch_candidate = func.instructions.at(likely_branch_idx); if (is_branch(likely_branch_candidate, true)) { @@ -389,12 +389,12 @@ std::vector setup_preds_and_succs(const Function& func, // need to find block target int block_target = -1; int label_target = likely_branch_candidate.get_label_target(); - assert(label_target != -1); + ASSERT(label_target != -1); const auto& label = file.labels.at(label_target); - // assert(label.target_segment == seg); - assert((label.offset % 4) == 0); + // ASSERT(label.target_segment == seg); + ASSERT((label.offset % 4) == 0); int offset = label.offset / 4 - func.start_word; - assert(offset >= 0); + ASSERT(offset >= 0); for (int j = int(func.basic_blocks.size()); j-- > 0;) { if (func.basic_blocks[j].start_word == offset) { block_target = j; @@ -402,7 +402,7 @@ std::vector setup_preds_and_succs(const Function& func, } } - assert(block_target != -1); + ASSERT(block_target != -1); // "branch" to delay slot, which then "falls through" to the destination. link_branch(i, i + 1, blocks); @@ -423,7 +423,7 @@ std::vector setup_preds_and_succs(const Function& func, delay_block.branch_always = true; delay_block.has_branch = true; auto inserted = likely_delay_slot_blocks.insert(i + 1).second; - assert(inserted); + ASSERT(inserted); link_branch(i + 1, block_target, blocks); } else { @@ -435,7 +435,7 @@ std::vector setup_preds_and_succs(const Function& func, } else { // try as a normal branch. int idx = b.end_word - 2; - assert(idx >= b.start_word); + ASSERT(idx >= b.start_word); auto& branch_candidate = func.instructions.at(idx); if (is_branch(branch_candidate, false)) { blocks.at(i).has_branch = true; @@ -445,12 +445,12 @@ std::vector setup_preds_and_succs(const Function& func, // need to find block target int block_target = -1; int label_target = branch_candidate.get_label_target(); - assert(label_target != -1); + ASSERT(label_target != -1); const auto& label = file.labels.at(label_target); - // assert(label.target_segment == seg); - assert((label.offset % 4) == 0); + // ASSERT(label.target_segment == seg); + ASSERT((label.offset % 4) == 0); int offset = label.offset / 4 - func.start_word; - assert(offset >= 0); + ASSERT(offset >= 0); for (int j = int(func.basic_blocks.size()); j-- > 0;) { if (func.basic_blocks[j].start_word == offset) { @@ -459,7 +459,7 @@ std::vector setup_preds_and_succs(const Function& func, } } - assert(block_target != -1); + ASSERT(block_target != -1); link_branch(i, block_target, blocks); if (branch_always) { @@ -539,7 +539,7 @@ Mips2C_Line handle_lwc1(const Instruction& i0, if (i0.get_src(0).is_label() && i0.get_src(1).is_reg(Register(Reg::GPR, Reg::FP))) { auto& label = file->labels.at(i0.get_src(0).get_label()); auto& word = file->words_by_seg.at(label.target_segment).at(label.offset / 4); - assert(word.kind() == LinkedWord::PLAIN_DATA); + ASSERT(word.kind() == LinkedWord::PLAIN_DATA); float f; memcpy(&f, &word.data, 4); return {fmt::format("c->fprs[{}] = {};", reg_to_name(i0.get_dst(0)), float_to_string(f)), @@ -562,9 +562,9 @@ Mips2C_Line handle_lw(Mips2C_Output& out, } if (i0.get_src(1).is_reg(rfp()) && i0.get_src(0).is_label()) { const auto& label = file->labels.at(i0.get_src(0).get_label()); - assert((label.offset % 4) == 0); + ASSERT((label.offset % 4) == 0); const auto& word = file->words_by_seg.at(label.target_segment).at(label.offset / 4); - assert(word.kind() == LinkedWord::PLAIN_DATA); + ASSERT(word.kind() == LinkedWord::PLAIN_DATA); u32 val_u32 = word.data; float val_float; memcpy(&val_float, &val_u32, 4); @@ -1151,16 +1151,16 @@ void run_mips2c_jump_table(Function* f, const std::vector& jump_table_locat output.lines.emplace_back(fmt::format("if ({}) {{", branch_line.code), branch_line.comment); // next block should be the delay slot - assert((int)block_idx + 1 == block.succ_branch); + ASSERT((int)block_idx + 1 == block.succ_branch); auto& delay_block = blocks.at(block.succ_branch); - assert(delay_block.end_instr - delay_block.start_instr == 1); // only 1 instr. + ASSERT(delay_block.end_instr - delay_block.start_instr == 1); // only 1 instr. auto& delay_instr = f->instructions.at(delay_block.start_instr); auto delay_instr_str = delay_instr.to_string(file->labels); auto delay_instr_line = handle_normal_instr(output, delay_instr, delay_instr_str, unknown_count, file); output.lines.emplace_back(fmt::format(" {}", delay_instr_line.code), delay_instr_line.comment); - assert(delay_block.succ_ft == -1); + ASSERT(delay_block.succ_ft == -1); output.lines.emplace_back(fmt::format(" next_block = {};", delay_block.succ_branch), ""); output.lines.emplace_back("break;"); output.lines.emplace_back("}", ""); @@ -1169,13 +1169,13 @@ void run_mips2c_jump_table(Function* f, const std::vector& jump_table_locat // skip the branch ins. output.lines.emplace_back("//" + instr_str, instr_str); // then the delay slot - assert(i + 1 < block.end_instr); + ASSERT(i + 1 < block.end_instr); i++; auto& delay_i = f->instructions.at(i); auto delay_i_str = delay_i.to_string(file->labels); output.lines.push_back( handle_normal_instr(output, delay_i, delay_i_str, unknown_count, file)); - assert(i + 1 == block.end_instr); + ASSERT(i + 1 == block.end_instr); // then the goto output.lines.emplace_back(fmt::format("next_block = {};", block.succ_branch), "branch always\n"); @@ -1185,13 +1185,13 @@ void run_mips2c_jump_table(Function* f, const std::vector& jump_table_locat // set the branch condition output.lines.push_back(handle_non_likely_branch_bc(instr, instr_str)); // then the delay slot - assert(i + 1 < block.end_instr); + ASSERT(i + 1 < block.end_instr); i++; auto& delay_i = f->instructions.at(i); auto delay_i_str = delay_i.to_string(file->labels); output.lines.push_back( handle_normal_instr(output, delay_i, delay_i_str, unknown_count, file)); - assert(i + 1 == block.end_instr); + ASSERT(i + 1 == block.end_instr); // then the goto output.lines.emplace_back( fmt::format("if (bc) {{next_block = {};}}", block.succ_branch), @@ -1203,7 +1203,7 @@ void run_mips2c_jump_table(Function* f, const std::vector& jump_table_locat // skip output.lines.emplace_back("//" + instr_str, instr_str); // then the delay slot - assert(i + 1 < block.end_instr); + ASSERT(i + 1 < block.end_instr); i++; auto& delay_i = f->instructions.at(i); auto delay_i_str = delay_i.to_string(file->labels); @@ -1214,8 +1214,8 @@ void run_mips2c_jump_table(Function* f, const std::vector& jump_table_locat output.lines.emplace_back(fmt::format("goto end_of_function;", block.succ_branch), "return\n"); } else if (instr.kind == InstructionKind::JALR) { - assert(instr.get_dst(0).is_reg(Register(Reg::GPR, Reg::RA))); - assert(i < block.end_instr - 1); + ASSERT(instr.get_dst(0).is_reg(Register(Reg::GPR, Reg::RA))); + ASSERT(i < block.end_instr - 1); output.lines.emplace_back( fmt::format("call_addr = c->gprs[{}].du32[0];", reg_to_name(instr.get_src(0))), "function call:"); @@ -1230,14 +1230,14 @@ void run_mips2c_jump_table(Function* f, const std::vector& jump_table_locat output.lines.emplace_back(fmt::format("next_block = 0x{:x} ^ c->gprs[{}].du32[0];", magic_code, reg_to_name(instr.get_src(0))), instr_str); - output.lines.emplace_back(fmt::format("assert(next_block < {});", f->basic_blocks.size())); + output.lines.emplace_back(fmt::format("ASSERT(next_block < {});", f->basic_blocks.size())); output.lines.emplace_back("break;"); } else { output.lines.push_back(handle_normal_instr(output, instr, instr_str, unknown_count, file)); } - assert(output.lines.size() > old_line_count); + ASSERT(output.lines.size() > old_line_count); } } @@ -1286,16 +1286,16 @@ void run_mips2c(Function* f) { output.lines.emplace_back(fmt::format("if ({}) {{", branch_line.code), branch_line.comment); // next block should be the delay slot - assert((int)block_idx + 1 == block.succ_branch); + ASSERT((int)block_idx + 1 == block.succ_branch); auto& delay_block = blocks.at(block.succ_branch); - assert(delay_block.end_instr - delay_block.start_instr == 1); // only 1 instr. + ASSERT(delay_block.end_instr - delay_block.start_instr == 1); // only 1 instr. auto& delay_instr = f->instructions.at(delay_block.start_instr); auto delay_instr_str = delay_instr.to_string(file->labels); auto delay_instr_line = handle_normal_instr(output, delay_instr, delay_instr_str, unknown_count, file); output.lines.emplace_back(fmt::format(" {}", delay_instr_line.code), delay_instr_line.comment); - assert(delay_block.succ_ft == -1); + ASSERT(delay_block.succ_ft == -1); output.lines.emplace_back(fmt::format(" goto block_{};", delay_block.succ_branch), ""); output.lines.emplace_back("}", ""); } else { @@ -1303,13 +1303,13 @@ void run_mips2c(Function* f) { // skip the branch ins. output.lines.emplace_back("//" + instr_str, instr_str); // then the delay slot - assert(i + 1 < block.end_instr); + ASSERT(i + 1 < block.end_instr); i++; auto& delay_i = f->instructions.at(i); auto delay_i_str = delay_i.to_string(file->labels); output.lines.push_back( handle_normal_instr(output, delay_i, delay_i_str, unknown_count, file)); - assert(i + 1 == block.end_instr); + ASSERT(i + 1 == block.end_instr); // then the goto output.lines.emplace_back(fmt::format("goto block_{};", block.succ_branch), "branch always\n"); @@ -1317,13 +1317,13 @@ void run_mips2c(Function* f) { // set the branch condition output.lines.push_back(handle_non_likely_branch_bc(instr, instr_str)); // then the delay slot - assert(i + 1 < block.end_instr); + ASSERT(i + 1 < block.end_instr); i++; auto& delay_i = f->instructions.at(i); auto delay_i_str = delay_i.to_string(file->labels); output.lines.push_back( handle_normal_instr(output, delay_i, delay_i_str, unknown_count, file)); - assert(i + 1 == block.end_instr); + ASSERT(i + 1 == block.end_instr); // then the goto output.lines.emplace_back(fmt::format("if (bc) {{goto block_{};}}", block.succ_branch), "branch non-likely\n"); @@ -1333,7 +1333,7 @@ void run_mips2c(Function* f) { // skip output.lines.emplace_back("//" + instr_str, instr_str); // then the delay slot - assert(i + 1 < block.end_instr); + ASSERT(i + 1 < block.end_instr); i++; auto& delay_i = f->instructions.at(i); auto delay_i_str = delay_i.to_string(file->labels); @@ -1344,8 +1344,8 @@ void run_mips2c(Function* f) { output.lines.emplace_back(fmt::format("goto end_of_function;", block.succ_branch), "return\n"); } else if (instr.kind == InstructionKind::JALR) { - assert(instr.get_dst(0).is_reg(Register(Reg::GPR, Reg::RA))); - assert(i < block.end_instr - 1); + ASSERT(instr.get_dst(0).is_reg(Register(Reg::GPR, Reg::RA))); + ASSERT(i < block.end_instr - 1); output.lines.emplace_back( fmt::format("call_addr = c->gprs[{}].du32[0];", reg_to_name(instr.get_src(0))), "function call:"); @@ -1359,7 +1359,7 @@ void run_mips2c(Function* f) { output.lines.push_back(handle_normal_instr(output, instr, instr_str, unknown_count, file)); } - assert(output.lines.size() > old_line_count); + ASSERT(output.lines.size() > old_line_count); } } diff --git a/decompiler/analysis/reg_usage.cpp b/decompiler/analysis/reg_usage.cpp index b1119620e2..7a6d035ee4 100644 --- a/decompiler/analysis/reg_usage.cpp +++ b/decompiler/analysis/reg_usage.cpp @@ -219,7 +219,7 @@ RegUsageInfo analyze_ir2_register_usage(const Function& function) { } result.op.pop_back(); - assert(result.op.size() == ops->ops.size()); + ASSERT(result.op.size() == ops->ops.size()); return result; } } // namespace decompiler \ No newline at end of file diff --git a/decompiler/analysis/stack_spill.cpp b/decompiler/analysis/stack_spill.cpp index b7589282f3..d27b2e1758 100644 --- a/decompiler/analysis/stack_spill.cpp +++ b/decompiler/analysis/stack_spill.cpp @@ -47,7 +47,7 @@ void StackSpillMap::finalize() { max_offset = std::max(max_offset, slot.second.offset + slot.second.size); } - assert(max_offset < 4096); // just a sanity check here + ASSERT(max_offset < 4096); // just a sanity check here std::vector var_count(max_offset, 0); for (auto& slot : m_slot_map) { diff --git a/decompiler/analysis/symbol_def_map.cpp b/decompiler/analysis/symbol_def_map.cpp index 62694a1b10..215c7481ec 100644 --- a/decompiler/analysis/symbol_def_map.cpp +++ b/decompiler/analysis/symbol_def_map.cpp @@ -21,7 +21,7 @@ void SymbolMapBuilder::add_object(const ObjectFileData& data) { // add deftypes in the top level function const auto& top_level_functions = data.linked_data.functions_by_seg.at(TOP_LEVEL_SEGMENT); - assert(top_level_functions.size() == 1); + ASSERT(top_level_functions.size() == 1); add_deftypes_from_top_level_function(top_level_functions.at(0), &m_first_detections.back()); } diff --git a/decompiler/analysis/type_analysis.cpp b/decompiler/analysis/type_analysis.cpp index 94304a5fc4..f1b7a1be25 100644 --- a/decompiler/analysis/type_analysis.cpp +++ b/decompiler/analysis/type_analysis.cpp @@ -5,9 +5,9 @@ namespace { TypeState construct_initial_typestate(const TypeSpec& f_ts, const Env& env) { TypeState result; int goal_args[] = {Reg::A0, Reg::A1, Reg::A2, Reg::A3, Reg::T0, Reg::T1, Reg::T2, Reg::T3}; - assert(f_ts.base_type() == "function"); - assert(f_ts.arg_count() >= 1); - assert(f_ts.arg_count() <= 8 + 1); // 8 args + 1 return. + ASSERT(f_ts.base_type() == "function"); + ASSERT(f_ts.arg_count() >= 1); + ASSERT(f_ts.arg_count() <= 8 + 1); // 8 args + 1 return. for (int i = 0; i < int(f_ts.arg_count()) - 1; i++) { auto reg_id = goal_args[i]; auto reg_type = f_ts.get_arg(i); @@ -50,7 +50,7 @@ void modify_input_types_for_casts( } } catch (std::exception& e) { printf("failed to parse hint: %s\n", e.what()); - assert(false); + ASSERT(false); } } } @@ -87,7 +87,7 @@ bool run_type_analysis_ir2(const TypeSpec& my_type, DecompilerTypeSystem& dts, F if (my_type.last_arg() == TypeSpec("none")) { auto as_end = dynamic_cast(func.ir2.atomic_ops->ops.back().get()); - assert(as_end); + ASSERT(as_end); as_end->mark_function_as_no_return_value(); } @@ -101,8 +101,8 @@ bool run_type_analysis_ir2(const TypeSpec& my_type, DecompilerTypeSystem& dts, F // - never visit unreachable blocks (we can't type propagate these) // - always visit at least one predecessor of a block before that block auto order = func.bb_topo_sort(); - assert(!order.vist_order.empty()); - assert(order.vist_order.front() == 0); + ASSERT(!order.vist_order.empty()); + ASSERT(order.vist_order.front() == 0); // STEP 2 - initialize type state for the first block to the function argument types. block_init_types.at(0) = construct_initial_typestate(my_type, func.ir2.env); diff --git a/decompiler/analysis/variable_naming.cpp b/decompiler/analysis/variable_naming.cpp index dba89a7e7b..e419a92bcd 100644 --- a/decompiler/analysis/variable_naming.cpp +++ b/decompiler/analysis/variable_naming.cpp @@ -64,7 +64,7 @@ int VarMapSSA::get_next_var_id(Register reg) { void VarMapSSA::merge(const VarSSA& var_a, const VarSSA& var_b) { auto& a = m_entries.at(var_a.m_entry_id); auto b = m_entries.at(var_b.m_entry_id); - assert(a.reg == b.reg); + ASSERT(a.reg == b.reg); if (b.var_id == 0) { // fmt::print("Merge {} <- {}\n", to_string(var_b), to_string(var_a)); @@ -102,7 +102,7 @@ void VarMapSSA::merge_to_first(const VarSSA& var_a, const VarSSA& var_b) { auto b = m_entries.at(var_b.m_entry_id); // fmt::print("Merge-to-first {} <- {}\n", to_string(var_a), to_string(var_b)); - assert(a.reg == b.reg); + ASSERT(a.reg == b.reg); // for (auto& entry : m_entries) { for (size_t i = 0; i < m_entries.size(); i++) { @@ -262,7 +262,7 @@ bool is_arg_reg(Register r) { } int arg_reg_idx(Register r) { - assert(is_arg_reg(r)); + ASSERT(is_arg_reg(r)); return (int)r.get_gpr() - (int)Reg::A0; } @@ -350,7 +350,7 @@ SSA make_rc_ssa(const Function& function, const RegUsageInfo& rui, const Functio // to avoid operator[] auto it = current_regs.find(reg); if (it != current_regs.end()) { - assert(false); + ASSERT(false); it->second = ssa.get_phi_dest(block_id, reg); } else { current_regs.insert(std::make_pair(reg, ssa.get_phi_dest(block_id, reg))); @@ -421,7 +421,7 @@ SSA make_rc_ssa(const Function& function, const RegUsageInfo& rui, const Functio } // todo - verify no duplicates here? - assert(op->write_regs().size() <= 1); + ASSERT(op->write_regs().size() <= 1); // reads: for (auto r : op->read_regs()) { if (r.get_kind() == Reg::FPR || r.get_kind() == Reg::GPR) { @@ -550,7 +550,7 @@ bool SSA::simplify() { } if (remove) { - assert(v_j.has_value()); + ASSERT(v_j.has_value()); map.merge(*v_j, v_i); } } @@ -603,7 +603,7 @@ void SSA::remap(int) { // we do this in two passes. the first pass collects only the B0 variables and adds those first, // so these remain index 0 (expected by later decompiler passes) for (auto& block : blocks) { - assert(block.phis.empty()); + ASSERT(block.phis.empty()); for (auto& instr : block.ins) { if (instr.dst.has_value() && map.var_id(*instr.dst) == 0) { used_vars[instr.dst->reg()].insert(map.var_id(*instr.dst)); @@ -618,7 +618,7 @@ void SSA::remap(int) { // and the second pass grabs all of them for (auto& block : blocks) { - assert(block.phis.empty()); + ASSERT(block.phis.empty()); for (auto& instr : block.ins) { if (instr.dst.has_value()) { used_vars[instr.dst->reg()].insert(map.var_id(*instr.dst)); @@ -637,12 +637,12 @@ void SSA::remap(int) { } // paranoid - assert(var_remap.size() == reg_vars.second.order.size()); + ASSERT(var_remap.size() == reg_vars.second.order.size()); std::unordered_set check; for (auto kv : var_remap) { check.insert(kv.second); } - assert(check.size() == var_remap.size()); + ASSERT(check.size() == var_remap.size()); map.remap_reg(reg_vars.first, var_remap); program_read_vars[reg_vars.first].resize(i); @@ -658,8 +658,8 @@ void update_var_info(VariableNames::VarInfo* info, const DecompilerTypeSystem& dts) { auto& type = ts.get(reg); if (info->initialized) { - assert(info->reg_id.id == var_id); - assert(info->reg_id.reg == reg); + ASSERT(info->reg_id.id == var_id); + ASSERT(info->reg_id.reg == reg); bool changed; info->type = dts.tp_lca(info->type, type, &changed); @@ -733,7 +733,7 @@ void SSA::make_vars(const Function& function, const DecompilerTypeSystem& dts) { } // override the types of the variables for function arguments: - assert(function.type.arg_count() > 0); + ASSERT(function.type.arg_count() > 0); for (int arg_idx = 0; arg_idx < int(function.type.arg_count()) - 1; arg_idx++) { auto arg_reg = Register::get_arg_reg(arg_idx); if (!program_read_vars[arg_reg].empty()) { @@ -751,7 +751,7 @@ void SSA::make_vars(const Function& function, const DecompilerTypeSystem& dts) { // auto return_reg = return_var.reg(); // const auto& last_block = blocks.at(blocks.size() - 1); // const auto& last_ins = last_block.ins.at(last_block.ins.size() - 1); - // assert(last_ins.src.size() == 1); + // ASSERT(last_ins.src.size() == 1); // auto return_idx = map.var_id(last_ins.src.at(0)); // // if (!program_read_vars[return_reg].empty()) { @@ -775,7 +775,7 @@ void SSA::make_vars(const Function& function, const DecompilerTypeSystem& dts) { if (Register::get_arg_reg(arg_idx) == src_ssa.reg()) { // copy the type from here. auto dst = instr.dst; - assert(dst); + ASSERT(dst); auto dst_reg = instr.dst->reg(); auto dst_varid = map.var_id(*dst); if ((int)program_read_vars[dst_reg].size() > dst_varid) { @@ -851,8 +851,8 @@ VariableNames SSA::get_vars() const { for (auto& instr : blocks.at(0).ins) { if (instr.is_arg_coloring_move) { result.eliminated_move_op_ids.insert(instr.op_id); - assert(instr.dst.has_value()); - assert(instr.src.size() == 1); + ASSERT(instr.dst.has_value()); + ASSERT(instr.src.size() == 1); RegId new_regid, old_regid; new_regid.reg = instr.src.at(0).reg(); new_regid.id = map.var_id(instr.src.at(0)); @@ -1017,7 +1017,7 @@ void promote_register_class(const Function& func, // first reads: auto read_info = try_lookup_read(result, promotion.first); auto write_info = try_lookup_write(result, promotion.first); - assert(read_info || write_info); + ASSERT(read_info || write_info); if (read_info && !is_128bit(read_info->type, dts)) { read_info->type = TP_Type::make_from_ts("uint128"); diff --git a/decompiler/analysis/variable_naming.h b/decompiler/analysis/variable_naming.h index ff4c22c224..fce578d79c 100644 --- a/decompiler/analysis/variable_naming.h +++ b/decompiler/analysis/variable_naming.h @@ -24,7 +24,7 @@ #include "decompiler/IR2/IR2_common.h" #include "decompiler/util/TP_Type.h" -#include "common/util/assert.h" +#include "common/util/Assert.h" namespace decompiler { diff --git a/decompiler/data/LinkedWordReader.h b/decompiler/data/LinkedWordReader.h index 88df49ce92..83c533664a 100644 --- a/decompiler/data/LinkedWordReader.h +++ b/decompiler/data/LinkedWordReader.h @@ -5,7 +5,7 @@ #include #include "common/common_types.h" #include "decompiler/ObjectFile/LinkedWord.h" -#include "common/util/assert.h" +#include "common/util/Assert.h" namespace decompiler { class LinkedWordReader { @@ -17,7 +17,7 @@ class LinkedWordReader { m_offset++; return result; } else { - assert(false); + ASSERT(false); throw std::runtime_error("LinkedWordReader::get_type_tag failed"); } } @@ -26,14 +26,14 @@ class LinkedWordReader { 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); + 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); + ASSERT(m_words->size() >= m_offset); return m_words->size() - m_offset; } diff --git a/decompiler/data/StrFileReader.cpp b/decompiler/data/StrFileReader.cpp index 3bbfd07eb0..8dc68b25d5 100644 --- a/decompiler/data/StrFileReader.cpp +++ b/decompiler/data/StrFileReader.cpp @@ -8,13 +8,13 @@ #include "game/common/overlord_common.h" #include "game/common/str_rpc_types.h" #include "StrFileReader.h" -#include "common/util/assert.h" +#include "common/util/Assert.h" namespace decompiler { StrFileReader::StrFileReader(const std::string& file_path) { auto data = file_util::read_binary_file(file_path); - assert(data.size() >= SECTOR_SIZE); // must have at least the header sector - assert(data.size() % SECTOR_SIZE == 0); // should be multiple of the sector size. + ASSERT(data.size() >= SECTOR_SIZE); // must have at least the header sector + ASSERT(data.size() % SECTOR_SIZE == 0); // should be multiple of the sector size. int end_sector = int(data.size()) / SECTOR_SIZE; auto* header = (StrFileHeaderSector*)data.data(); @@ -30,9 +30,9 @@ StrFileReader::StrFileReader(const std::string& file_path) { next_sector = header->sectors[i + 1]; } if (sector) { - assert(!got_zero); // shouldn't have a non-zero after a zero! - assert(next_sector > sector); // should have a positive size. - assert(next_sector * SECTOR_SIZE <= int(data.size())); // check for overflowing the file + ASSERT(!got_zero); // shouldn't have a non-zero after a zero! + ASSERT(next_sector > sector); // should have a positive size. + ASSERT(next_sector * SECTOR_SIZE <= int(data.size())); // check for overflowing the file // get chunk data. std::vector chunk; chunk.insert(chunk.end(), data.begin() + sector * SECTOR_SIZE, @@ -47,15 +47,15 @@ StrFileReader::StrFileReader(const std::string& file_path) { // are sized assuming they are packed in order and dense (sectors); for (int i = 0; i < SECTOR_TABLE_SIZE; i++) { if (header->sectors[i]) { - assert(header->sizes[i] == m_chunks.at(i).size()); + ASSERT(header->sizes[i] == m_chunks.at(i).size()); } else { - assert(header->sizes[i] == 0); + ASSERT(header->sizes[i] == 0); } } // check nothing stored in the padding. for (auto x : header->pad) { - assert(x == 0); + ASSERT(x == 0); } } @@ -87,7 +87,7 @@ std::string get_string_of_max_length(const char* data, int max_length) { return result; } } - assert(false); + ASSERT(false); return ""; } @@ -99,8 +99,8 @@ struct FullName { FullName extract_name(const std::string& file_info_name) { FullName name; name.name = file_info_name; - assert(name.name.length() > 10); - assert(name.name.substr(name.name.length() - 6, 6) == "-ag.go"); + ASSERT(name.name.length() > 10); + ASSERT(name.name.substr(name.name.length() - 6, 6) == "-ag.go"); name.name = name.name.substr(0, name.name.length() - 6); int chunk_id = 0; int place = 0; @@ -118,7 +118,7 @@ FullName extract_name(const std::string& file_info_name) { break; } } - assert(name.name.back() == '+'); + ASSERT(name.name.back() == '+'); name.name.pop_back(); name.chunk_idx = chunk_id; return name; @@ -147,7 +147,7 @@ std::string StrFileReader::get_full_name(const std::string& short_name) const { if (find_string_in_data(chunk.data(), int(chunk.size()), file_info_string, &offset)) { offset += file_info_string.length(); } else { - assert(false); + ASSERT(false); } // extract the name info as a "name" + "chunk id" + "-ag.go" format. @@ -158,11 +158,11 @@ std::string StrFileReader::get_full_name(const std::string& short_name) const { if (!done_first) { result = full_name.name; } else { - assert(result == full_name.name); + ASSERT(result == full_name.name); } // make sure the index is right. - assert(full_name.chunk_idx == chunk_id); + ASSERT(full_name.chunk_idx == chunk_id); done_first = true; chunk_id++; @@ -176,7 +176,7 @@ std::string StrFileReader::get_full_name(const std::string& short_name) const { file_util::MakeISOName(iso_name_1, short_name.c_str()); // second, using the full name. file_util::ISONameFromAnimationName(iso_name_2, result.c_str()); - assert(strcmp(iso_name_1, iso_name_2) == 0); + ASSERT(strcmp(iso_name_1, iso_name_2) == 0); return result; } diff --git a/decompiler/data/TextureDB.cpp b/decompiler/data/TextureDB.cpp index 6cda1fa408..79043498bd 100644 --- a/decompiler/data/TextureDB.cpp +++ b/decompiler/data/TextureDB.cpp @@ -1,7 +1,7 @@ #include "TextureDB.h" #include "third-party/fmt/core.h" -#include "common/util/assert.h" +#include "common/util/Assert.h" namespace decompiler { @@ -16,17 +16,17 @@ void TextureDB::add_texture(u32 tpage, if (existing_tpage_name == tpage_names.end()) { tpage_names[tpage] = tpage_name; } else { - assert(existing_tpage_name->second == tpage_name); + ASSERT(existing_tpage_name->second == tpage_name); } u32 combo_id = (tpage << 16) | texid; auto existing_tex = textures.find(combo_id); if (existing_tex != textures.end()) { - assert(existing_tex->second.name == tex_name); - assert(existing_tex->second.w == w); - assert(existing_tex->second.h == h); - assert(existing_tex->second.rgba_bytes == data); - assert(existing_tex->second.page == tpage); + ASSERT(existing_tex->second.name == tex_name); + ASSERT(existing_tex->second.w == w); + ASSERT(existing_tex->second.h == h); + ASSERT(existing_tex->second.rgba_bytes == data); + ASSERT(existing_tex->second.page == tpage); } else { auto& new_tex = textures[combo_id]; new_tex.rgba_bytes = data; diff --git a/decompiler/data/dir_tpages.cpp b/decompiler/data/dir_tpages.cpp index f5d5b76de1..8b5e0cde31 100644 --- a/decompiler/data/dir_tpages.cpp +++ b/decompiler/data/dir_tpages.cpp @@ -20,30 +20,30 @@ DirTpageResult process_dir_tpages(ObjectFileData& data) { int word_idx = 0; // first is type - assert(words.at(word_idx).kind() == LinkedWord::TYPE_PTR); - assert(words.at(word_idx).symbol_name() == "texture-page-dir"); + ASSERT(words.at(word_idx).kind() == LinkedWord::TYPE_PTR); + ASSERT(words.at(word_idx).symbol_name() == "texture-page-dir"); word_idx++; // next is length - assert(words.at(word_idx).kind() == LinkedWord::PLAIN_DATA); + ASSERT(words.at(word_idx).kind() == LinkedWord::PLAIN_DATA); int dir_length = words.at(word_idx).data; word_idx++; for (int i = 0; i < dir_length; i++) { - assert(words.at(word_idx).kind() == LinkedWord::PLAIN_DATA); + ASSERT(words.at(word_idx).kind() == LinkedWord::PLAIN_DATA); u32 entry = words.at(word_idx).data; - assert((entry & 0xffff7000) == 0); // 7 checks for sign bit. + ASSERT((entry & 0xffff7000) == 0); // 7 checks for sign bit. word_idx++; result.lengths.push_back(entry & 0xffff); - assert(words.at(word_idx).kind() == LinkedWord::SYM_PTR); - assert(words.at(word_idx).symbol_name() == "#f"); + ASSERT(words.at(word_idx).kind() == LinkedWord::SYM_PTR); + ASSERT(words.at(word_idx).symbol_name() == "#f"); word_idx++; - assert(words.at(word_idx).kind() == LinkedWord::SYM_PTR); - assert(words.at(word_idx).symbol_name() == "#f"); + ASSERT(words.at(word_idx).kind() == LinkedWord::SYM_PTR); + ASSERT(words.at(word_idx).symbol_name() == "#f"); word_idx++; } - assert(word_idx == (int)words.size()); + ASSERT(word_idx == (int)words.size()); return result; } diff --git a/decompiler/data/game_count.cpp b/decompiler/data/game_count.cpp index 8be9cf2fc5..ded897cc7b 100644 --- a/decompiler/data/game_count.cpp +++ b/decompiler/data/game_count.cpp @@ -9,7 +9,7 @@ GameCountResult process_game_count(ObjectFileData& data) { auto& words = data.linked_data.words_by_seg.at(0); auto reader = LinkedWordReader(&words); auto type = reader.get_type_tag(); - assert(type == "game-count-info"); + ASSERT(type == "game-count-info"); auto length = reader.get_word(); for (s32 i = 0; i < length; i++) { @@ -21,7 +21,7 @@ GameCountResult process_game_count(ObjectFileData& data) { result.mystery_data[0] = reader.get_word(); result.mystery_data[1] = reader.get_word(); - assert(reader.words_left() == 0); + ASSERT(reader.words_left() == 0); return result; } diff --git a/decompiler/data/game_text.cpp b/decompiler/data/game_text.cpp index 25b9c45d52..e3192ec0c0 100644 --- a/decompiler/data/game_text.cpp +++ b/decompiler/data/game_text.cpp @@ -13,14 +13,14 @@ namespace { template T get_word(const LinkedWord& word) { T result; - assert(word.kind() == LinkedWord::PLAIN_DATA); + ASSERT(word.kind() == LinkedWord::PLAIN_DATA); static_assert(sizeof(T) == 4, "bad get_word size"); memcpy(&result, &word.data, 4); return result; } DecompilerLabel get_label(ObjectFileData& data, const LinkedWord& word) { - assert(word.kind() == LinkedWord::PTR); + ASSERT(word.kind() == LinkedWord::PTR); return data.linked_data.labels.at(word.label_id()); } @@ -52,7 +52,7 @@ GameTextResult process_game_text(ObjectFileData& data, GameTextVersion version) // type tag for game-text-info if (words.at(offset).kind() != LinkedWord::TYPE_PTR || words.front().symbol_name() != "game-text-info") { - assert(false); + ASSERT(false); } read_words.at(offset)++; offset++; @@ -70,7 +70,7 @@ GameTextResult process_game_text(ObjectFileData& data, GameTextVersion version) read_words.at(offset)++; auto group_label = get_label(data, words.at(offset++)); auto group_name = data.linked_data.get_goal_string_by_label(group_label); - assert(group_name == "common"); + ASSERT(group_name == "common"); // remember that we read these bytes auto group_start = (group_label.offset / 4) - 1; for (int j = 0; j < align16(8 + 1 + (int)group_name.length()) / 4; j++) { @@ -94,7 +94,7 @@ GameTextResult process_game_text(ObjectFileData& data, GameTextVersion version) // no duplicate ids if (result.text.find(text_id) != result.text.end()) { - assert(false); + ASSERT(false); } // escape characters @@ -126,7 +126,7 @@ GameTextResult process_game_text(ObjectFileData& data, GameTextVersion version) std::string debug; data.linked_data.append_word_to_string(debug, words.at(i)); printf("[%d] %d 0x%s\n", i, int(read_words[i]), debug.c_str()); - assert(false); + ASSERT(false); } } diff --git a/decompiler/data/streamed_audio.cpp b/decompiler/data/streamed_audio.cpp index 77cc58af6a..7d1855b4c0 100644 --- a/decompiler/data/streamed_audio.cpp +++ b/decompiler/data/streamed_audio.cpp @@ -51,7 +51,7 @@ struct AudioDir { */ std::vector read_entry(const AudioDir& dir, const std::vector& data, int entry_idx) { const auto& entry = dir.entries.at(entry_idx); - assert(entry.end_byte > 0); + ASSERT(entry.end_byte > 0); return std::vector(data.begin() + entry.start_byte, data.begin() + entry.end_byte); } @@ -100,19 +100,19 @@ AudioDir read_audio_dir(const std::string& path) { u32 count = reader.read(); u32 data_end = sizeof(u32) + sizeof(DirEntry) * count; - assert(data_end <= data.size()); + ASSERT(data_end <= data.size()); std::vector entries; for (u32 i = 0; i < count; i++) { entries.push_back(reader.read()); } while (reader.bytes_left()) { - assert(reader.read() == 0); + ASSERT(reader.read() == 0); } AudioDir result; - assert(!entries.empty()); + ASSERT(!entries.empty()); for (size_t i = 0; i < entries.size(); i++) { AudioDir::Entry e; for (auto c : entries[i].name) { @@ -153,18 +153,18 @@ AudioFileInfo process_audio_file(const std::vector& data, if (header.magic[0] == 'V') { header = header.swapped_endian(); } else { - assert(false); + ASSERT(false); } header.debug_print(); for (int i = 0; i < 16; i++) { - assert(reader.read() == 0); + ASSERT(reader.read() == 0); } std::vector decoded_samples = decode_adpcm(reader); while (reader.bytes_left()) { - assert(reader.read() == 0); + ASSERT(reader.read() == 0); } file_util::create_dir_if_needed(file_util::get_file_path({"assets", "streaming_audio", suffix})); diff --git a/decompiler/data/tpage.cpp b/decompiler/data/tpage.cpp index 21523e5cf0..ea749c2a3d 100644 --- a/decompiler/data/tpage.cpp +++ b/decompiler/data/tpage.cpp @@ -214,7 +214,7 @@ struct TexturePage { * If basic is set, gives you a pointer to the beginning of the memory, if the thing is a basic. */ int label_to_word_offset(DecompilerLabel l, bool basic) { - assert((l.offset & 3) == 0); + ASSERT((l.offset & 3) == 0); int result = l.offset / 4; if (basic) { result--; @@ -223,7 +223,7 @@ int label_to_word_offset(DecompilerLabel l, bool basic) { } std::string get_type_tag(const LinkedWord& word) { - assert(word.kind() == LinkedWord::TYPE_PTR); + ASSERT(word.kind() == LinkedWord::TYPE_PTR); return word.symbol_name(); } @@ -232,14 +232,14 @@ bool is_type_tag(const LinkedWord& word, const std::string& type) { } DecompilerLabel get_label(ObjectFileData& data, const LinkedWord& word) { - assert(word.kind() == LinkedWord::PTR); + ASSERT(word.kind() == LinkedWord::PTR); return data.linked_data.labels.at(word.label_id()); } template T get_word(const LinkedWord& word) { T result; - assert(word.kind() == LinkedWord::PLAIN_DATA); + ASSERT(word.kind() == LinkedWord::PLAIN_DATA); static_assert(sizeof(T) == 4, "bad get_word size"); memcpy(&result, &word.data, 4); return result; @@ -251,7 +251,7 @@ T get_word(const LinkedWord& word) { Texture read_texture(ObjectFileData& data, const std::vector& words, int offset) { Texture tex; if (!is_type_tag(words.at(offset), "texture")) { - assert(false); + ASSERT(false); } offset++; @@ -259,7 +259,7 @@ Texture read_texture(ObjectFileData& data, const std::vector& words, word = get_word(words.at(offset)); offset++; } - assert(tex.pad == 0); + ASSERT(tex.pad == 0); tex.name_label = get_label(data, words.at(offset)); offset++; @@ -277,7 +277,7 @@ Texture read_texture(ObjectFileData& data, const std::vector& words, auto kv = psms.find(tex.psm); if (kv == psms.end()) { printf("Got unsupported texture 0x%x!\n", tex.psm); - assert(false); + ASSERT(false); } return tex; @@ -289,7 +289,7 @@ Texture read_texture(ObjectFileData& data, const std::vector& words, FileInfo read_file_info(ObjectFileData& data, const std::vector& words, int offset) { FileInfo info; if (!is_type_tag(words.at(offset), "file-info")) { - assert(false); + ASSERT(false); } offset++; @@ -331,18 +331,18 @@ TexturePage read_texture_page(ObjectFileData& data, TexturePage tpage; // offset 0 - 4, type tag if (!is_type_tag(words.at(offset), "texture-page")) { - assert(false); + ASSERT(false); } offset++; // offset 4 - 8, info label tpage.info_label = get_label(data, words.at(offset)); tpage.info = read_file_info(data, words, label_to_word_offset(tpage.info_label, true)); - assert(tpage.info.file_type == "texture-page"); - assert(tpage.info.major_version == versions::TX_PAGE_VERSION); - assert(tpage.info.minor_version == 0); - assert(tpage.info.maya_file_name == "Unknown"); - assert(tpage.info.mdb_file_name == 0); + ASSERT(tpage.info.file_type == "texture-page"); + ASSERT(tpage.info.major_version == versions::TX_PAGE_VERSION); + ASSERT(tpage.info.minor_version == 0); + ASSERT(tpage.info.maya_file_name == "Unknown"); + ASSERT(tpage.info.mdb_file_name == 0); offset++; // offset 8 - 12, name @@ -381,7 +381,7 @@ TexturePage read_texture_page(ObjectFileData& data, for (unsigned int& i : tpage.pad) { i = get_word(words.at(offset)); offset++; - assert(i == 0); + ASSERT(i == 0); } for (int i = 0; i < tpage.length; i++) { @@ -392,7 +392,7 @@ TexturePage read_texture_page(ObjectFileData& data, null_tex.null_texture = true; tpage.textures.push_back(null_tex); } else { - assert(false); + ASSERT(false); } } else { tpage.data.push_back(get_label(data, words.at(offset))); @@ -404,7 +404,7 @@ TexturePage read_texture_page(ObjectFileData& data, } auto aligned_end = (offset + 3) & (~3); - assert(aligned_end == end); + ASSERT(aligned_end == end); return tpage; } @@ -429,7 +429,7 @@ TPageResultStats process_tpage(ObjectFileData& data, TextureDB& texture_db) { } } - assert(end_of_texture_page != -1); + ASSERT(end_of_texture_page != -1); // todo check it's not too small. // Read the texture_page struct @@ -439,7 +439,7 @@ TPageResultStats process_tpage(ObjectFileData& data, TextureDB& texture_db) { std::vector tex_data; auto tex_start = label_to_word_offset(texture_page.segments[0].block_data_label, false); auto tex_size = int(words.size()) - int(tex_start); - assert(tex_size > 0); + ASSERT(tex_size > 0); tex_data.resize(tex_size); for (int i = 0; i < tex_size; i++) { tex_data[i] = get_word(words.at(tex_start + i)); diff --git a/decompiler/level_extractor/BspHeader.cpp b/decompiler/level_extractor/BspHeader.cpp index 56704afde0..34c76180e8 100644 --- a/decompiler/level_extractor/BspHeader.cpp +++ b/decompiler/level_extractor/BspHeader.cpp @@ -213,11 +213,11 @@ void tfrag_debug_print_unpack(Ref start, int qwc_total) { switch (next.kind) { case VifCode::Kind::UNPACK_V4_16: { VifCodeUnpack up(next); - assert(up.use_tops_flag == true); - assert(up.is_unsigned == true); - // assert(up.addr_qw == 0); + ASSERT(up.use_tops_flag == true); + ASSERT(up.is_unsigned == true); + // ASSERT(up.addr_qw == 0); int qw_to_write = next.num; - assert(next.num); + ASSERT(next.num); for (int qw = 0; qw < qw_to_write; qw++) { u32 words[2]; words[0] = deref_u32(start, word_offset++); @@ -232,10 +232,10 @@ void tfrag_debug_print_unpack(Ref start, int qwc_total) { case VifCode::Kind::UNPACK_V4_32: { VifCodeUnpack up(next); - assert(up.use_tops_flag == true); - assert(up.is_unsigned == false); - // assert(up.addr_qw == 9); - assert(next.num); + ASSERT(up.use_tops_flag == true); + ASSERT(up.is_unsigned == false); + // ASSERT(up.addr_qw == 9); + ASSERT(next.num); for (int qw = 0; qw < next.num; qw++) { u32 words[4]; words[0] = deref_u32(start, word_offset++); @@ -248,10 +248,10 @@ void tfrag_debug_print_unpack(Ref start, int qwc_total) { case VifCode::Kind::UNPACK_V3_32: { VifCodeUnpack up(next); - assert(up.use_tops_flag == true); - assert(up.is_unsigned == false); - // assert(up.addr_qw == 19); - assert(next.num); + ASSERT(up.use_tops_flag == true); + ASSERT(up.is_unsigned == false); + // ASSERT(up.addr_qw == 19); + ASSERT(next.num); for (int qw = 0; qw < next.num; qw++) { u32 words[3]; words[0] = deref_u32(start, word_offset++); @@ -278,10 +278,10 @@ void tfrag_debug_print_unpack(Ref start, int qwc_total) { case VifCode::Kind::UNPACK_V4_8: { VifCodeUnpack up(next); - assert(up.use_tops_flag == true); - // assert(up.is_unsigned == false); - // assert(up.addr_qw == 129); - assert(next.num); + ASSERT(up.use_tops_flag == true); + // ASSERT(up.is_unsigned == false); + // ASSERT(up.addr_qw == 129); + ASSERT(next.num); for (int qw = 0; qw < next.num; qw++) { s8 words[4]; u32 all = deref_u32(start, word_offset++); @@ -293,7 +293,7 @@ void tfrag_debug_print_unpack(Ref start, int qwc_total) { break; default: fmt::print("unknown: {}\n", next.print()); - assert(false); + ASSERT(false); } } fmt::print("-------------------------------------------\n"); @@ -392,15 +392,15 @@ void TFragment::read_from_file(TypedRef ref, color_indices.push_back(high & 0xffff); color_indices.push_back(high >> 16); } - assert((int)color_indices.size() == num_colors); + ASSERT((int)color_indices.size() == num_colors); // todo shader - assert(num_colors / 4 == color_count); + ASSERT(num_colors / 4 == color_count); // fmt::print("colors: {} {} {}\n", num_base_colors, num_level0_colors, num_level1_colors); - assert(read_plain_data_field(ref, "pad0", dts) == 0); - assert(read_plain_data_field(ref, "pad1", dts) == 0); - assert(read_plain_data_field(ref, "generic-u32", dts) == 0); + ASSERT(read_plain_data_field(ref, "pad0", dts) == 0); + ASSERT(read_plain_data_field(ref, "pad1", dts) == 0); + ASSERT(read_plain_data_field(ref, "generic-u32", dts) == 0); } std::string TFragment::print(const PrintSettings& settings, int indent) const { @@ -445,13 +445,13 @@ void TieFragment::read_from_file(TypedRef ref, auto gif_data_ref = deref_label(get_field_ref(ref, "gif-ref", dts)); - assert((tex_count % 5) == 0); + ASSERT((tex_count % 5) == 0); u32 total_gif_qw = tex_count + gif_count; gif_data.resize(16 * total_gif_qw); for (u32 i = 0; i < total_gif_qw * 4; i++) { auto& word = gif_data_ref.data->words_by_seg.at(gif_data_ref.seg).at((gif_data_ref.byte_offset / 4) + i); - assert(word.kind() == decompiler::LinkedWord::PLAIN_DATA); + ASSERT(word.kind() == decompiler::LinkedWord::PLAIN_DATA); memcpy(gif_data.data() + (i * 4), &word.data, 4); } @@ -461,7 +461,7 @@ void TieFragment::read_from_file(TypedRef ref, for (u32 i = 0; i < vertex_count * 4; i++) { auto& word = points_data_ref.data->words_by_seg.at(points_data_ref.seg) .at((points_data_ref.byte_offset / 4) + i); - assert(word.kind() == decompiler::LinkedWord::PLAIN_DATA); + ASSERT(word.kind() == decompiler::LinkedWord::PLAIN_DATA); memcpy(point_ref.data() + (i * 4), &word.data, 4); } @@ -498,7 +498,7 @@ void InstanceTie::read_from_file(TypedRef ref, bucket_index = read_plain_data_field(ref, "bucket-index", dts); id = read_plain_data_field(ref, "id", dts); flags = read_plain_data_field(ref, "flags", dts); - // assert(flags == 0); // TODO + // ASSERT(flags == 0); // TODO origin.read_from_file(get_field_ref(ref, "origin", dts)); wind_index = read_plain_data_field(ref, "wind-index", dts); color_indices = deref_label(get_field_ref(ref, "color-indices", dts)); @@ -772,10 +772,10 @@ void DrawableTreeTfrag::read_from_file(TypedRef ref, auto palette = deref_label(get_field_ref(ref, "time-of-day-pal", dts)); time_of_day.width = deref_u32(palette, 0); - assert(time_of_day.width == 8); + ASSERT(time_of_day.width == 8); time_of_day.height = deref_u32(palette, 1); time_of_day.pad = deref_u32(palette, 2); - assert(time_of_day.pad == 0); + ASSERT(time_of_day.pad == 0); for (int i = 0; i < int(8 * time_of_day.height); i++) { time_of_day.colors.push_back(deref_u32(palette, 3 + i)); } @@ -869,7 +869,7 @@ void PrototypeBucketTie::read_from_file(TypedRef ref, DrawStats* stats) { name = read_string_field(ref, "name", dts, true); flags = read_plain_data_field(ref, "flags", dts); - assert(flags == 0 || flags == 2); + ASSERT(flags == 0 || flags == 2); in_level = read_plain_data_field(ref, "in-level", dts); utextures = read_plain_data_field(ref, "utextures", dts); // todo drawables @@ -918,16 +918,16 @@ void PrototypeBucketTie::read_from_file(TypedRef ref, } for (auto x : next) { - assert(x == 0); + ASSERT(x == 0); } for (auto x : count) { - assert(x == 0); + ASSERT(x == 0); } for (auto x : generic_count) { - assert(x == 0); + ASSERT(x == 0); } for (auto x : generic_next) { - assert(x == 0); + ASSERT(x == 0); } // get the color count data @@ -937,7 +937,7 @@ void PrototypeBucketTie::read_from_file(TypedRef ref, u32 start = index_start[i]; u32 end = start + frag_count[i]; // fmt::print("i = {}: {} -> {}\n", i, start, end); - assert(num_color_qwcs <= end); + ASSERT(num_color_qwcs <= end); num_color_qwcs = std::max(end, num_color_qwcs); } @@ -953,10 +953,10 @@ void PrototypeBucketTie::read_from_file(TypedRef ref, auto palette = deref_label(get_field_ref(ref, "tie-colors", dts)); time_of_day.width = deref_u32(palette, 0); - assert(time_of_day.width == 8); + ASSERT(time_of_day.width == 8); time_of_day.height = deref_u32(palette, 1); time_of_day.pad = deref_u32(palette, 2); - assert(time_of_day.pad == 0); + ASSERT(time_of_day.pad == 0); for (int i = 0; i < int(8 * time_of_day.height); i++) { time_of_day.colors.push_back(deref_u32(palette, 3 + i)); } diff --git a/decompiler/level_extractor/extract_level.cpp b/decompiler/level_extractor/extract_level.cpp index 113aae95c4..acffb166f1 100644 --- a/decompiler/level_extractor/extract_level.cpp +++ b/decompiler/level_extractor/extract_level.cpp @@ -17,7 +17,7 @@ std::optional get_bsp_file(const std::vector bool found = false; for (auto& file : records) { if (file.name.length() > 4 && file.name.substr(file.name.length() - 4) == "-vis") { - assert(!found); + ASSERT(!found); found = true; result = file; } @@ -68,13 +68,13 @@ void extract_from_level(ObjectFileDB& db, fmt::print("Processing level {} ({})\n", dgo_name, level_name); auto& bsp_file = db.lookup_record(*bsp_rec); bool ok = is_valid_bsp(bsp_file.linked_data); - assert(ok); + ASSERT(ok); level_tools::DrawStats draw_stats; // draw_stats.debug_print_dma_data = true; level_tools::BspHeader bsp_header; bsp_header.read_from_file(bsp_file.linked_data, db.dts, &draw_stats); - assert((int)bsp_header.drawable_tree_array.trees.size() == bsp_header.drawable_tree_array.length); + ASSERT((int)bsp_header.drawable_tree_array.trees.size() == bsp_header.drawable_tree_array.length); const std::set tfrag_trees = { "drawable-tree-tfrag", "drawable-tree-trans-tfrag", "drawable-tree-dirt-tfrag", @@ -86,7 +86,7 @@ void extract_from_level(ObjectFileDB& db, if (tfrag_trees.count(draw_tree->my_type())) { auto as_tfrag_tree = dynamic_cast(draw_tree.get()); fmt::print(" extracting tree {}\n", draw_tree->my_type()); - assert(as_tfrag_tree); + ASSERT(as_tfrag_tree); std::vector> expected_missing_textures; auto it = hacks.missing_textures_by_level.find(level_name); if (it != hacks.missing_textures_by_level.end()) { @@ -98,7 +98,7 @@ void extract_from_level(ObjectFileDB& db, } else if (draw_tree->my_type() == "drawable-tree-instance-tie") { fmt::print(" extracting TIE\n"); auto as_tie_tree = dynamic_cast(draw_tree.get()); - assert(as_tie_tree); + ASSERT(as_tie_tree); extract_tie(as_tie_tree, fmt::format("{}-{}-tie", dgo_name, i++), bsp_header.texture_remap_table, tex_db, tfrag_level, dump_level); } else { diff --git a/decompiler/level_extractor/extract_tfrag.cpp b/decompiler/level_extractor/extract_tfrag.cpp index 5e2b556909..30a4ea751b 100644 --- a/decompiler/level_extractor/extract_tfrag.cpp +++ b/decompiler/level_extractor/extract_tfrag.cpp @@ -4,7 +4,7 @@ #include "decompiler/ObjectFile/LinkedObjectFile.h" #include "common/util/FileUtil.h" #include "common/dma/gs.h" -#include "common/util/assert.h" +#include "common/util/Assert.h" namespace decompiler { namespace { @@ -19,7 +19,7 @@ u16 get_first_idx(const level_tools::DrawableInlineArray* array) { } else if (as_nodes) { return as_nodes->draw_nodes.at(0).id; } else { - assert(false); + ASSERT(false); } } @@ -86,14 +86,14 @@ VisNodeTree extract_vis_data(const level_tools::DrawableTreeTfrag* tree, u16 fir } else if (tree->arrays.size() == 1) { auto array = dynamic_cast(tree->arrays.at(0).get()); - assert(array); + ASSERT(array); result.first_root = array->tfragments.at(0).id; result.num_roots = array->tfragments.size(); result.only_children = true; } else { auto array = dynamic_cast(tree->arrays.at(0).get()); - assert(array); + ASSERT(array); result.first_root = array->draw_nodes.at(0).id; result.num_roots = array->draw_nodes.size(); result.only_children = false; @@ -107,29 +107,29 @@ VisNodeTree extract_vis_data(const level_tools::DrawableTreeTfrag* tree, u16 fir auto array = dynamic_cast(tree->arrays.at(i).get()); - assert(array); + ASSERT(array); u16 idx = first_child; for (auto& elt : array->draw_nodes) { auto& vis = result.vis_nodes.at(elt.id - result.first_root); - assert(vis.num_kids == 0xff); + ASSERT(vis.num_kids == 0xff); for (int j = 0; j < 4; j++) { vis.bsphere[j] = elt.bsphere.data[j]; } vis.num_kids = elt.child_count; vis.flags = elt.flags; vis.my_id = elt.id; - assert(vis.flags == expecting_leaves ? 0 : 1); - assert(vis.num_kids > 0); - assert(vis.num_kids <= 8); - assert(elt.children.size() == vis.num_kids); + ASSERT(vis.flags == expecting_leaves ? 0 : 1); + ASSERT(vis.num_kids > 0); + ASSERT(vis.num_kids <= 8); + ASSERT(elt.children.size() == vis.num_kids); if (expecting_leaves) { for (int leaf = 0; leaf < (int)vis.num_kids; leaf++) { auto l = dynamic_cast(elt.children.at(leaf).get()); - assert(l); + ASSERT(l); - assert(idx == l->id); + ASSERT(idx == l->id); - assert(l->id >= result.first_child_node); + ASSERT(l->id >= result.first_child_node); if (leaf == 0) { vis.child_id = l->id; } @@ -141,18 +141,18 @@ VisNodeTree extract_vis_data(const level_tools::DrawableTreeTfrag* tree, u16 fir u16 arr_idx = 0; for (int child = 0; child < (int)vis.num_kids; child++) { auto l = dynamic_cast(elt.children.at(child).get()); - assert(l); + ASSERT(l); if (child == 0) { arr_idx = l->id; } else { - assert(arr_idx < l->id); + ASSERT(arr_idx < l->id); arr_idx = l->id; } if (child == 0) { vis.child_id = l->id; } - assert(l->id < result.first_child_node); + ASSERT(l->id < result.first_child_node); } } } @@ -195,20 +195,20 @@ int handle_unpack_v4_8_mode0(const VifCode& code, int wl, u8* out) { VifCodeUnpack unpack(code); - assert(unpack.use_tops_flag); + ASSERT(unpack.use_tops_flag); int offset = offset_word * 4; // CL x (num/WL)+(num%WL) if (unpack.is_unsigned) { // note: formulas below assume this! - assert(cl == 2); - assert(wl == 1); - assert(code.num); + ASSERT(cl == 2); + ASSERT(wl == 1); + ASSERT(code.num); for (int i = 0; i < code.num; i++) { // write every other qw int dest_qw = unpack.addr_qw + 2 * i; - assert(dest_qw <= 328); + ASSERT(dest_qw <= 328); u32 qw[4]; qw[0] = dma[offset++]; qw[1] = dma[offset++]; @@ -218,13 +218,13 @@ int handle_unpack_v4_8_mode0(const VifCode& code, } } else { // note: formulas below assume this! - assert(cl == 4); - assert(wl == 4); - assert(code.num); + ASSERT(cl == 4); + ASSERT(wl == 4); + ASSERT(code.num); for (int i = 0; i < code.num; i++) { // write every other qw int dest_qw = unpack.addr_qw + i; - assert(dest_qw <= 328); + ASSERT(dest_qw <= 328); s32 qw[4]; qw[0] = (s8)dma[offset++]; qw[1] = (s8)dma[offset++]; @@ -234,7 +234,7 @@ int handle_unpack_v4_8_mode0(const VifCode& code, } } - assert((offset % 4) == 0); + ASSERT((offset % 4) == 0); return offset / 4; } @@ -246,19 +246,19 @@ int handle_unpack_v4_8_mode1(const VifCode& code, const u32 row[4], u8* out) { VifCodeUnpack unpack(code); - assert(unpack.use_tops_flag); + ASSERT(unpack.use_tops_flag); int offset = offset_word * 4; // CL x (num/WL)+(num%WL) if (unpack.is_unsigned) { // note: formulas below assume this! - assert(cl == 4); - assert(wl == 4); - assert(code.num); + ASSERT(cl == 4); + ASSERT(wl == 4); + ASSERT(code.num); for (int i = 0; i < code.num; i++) { // write every other qw int dest_qw = unpack.addr_qw + i; - assert(dest_qw <= 328); + ASSERT(dest_qw <= 328); u32 qw[4]; qw[0] = row[0] + dma[offset++]; qw[1] = row[1] + dma[offset++]; @@ -268,13 +268,13 @@ int handle_unpack_v4_8_mode1(const VifCode& code, } } else { // note: formulas below assume this! - assert(cl == 4); - assert(wl == 4); - assert(code.num); + ASSERT(cl == 4); + ASSERT(wl == 4); + ASSERT(code.num); for (int i = 0; i < code.num; i++) { // write every other qw int dest_qw = unpack.addr_qw + i; - assert(dest_qw <= 328); + ASSERT(dest_qw <= 328); s32 qw[4]; qw[0] = row[0] + (s8)dma[offset++]; qw[1] = row[1] + (s8)dma[offset++]; @@ -284,7 +284,7 @@ int handle_unpack_v4_8_mode1(const VifCode& code, } } - assert((offset % 4) == 0); + ASSERT((offset % 4) == 0); return offset / 4; } @@ -302,20 +302,20 @@ int handle_unpack_v4_16_mode0(const VifCode& code, int wl, u8* vu_mem) { VifCodeUnpack unpack(code); - assert(unpack.use_tops_flag); - assert(unpack.is_unsigned); + ASSERT(unpack.use_tops_flag); + ASSERT(unpack.is_unsigned); // note: formulas below assume this! - assert(cl == 4); - assert(wl == 4); + ASSERT(cl == 4); + ASSERT(wl == 4); int offset = offset_word * 4; - assert(code.num); + ASSERT(code.num); for (int i = 0; i < code.num; i++) { // write every other qw int dest_qw = unpack.addr_qw + i; - assert(dest_qw <= 328); + ASSERT(dest_qw <= 328); u32 qw[4]; qw[0] = deref_ptr(dma + offset); offset += 2; @@ -327,7 +327,7 @@ int handle_unpack_v4_16_mode0(const VifCode& code, offset += 2; memcpy(vu_mem + (dest_qw * 16), qw, 16); } - assert((offset % 4) == 0); + ASSERT((offset % 4) == 0); return offset / 4; } @@ -339,19 +339,19 @@ int handle_unpack_v4_16_mode1(const VifCode& code, const u32 row[4], u8* vu_mem) { VifCodeUnpack unpack(code); - assert(unpack.use_tops_flag); - assert(unpack.is_unsigned); + ASSERT(unpack.use_tops_flag); + ASSERT(unpack.is_unsigned); // note: formulas below assume this! - assert(cl == 4); - assert(wl == 4); + ASSERT(cl == 4); + ASSERT(wl == 4); - assert(code.num); + ASSERT(code.num); int offset = offset_word * 4; for (int i = 0; i < code.num; i++) { // write every other qw int dest_qw = unpack.addr_qw + i; - assert(dest_qw <= 328); + ASSERT(dest_qw <= 328); u32 qw[4]; qw[0] = row[0] + (u32)deref_ptr(dma + offset); offset += 2; @@ -365,7 +365,7 @@ int handle_unpack_v4_16_mode1(const VifCode& code, // fmt::print(" unpack rgba?: {:x} {:x} {:x} {:x}\n", qw[0], qw[1], qw[2], qw[3]); memcpy(vu_mem + (dest_qw * 16), qw, 16); } - assert((offset % 4) == 0); + ASSERT((offset % 4) == 0); return offset / 4; } @@ -376,19 +376,19 @@ int handle_unpack_v3_32(const VifCode& code, int wl, u8* vu_mem) { VifCodeUnpack unpack(code); - assert(unpack.use_tops_flag); - assert(!unpack.is_unsigned); + ASSERT(unpack.use_tops_flag); + ASSERT(!unpack.is_unsigned); // note: formulas below assume this! - assert(cl == 2); - assert(wl == 1); + ASSERT(cl == 2); + ASSERT(wl == 1); - assert(code.num); + ASSERT(code.num); int offset = offset_word * 4; for (int i = 0; i < code.num; i++) { // write every other qw int dest_qw = unpack.addr_qw + i * 2; - assert(dest_qw <= 328); + ASSERT(dest_qw <= 328); u32 qw[4]; qw[0] = deref_ptr(dma + offset); offset += 4; @@ -399,7 +399,7 @@ int handle_unpack_v3_32(const VifCode& code, qw[3] = 0x80; // this can be anything... memcpy(vu_mem + (dest_qw * 16), qw, 16); } - assert((offset % 4) == 0); + ASSERT((offset % 4) == 0); return offset / 4; } @@ -410,18 +410,18 @@ int handle_unpack_v4_32(const VifCode& code, int wl, u8* vu_mem) { VifCodeUnpack unpack(code); - assert(unpack.use_tops_flag); - assert(!unpack.is_unsigned); + ASSERT(unpack.use_tops_flag); + ASSERT(!unpack.is_unsigned); // note: formulas below assume this! - assert(cl == 4); - assert(wl == 4); + ASSERT(cl == 4); + ASSERT(wl == 4); int offset = offset_word * 4; - assert(code.num); + ASSERT(code.num); for (int i = 0; i < code.num; i++) { // write every other qw int dest_qw = unpack.addr_qw + i; - assert(dest_qw <= 328); + ASSERT(dest_qw <= 328); u32 qw[4]; qw[0] = deref_ptr(dma + offset); offset += 4; @@ -433,11 +433,11 @@ int handle_unpack_v4_32(const VifCode& code, offset += 4; memcpy(vu_mem + (dest_qw * 16), qw, 16); } - assert((offset % 4) == 0); + ASSERT((offset % 4) == 0); return offset / 4; // u8* write_base = get_upload_buffer(); - // assert(code.num + unpack.addr_qw <= 328); + // ASSERT(code.num + unpack.addr_qw <= 328); // memcpy(write_base + (unpack.addr_qw * 16), dma.data + offset, code.num * 16); // return offset + code.num * 16; } @@ -459,10 +459,10 @@ void emulate_chain(UnpackState& state, u32 max_words, const u32* start, u8* vu_m break; case VifCode::Kind::STMOD: if (state.stmod == 0) { - assert(code.immediate == 1); + ASSERT(code.immediate == 1); } else { - assert(state.stmod == 1); - assert(code.immediate == 0 || code.immediate == 1); // kinda weird. + ASSERT(state.stmod == 1); + ASSERT(code.immediate == 0 || code.immediate == 1); // kinda weird. } state.stmod = code.immediate; break; @@ -470,11 +470,11 @@ void emulate_chain(UnpackState& state, u32 max_words, const u32* start, u8* vu_m if (state.stmod == 0) { word = handle_unpack_v4_8_mode0(code, (const u8*)start, word, state.cl, state.wl, vu_mem); } else if (state.stmod == 1) { - assert(state.row_init); + ASSERT(state.row_init); word = handle_unpack_v4_8_mode1(code, (const u8*)start, word, state.cl, state.wl, state.row, vu_mem); } else { - assert(false); + ASSERT(false); } break; case VifCode::Kind::UNPACK_V4_16: @@ -482,19 +482,19 @@ void emulate_chain(UnpackState& state, u32 max_words, const u32* start, u8* vu_m word = handle_unpack_v4_16_mode0(code, (const u8*)start, word, state.cl, state.wl, vu_mem); } else if (state.stmod == 1) { - assert(state.row_init); + ASSERT(state.row_init); word = handle_unpack_v4_16_mode1(code, (const u8*)start, word, state.cl, state.wl, state.row, vu_mem); } else { - assert(false); + ASSERT(false); } break; case VifCode::Kind::UNPACK_V4_32: - assert(state.stmod == 0); + ASSERT(state.stmod == 0); word = handle_unpack_v4_32(code, (const u8*)start, word, state.cl, state.wl, vu_mem); break; case VifCode::Kind::UNPACK_V3_32: - assert(state.stmod == 0); + ASSERT(state.stmod == 0); word = handle_unpack_v3_32(code, (const u8*)start, word, state.cl, state.wl, vu_mem); break; case VifCode::Kind::NOP: @@ -513,8 +513,8 @@ void emulate_chain(UnpackState& state, u32 max_words, const u32* start, u8* vu_m } } - assert(word == max_words); - assert(state.stmod == 0); + ASSERT(word == max_words); + ASSERT(state.stmod == 0); } struct TFragColorUnpack { @@ -548,7 +548,7 @@ void emulate_dma_building_for_tfrag(const level_tools::TFragment& frag, // do the "canned" unpacks if (frag.num_level0_colors == 0) { // we're using base - assert(frag.num_level1_colors == 0); + ASSERT(frag.num_level1_colors == 0); stats->num_base++; emulate_chain(state, frag.dma_qwc[1] * 4, (const u32*)frag.dma_base.data(), vu_mem.data()); @@ -623,8 +623,8 @@ struct VuMemWrapper { u16 ilw_data(int offset, int xyzw) { u16 result; - assert(offset < 328); - assert(offset >= 0); + ASSERT(offset < 328); + ASSERT(offset >= 0); int mem_offset = (xyzw * 4) + (offset * 16); memcpy(&result, mem->data() + mem_offset, 2); return result; @@ -633,8 +633,8 @@ struct VuMemWrapper { math::Vector4f load_vector_data(int offset) { math::Vector4f result; // offset = offset & 0x3ff; // not super happy with this... - assert(offset < 328); - assert(offset >= 0); + ASSERT(offset < 328); + ASSERT(offset >= 0); memcpy(&result, mem->data() + (offset * 16), 16); return result; } @@ -1025,7 +1025,7 @@ std::vector emulate_tfrag_execution(const level_tools::TFragment& fra //////////////////////////////////////////////////////////////////////////////////////// // ilwr.x vi02, vi03 | nop - assert(vi03_vert_addr_book < 328); // should be a buffer 0 addr + ASSERT(vi03_vert_addr_book < 328); // should be a buffer 0 addr u16 vi02_pre_vtx_ptr = mem.ilw_data(vi03_vert_addr_book, 0); // is an addr? v4/16 with strom if (DEBUG) { fmt::print("vi02-warmup 0: {}\n", vi02_pre_vtx_ptr); @@ -1579,7 +1579,7 @@ std::vector emulate_tfrag_execution(const level_tools::TFragment& fra // mtir vi04, vf28.w | maxy.w vf15, vf15, vf01 vi04_vtx_ptr = float_2_u32(vf28_w_addr_of_next_vtx); // L131 previously - // assert(vars.vi04 != 0xbeef); // hit + // ASSERT(vars.vi04 != 0xbeef); // hit // vars.vf15_loop_pos_1.w() = std::max(vars.vf15_loop_pos_1.w(), m_tfrag_data.fog.y()); // fcand vi01, 0x3ffff | maddax.xyzw ACC, vf04, vf13 @@ -1665,7 +1665,7 @@ std::vector emulate_tfrag_execution(const level_tools::TFragment& fra } } - // assert(false); + // ASSERT(false); } end: @@ -1685,7 +1685,7 @@ std::string debug_dump_to_obj(const std::vector& draws) { for (auto& draw : draws) { // add verts... - assert(draw.verts.size() >= 3); + ASSERT(draw.verts.size() >= 3); int vert_idx = 0; @@ -1750,7 +1750,7 @@ void update_mode_from_alpha1(u64 val, DrawMode& mode) { reg.b_mode() == GsAlpha::BlendMode::ZERO_OR_FIXED && reg.c_mode() == GsAlpha::BlendMode::ZERO_OR_FIXED && reg.d_mode() == GsAlpha::BlendMode::DEST) { - assert(reg.fix() == 128); + ASSERT(reg.fix() == 128); // Cv = (Cs - 0) * FIX + Cd // if fix = 128, it works out to 1.0 mode.set_alpha_blend(DrawMode::AlphaBlend::SRC_0_FIX_DST); @@ -1759,7 +1759,7 @@ void update_mode_from_alpha1(u64 val, DrawMode& mode) { fmt::print("unsupported blend: a {} b {} c {} d {}\n", (int)reg.a_mode(), (int)reg.b_mode(), (int)reg.c_mode(), (int)reg.d_mode()); mode.set_alpha_blend(DrawMode::AlphaBlend::SRC_DST_SRC_DST); - assert(false); + ASSERT(false); } } @@ -1784,7 +1784,7 @@ void update_mode_from_test1(u64 val, DrawMode& mode) { default: fmt::print("Alpha test: {} not supported\n", (int)test.alpha_test()); mode.set_alpha_test(DrawMode::AlphaTest::ALWAYS); - assert(false); + ASSERT(false); } // AREF @@ -1794,7 +1794,7 @@ void update_mode_from_test1(u64 val, DrawMode& mode) { mode.set_alpha_fail(test.afail()); // DATE - assert(test.date() == false); + ASSERT(test.date() == false); // DATM // who cares, if date is off @@ -1870,7 +1870,7 @@ void process_draw_mode(std::vector& all_draws, mode.enable_ab(); break; default: - assert(false); + ASSERT(false); } for (auto& draw : all_draws) { @@ -1879,14 +1879,14 @@ void process_draw_mode(std::vector& all_draws, u64 val = draw.get_adgif_val(ad_idx); switch (addr) { case GsRegisterAddress::TEST_1: - assert(false); + ASSERT(false); update_mode_from_test1(val, mode); break; case GsRegisterAddress::TEX0_1: - assert(val == 0); + ASSERT(val == 0); break; case GsRegisterAddress::TEX1_1: - assert(val == 0x120); // some flag + ASSERT(val == 0x120); // some flag { u32 original_tex = draw.get_adgif_upper(ad_idx); u32 new_tex = remap_texture(original_tex, map); @@ -1906,7 +1906,7 @@ void process_draw_mode(std::vector& all_draws, case GsRegisterAddress::CLAMP_1: if (!(val == 0b101 || val == 0 || val == 1 || val == 0b100)) { fmt::print("clamp: 0x{:x}\n", val); - assert(false); + ASSERT(false); } // this isn't quite right, but I'm hoping it's enough! @@ -2015,7 +2015,7 @@ void make_tfrag3_data(std::map>& draws, combo_tex_id); fmt::print("tpage is {}\n", combo_tex_id >> 16); fmt::print("id is {} (0x{:x})\n", combo_tex_id & 0xffff, combo_tex_id & 0xffff); - assert(false); + ASSERT(false); } } tfrag3_tex_id = texture_pool.size(); @@ -2051,10 +2051,10 @@ void make_tfrag3_data(std::map>& draws, vtx.t = vert.stq.y(); vtx.q = vert.stq.z(); // if this is true, we can remove a divide in the shader - assert(vtx.q == 1.f); + ASSERT(vtx.q == 1.f); vtx.color_index = vert.rgba / 4; - // assert((vert.rgba >> 2) < 1024); spider cave has 2048? - assert((vert.rgba & 3) == 0); + // ASSERT((vert.rgba >> 2) < 1024); spider cave has 2048? + ASSERT((vert.rgba & 3) == 0); size_t vert_idx = tree_out.vertices.size(); tree_out.vertices.push_back(vtx); @@ -2150,25 +2150,25 @@ void extract_tfrag(const level_tools::DrawableTreeTfrag* tree, this_tree.kind = tfrag3::TFragmentTreeKind::TRANS; } else { fmt::print("unknown tfrag tree kind: {}\n", tree->my_type()); - assert(false); + ASSERT(false); } - assert(tree->length == (int)tree->arrays.size()); - assert(tree->length > 0); + ASSERT(tree->length == (int)tree->arrays.size()); + ASSERT(tree->length > 0); auto last_array = tree->arrays.back().get(); auto as_tfrag_array = dynamic_cast(last_array); - assert(as_tfrag_array); - assert(as_tfrag_array->length == (int)as_tfrag_array->tfragments.size()); - assert(as_tfrag_array->length > 0); + ASSERT(as_tfrag_array); + ASSERT(as_tfrag_array->length == (int)as_tfrag_array->tfragments.size()); + ASSERT(as_tfrag_array->length > 0); u16 idx = as_tfrag_array->tfragments.front().id; for (auto& elt : as_tfrag_array->tfragments) { - assert(elt.id == idx); + ASSERT(elt.id == idx); idx++; } bool ok = verify_node_indices(tree); - assert(ok); + ASSERT(ok); fmt::print(" tree has {} arrays and {} tfragments\n", tree->length, as_tfrag_array->length); auto vis_nodes = extract_vis_data(tree, as_tfrag_array->tfragments.front().id); @@ -2189,7 +2189,7 @@ void extract_tfrag(const level_tools::DrawableTreeTfrag* tree, } } } - // assert(result.vis_nodes.last_child_node + 1 == idx); + // ASSERT(result.vis_nodes.last_child_node + 1 == idx); emulate_tfrags(as_tfrag_array->tfragments, debug_name, map, out, this_tree, tex_db, expected_missing_textures, dump_level); diff --git a/decompiler/level_extractor/extract_tie.cpp b/decompiler/level_extractor/extract_tie.cpp index 5f67f9ef63..95a5e3016e 100644 --- a/decompiler/level_extractor/extract_tie.cpp +++ b/decompiler/level_extractor/extract_tie.cpp @@ -19,7 +19,7 @@ u16 get_first_idx(const level_tools::DrawableInlineArray* array) { } else if (as_nodes) { return as_nodes->draw_nodes.at(0).id; } else { - assert(false); + ASSERT(false); } } @@ -88,14 +88,14 @@ void extract_vis_data(const level_tools::DrawableTreeInstanceTie* tree, } else if (tree->arrays.size() == 1) { auto array = dynamic_cast(tree->arrays.at(0).get()); - assert(array); + ASSERT(array); out.bvh.first_root = array->instances.at(0).id; out.bvh.num_roots = array->instances.size(); out.bvh.only_children = true; } else { auto array = dynamic_cast(tree->arrays.at(0).get()); - assert(array); + ASSERT(array); out.bvh.first_root = array->draw_nodes.at(0).id; out.bvh.num_roots = array->draw_nodes.size(); out.bvh.only_children = false; @@ -109,29 +109,29 @@ void extract_vis_data(const level_tools::DrawableTreeInstanceTie* tree, auto array = dynamic_cast(tree->arrays.at(i).get()); - assert(array); + ASSERT(array); u16 idx = first_child; for (auto& elt : array->draw_nodes) { auto& vis = out.bvh.vis_nodes.at(elt.id - out.bvh.first_root); - assert(vis.num_kids == 0xff); + ASSERT(vis.num_kids == 0xff); for (int j = 0; j < 4; j++) { vis.bsphere[j] = elt.bsphere.data[j]; } vis.num_kids = elt.child_count; vis.flags = elt.flags; vis.my_id = elt.id; - assert(vis.flags == expecting_leaves ? 0 : 1); - assert(vis.num_kids > 0); - assert(vis.num_kids <= 8); - assert(elt.children.size() == vis.num_kids); + ASSERT(vis.flags == expecting_leaves ? 0 : 1); + ASSERT(vis.num_kids > 0); + ASSERT(vis.num_kids <= 8); + ASSERT(elt.children.size() == vis.num_kids); if (expecting_leaves) { for (int leaf = 0; leaf < (int)vis.num_kids; leaf++) { auto l = dynamic_cast(elt.children.at(leaf).get()); - assert(l); + ASSERT(l); - assert(idx == l->id); + ASSERT(idx == l->id); - assert(l->id >= out.bvh.first_leaf_node); + ASSERT(l->id >= out.bvh.first_leaf_node); if (leaf == 0) { vis.child_id = l->id; } @@ -143,18 +143,18 @@ void extract_vis_data(const level_tools::DrawableTreeInstanceTie* tree, u16 arr_idx = 0; for (int child = 0; child < (int)vis.num_kids; child++) { auto l = dynamic_cast(elt.children.at(child).get()); - assert(l); + ASSERT(l); if (child == 0) { arr_idx = l->id; } else { - assert(arr_idx < l->id); + ASSERT(arr_idx < l->id); arr_idx = l->id; } if (child == 0) { vis.child_id = l->id; } - assert(l->id < out.bvh.first_leaf_node); + ASSERT(l->id < out.bvh.first_leaf_node); } } } @@ -266,9 +266,9 @@ struct TieFrag { // simulate a load in the points data (using vu mem addr) math::Vector lq_points(u32 qw) const { - assert(qw >= 50); + ASSERT(qw >= 50); qw -= 50; - assert((qw * 16) + 16 <= points_data.size()); + ASSERT((qw * 16) + 16 <= points_data.size()); math::Vector result; memcpy(result.data(), points_data.data() + (qw * 16), 16); return result; @@ -277,7 +277,7 @@ struct TieFrag { // simulate a load from points, but don't die if we load past the end // this can happen when pipelining. math::Vector lq_points_allow_past_end(u32 qw) const { - assert(qw >= 50); + ASSERT(qw >= 50); qw -= 50; if ((qw * 16) + 16 <= points_data.size()) { math::Vector result; @@ -291,9 +291,9 @@ struct TieFrag { // store data into points. annoyingly the points have to be unpacked // and they are modified in place. void sq_points(u32 qw, const math::Vector4f& data) { - assert(qw >= 50); + ASSERT(qw >= 50); qw -= 50; - assert((qw * 16) + 16 <= points_data.size()); + ASSERT((qw * 16) + 16 <= points_data.size()); memcpy(points_data.data() + (qw * 16), data.data(), 16); } @@ -302,7 +302,7 @@ struct TieFrag { // unpacked with v8. int qwi = qw; qwi -= (adgifs.size() * 5); - assert(qwi >= 0); + ASSERT(qwi >= 0); return other_gif_data.at(qwi * 4 + offset); } @@ -380,8 +380,8 @@ void check_wind_vectors_zero(const std::vector& protos, Ref wind_r wind_words *= 4; for (size_t i = 0; i < wind_words; i++) { auto& word = wind_ref.data->words_by_seg.at(wind_ref.seg).at(wind_ref.byte_offset / 4 + i); - assert(word.kind() == LinkedWord::PLAIN_DATA); - assert(word.data == 0); + ASSERT(word.kind() == LinkedWord::PLAIN_DATA); + ASSERT(word.data == 0); } } @@ -436,7 +436,7 @@ std::vector collect_instance_info( } } info.frags.push_back(std::move(frag_info)); - assert(info.frags.back().color_indices.size() > 0); + ASSERT(info.frags.back().color_indices.size() > 0); offset_bytes += num_color_qwc * 16; } @@ -459,7 +459,7 @@ u32 remap_texture(u32 original, const std::vector& ma for (auto& t : map) { if (t.original_texid == masked) { fmt::print("OKAY! remapped!\n"); - assert(false); + ASSERT(false); return t.new_texid | 20; } } @@ -478,7 +478,7 @@ void update_proto_info(std::vector* out, const auto& proto = protos[i]; auto& info = out->at(i); // the flags can either be 0 or 2. - assert(proto.flags == 0 || proto.flags == 2); + ASSERT(proto.flags == 0 || proto.flags == 2); // flag of 2 means it should use the generic renderer (determined from EE asm) // for now, we ignore this and use TIE on everything. info.uses_generic = (proto.flags == 2); @@ -519,11 +519,11 @@ void update_proto_info(std::vector* out, memcpy(&ra_tex0_val, &gif_data.at(16 * (tex_idx * 5 + 0)), 8); // always expecting TEX0_1 - assert(ra_tex0 == (u8)GsRegisterAddress::TEX0_1); + ASSERT(ra_tex0 == (u8)GsRegisterAddress::TEX0_1); // the value is overwritten by the login function. We don't care about this value, it's // specific to the PS2's texture system. - assert(ra_tex0_val == 0 || ra_tex0_val == 0x800000000); // note: decal + ASSERT(ra_tex0_val == 0 || ra_tex0_val == 0x800000000); // note: decal // the original value is a flag. this means to use decal texture mode (todo) frag_info.has_magic_tex0_bit = ra_tex0_val == 0x800000000; // there's also a hidden value in the unused bits of the a+d data. it'll be used by the @@ -534,8 +534,8 @@ void update_proto_info(std::vector* out, u8 ra_tex1 = gif_data.at(16 * (tex_idx * 5 + 1) + 8); u64 ra_tex1_val; memcpy(&ra_tex1_val, &gif_data.at(16 * (tex_idx * 5 + 1)), 8); - assert(ra_tex1 == (u8)GsRegisterAddress::TEX1_1); - assert(ra_tex1_val == 0x120); // some flag + ASSERT(ra_tex1 == (u8)GsRegisterAddress::TEX1_1); + ASSERT(ra_tex1_val == 0x120); // some flag u32 original_tex; memcpy(&original_tex, &gif_data.at(16 * (tex_idx * 5 + 1) + 8), 4); // try remapping it @@ -549,7 +549,7 @@ void update_proto_info(std::vector* out, u32 tex_combo = (((u32)tpage) << 16) | tidx; // look up the texture to make sure it's valid auto tex = tdb.textures.find(tex_combo); - assert(tex != tdb.textures.end()); + ASSERT(tex != tdb.textures.end()); // remember the texture id adgif.combo_tex = tex_combo; // and the hidden value in the unused a+d @@ -561,20 +561,20 @@ void update_proto_info(std::vector* out, // mipmap settings. we ignore, but get the hidden value u8 ra_mip = gif_data.at(16 * (tex_idx * 5 + 2) + 8); - assert(ra_mip == (u8)GsRegisterAddress::MIPTBP1_1); + ASSERT(ra_mip == (u8)GsRegisterAddress::MIPTBP1_1); memcpy(&adgif.third_w, &gif_data.at(16 * (tex_idx * 5 + 2) + 12), 4); // who cares about the value // clamp settings. we care about these. no hidden value. u8 ra_clamp = gif_data.at(16 * (tex_idx * 5 + 3) + 8); - assert(ra_clamp == (u8)GsRegisterAddress::CLAMP_1); + ASSERT(ra_clamp == (u8)GsRegisterAddress::CLAMP_1); u64 clamp; memcpy(&clamp, &gif_data.at(16 * (tex_idx * 5 + 3)), 8); adgif.clamp_val = clamp; // alpha settings. we care about these, but no hidden value u8 ra_alpha = gif_data.at(16 * (tex_idx * 5 + 4) + 8); - assert(ra_alpha == (u8)GsRegisterAddress::ALPHA_1); + ASSERT(ra_alpha == (u8)GsRegisterAddress::ALPHA_1); u64 alpha; memcpy(&alpha, &gif_data.at(16 * (tex_idx * 5 + 4)), 8); adgif.alpha_val = alpha; @@ -763,20 +763,20 @@ void emulate_tie_prototype_program(std::vector& protos) { // the first one has the offset in the gif buffer. // we expect this to be 0 for the first one - we should start with adgif shaders always. u16 vi04 = frag.adgifs.at(0).first_w; - assert(vi04 == 0); + ASSERT(vi04 == 0); // ilw.w vi_ind, 1(vi_point_ptr) | nop // the next hidden integer is the number of adgif shaders used in this fragment. // we already know this, so check it. u16 vi_ind = frag.adgifs.at(0).second_w; - assert(vi_ind == frag.adgifs.size()); + ASSERT(vi_ind == frag.adgifs.size()); // mtir vi06, vf_gifbufs.y | nop // vi06 will be one of our gifbufs we can use. u16 vi06; memcpy(&vi06, &vf_gifbufs.y(), sizeof(u16)); // fmt::print("vi06: {}\n", vi06); - assert(vi06 == 470 || vi06 == 286 || vi06 == 654); // should be one of the three gifbufs. + ASSERT(vi06 == 470 || vi06 == 286 || vi06 == 654); // should be one of the three gifbufs. // lqi.xyzw vf02, vi_point_ptr | suby.xz vf_gifbufs, vf_gifbufs, vf_gifbufs // lqi.xyzw vf03, vi_point_ptr | nop @@ -795,11 +795,11 @@ void emulate_tie_prototype_program(std::vector& protos) { // fmt::print("vi05: {}\n", vi05); // check that we understand the buffer rotation. if (vi06 == 470) { - assert(vi05 == 286); + ASSERT(vi05 == 286); } else if (vi06 == 286) { - assert(vi05 == 654); + ASSERT(vi05 == 654); } else { - assert(vi05 == 470); + ASSERT(vi05 == 470); } vi_point_ptr += 5; @@ -863,7 +863,7 @@ void emulate_tie_prototype_program(std::vector& protos) { // again, we do it in two parts. The extra gif data gives us offsets, // The extra gif stuff is unpacked immediately after adgifs. Unpacked with v8 4. // the above adgif loop will run off the end and vf02 will have the first byte in it's w. - assert(frag.other_gif_data.size() > 1); + ASSERT(frag.other_gif_data.size() > 1); // mtir vi_ind, vf02.w | nop // vi_ind will contain the number of drawing packets for this fragment. vi_ind = frag.other_gif_data.at(3); @@ -878,8 +878,8 @@ void emulate_tie_prototype_program(std::vector& protos) { u16 vf04_y = frag.other_gif_data.at(9); u16 vf04_z = frag.other_gif_data.at(10); // u16 vf04_w = frag.other_gif_data.at(11); - assert(vi_ind >= frag.adgifs.size()); // at least 1 draw per shader. - assert(vi_ind < 1000); // check for insane value. + ASSERT(vi_ind >= frag.adgifs.size()); // at least 1 draw per shader. + ASSERT(vi_ind < 1000); // check for insane value. // fmt::print("got: {}, other size: {}\n", vi_ind, frag.other_gif_data.size()); // iaddi vi_point_ptr, vi_point_ptr, -0x2 | subw.w vf07, vf07, vf07 @@ -895,7 +895,7 @@ void emulate_tie_prototype_program(std::vector& protos) { // ilwr.y vi08, vi_point_ptr | nop u16 vi08 = frag.ilw_other_gif(vi_point_ptr, 1); // this can toggle to a different mode but I don't understand it yet. - assert(vi08 == 0); + ASSERT(vi08 == 0); // ilwr.z vi04, vi_point_ptr | nop vi04 = frag.ilw_other_gif(vi_point_ptr, 2); @@ -930,7 +930,7 @@ void emulate_tie_prototype_program(std::vector& protos) { // iswr.x vi07, vi03 | nop info.nloop = vi07 & 0x7fff; info.eop = vi07 & 0x8000; - assert(!info.eop); // seems like we handle this manually after the loop + ASSERT(!info.eop); // seems like we handle this manually after the loop info.mode = next_mode; // sq.xyzw vf07, 0(vi04) | nop @@ -1263,7 +1263,7 @@ void emulate_tie_prototype_program(std::vector& protos) { // todo: maybe we need more. } - // assert(false); + // ASSERT(false); } } @@ -1450,7 +1450,7 @@ void emulate_tie_instance_program(std::vector& protos) { vertex_info.tex.z() = tex_coord.z(); bool inserted = frag.vertex_by_dest_addr.insert({(u32)dest_ptr, vertex_info}).second; - assert(inserted); + ASSERT(inserted); if (reached_target) { past_target++; @@ -1492,10 +1492,10 @@ void emulate_tie_instance_program(std::vector& protos) { // fmt::print("double draw: {} {}\n", dest_ptr, dest2_ptr); bool inserted = frag.vertex_by_dest_addr.insert({(u32)dest_ptr, vertex_info}).second; - assert(inserted); + ASSERT(inserted); bool inserted2 = frag.vertex_by_dest_addr.insert({(u32)dest2_ptr, vertex_info}).second; - assert(inserted2); + ASSERT(inserted2); if (reached_target) { past_target++; @@ -1612,7 +1612,7 @@ void emulate_tie_instance_program(std::vector& protos) { vertex_info.tex.z() = tex_coord.z(); bool inserted = frag.vertex_by_dest_addr.insert({(u32)dest_ptr, vertex_info}).second; - assert(inserted); + ASSERT(inserted); ip_1_count++; } @@ -1644,14 +1644,14 @@ void emulate_tie_instance_program(std::vector& protos) { vertex_info.tex.z() = tex_coord.z(); bool inserted = frag.vertex_by_dest_addr.insert({(u32)dest_ptr, vertex_info}).second; - assert(inserted); + ASSERT(inserted); // first iteration of ip2 is a bit strange because how it jumps from loop to loop. // in some cases it uses ip2 on a point that should have used ip1 with the same addr // twice. I am pretty sure it's not our fault because we get exactly the right dvert. bool inserted2 = frag.vertex_by_dest_addr.insert({(u32)dest2_ptr, vertex_info}).second; if (!first_iter) { - assert(inserted2); + ASSERT(inserted2); } first_iter = false; ip_1_count++; @@ -1659,10 +1659,10 @@ void emulate_tie_instance_program(std::vector& protos) { } // now, let's check count: - assert(frag.vertex_by_dest_addr.size() == frag.expected_dverts); + ASSERT(frag.vertex_by_dest_addr.size() == frag.expected_dverts); program_end:; - // assert(false); + // ASSERT(false); } // } @@ -1685,9 +1685,9 @@ void emulate_kicks(std::vector& protos) { // but, we should always start with an adgif (otherwise we'd use the draw settings from // the last model, which we don't know) - assert(frag.prog_info.adgif_offset_in_gif_buf_qw.at(0) == 0); + ASSERT(frag.prog_info.adgif_offset_in_gif_buf_qw.at(0) == 0); // and we expect that the VU program placed all adgifs somewhere - assert(frag.prog_info.adgif_offset_in_gif_buf_qw.size() == frag.adgifs.size()); + ASSERT(frag.prog_info.adgif_offset_in_gif_buf_qw.size() == frag.adgifs.size()); const AdgifInfo* adgif_info = nullptr; int expected_next_tag = 0; @@ -1703,10 +1703,10 @@ void emulate_kicks(std::vector& protos) { expected_next_tag += 6; adgif_it++; } - assert(adgif_info); + ASSERT(adgif_info); // make sure the next str is where we expect - assert(expected_next_tag == str_it->address); + ASSERT(expected_next_tag == str_it->address); // the next tag (either str/adgif) should be located at the end of this tag's data. expected_next_tag += 3 * str_it->nloop + 1; // here we have the right str and adgif. @@ -1715,7 +1715,7 @@ void emulate_kicks(std::vector& protos) { // 286 gifbuf // 470 gifbuf again // 654 ?? - assert(!frag.vertex_by_dest_addr.empty()); + ASSERT(!frag.vertex_by_dest_addr.empty()); int gifbuf_addr = frag.vertex_by_dest_addr.begin()->first; int base_address = 286; if (gifbuf_addr >= 654) { @@ -1739,7 +1739,7 @@ void emulate_kicks(std::vector& protos) { str_it++; } - assert(adgif_it == adgif_end); + ASSERT(adgif_it == adgif_end); } } } @@ -1757,7 +1757,7 @@ std::string debug_dump_proto_to_obj(const TieProtoInfo& proto) { for (auto& frag : proto.frags) { for (auto& strip : frag.strips) { // add verts... - assert(strip.verts.size() >= 3); + ASSERT(strip.verts.size() >= 3); int vert_idx = 0; @@ -1833,7 +1833,7 @@ std::string dump_full_to_obj(const std::vector& protos) { for (auto& frag : proto.frags) { for (auto& strip : frag.strips) { // add verts... - assert(strip.verts.size() >= 3); + ASSERT(strip.verts.size() >= 3); int vert_idx = 0; @@ -1916,7 +1916,7 @@ BigPalette make_big_palette(std::vector& protos) { for (u32 instance_idx = 0; instance_idx < proto.instances.size(); instance_idx++) { auto& instance = proto.instances[instance_idx]; - assert(proto.frags.size() == instance.frags.size()); + ASSERT(proto.frags.size() == instance.frags.size()); for (u32 frag_idx = 0; frag_idx < proto.frags.size(); frag_idx++) { auto& ifrag = instance.frags.at(frag_idx); ifrag.color_index_offset_in_big_palette = base_color_of_proto; @@ -1924,7 +1924,7 @@ BigPalette make_big_palette(std::vector& protos) { } } - assert(result.colors.size() < UINT16_MAX); + ASSERT(result.colors.size() < UINT16_MAX); return result; } @@ -1950,7 +1950,7 @@ void update_mode_from_alpha1(u64 val, DrawMode& mode) { reg.b_mode() == GsAlpha::BlendMode::ZERO_OR_FIXED && reg.c_mode() == GsAlpha::BlendMode::ZERO_OR_FIXED && reg.d_mode() == GsAlpha::BlendMode::DEST) { - assert(reg.fix() == 128); + ASSERT(reg.fix() == 128); // Cv = (Cs - 0) * FIX + Cd // if fix = 128, it works out to 1.0 mode.set_alpha_blend(DrawMode::AlphaBlend::SRC_0_FIX_DST); @@ -1960,7 +1960,7 @@ void update_mode_from_alpha1(u64 val, DrawMode& mode) { reg.c_mode() == GsAlpha::BlendMode::ZERO_OR_FIXED && reg.d_mode() == GsAlpha::BlendMode::DEST) { // Cv = (Cs - Cd) * FIX + Cd - assert(reg.fix() == 64); + ASSERT(reg.fix() == 64); mode.set_alpha_blend(DrawMode::AlphaBlend::SRC_DST_FIX_DST); } @@ -1968,7 +1968,7 @@ void update_mode_from_alpha1(u64 val, DrawMode& mode) { fmt::print("unsupported blend: a {} b {} c {} d {}\n", (int)reg.a_mode(), (int)reg.b_mode(), (int)reg.c_mode(), (int)reg.d_mode()); mode.set_alpha_blend(DrawMode::AlphaBlend::SRC_DST_SRC_DST); - assert(false); + ASSERT(false); } } @@ -2006,7 +2006,7 @@ DrawMode process_draw_mode(const AdgifInfo& info, bool use_atest, bool use_decal if (!(info.clamp_val == 0b101 || info.clamp_val == 0 || info.clamp_val == 1 || info.clamp_val == 0b100)) { fmt::print("clamp: 0x{:x}\n", info.clamp_val); - assert(false); + ASSERT(false); } mode.set_clamp_s_enable(info.clamp_val & 0b1); @@ -2082,7 +2082,7 @@ void add_vertices_and_static_draw(tfrag3::TieTree& tree, combo_tex); fmt::print("tpage is {}\n", combo_tex >> 16); fmt::print("id is {} (0x{:x})\n", combo_tex & 0xffff, combo_tex & 0xffff); - assert(false); + ASSERT(false); } } // add a new texture to the level data @@ -2144,12 +2144,12 @@ void add_vertices_and_static_draw(tfrag3::TieTree& tree, vtx.t = vert.tex.y(); vtx.q = vert.tex.z(); // if this is true, we can remove a divide in the shader - assert(vtx.q == 1.f); + ASSERT(vtx.q == 1.f); if (vert.color_index_index == UINT32_MAX) { vtx.color_index = 0; } else { vtx.color_index = ifrag.color_indices.at(vert.color_index_index); - assert(vert.color_index_index < ifrag.color_indices.size()); + ASSERT(vert.color_index_index < ifrag.color_indices.size()); vtx.color_index += ifrag.color_index_offset_in_big_palette; } @@ -2197,12 +2197,12 @@ void add_vertices_and_static_draw(tfrag3::TieTree& tree, vtx.t = vert.tex.y(); vtx.q = vert.tex.z(); // if this is true, we can remove a divide in the shader - assert(vtx.q == 1.f); + ASSERT(vtx.q == 1.f); if (vert.color_index_index == UINT32_MAX) { vtx.color_index = 0; } else { vtx.color_index = ifrag.color_indices.at(vert.color_index_index); - assert(vert.color_index_index < ifrag.color_indices.size()); + ASSERT(vert.color_index_index < ifrag.color_indices.size()); vtx.color_index += ifrag.color_index_offset_in_big_palette; } @@ -2266,20 +2266,20 @@ void extract_tie(const level_tools::DrawableTreeInstanceTie* tree, tfrag3::TieTree this_tree; // sanity check the vis tree (not a perfect check, but this is used in game and should be right) - assert(tree->length == (int)tree->arrays.size()); - assert(tree->length > 0); + ASSERT(tree->length == (int)tree->arrays.size()); + ASSERT(tree->length > 0); auto last_array = tree->arrays.back().get(); auto as_instance_array = dynamic_cast(last_array); - assert(as_instance_array); - assert(as_instance_array->length == (int)as_instance_array->instances.size()); - assert(as_instance_array->length > 0); + ASSERT(as_instance_array); + ASSERT(as_instance_array->length == (int)as_instance_array->instances.size()); + ASSERT(as_instance_array->length > 0); u16 idx = as_instance_array->instances.front().id; for (auto& elt : as_instance_array->instances) { - assert(elt.id == idx); + ASSERT(elt.id == idx); idx++; } bool ok = verify_node_indices(tree); - assert(ok); + ASSERT(ok); fmt::print(" tree has {} arrays and {} instances\n", tree->length, as_instance_array->length); // extract the vis tree. Note that this extracts the tree only down to the last draw node, a diff --git a/decompiler/util/DataParser.cpp b/decompiler/util/DataParser.cpp index 784848b5ec..96b1c6ff6e 100644 --- a/decompiler/util/DataParser.cpp +++ b/decompiler/util/DataParser.cpp @@ -1,7 +1,7 @@ #include #include "DataParser.h" #include "third-party/fmt/core.h" -#include "common/util/assert.h" +#include "common/util/Assert.h" /* * Allowable lines: @@ -35,7 +35,7 @@ std::vector string_to_lines(const std::string& str) { } std::string get_until_space(std::string& instr) { - assert(!instr.empty()); + ASSERT(!instr.empty()); size_t i; for (i = 0; i < instr.length(); i++) { if (instr[i] == ' ') { @@ -155,7 +155,7 @@ ParsedData parse_data(const std::string& str) { continue; } else { auto val = std::stoull(line, nullptr, 16); - assert(val <= UINT32_MAX); + ASSERT(val <= UINT32_MAX); LinkedWord word(val); word.set_to_plain_data(); result.words.push_back(word); @@ -211,7 +211,7 @@ std::string ParsedData::print() const { result += " .empty-list\n"; break; default: - assert(false); + ASSERT(false); } } diff --git a/decompiler/util/DecompilerTypeSystem.cpp b/decompiler/util/DecompilerTypeSystem.cpp index dca38e1b9b..0d86bdf31a 100644 --- a/decompiler/util/DecompilerTypeSystem.cpp +++ b/decompiler/util/DecompilerTypeSystem.cpp @@ -100,7 +100,7 @@ TypeSpec DecompilerTypeSystem::parse_type_spec(const std::string& str) const { } std::string DecompilerTypeSystem::dump_symbol_types() { - assert(symbol_add_order.size() == symbols.size()); + ASSERT(symbol_add_order.size() == symbols.size()); std::string result; for (auto& symbol_name : symbol_add_order) { auto skv = symbol_types.find(symbol_name); @@ -303,7 +303,7 @@ TP_Type DecompilerTypeSystem::tp_lca(const TP_Type& existing, case TP_Type::Kind::DYNAMIC_METHOD_ACCESS: case TP_Type::Kind::INVALID: default: - assert(false); + ASSERT(false); return {}; } } else { diff --git a/decompiler/util/TP_Type.cpp b/decompiler/util/TP_Type.cpp index 51c94a2310..841898354d 100644 --- a/decompiler/util/TP_Type.cpp +++ b/decompiler/util/TP_Type.cpp @@ -79,7 +79,7 @@ std::string TP_Type::print() const { return ""; case Kind::INVALID: default: - assert(false); + ASSERT(false); return {}; } } @@ -136,7 +136,7 @@ bool TP_Type::operator==(const TP_Type& other) const { return true; case Kind::INVALID: default: - assert(false); + ASSERT(false); return false; } } @@ -201,7 +201,7 @@ TypeSpec TP_Type::typespec() const { return TypeSpec("function"); case Kind::INVALID: default: - assert(false); + ASSERT(false); return {}; } } diff --git a/decompiler/util/TP_Type.h b/decompiler/util/TP_Type.h index 961fbb3d3c..aab496b972 100644 --- a/decompiler/util/TP_Type.h +++ b/decompiler/util/TP_Type.h @@ -5,7 +5,7 @@ #include "common/type_system/TypeSpec.h" #include "common/common_types.h" #include "decompiler/Disasm/Register.h" -#include "common/util/assert.h" +#include "common/util/Assert.h" namespace decompiler { /*! @@ -80,7 +80,7 @@ class TP_Type { return m_ts.base_type() != "pointer"; case Kind::INVALID: default: - assert(false); + ASSERT(false); } } @@ -96,12 +96,12 @@ class TP_Type { bool can_be_format_string() const { return is_format_string() || is_constant_string(); } int get_format_string_arg_count() const { - assert(is_format_string()); + ASSERT(is_format_string()); return m_int; } const std::string& get_string() const { - assert(is_constant_string()); + ASSERT(is_constant_string()); return m_str; } @@ -286,52 +286,52 @@ class TP_Type { } const TypeSpec& get_objects_typespec() const { - assert(kind == Kind::TYPESPEC || kind == Kind::INTEGER_CONSTANT_PLUS_VAR); + ASSERT(kind == Kind::TYPESPEC || kind == Kind::INTEGER_CONSTANT_PLUS_VAR); return m_ts; } const TypeSpec& get_type_objects_typespec() const { - assert(kind == Kind::TYPE_OF_TYPE_OR_CHILD || kind == Kind::TYPE_OF_TYPE_NO_VIRTUAL); + ASSERT(kind == Kind::TYPE_OF_TYPE_OR_CHILD || kind == Kind::TYPE_OF_TYPE_NO_VIRTUAL); return m_ts; } const TypeSpec& get_method_new_object_typespec() const { - assert(kind == Kind::OBJECT_NEW_METHOD); + ASSERT(kind == Kind::OBJECT_NEW_METHOD); return m_ts; } const TypeSpec& get_obj_plus_const_mult_typespec() const { - assert(kind == Kind::OBJECT_PLUS_PRODUCT_WITH_CONSTANT); + ASSERT(kind == Kind::OBJECT_PLUS_PRODUCT_WITH_CONSTANT); return m_ts; } uint64_t get_multiplier() const { - assert(kind == Kind::PRODUCT_WITH_CONSTANT || kind == Kind::OBJECT_PLUS_PRODUCT_WITH_CONSTANT); + ASSERT(kind == Kind::PRODUCT_WITH_CONSTANT || kind == Kind::OBJECT_PLUS_PRODUCT_WITH_CONSTANT); return m_int; } uint64_t get_integer_constant() const { - assert(kind == Kind::INTEGER_CONSTANT || kind == Kind::INTEGER_CONSTANT_PLUS_VAR); + ASSERT(kind == Kind::INTEGER_CONSTANT || kind == Kind::INTEGER_CONSTANT_PLUS_VAR); return m_int; } u64 get_add_int_constant() const { - assert(kind == Kind::INTEGER_CONSTANT_PLUS_VAR_MULT); + ASSERT(kind == Kind::INTEGER_CONSTANT_PLUS_VAR_MULT); return m_int; } u64 get_mult_int_constant() const { - assert(kind == Kind::INTEGER_CONSTANT_PLUS_VAR_MULT); + ASSERT(kind == Kind::INTEGER_CONSTANT_PLUS_VAR_MULT); return m_extra_multiplier; } int get_left_shift() const { - assert(kind == Kind::LEFT_SHIFTED_BITFIELD); + ASSERT(kind == Kind::LEFT_SHIFTED_BITFIELD); return m_int; } const TypeSpec& get_bitfield_type() const { - assert(kind == Kind::LEFT_SHIFTED_BITFIELD || kind == Kind::PCPYUD_BITFIELD || + ASSERT(kind == Kind::LEFT_SHIFTED_BITFIELD || kind == Kind::PCPYUD_BITFIELD || kind == Kind::PCPYUD_BITFIELD_AND); return m_ts; } @@ -340,27 +340,27 @@ class TP_Type { if (kind == Kind::LEFT_SHIFTED_BITFIELD) { return m_pcpyud; } - assert(false); + ASSERT(false); return false; } const TypeSpec& method_from_type() const { - assert(kind == Kind::VIRTUAL_METHOD || kind == Kind::NON_VIRTUAL_METHOD); + ASSERT(kind == Kind::VIRTUAL_METHOD || kind == Kind::NON_VIRTUAL_METHOD); return m_method_from_type; } int method_id() const { - assert(kind == Kind::VIRTUAL_METHOD || kind == Kind::NON_VIRTUAL_METHOD); + ASSERT(kind == Kind::VIRTUAL_METHOD || kind == Kind::NON_VIRTUAL_METHOD); return m_method_id; } bool flipped_add_order() const { - assert(kind == Kind::OBJECT_PLUS_PRODUCT_WITH_CONSTANT); + ASSERT(kind == Kind::OBJECT_PLUS_PRODUCT_WITH_CONSTANT); return m_flipped_order; } int label_id() const { - assert(kind == Kind::LABEL_ADDR); + ASSERT(kind == Kind::LABEL_ADDR); return m_int; } @@ -391,7 +391,7 @@ class TypeState { case Reg::FPR: return fpr_types[r.get_fpr()]; default: - assert(false); + ASSERT(false); throw std::runtime_error("TP_Type::get failed"); } } @@ -403,7 +403,7 @@ class TypeState { case Reg::FPR: return fpr_types[r.get_fpr()]; default: - assert(false); + ASSERT(false); throw std::runtime_error("TP_Type::get failed"); } } diff --git a/decompiler/util/data_decompile.cpp b/decompiler/util/data_decompile.cpp index 519ba96c18..b93dbcdd35 100644 --- a/decompiler/util/data_decompile.cpp +++ b/decompiler/util/data_decompile.cpp @@ -10,7 +10,7 @@ #include "decompiler/IR2/Form.h" #include "decompiler/analysis/final_output.h" #include "decompiler/util/sparticle_decompile.h" -#include "common/util/assert.h" +#include "common/util/Assert.h" namespace decompiler { @@ -208,7 +208,7 @@ goos::Object decompile_string_at_label(const DecompilerLabel& label, throw std::runtime_error(fmt::format("Cannot get string at label {}, alignment of label is {}", label.name, label.offset)); } - assert(label.offset >= 4); + ASSERT(label.offset >= 4); const auto& type_ptr = words.at(label.target_segment).at((label.offset - 4) / 4); if (type_ptr.kind() != LinkedWord::TYPE_PTR) { @@ -248,7 +248,7 @@ goos::Object decompile_string_at_label(const DecompilerLabel& label, char cword[4]; memcpy(cword, &word.data, 4); result += cword[byte_offset]; - assert(result.back() != 0); + ASSERT(result.back() != 0); } return goos::StringObject::make_new(result); } @@ -274,7 +274,7 @@ goos::Object decompile_value_array(const TypeSpec& elt_type, } elt_bytes.push_back(word.get_byte(j % 4)); } - assert(elt_type != TypeSpec("uint128")); + ASSERT(elt_type != TypeSpec("uint128")); array_def.push_back(decompile_value(elt_type, elt_bytes, ts)); } @@ -336,14 +336,14 @@ goos::Object decomp_ref_to_integer_array_guess_size( // verify types auto elt_type_info = ts.lookup_type(array_elt_type); - assert(stride == elt_type_info->get_size_in_memory()); - assert(!elt_type_info->is_reference()); + ASSERT(stride == elt_type_info->get_size_in_memory()); + ASSERT(!elt_type_info->is_reference()); // the input is the location of the data field. // we expect that to be a label: - assert((field_location % 4) == 0); + ASSERT((field_location % 4) == 0); auto pointer_to_data = words.at(field_location / 4); - assert(pointer_to_data.kind() == LinkedWord::PTR); + ASSERT(pointer_to_data.kind() == LinkedWord::PTR); // the data shouldn't have any labels in the middle of it, so we can find the end of the array // by searching for the label after the start label. @@ -383,12 +383,12 @@ goos::Object decomp_ref_to_integer_array_guess_size( auto& word = all_words.at(my_seg).at(pad_byte_idx / 4); switch (word.kind()) { case LinkedWord::PLAIN_DATA: - assert(word.get_byte(pad_byte_idx) == 0); + ASSERT(word.get_byte(pad_byte_idx) == 0); break; case LinkedWord::TYPE_PTR: break; default: - assert(false); + ASSERT(false); } } @@ -415,13 +415,13 @@ goos::Object decomp_ref_to_inline_array_guess_size( auto elt_type_info = ts.lookup_type(array_elt_type); int ye = align(elt_type_info->get_size_in_memory(), elt_type_info->get_inline_array_stride_alignment()); - assert(stride == ye); + ASSERT(stride == ye); // the input is the location of the data field. // we expect that to be a label: - assert((field_location % 4) == 0); + ASSERT((field_location % 4) == 0); auto pointer_to_data = words.at(field_location / 4); - assert(pointer_to_data.kind() == LinkedWord::PTR); + ASSERT(pointer_to_data.kind() == LinkedWord::PTR); // the data shouldn't have any labels in the middle of it, so we can find the end of the array // by searching for the label after the start label. @@ -461,12 +461,12 @@ goos::Object decomp_ref_to_inline_array_guess_size( auto& word = all_words.at(my_seg).at(pad_byte_idx / 4); switch (word.kind()) { case LinkedWord::PLAIN_DATA: - assert(word.get_byte(pad_byte_idx) == 0); + ASSERT(word.get_byte(pad_byte_idx) == 0); break; case LinkedWord::TYPE_PTR: break; default: - assert(false); + ASSERT(false); } } @@ -694,7 +694,7 @@ goos::Object decompile_structure(const TypeSpec& type, continue; } if (is_basic && idx == 0) { - assert(field.name() == "type" && field.offset() == 0); + ASSERT(field.name() == "type" && field.offset() == 0); auto& word = obj_words.at(0); if (word.kind() != LinkedWord::TYPE_PTR) { throw std::runtime_error("Basic does not start with type pointer"); @@ -702,7 +702,7 @@ goos::Object decompile_structure(const TypeSpec& type, if (word.symbol_name() != actual_type.base_type()) { // the check above should have caught this. - assert(false); + ASSERT(false); } for (int k = 0; k < 4; k++) { field_status_per_byte.at(k) = HAS_DATA_READ; @@ -759,12 +759,12 @@ goos::Object decompile_structure(const TypeSpec& type, auto field_type_info = ts.lookup_type(field.type()); if (!field_type_info->is_reference()) { // value type. need to get bytes. - assert(!field.is_inline()); + ASSERT(!field.is_inline()); if (field.is_array()) { // array of values. auto len = field.array_size(); auto stride = ts.get_size_in_type(field) / len; - assert(stride == field_type_info->get_size_in_memory()); + ASSERT(stride == field_type_info->get_size_in_memory()); field_defs_out.emplace_back( field.name(), decompile_value_array(field.type(), field_type_info, len, stride, @@ -850,8 +850,8 @@ goos::Object decompile_structure(const TypeSpec& type, auto len = field.array_size(); auto total_size = ts.get_size_in_type(field); auto stride = total_size / len; - assert(stride * len == total_size); - assert(stride == align(field_type_info->get_size_in_memory(), + ASSERT(stride * len == total_size); + ASSERT(stride == align(field_type_info->get_size_in_memory(), field_type_info->get_inline_array_stride_alignment())); std::vector array_def = {pretty_print::to_symbol(fmt::format( @@ -872,8 +872,8 @@ goos::Object decompile_structure(const TypeSpec& type, auto len = field.array_size(); auto total_size = ts.get_size_in_type(field); auto stride = total_size / len; - assert(stride * len == total_size); - assert(stride == 4); + ASSERT(stride * len == total_size); + ASSERT(stride == 4); std::vector array_def = {pretty_print::to_symbol( fmt::format("new 'static 'array {} {}", field.type().print(), field.array_size()))}; @@ -920,7 +920,7 @@ goos::Object decompile_structure(const TypeSpec& type, field.name(), actual_type.print())); } else { // then we expect a label. - assert(field_end - field_start == 4); + ASSERT(field_end - field_start == 4); auto& word = obj_words.at(field_start / 4); if (word.kind() == LinkedWord::PTR) { @@ -1020,8 +1020,8 @@ goos::Object decompile_value(const TypeSpec& type, const TypeSystem& ts) { auto as_enum = ts.try_enum_lookup(type); if (as_enum) { - assert((int)bytes.size() == as_enum->get_load_size()); - assert(bytes.size() <= 8); + ASSERT((int)bytes.size() == as_enum->get_load_size()); + ASSERT(bytes.size() <= 8); u64 value = 0; memcpy(&value, bytes.data(), bytes.size()); if (as_enum->is_bitfield()) { @@ -1040,7 +1040,7 @@ goos::Object decompile_value(const TypeSpec& type, auto as_bitfield = dynamic_cast(ts.lookup_type(type)); if (as_bitfield) { if (as_bitfield->get_name() == "sound-name") { - assert(bytes.size() == 16); + ASSERT(bytes.size() == 16); char name[17]; memcpy(name, bytes.data(), 16); name[16] = '\0'; @@ -1051,14 +1051,14 @@ goos::Object decompile_value(const TypeSpec& type, got_zero = true; } else { if (got_zero) { - assert(false); + ASSERT(false); } } } return pretty_print::to_symbol(fmt::format("(static-sound-name \"{}\")", name)); } else { - assert((int)bytes.size() == as_bitfield->get_load_size()); - assert(bytes.size() <= 8); + ASSERT((int)bytes.size() == as_bitfield->get_load_size()); + ASSERT(bytes.size() <= 8); u64 value = 0; memcpy(&value, bytes.data(), bytes.size()); auto defs = decompile_bitfield_from_int(type, ts, value); @@ -1068,12 +1068,12 @@ goos::Object decompile_value(const TypeSpec& type, // try as common integer types: if (ts.tc(TypeSpec("uint32"), type)) { - assert(bytes.size() == 4); + ASSERT(bytes.size() == 4); u32 value; memcpy(&value, bytes.data(), 4); return pretty_print::to_symbol(fmt::format("#x{:x}", u64(value))); } else if (ts.tc(TypeSpec("int32"), type)) { - assert(bytes.size() == 4); + ASSERT(bytes.size() == 4); s32 value; memcpy(&value, bytes.data(), 4); if (value > 100) { @@ -1082,12 +1082,12 @@ goos::Object decompile_value(const TypeSpec& type, return pretty_print::to_symbol(fmt::format("{}", value)); } } else if (ts.tc(TypeSpec("uint16"), type)) { - assert(bytes.size() == 2); + ASSERT(bytes.size() == 2); u16 value; memcpy(&value, bytes.data(), 2); return pretty_print::to_symbol(fmt::format("#x{:x}", u64(value))); } else if (ts.tc(TypeSpec("int16"), type)) { - assert(bytes.size() == 2); + ASSERT(bytes.size() == 2); s16 value; memcpy(&value, bytes.data(), 2); if (value > 100) { @@ -1096,7 +1096,7 @@ goos::Object decompile_value(const TypeSpec& type, return pretty_print::to_symbol(fmt::format("{}", value)); } } else if (ts.tc(TypeSpec("int8"), type)) { - assert(bytes.size() == 1); + ASSERT(bytes.size() == 1); s8 value; memcpy(&value, bytes.data(), 1); if (value > 5) { @@ -1105,7 +1105,7 @@ goos::Object decompile_value(const TypeSpec& type, return pretty_print::to_symbol(fmt::format("{}", value)); } } else if (type == TypeSpec("seconds")) { - assert(bytes.size() == 8); + ASSERT(bytes.size() == 8); s64 value; memcpy(&value, bytes.data(), 8); @@ -1120,12 +1120,12 @@ goos::Object decompile_value(const TypeSpec& type, } return pretty_print::to_symbol(fmt::format("#x{:x}", value)); } else if (ts.tc(TypeSpec("uint64"), type)) { - assert(bytes.size() == 8); + ASSERT(bytes.size() == 8); u64 value; memcpy(&value, bytes.data(), 8); return pretty_print::to_symbol(fmt::format("#x{:x}", value)); } else if (ts.tc(TypeSpec("int64"), type)) { - assert(bytes.size() == 8); + ASSERT(bytes.size() == 8); s64 value; memcpy(&value, bytes.data(), 8); if (value > 100) { @@ -1134,7 +1134,7 @@ goos::Object decompile_value(const TypeSpec& type, return pretty_print::to_symbol(fmt::format("{}", value)); } } else if (type == TypeSpec("meters")) { - assert(bytes.size() == 4); + ASSERT(bytes.size() == 4); float value; memcpy(&value, bytes.data(), 4); double meters = (double)value / METER_LENGTH; @@ -1146,18 +1146,18 @@ goos::Object decompile_value(const TypeSpec& type, return pretty_print::build_list("meters", rep); } } else if (type == TypeSpec("degrees")) { - assert(bytes.size() == 4); + ASSERT(bytes.size() == 4); float value; memcpy(&value, bytes.data(), 4); double degrees = (double)value / DEGREES_LENGTH; return pretty_print::build_list("degrees", pretty_print::float_representation(degrees)); } else if (ts.tc(TypeSpec("float"), type)) { - assert(bytes.size() == 4); + ASSERT(bytes.size() == 4); float value; memcpy(&value, bytes.data(), 4); return pretty_print::float_representation(value); } else if (ts.tc(TypeSpec("uint8"), type)) { - assert(bytes.size() == 1); + ASSERT(bytes.size() == 1); u8 value; memcpy(&value, bytes.data(), 1); return pretty_print::to_symbol(fmt::format("#x{:x}", value)); @@ -1287,7 +1287,7 @@ goos::Object decompile_boxed_array(const DecompilerLabel& label, } elt_bytes.push_back(word.get_byte(j % 4)); } - assert(content_type != TypeSpec("uint128")); + ASSERT(content_type != TypeSpec("uint128")); result.push_back(decompile_value(content_type, elt_bytes, ts)); } return pretty_print::build_list(result); @@ -1441,7 +1441,7 @@ goos::Object decompile_bitfield(const TypeSpec& type, while (elt_bytes.size() < 8) { elt_bytes.push_back(0); } - assert(elt_bytes.size() == 8); + ASSERT(elt_bytes.size() == 8); // read as u64 u64 value = *(u64*)(elt_bytes.data()); @@ -1459,7 +1459,7 @@ std::optional> try_decompile_bitfield_from_int( std::vector result; auto type_info = dynamic_cast(ts.lookup_type(type)); - assert(type_info); + ASSERT(type_info); int start_bit = 0; @@ -1539,8 +1539,8 @@ std::vector decompile_bitfield_enum_from_int(const TypeSpec& type, u64 reconstructed = 0; std::vector result; auto type_info = ts.try_enum_lookup(type.base_type()); - assert(type_info); - assert(type_info->is_bitfield()); + ASSERT(type_info); + ASSERT(type_info->is_bitfield()); std::vector bit_sorted_names; for (auto& field : type_info->entries()) { @@ -1594,8 +1594,8 @@ std::vector decompile_bitfield_enum_from_int(const TypeSpec& type, std::string decompile_int_enum_from_int(const TypeSpec& type, const TypeSystem& ts, u64 value) { auto type_info = ts.try_enum_lookup(type.base_type()); - assert(type_info); - assert(!type_info->is_bitfield()); + ASSERT(type_info); + ASSERT(!type_info->is_bitfield()); std::vector matches; for (auto& field : type_info->entries()) { diff --git a/decompiler/util/goal_data_reader.cpp b/decompiler/util/goal_data_reader.cpp index 728c538bd3..9b216e28d8 100644 --- a/decompiler/util/goal_data_reader.cpp +++ b/decompiler/util/goal_data_reader.cpp @@ -276,6 +276,6 @@ std::string inspect_ref(const Ref& ref) { case decompiler::LinkedWord::TYPE_PTR: return fmt::format("[t'{}]", word.symbol_name()); default: - assert(false); + ASSERT(false); } } \ No newline at end of file diff --git a/decompiler/util/sparticle_decompile.cpp b/decompiler/util/sparticle_decompile.cpp index a43a213538..551eed7854 100644 --- a/decompiler/util/sparticle_decompile.cpp +++ b/decompiler/util/sparticle_decompile.cpp @@ -2,7 +2,7 @@ #include "decompiler/util/data_decompile.h" #include "common/goos/PrettyPrinter.h" #include "common/util/print_float.h" -#include "common/util/assert.h" +#include "common/util/Assert.h" namespace decompiler { // sparticle fields. @@ -203,12 +203,12 @@ goos::Object decompile_sparticle_tex_field_init(const std::vector& w const TypeSystem& ts, const std::string& field_name, const std::string& flag_name) { - assert(words.at(1).kind() == LinkedWord::PLAIN_DATA); - assert(words.at(2).kind() == LinkedWord::PLAIN_DATA); - assert(words.at(2).data == 0); - assert(words.at(3).kind() == LinkedWord::PLAIN_DATA); - assert(words.at(3).data == 0); - assert(flag_name == "plain-v1"); + ASSERT(words.at(1).kind() == LinkedWord::PLAIN_DATA); + ASSERT(words.at(2).kind() == LinkedWord::PLAIN_DATA); + ASSERT(words.at(2).data == 0); + ASSERT(words.at(3).kind() == LinkedWord::PLAIN_DATA); + ASSERT(words.at(3).data == 0); + ASSERT(flag_name == "plain-v1"); auto tex_id_type = TypeSpec("texture-id"); auto tex_id_str = bitfield_defs_print( @@ -218,26 +218,26 @@ goos::Object decompile_sparticle_tex_field_init(const std::vector& w } float word_as_float(const LinkedWord& w) { - assert(w.kind() == LinkedWord::PLAIN_DATA); + ASSERT(w.kind() == LinkedWord::PLAIN_DATA); float v; memcpy(&v, &w.data, 4); return v; } s32 word_as_s32(const LinkedWord& w) { - assert(w.kind() == LinkedWord::PLAIN_DATA); + ASSERT(w.kind() == LinkedWord::PLAIN_DATA); return w.data; } goos::Object decompile_sparticle_func(const std::vector& words, const std::string& field_name, const std::string& flag_name) { - assert(words.at(1).kind() == LinkedWord::SYM_PTR); - assert(words.at(2).kind() == LinkedWord::PLAIN_DATA); - assert(words.at(2).data == 0); - assert(words.at(3).kind() == LinkedWord::PLAIN_DATA); - assert(words.at(3).data == 0); - assert(flag_name == "from-pointer"); + ASSERT(words.at(1).kind() == LinkedWord::SYM_PTR); + ASSERT(words.at(2).kind() == LinkedWord::PLAIN_DATA); + ASSERT(words.at(2).data == 0); + ASSERT(words.at(3).kind() == LinkedWord::PLAIN_DATA); + ASSERT(words.at(3).data == 0); + ASSERT(flag_name == "from-pointer"); return pretty_print::to_symbol( fmt::format("(sp-func {} '{})", field_name, words.at(1).symbol_name())); } @@ -245,21 +245,21 @@ goos::Object decompile_sparticle_func(const std::vector& words, goos::Object decompile_sparticle_end(const std::vector& words, const std::string& field_name, const std::string& flag_name) { - assert(words.at(1).kind() == LinkedWord::PLAIN_DATA); - assert(words.at(1).data == 0); - assert(words.at(2).kind() == LinkedWord::PLAIN_DATA); - assert(words.at(2).data == 0); - assert(words.at(3).kind() == LinkedWord::PLAIN_DATA); - assert(words.at(3).data == 0); - assert(flag_name == "plain-v1"); - assert(field_name == "spt-end"); + ASSERT(words.at(1).kind() == LinkedWord::PLAIN_DATA); + ASSERT(words.at(1).data == 0); + ASSERT(words.at(2).kind() == LinkedWord::PLAIN_DATA); + ASSERT(words.at(2).data == 0); + ASSERT(words.at(3).kind() == LinkedWord::PLAIN_DATA); + ASSERT(words.at(3).data == 0); + ASSERT(flag_name == "plain-v1"); + ASSERT(field_name == "spt-end"); return pretty_print::to_symbol("(sp-end)"); } goos::Object decompile_sparticle_int_with_rand_to_float(const std::vector& words, const std::string& field_name, const std::string& flag_name) { - assert(flag_name == "int-with-rand"); + ASSERT(flag_name == "int-with-rand"); return pretty_print::to_symbol(fmt::format("(sp-rnd-int {} {} {} {})", field_name, word_as_s32(words.at(1)), word_as_s32(words.at(2)), @@ -272,7 +272,7 @@ goos::Object decompile_sparticle_float_with_rand_init(const std::vector& words, goos::Object decompile_sparticle_int_init(const std::vector& words, const std::string& field_name, const std::string& flag_name) { - assert(words.at(1).kind() == LinkedWord::PLAIN_DATA); - assert(words.at(2).kind() == LinkedWord::PLAIN_DATA); - assert(words.at(2).data == 0); - assert(words.at(3).kind() == LinkedWord::PLAIN_DATA); - assert(words.at(3).data == 1); - assert(flag_name == "plain-v1"); + ASSERT(words.at(1).kind() == LinkedWord::PLAIN_DATA); + ASSERT(words.at(2).kind() == LinkedWord::PLAIN_DATA); + ASSERT(words.at(2).data == 0); + ASSERT(words.at(3).kind() == LinkedWord::PLAIN_DATA); + ASSERT(words.at(3).data == 1); + ASSERT(flag_name == "plain-v1"); return pretty_print::to_symbol( fmt::format("(sp-int {} {})", field_name, word_as_s32(words.at(1)))); } @@ -327,7 +327,7 @@ goos::Object decompile_sparticle_int_with_rand_init(const std::vector& words, const std::string& field_name, const std::string& flag_name) { - assert(words.at(1).kind() == LinkedWord::PLAIN_DATA); - assert(words.at(2).kind() == LinkedWord::PLAIN_DATA); - assert(words.at(2).data == 0); - assert(words.at(3).kind() == LinkedWord::PLAIN_DATA); - assert(words.at(3).data == 0); - assert(flag_name == "part-by-id"); + ASSERT(words.at(1).kind() == LinkedWord::PLAIN_DATA); + ASSERT(words.at(2).kind() == LinkedWord::PLAIN_DATA); + ASSERT(words.at(2).data == 0); + ASSERT(words.at(3).kind() == LinkedWord::PLAIN_DATA); + ASSERT(words.at(3).data == 0); + ASSERT(flag_name == "part-by-id"); return pretty_print::to_symbol( fmt::format("(sp-launcher-by-id {} {})", field_name, word_as_s32(words.at(1)))); } @@ -353,12 +353,12 @@ goos::Object decompile_sparticle_flags(const std::vector& words, const TypeSystem& ts, const std::string& field_name, const std::string& flag_name) { - assert(flag_name == "plain-v1"); - assert(field_name == "spt-flags"); - assert(words.at(3).kind() == LinkedWord::PLAIN_DATA); - assert(words.at(3).data == 1); - assert(words.at(2).kind() == LinkedWord::PLAIN_DATA); - assert(words.at(2).data == 0); + ASSERT(flag_name == "plain-v1"); + ASSERT(field_name == "spt-flags"); + ASSERT(words.at(3).kind() == LinkedWord::PLAIN_DATA); + ASSERT(words.at(3).data == 1); + ASSERT(words.at(2).kind() == LinkedWord::PLAIN_DATA); + ASSERT(words.at(2).data == 0); auto flag_def = decompile_bitfield_enum_from_int(TypeSpec("sp-cpuinfo-flag"), ts, word_as_s32(words.at(1))); std::string result = "(sp-cpuinfo-flags"; @@ -373,12 +373,12 @@ goos::Object decompile_sparticle_flags(const std::vector& words, goos::Object decompile_sparticle_from_other(const std::vector& words, const std::string& field_name, const std::string& flag_name) { - assert(words.at(1).kind() == LinkedWord::PLAIN_DATA); - assert(words.at(2).kind() == LinkedWord::PLAIN_DATA); - assert(words.at(2).data == 0); - assert(words.at(3).kind() == LinkedWord::PLAIN_DATA); - assert(words.at(3).data == 1); - assert(flag_name == "copy-from-other-field"); + ASSERT(words.at(1).kind() == LinkedWord::PLAIN_DATA); + ASSERT(words.at(2).kind() == LinkedWord::PLAIN_DATA); + ASSERT(words.at(2).data == 0); + ASSERT(words.at(3).kind() == LinkedWord::PLAIN_DATA); + ASSERT(words.at(3).data == 1); + ASSERT(flag_name == "copy-from-other-field"); return pretty_print::to_symbol( fmt::format("(sp-copy-from-other {} {})", field_name, word_as_s32(words.at(1)))); } @@ -392,7 +392,7 @@ goos::Object decompile_sparticle_float_meters_with_rand_init(const std::vector& /*wor const std::string& field_name, const std::string& flag_name, const goos::Object& original) { - assert(field_name == "spt-sound"); - assert(flag_name == "plain-v2"); + ASSERT(field_name == "spt-sound"); + ASSERT(flag_name == "plain-v2"); return pretty_print::build_list("sp-sound", original); } @@ -455,7 +455,7 @@ goos::Object decompile_sparticle_group_item(const TypeSpec& type, if (!type_info) { throw std::runtime_error(fmt::format("Type {} wasn't a structure type.", type.print())); } - assert(type_info->get_size_in_memory() == 0x1c); + ASSERT(type_info->get_size_in_memory() == 0x1c); // get words for real auto offset_location = label.offset - type_info->get_offset(); @@ -545,7 +545,7 @@ goos::Object decompile_sparticle_field_init(const TypeSpec& type, if (!type_info) { throw std::runtime_error(fmt::format("Type {} wasn't a structure type.", type.print())); } - assert(type_info->get_size_in_memory() == 16); + ASSERT(type_info->get_size_in_memory() == 16); // get words for real auto offset_location = label.offset - type_info->get_offset(); @@ -555,11 +555,11 @@ goos::Object decompile_sparticle_field_init(const TypeSpec& type, words.at(label.target_segment).begin() + (offset_location / 4), words.at(label.target_segment).begin() + (offset_location / 4) + word_count); - assert(obj_words.at(0).kind() == LinkedWord::PLAIN_DATA); + ASSERT(obj_words.at(0).kind() == LinkedWord::PLAIN_DATA); u16 field_id = obj_words.at(0).data & 0xffff; u16 flags = obj_words.at(0).data >> 16; - assert(field_id <= (u32)FieldId::SPT_END); + ASSERT(field_id <= (u32)FieldId::SPT_END); auto field_name = decompile_int_enum_from_int(TypeSpec("sp-field-id"), ts, field_id); const auto& field_info = field_kinds[field_id]; if (!field_info.known) { @@ -617,7 +617,7 @@ goos::Object decompile_sparticle_field_init(const TypeSpec& type, result = decompile_sparticle_rot_x(obj_words, field_name, flag_name); break; default: - assert(false); + ASSERT(false); } } @@ -625,13 +625,13 @@ goos::Object decompile_sparticle_field_init(const TypeSpec& type, return result; } -goos::Object decompile_sparticle_userdata_assert(const std::vector& words, +goos::Object decompile_sparticle_userdata_ASSERT(const std::vector& words, const std::string& field_name, const std::string& flag_name) { if (flag_name == "int-with-rand" || flag_name == "float-with-rand") { return decompile_sparticle_float_with_rand_init(words, field_name, flag_name); } else { - assert(false); + ASSERT(false); } } @@ -640,7 +640,7 @@ goos::Object decompile_sparticle_field_init(const DefpartElement::StaticInfo::Pa auto field_id = field.field_id; auto flags = field.flags; - assert(field_id <= (u32)FieldId::SPT_END); + ASSERT(field_id <= (u32)FieldId::SPT_END); auto field_name = decompile_int_enum_from_int(TypeSpec("sp-field-id"), ts, field_id); const auto& field_info = field_kinds[field_id]; if (!field_info.known) { @@ -686,13 +686,13 @@ goos::Object decompile_sparticle_field_init(const DefpartElement::StaticInfo::Pa result = decompile_sparticle_launcher_by_id(field.data, field_name, flag_name); break; case FieldKind::NO_FANCY_DECOMP: - assert(false); + ASSERT(false); break; case FieldKind::FUNCTION: result = decompile_sparticle_func(field.data, field_name, flag_name); break; case FieldKind::USERDATA: - result = decompile_sparticle_userdata_assert(field.data, field_name, flag_name); + result = decompile_sparticle_userdata_ASSERT(field.data, field_name, flag_name); break; case FieldKind::ROT_X: result = decompile_sparticle_rot_x(field.data, field_name, flag_name); @@ -702,7 +702,7 @@ goos::Object decompile_sparticle_field_init(const DefpartElement::StaticInfo::Pa decompile_sparticle_sound_spec(field.data, field_name, flag_name, field.sound_spec); break; default: - assert(false); + ASSERT(false); } } diff --git a/game/discord.cpp b/game/discord.cpp index d6ee7154e8..908f12f7ef 100644 --- a/game/discord.cpp +++ b/game/discord.cpp @@ -55,7 +55,11 @@ const char* jak1_get_full_level_name(char* level_name) { level_name = "maincave"; } - return jak1_level_names.at(level_name).c_str(); + const auto& nice_name = jak1_level_names.find(level_name); + if (nice_name != jak1_level_names.end()) { + return nice_name->second.c_str(); + } + return "Unknown"; }; void handleDiscordReady(const DiscordUser* user) { diff --git a/game/graphics/opengl_renderer/BucketRenderer.cpp b/game/graphics/opengl_renderer/BucketRenderer.cpp index 6de77c719b..25d333d328 100644 --- a/game/graphics/opengl_renderer/BucketRenderer.cpp +++ b/game/graphics/opengl_renderer/BucketRenderer.cpp @@ -22,7 +22,7 @@ void EmptyBucketRenderer::render(DmaFollower& dma, // NEXT auto first_tag = dma.current_tag(); dma.read_and_advance(); - assert(first_tag.kind == DmaTag::Kind::NEXT && first_tag.qwc == 0); + ASSERT(first_tag.kind == DmaTag::Kind::NEXT && first_tag.qwc == 0); // CALL auto call_tag = dma.current_tag(); @@ -30,22 +30,22 @@ void EmptyBucketRenderer::render(DmaFollower& dma, if (!(call_tag.kind == DmaTag::Kind::CALL && call_tag.qwc == 0)) { fmt::print("Bucket renderer {} ({}) was supposed to be empty, but wasn't\n", m_my_id, m_name); } - assert(call_tag.kind == DmaTag::Kind::CALL && call_tag.qwc == 0); + ASSERT(call_tag.kind == DmaTag::Kind::CALL && call_tag.qwc == 0); // in the default reg buffer: - assert(dma.current_tag_offset() == render_state->default_regs_buffer); + ASSERT(dma.current_tag_offset() == render_state->default_regs_buffer); dma.read_and_advance(); - assert(dma.current_tag().kind == DmaTag::Kind::RET); + ASSERT(dma.current_tag().kind == DmaTag::Kind::RET); dma.read_and_advance(); // NEXT to next buffer auto to_next_buffer = dma.current_tag(); - assert(to_next_buffer.kind == DmaTag::Kind::NEXT); - assert(to_next_buffer.qwc == 0); + ASSERT(to_next_buffer.kind == DmaTag::Kind::NEXT); + ASSERT(to_next_buffer.qwc == 0); dma.read_and_advance(); // and we should now be in the next bucket! - assert(dma.current_tag_offset() == render_state->next_bucket); + ASSERT(dma.current_tag_offset() == render_state->next_bucket); } SkipRenderer::SkipRenderer(const std::string& name, BucketId my_id) : BucketRenderer(name, my_id) {} diff --git a/game/graphics/opengl_renderer/DirectRenderer.cpp b/game/graphics/opengl_renderer/DirectRenderer.cpp index 120898f0c4..20e46fa8b4 100644 --- a/game/graphics/opengl_renderer/DirectRenderer.cpp +++ b/game/graphics/opengl_renderer/DirectRenderer.cpp @@ -4,7 +4,7 @@ #include "third-party/fmt/core.h" #include "game/graphics/pipelines/opengl.h" #include "third-party/imgui/imgui.h" -#include "common/util/assert.h" +#include "common/util/Assert.h" DirectRenderer::DirectRenderer(const std::string& name, BucketId my_id, int batch_size, Mode mode) : BucketRenderer(name, my_id), m_prim_buffer(batch_size), m_mode(mode) { @@ -79,7 +79,7 @@ void DirectRenderer::render(DmaFollower& dma, if (dma.current_tag_offset() == render_state->default_regs_buffer) { // reset_state(); dma.read_and_advance(); // cnt - assert(dma.current_tag().kind == DmaTag::Kind::RET); + ASSERT(dma.current_tag().kind == DmaTag::Kind::RET); dma.read_and_advance(); // ret } } @@ -206,8 +206,8 @@ void DirectRenderer::flush_pending(SharedRenderState* render_state, ScopedProfil if (!m_prim_gl_state.texture_enable) { render_state->shaders[ShaderId::DIRECT_BASIC].activate(); } else { - // assert(m_global_texture_state.tcc); - assert(m_prim_gl_state.texture_enable); + // ASSERT(m_global_texture_state.tcc); + ASSERT(m_prim_gl_state.texture_enable); render_state->shaders[ShaderId::SPRITE_CPU].activate(); } @@ -256,13 +256,13 @@ void DirectRenderer::update_gl_prim(SharedRenderState* render_state) { break; default: fmt::print("unknown alpha test: {}\n", (int)m_test_state.alpha_test); - assert(false); + ASSERT(false); } } if (m_mode == Mode::SPRITE_CPU) { render_state->shaders[ShaderId::SPRITE_CPU].activate(); } else if (m_mode == Mode::SKY) { - assert(false); + ASSERT(false); } else { render_state->shaders[ShaderId::DIRECT_BASIC_TEXTURED].activate(); glUniform1f(glGetUniformLocation(render_state->shaders[ShaderId::DIRECT_BASIC_TEXTURED].id(), @@ -279,19 +279,19 @@ void DirectRenderer::update_gl_prim(SharedRenderState* render_state) { } } if (state.fogging_enable) { - // assert(false); + // ASSERT(false); } if (state.aa_enable) { - assert(false); + ASSERT(false); } if (state.use_uv) { - assert(false); + ASSERT(false); } if (state.ctxt) { - assert(false); + ASSERT(false); } if (state.fix) { - assert(false); + ASSERT(false); } } @@ -317,7 +317,7 @@ void DirectRenderer::update_gl_texture(SharedRenderState* render_state, int unit tex = render_state->texture_pool->get_random_texture(); } } - assert(tex); + ASSERT(tex); // first: do we need to load the texture? if (!tex->on_gpu) { @@ -368,7 +368,7 @@ void DirectRenderer::update_gl_blend() { // (Cs - 0) * As + Cd // Cs * As + (1) * Cd // s, d - assert(state.fix == 0); + ASSERT(state.fix == 0); glBlendFunc(GL_SRC_ALPHA, GL_ONE); glBlendEquation(GL_FUNC_ADD); } else if (state.a == GsAlpha::BlendMode::ZERO_OR_FIXED && @@ -391,7 +391,7 @@ void DirectRenderer::update_gl_blend() { // unsupported blend: a 0 b 2 c 2 d 1 lg::error("unsupported blend: a {} b {} c {} d {}", (int)state.a, (int)state.b, (int)state.c, (int)state.d); - // assert(false); + // ASSERT(false); } } } @@ -415,15 +415,15 @@ void DirectRenderer::update_gl_test() { glDepthFunc(GL_GREATER); break; default: - assert(false); + ASSERT(false); } } else { // you aren't supposed to turn off z test enable, the GS had some bugs - assert(false); + ASSERT(false); } if (state.date) { - assert(false); + ASSERT(false); } if (state.depth_writes) { @@ -455,7 +455,7 @@ u32 get_direct_qwc_or_nop(const VifCode& code) { return code.immediate; } default: - assert(false); + ASSERT(false); } } } // namespace @@ -476,7 +476,7 @@ void DirectRenderer::render_vif(u32 vif0, u32 gif_qwc = get_direct_qwc_or_nop(VifCode(vif0)); if (gif_qwc) { // we got a direct. expect the second thing to be a nop/similar. - assert(get_direct_qwc_or_nop(VifCode(vif1)) == 0); + ASSERT(get_direct_qwc_or_nop(VifCode(vif1)) == 0); } else { gif_qwc = get_direct_qwc_or_nop(VifCode(vif1)); } @@ -489,7 +489,7 @@ void DirectRenderer::render_vif(u32 vif0, u32 vif; memcpy(&vif, data + offset_into_data, 4); offset_into_data += 4; - assert(get_direct_qwc_or_nop(VifCode(vif)) == 0); + ASSERT(get_direct_qwc_or_nop(VifCode(vif)) == 0); } else { // aligned! do a gif transfer! render_gif(data + offset_into_data, gif_qwc * 16, render_state, prof); @@ -513,7 +513,7 @@ void DirectRenderer::render_gif(const u8* data, SharedRenderState* render_state, ScopedProfilerNode& prof) { if (size != UINT32_MAX) { - assert(size >= 16); + ASSERT(size >= 16); } bool eop = false; @@ -521,7 +521,7 @@ void DirectRenderer::render_gif(const u8* data, u32 offset = 0; while (!eop) { if (size != UINT32_MAX) { - assert(offset < size); + ASSERT(offset < size); } GifTag tag(data + offset); offset += 16; @@ -564,7 +564,7 @@ void DirectRenderer::render_gif(const u8* data, default: fmt::print("Register {} is not supported in packed mode yet\n", reg_descriptor_name(reg_desc[reg])); - assert(false); + ASSERT(false); } offset += 16; // PACKED = quadwords } @@ -588,20 +588,20 @@ void DirectRenderer::render_gif(const u8* data, default: fmt::print("Register {} is not supported in reglist mode yet\n", reg_descriptor_name(reg_desc[reg])); - assert(false); + ASSERT(false); } offset += 8; // PACKED = quadwords } } } else { - assert(false); // format not packed or reglist. + ASSERT(false); // format not packed or reglist. } eop = tag.eop(); } if (size != UINT32_MAX) { - assert((offset + 15) / 16 == size / 16); + ASSERT((offset + 15) / 16 == size / 16); } // fmt::print("{}\n", GifTag(data).print()); @@ -662,7 +662,7 @@ void DirectRenderer::handle_ad(const u8* data, break; default: fmt::print("Address {} is not supported\n", register_address_name(addr)); - assert(false); + ASSERT(false); } } @@ -671,7 +671,7 @@ void DirectRenderer::handle_tex1_1(u64 val, ScopedProfilerNode& prof) { GsTex1 reg(val); // for now, we aren't going to handle mipmapping. I don't think it's used with direct. - // assert(reg.mxl() == 0); + // ASSERT(reg.mxl() == 0); // if that's true, we can ignore LCM, MTBA, L, K bool want_tex_filt = reg.mmag(); @@ -692,7 +692,7 @@ void DirectRenderer::handle_tex1_1(u64 val, } // MMAG/MMIN specify texture filtering. For now, assume always linear - // assert(reg.mmag() == true); + // ASSERT(reg.mmag() == true); // if (!(reg.mmin() == 1 || reg.mmin() == 4)) { // with mipmap off, both of these are linear // // lg::error("unsupported mmin"); // } @@ -737,7 +737,7 @@ void DirectRenderer::handle_tex0_1(u64 val, // th: assume they got it right // MERC hack - // assert(reg.tfx() == GsTex0::TextureFunction::MODULATE); + // ASSERT(reg.tfx() == GsTex0::TextureFunction::MODULATE); // cbp: assume they got it right // cpsm: assume they got it right @@ -749,10 +749,10 @@ void DirectRenderer::handle_texa(u64 val) { // rgba16 isn't used so this doesn't matter? // but they use sane defaults anyway - assert(reg.ta0() == 0); - assert(reg.ta1() == 0x80); // note: check rgba16_to_rgba32 if this changes. + ASSERT(reg.ta0() == 0); + ASSERT(reg.ta1() == 0x80); // note: check rgba16_to_rgba32 if this changes. - assert(reg.aem() == false); + ASSERT(reg.aem() == false); } void DirectRenderer::handle_st_packed(const u8* data) { @@ -791,11 +791,11 @@ void DirectRenderer::handle_zbuf1(u64 val, // note: we can basically ignore this. There's a single z buffer that's always configured the same // way - 24-bit, at offset 448. GsZbuf x(val); - assert(x.psm() == TextureFormat::PSMZ24); - assert(x.zbp() == 448); + ASSERT(x.psm() == TextureFormat::PSMZ24); + ASSERT(x.zbp() == 448); bool write = !x.zmsk(); - // assert(write); + // ASSERT(write); if (write != m_test_state.depth_writes) { m_stats.flush_from_zbuf++; @@ -811,9 +811,9 @@ void DirectRenderer::handle_test1(u64 val, ScopedProfilerNode& prof) { GsTest reg(val); if (reg.alpha_test_enable()) { - // assert(reg.alpha_test() == GsTest::AlphaTest::ALWAYS); + // ASSERT(reg.alpha_test() == GsTest::AlphaTest::ALWAYS); } - assert(!reg.date()); + ASSERT(!reg.date()); if (m_test_state.current_register != reg) { m_stats.flush_from_test++; flush_pending(render_state, prof); @@ -836,7 +836,7 @@ void DirectRenderer::handle_alpha1(u64 val, } void DirectRenderer::handle_pabe(u64 val) { - assert(val == 0); // not really sure how to handle this yet. + ASSERT(val == 0); // not really sure how to handle this yet. } void DirectRenderer::handle_clamp1(u64 val, @@ -844,7 +844,7 @@ void DirectRenderer::handle_clamp1(u64 val, ScopedProfilerNode& prof) { if (!(val == 0b101 || val == 0 || val == 1 || val == 0b100)) { // fmt::print("clamp: 0x{:x}\n", val); - // assert(false); + // ASSERT(false); } if (current_texture_state()->m_clamp_state.current_register != val) { @@ -884,7 +884,7 @@ void DirectRenderer::handle_prim(u64 val, m_prim_building.building_idx = 0; } else { if (m_prim_building.building_idx > 0) { - assert(false); // shouldn't leave any half-finished prims + ASSERT(false); // shouldn't leave any half-finished prims } } // need to flush any in progress prims to the buffer. @@ -903,7 +903,7 @@ void DirectRenderer::handle_prim(u64 val, } void DirectRenderer::handle_rgbaq(u64 val) { - assert((val >> 32) == 0); // q = 0 + ASSERT((val >> 32) == 0); // q = 0 memcpy(m_prim_building.rgba_reg.data(), &val, 4); } @@ -914,7 +914,7 @@ void DirectRenderer::handle_xyzf2_common(u32 x, SharedRenderState* render_state, ScopedProfilerNode& prof, bool advance) { - assert(z < (1 << 24)); + ASSERT(z < (1 << 24)); (void)f; // TODO: do something with this. if (m_prim_buffer.is_full()) { // fmt::print("flush due to fill {} {}\n", m_prim_buffer.vert_count, m_prim_buffer.max_verts); @@ -943,7 +943,7 @@ void DirectRenderer::handle_xyzf2_common(u32 x, if (m_prim_gl_state.gouraud_enable) { // I'm not really sure what the GS does here. - assert(false); + ASSERT(false); } auto& corner3_rgba = corner2_rgba; auto& corner4_rgba = corner2_rgba; @@ -1035,7 +1035,7 @@ void DirectRenderer::handle_xyzf2_common(u32 x, } break; default: fmt::print("prim type {} is unsupported.\n", (int)m_prim_building.kind); - assert(false); + ASSERT(false); } current_texture_state()->used = true; diff --git a/game/graphics/opengl_renderer/MercProgram.cpp b/game/graphics/opengl_renderer/MercProgram.cpp index 883547f768..2e09fda282 100644 --- a/game/graphics/opengl_renderer/MercProgram.cpp +++ b/game/graphics/opengl_renderer/MercProgram.cpp @@ -24,7 +24,7 @@ u16 MercRenderer::xtop() { } void MercRenderer::lq_buffer(Mask mask, Vf& dest, u16 addr) { - assert(addr * 16 < sizeof(m_buffer.data)); + ASSERT(addr * 16 < sizeof(m_buffer.data)); for (int i = 0; i < 4; i++) { if ((u64)mask & (1 << i)) { memcpy(dest.data + i, m_buffer.data + addr * 16 + i * 4, 4); @@ -35,7 +35,7 @@ void MercRenderer::lq_buffer(Mask mask, Vf& dest, u16 addr) { template REALLY_INLINE void MercRenderer::lq_buffer_xyzw(Vf& dest, u16 addr) { if constexpr (DEBUG) { - assert(addr * 16 < sizeof(m_buffer.data)); + ASSERT(addr * 16 < sizeof(m_buffer.data)); } copy_vector(dest.data, m_buffer.data + addr * 16); } @@ -43,7 +43,7 @@ REALLY_INLINE void MercRenderer::lq_buffer_xyzw(Vf& dest, u16 addr) { template REALLY_INLINE void MercRenderer::lq_buffer_xyz(Vf& dest, u16 addr) { if constexpr (DEBUG) { - assert(addr * 16 < sizeof(m_buffer.data)); + ASSERT(addr * 16 < sizeof(m_buffer.data)); } auto reg = _mm_load_ps(dest.data); auto mem = _mm_load_ps((const float*)(m_buffer.data + addr * 16)); @@ -53,13 +53,13 @@ REALLY_INLINE void MercRenderer::lq_buffer_xyz(Vf& dest, u16 addr) { template REALLY_INLINE void MercRenderer::sq_buffer_xyzw(const Vf& src, u16 addr) { if constexpr (DEBUG) { - assert(addr * 16 < sizeof(m_buffer.data)); + ASSERT(addr * 16 < sizeof(m_buffer.data)); } copy_vector(m_buffer.data + addr * 16, src.data); } void MercRenderer::isw_buffer(Mask mask, u16 val, u16 addr) { - assert(addr * 16 < sizeof(m_buffer.data)); + ASSERT(addr * 16 < sizeof(m_buffer.data)); u32 val32 = val; int offset; switch (mask) { @@ -76,14 +76,14 @@ void MercRenderer::isw_buffer(Mask mask, u16 val, u16 addr) { offset = 12; break; default: - assert(false); + ASSERT(false); } memcpy(m_buffer.data + addr * 16 + offset, &val32, 4); } void MercRenderer::ilw_buffer(Mask mask, u16& dest, u16 addr) { // fmt::print("addr is {}\n", addr); - assert(addr * 16 < sizeof(m_buffer.data)); + ASSERT(addr * 16 < sizeof(m_buffer.data)); int offset; switch (mask) { case Mask::x: @@ -99,7 +99,7 @@ void MercRenderer::ilw_buffer(Mask mask, u16& dest, u16 addr) { offset = 12; break; default: - assert(false); + ASSERT(false); } memcpy(&dest, m_buffer.data + addr * 16 + offset, 2); } @@ -123,7 +123,7 @@ void MercRenderer::mscal_impl(int enter_address, case 35: goto ENTER_35; default: - assert(false); + ASSERT(false); } ENTER_0: // lq.xyzw vf01, 7(vi00) | nop @@ -1195,7 +1195,7 @@ void MercRenderer::mscal_impl(int enter_address, case 0x243: goto JUMP_243; default: -assert(false); +ASSERT(false); } L29: // lqi.xyzw vf10, vi01 | mulax.xyzw ACC, vf01, vf11 @@ -3146,7 +3146,7 @@ assert(false); goto JUMP_539; default: fmt::print("bad jump to {:x}\n", vu.vi08); - assert(false); + ASSERT(false); } L94: // 3072.0 | mulax.xyzw ACC, vf01, vf11 :i diff --git a/game/graphics/opengl_renderer/MercRenderer.cpp b/game/graphics/opengl_renderer/MercRenderer.cpp index 8cc0395f33..26a58fae4c 100644 --- a/game/graphics/opengl_renderer/MercRenderer.cpp +++ b/game/graphics/opengl_renderer/MercRenderer.cpp @@ -23,21 +23,21 @@ void MercRenderer::render(DmaFollower& dma, // process the first tag. this is just jumping to the merc-specific dma. auto data0 = dma.read_and_advance(); - assert(data0.vif1() == 0); - assert(data0.vif0() == 0); - assert(data0.size_bytes == 0); + ASSERT(data0.vif1() == 0); + ASSERT(data0.vif0() == 0); + ASSERT(data0.size_bytes == 0); if (dma.current_tag().kind == DmaTag::Kind::CALL) { // renderer didn't run, let's just get out of here. for (int i = 0; i < 4; i++) { dma.read_and_advance(); } - assert(dma.current_tag_offset() == render_state->next_bucket); + ASSERT(dma.current_tag_offset() == render_state->next_bucket); return; } m_stats.had_data = true; - assert(data0.size_bytes == 0); - assert(data0.vif0() == 0); - assert(data0.vif1() == 0); + ASSERT(data0.size_bytes == 0); + ASSERT(data0.vif0() == 0); + ASSERT(data0.vif1() == 0); // if we reach here, there's stuff to draw handle_setup(dma, render_state, prof); @@ -46,7 +46,7 @@ void MercRenderer::render(DmaFollower& dma, while (dma.current_tag_offset() != render_state->next_bucket) { handle_merc_chain(dma, render_state, prof); } - assert(dma.current_tag_offset() == render_state->next_bucket); + ASSERT(dma.current_tag_offset() == render_state->next_bucket); m_direct.flush_pending(render_state, prof); } @@ -56,35 +56,35 @@ bool tag_is_nothing_next(const DmaFollower& dma) { } void MercRenderer::unpack32(const VifCodeUnpack& up, const u8* data, u32 imm) { - assert(!up.is_unsigned); + ASSERT(!up.is_unsigned); u32 addr = up.addr_qw; - assert(imm != 0); - assert(!m_vif.stmod); + ASSERT(imm != 0); + ASSERT(!m_vif.stmod); if (up.use_tops_flag) { addr += xitop(); } u32 start_in_buff = (addr)*16; u32 end_in_buff = start_in_buff + imm * 16; - assert(start_in_buff < sizeof(m_buffer.data)); - assert(end_in_buff <= sizeof(m_buffer.data)); + ASSERT(start_in_buff < sizeof(m_buffer.data)); + ASSERT(end_in_buff <= sizeof(m_buffer.data)); memcpy(m_buffer.data + start_in_buff, data, imm * 16); } void MercRenderer::unpack8(const VifCodeUnpack& up, const u8* data, u32 imm) { - // assert(m_vif.stmod); + // ASSERT(m_vif.stmod); - assert(up.is_unsigned); + ASSERT(up.is_unsigned); u32 addr = up.addr_qw; if (up.use_tops_flag) { addr += xitop(); } - assert(imm != 0); + ASSERT(imm != 0); u32 start_in_buff = (addr)*16; u32 end_in_buff = start_in_buff + imm * 16; - assert(start_in_buff < sizeof(m_buffer.data)); - assert(end_in_buff <= sizeof(m_buffer.data)); + ASSERT(start_in_buff < sizeof(m_buffer.data)); + ASSERT(end_in_buff <= sizeof(m_buffer.data)); u8* out_ptr = m_buffer.data + start_in_buff; @@ -130,7 +130,7 @@ void MercRenderer::handle_merc_chain(DmaFollower& dma, // fmt::print("DMA: {}\n", dma.current_tag().print()); while (tag_is_nothing_next(dma)) { auto nothing = dma.read_and_advance(); - assert(nothing.size_bytes == 0); + ASSERT(nothing.size_bytes == 0); } if (dma.current_tag().kind == DmaTag::Kind::CALL) { for (int i = 0; i < 4; i++) { @@ -141,13 +141,13 @@ void MercRenderer::handle_merc_chain(DmaFollower& dma, auto init = dma.read_and_advance(); - assert(init.vifcode0().kind == VifCode::Kind::STROW); - assert(init.size_bytes == 16); + ASSERT(init.vifcode0().kind == VifCode::Kind::STROW); + ASSERT(init.size_bytes == 16); m_vif.row[0] = init.vif1(); memcpy(m_vif.row + 1, init.data, 12); u32 extra; memcpy(&extra, init.data + 12, 4); - assert(extra == 0); + ASSERT(extra == 0); DmaTransfer next; bool setting_up = true; @@ -163,11 +163,11 @@ void MercRenderer::handle_merc_chain(DmaFollower& dma, case VifCode::Kind::FLUSHE: break; case VifCode::Kind::STMOD: - assert(vif0.immediate == 0 || vif0.immediate == 1); + ASSERT(vif0.immediate == 0 || vif0.immediate == 1); m_vif.stmod = vif0.immediate; break; default: - assert(false); + ASSERT(false); } auto vif1 = next.vifcode1(); @@ -189,23 +189,23 @@ void MercRenderer::handle_merc_chain(DmaFollower& dma, } break; case VifCode::Kind::MSCAL: mscal_addr = vif1.immediate; - assert(next.size_bytes == 0); + ASSERT(next.size_bytes == 0); setting_up = false; break; default: - assert(false); + ASSERT(false); } - assert(offset_in_data <= next.size_bytes); + ASSERT(offset_in_data <= next.size_bytes); if (offset_in_data < next.size_bytes) { - assert((offset_in_data % 4) == 0); + ASSERT((offset_in_data % 4) == 0); u32 leftover = next.size_bytes - offset_in_data; if (leftover < 16) { for (u32 i = 0; i < leftover; i++) { - assert(next.data[offset_in_data + i] == 0); + ASSERT(next.data[offset_in_data + i] == 0); } } else { - assert(false); + ASSERT(false); } } } @@ -239,7 +239,7 @@ void MercRenderer::handle_merc_chain(DmaFollower& dma, break; default: fmt::print("unknown mscal: {}\n", mscal_addr); - assert(false); + ASSERT(false); } // while (true) { @@ -248,7 +248,7 @@ void MercRenderer::handle_merc_chain(DmaFollower& dma, // // } else { // fmt::print("{} : {} {}\n", next.size_bytes, next.vifcode0().print(), - // next.vifcode1().print()); assert(false); + // next.vifcode1().print()); ASSERT(false); // } // } } @@ -262,7 +262,7 @@ void MercRenderer::handle_setup(DmaFollower& dma, auto first = dma.read_and_advance(); // 10 quadword setup packet - assert(first.size_bytes == 10 * 16); + ASSERT(first.size_bytes == 10 * 16); // m_stats.str += fmt::format("Setup 0: {} {} {}", first.size_bytes / 16, // first.vifcode0().print(), first.vifcode1().print()); @@ -271,12 +271,12 @@ void MercRenderer::handle_setup(DmaFollower& dma, auto vif0 = first.vifcode0(); auto vif1 = first.vifcode1(); // STCYCL 4, 4 - assert(vif0.kind == VifCode::Kind::STCYCL); + ASSERT(vif0.kind == VifCode::Kind::STCYCL); auto vif0_st = VifCodeStcycl(vif0); - assert(vif0_st.cl == 4 && vif0_st.wl == 4); + ASSERT(vif0_st.cl == 4 && vif0_st.wl == 4); // STMOD - assert(vif1.kind == VifCode::Kind::STMOD); - assert(vif1.immediate == 0); + ASSERT(vif1.kind == VifCode::Kind::STMOD); + ASSERT(vif1.immediate == 0); } // 1 qw with 4 vifcodes. @@ -284,19 +284,19 @@ void MercRenderer::handle_setup(DmaFollower& dma, memcpy(vifcode_data, first.data, 16); { auto vif0 = VifCode(vifcode_data[0]); - assert(vif0.kind == VifCode::Kind::BASE); - assert(vif0.immediate == MercDataMemory::BUFFER_BASE); + ASSERT(vif0.kind == VifCode::Kind::BASE); + ASSERT(vif0.immediate == MercDataMemory::BUFFER_BASE); auto vif1 = VifCode(vifcode_data[1]); - assert(vif1.kind == VifCode::Kind::OFFSET); - assert((s16)vif1.immediate == MercDataMemory::BUFFER_OFFSET); + ASSERT(vif1.kind == VifCode::Kind::OFFSET); + ASSERT((s16)vif1.immediate == MercDataMemory::BUFFER_OFFSET); auto vif2 = VifCode(vifcode_data[2]); - assert(vif2.kind == VifCode::Kind::NOP); + ASSERT(vif2.kind == VifCode::Kind::NOP); auto vif3 = VifCode(vifcode_data[3]); - assert(vif3.kind == VifCode::Kind::UNPACK_V4_32); + ASSERT(vif3.kind == VifCode::Kind::UNPACK_V4_32); VifCodeUnpack up(vif3); - assert(up.addr_qw == MercDataMemory::LOW_MEMORY); - assert(!up.use_tops_flag); - assert(vif3.num == 8); + ASSERT(up.addr_qw == MercDataMemory::LOW_MEMORY); + ASSERT(!up.use_tops_flag); + ASSERT(vif3.num == 8); } // 8 qw's of low memory data @@ -307,12 +307,12 @@ void MercRenderer::handle_setup(DmaFollower& dma, u32 vifcode_final_data[4]; memcpy(vifcode_final_data, first.data + 16 + sizeof(LowMemory), 16); { - assert(VifCode(vifcode_final_data[0]).kind == VifCode::Kind::FLUSHE); - assert(vifcode_final_data[1] == 0); - assert(vifcode_final_data[2] == 0); + ASSERT(VifCode(vifcode_final_data[0]).kind == VifCode::Kind::FLUSHE); + ASSERT(vifcode_final_data[1] == 0); + ASSERT(vifcode_final_data[2] == 0); VifCode mscal(vifcode_final_data[3]); - assert(mscal.kind == VifCode::Kind::MSCAL); - assert(mscal.immediate == 0); + ASSERT(mscal.kind == VifCode::Kind::MSCAL); + ASSERT(mscal.immediate == 0); } // copy low memory into the VU "emulation" RAM. @@ -320,12 +320,12 @@ void MercRenderer::handle_setup(DmaFollower& dma, mscal(0, render_state, prof); auto second = dma.read_and_advance(); - assert(second.size_bytes == 32); // setting up test register. + ASSERT(second.size_bytes == 32); // setting up test register. m_direct.render_gif(second.data, 32, render_state, prof); auto nothing = dma.read_and_advance(); - assert(nothing.size_bytes == 0); - assert(nothing.vif0() == 0); - assert(nothing.vif1() == 0); + ASSERT(nothing.size_bytes == 0); + ASSERT(nothing.vif0() == 0); + ASSERT(nothing.vif1() == 0); } void MercRenderer::draw_debug_window() { diff --git a/game/graphics/opengl_renderer/MercRenderer.h b/game/graphics/opengl_renderer/MercRenderer.h index 07a0d6f095..a58bf65720 100644 --- a/game/graphics/opengl_renderer/MercRenderer.h +++ b/game/graphics/opengl_renderer/MercRenderer.h @@ -472,7 +472,7 @@ class MercRenderer : public BucketRenderer { // } // sketchy... // qw &= 1023; - assert(qw * 16 < sizeof(m_buffer.data)); + ASSERT(qw * 16 < sizeof(m_buffer.data)); for (int i = 0; i < 4; i++) { if ((u64)mask & (1 << i)) { memcpy(m_buffer.data + qw * 16 + i * 4, data.data + i, 4); diff --git a/game/graphics/opengl_renderer/OpenGLRenderer.cpp b/game/graphics/opengl_renderer/OpenGLRenderer.cpp index 7e52fc13b3..3535b7af5e 100644 --- a/game/graphics/opengl_renderer/OpenGLRenderer.cpp +++ b/game/graphics/opengl_renderer/OpenGLRenderer.cpp @@ -326,22 +326,22 @@ void OpenGLRenderer::dispatch_buckets(DmaFollower dma, ScopedProfilerNode& prof) // Find the default regs buffer auto initial_call_tag = dma.current_tag(); - assert(initial_call_tag.kind == DmaTag::Kind::CALL); + ASSERT(initial_call_tag.kind == DmaTag::Kind::CALL); auto initial_call_default_regs = dma.read_and_advance(); - assert(initial_call_default_regs.transferred_tag == 0); // should be a nop. + ASSERT(initial_call_default_regs.transferred_tag == 0); // should be a nop. m_render_state.default_regs_buffer = dma.current_tag_offset(); auto default_regs_tag = dma.current_tag(); - assert(default_regs_tag.kind == DmaTag::Kind::CNT); - assert(default_regs_tag.qwc == 10); + ASSERT(default_regs_tag.kind == DmaTag::Kind::CNT); + ASSERT(default_regs_tag.qwc == 10); // TODO verify data in here. dma.read_and_advance(); auto default_ret_tag = dma.current_tag(); - assert(default_ret_tag.qwc == 0); - assert(default_ret_tag.kind == DmaTag::Kind::RET); + ASSERT(default_ret_tag.qwc == 0); + ASSERT(default_ret_tag.kind == DmaTag::Kind::RET); dma.read_and_advance(); // now we should point to the first bucket! - assert(dma.current_tag_offset() == m_render_state.next_bucket); + ASSERT(dma.current_tag_offset() == m_render_state.next_bucket); m_render_state.next_bucket += 16; // loop over the buckets! @@ -353,7 +353,7 @@ void OpenGLRenderer::dispatch_buckets(DmaFollower dma, ScopedProfilerNode& prof) renderer->render(dma, &m_render_state, bucket_prof); // lg::info("Render: {} end", g_current_render); // should have ended at the start of the next chain - assert(dma.current_tag_offset() == m_render_state.next_bucket); + ASSERT(dma.current_tag_offset() == m_render_state.next_bucket); m_render_state.next_bucket += 16; if (!m_render_state.dump_playback) { diff --git a/game/graphics/opengl_renderer/Profiler.cpp b/game/graphics/opengl_renderer/Profiler.cpp index f2d9ff7968..85655f471c 100644 --- a/game/graphics/opengl_renderer/Profiler.cpp +++ b/game/graphics/opengl_renderer/Profiler.cpp @@ -54,7 +54,7 @@ void ProfilerNode::sort(ProfilerSort mode) { case ProfilerSort::TRIANGLES: return a.m_stats.triangles > b.m_stats.triangles; default: - assert(false); + ASSERT(false); } }); for (auto& child : m_children) { diff --git a/game/graphics/opengl_renderer/Shader.cpp b/game/graphics/opengl_renderer/Shader.cpp index 375a40674c..e1951ab8cc 100644 --- a/game/graphics/opengl_renderer/Shader.cpp +++ b/game/graphics/opengl_renderer/Shader.cpp @@ -2,7 +2,7 @@ #include "common/util/FileUtil.h" #include "common/log/log.h" #include "game/graphics/pipelines/opengl.h" -#include "common/util/assert.h" +#include "common/util/Assert.h" Shader::Shader(const std::string& shader_name) { // read the shader source @@ -60,7 +60,7 @@ Shader::Shader(const std::string& shader_name) { } void Shader::activate() { - assert(m_is_okay); + ASSERT(m_is_okay); glUseProgram(m_program); } diff --git a/game/graphics/opengl_renderer/SkyBlendCPU.cpp b/game/graphics/opengl_renderer/SkyBlendCPU.cpp index 864d38a733..d8142365fa 100644 --- a/game/graphics/opengl_renderer/SkyBlendCPU.cpp +++ b/game/graphics/opengl_renderer/SkyBlendCPU.cpp @@ -62,12 +62,12 @@ SkyBlendStats SkyBlendCPU::do_sky_blends(DmaFollower& dma, // first is an adgif AdgifHelper adgif(setup_data.data + 16); - assert(adgif.is_normal_adgif()); - assert(adgif.alpha().data == 0x8000000068); // Cs + Cd + ASSERT(adgif.is_normal_adgif()); + ASSERT(adgif.alpha().data == 0x8000000068); // Cs + Cd // next is the actual draw auto draw_data = dma.read_and_advance(); - assert(draw_data.size_bytes == 6 * 16); + ASSERT(draw_data.size_bytes == 6 * 16); GifTag draw_or_blend_tag(draw_data.data); @@ -89,13 +89,13 @@ SkyBlendStats SkyBlendCPU::do_sky_blends(DmaFollower& dma, } else if (coord == 0x400) { buffer_idx = 1; } else { - assert(false); // bad data + ASSERT(false); // bad data } // look up the source texture auto tex = render_state->texture_pool->lookup(adgif.tex0().tbp0()); - assert(tex); - assert(!tex->only_on_gpu); // we need the actual data!! + ASSERT(tex); + ASSERT(!tex->only_on_gpu); // we need the actual data!! // slow version /* @@ -105,8 +105,8 @@ SkyBlendStats SkyBlendCPU::do_sky_blends(DmaFollower& dma, // intensities should be 0-128 (maybe higher is okay, but I don't see how this could be // generated with the GOAL code.) - assert(intensity <= 128); - assert(m_texture_data[buffer_idx].size() == tex->data.size()); + ASSERT(intensity <= 128); + ASSERT(m_texture_data[buffer_idx].size() == tex->data.size()); for (size_t i = 0; i < m_texture_data[buffer_idx].size(); i++) { u32 val = tex->data[i] * intensity; val >>= 7; diff --git a/game/graphics/opengl_renderer/SkyBlendGPU.cpp b/game/graphics/opengl_renderer/SkyBlendGPU.cpp index 7a1ffed2b3..cebd25eb6d 100644 --- a/game/graphics/opengl_renderer/SkyBlendGPU.cpp +++ b/game/graphics/opengl_renderer/SkyBlendGPU.cpp @@ -82,12 +82,12 @@ SkyBlendStats SkyBlendGPU::do_sky_blends(DmaFollower& dma, // first is an adgif AdgifHelper adgif(setup_data.data + 16); - assert(adgif.is_normal_adgif()); - assert(adgif.alpha().data == 0x8000000068); // Cs + Cd + ASSERT(adgif.is_normal_adgif()); + ASSERT(adgif.alpha().data == 0x8000000068); // Cs + Cd // next is the actual draw auto draw_data = dma.read_and_advance(); - assert(draw_data.size_bytes == 6 * 16); + ASSERT(draw_data.size_bytes == 6 * 16); GifTag draw_or_blend_tag(draw_data.data); @@ -109,12 +109,12 @@ SkyBlendStats SkyBlendGPU::do_sky_blends(DmaFollower& dma, } else if (coord == 0x400) { buffer_idx = 1; } else { - assert(false); // bad data + ASSERT(false); // bad data } // look up the source texture auto tex = render_state->texture_pool->lookup(adgif.tex0().tbp0()); - assert(tex); + ASSERT(tex); if (!tex->on_gpu) { render_state->texture_pool->upload_to_gpu(tex); @@ -135,7 +135,7 @@ SkyBlendStats SkyBlendGPU::do_sky_blends(DmaFollower& dma, // intensities should be 0-128 (maybe higher is okay, but I don't see how this could be // generated with the GOAL code.) - assert(intensity <= 128); + ASSERT(intensity <= 128); // todo - could do this on the GPU, but probably not worth it for <20 triangles... float intensity_float = intensity / 128.f; diff --git a/game/graphics/opengl_renderer/SkyRenderer.cpp b/game/graphics/opengl_renderer/SkyRenderer.cpp index efad20bd0a..e7ff3d4d7b 100644 --- a/game/graphics/opengl_renderer/SkyRenderer.cpp +++ b/game/graphics/opengl_renderer/SkyRenderer.cpp @@ -58,16 +58,16 @@ void SkyBlendHandler::render(DmaFollower& dma, m_gpu_stats = {}; // First thing should be a NEXT with two nops. this is a jump from buckets to sprite data auto data0 = dma.read_and_advance(); - assert(data0.vif1() == 0); - assert(data0.vif0() == 0); - assert(data0.size_bytes == 0); + ASSERT(data0.vif1() == 0); + ASSERT(data0.vif0() == 0); + ASSERT(data0.size_bytes == 0); if (dma.current_tag().kind == DmaTag::Kind::CALL) { // sky renderer didn't run, let's just get out of here. for (int i = 0; i < 4; i++) { dma.read_and_advance(); } - assert(dma.current_tag_offset() == render_state->next_bucket); + ASSERT(dma.current_tag_offset() == render_state->next_bucket); return; } @@ -79,32 +79,32 @@ void SkyBlendHandler::render(DmaFollower& dma, // first is the set-display-gs-state auto set_display = dma.read_and_advance(); - assert(set_display.size_bytes == 8 * 16); + ASSERT(set_display.size_bytes == 8 * 16); handle_sky_copies(dma, render_state, prof); auto reset_alpha = dma.read_and_advance(); - assert(reset_alpha.size_bytes == 16 * 2); + ASSERT(reset_alpha.size_bytes == 16 * 2); auto reset_gs = dma.read_and_advance(); - assert(reset_gs.size_bytes == 16 * 8); + ASSERT(reset_gs.size_bytes == 16 * 8); auto empty = dma.read_and_advance(); - assert(empty.size_bytes == 0); - assert(empty.vif0() == 0); - assert(empty.vif1() == 0); + ASSERT(empty.size_bytes == 0); + ASSERT(empty.vif0() == 0); + ASSERT(empty.vif1() == 0); if (dma.current_tag().kind != DmaTag::Kind::CALL) { auto tfrag_prof = prof.make_scoped_child("tfrag-trans"); m_tfrag_renderer.render(dma, render_state, tfrag_prof); } else { - assert(dma.current_tag().kind == DmaTag::Kind::CALL); + ASSERT(dma.current_tag().kind == DmaTag::Kind::CALL); dma.read_and_advance(); dma.read_and_advance(); // cnt - assert(dma.current_tag().kind == DmaTag::Kind::RET); + ASSERT(dma.current_tag().kind == DmaTag::Kind::RET); dma.read_and_advance(); // ret dma.read_and_advance(); // ret - assert(dma.current_tag_offset() == render_state->next_bucket); + ASSERT(dma.current_tag_offset() == render_state->next_bucket); } } @@ -130,21 +130,21 @@ void SkyRenderer::render(DmaFollower& dma, m_frame_stats = {}; // First thing should be a NEXT with two nops. this is a jump from buckets to sprite data auto data0 = dma.read_and_advance(); - assert(data0.vif1() == 0); - assert(data0.vif0() == 0); - assert(data0.size_bytes == 0); + ASSERT(data0.vif1() == 0); + ASSERT(data0.vif0() == 0); + ASSERT(data0.size_bytes == 0); if (dma.current_tag().kind == DmaTag::Kind::CALL) { // sky renderer didn't run, let's just get out of here. for (int i = 0; i < 4; i++) { dma.read_and_advance(); } - assert(dma.current_tag_offset() == render_state->next_bucket); + ASSERT(dma.current_tag_offset() == render_state->next_bucket); return; } auto setup_packet = dma.read_and_advance(); - assert(setup_packet.size_bytes == 16 * 4); + ASSERT(setup_packet.size_bytes == 16 * 4); m_direct_renderer.render_gif(setup_packet.data, setup_packet.size_bytes, render_state, prof); if (dma.current_tag().qwc == 5) { @@ -159,9 +159,9 @@ void SkyRenderer::render(DmaFollower& dma, while (dma.current_tag().kind == DmaTag::Kind::CNT) { m_frame_stats.gif_packets++; auto data = dma.read_and_advance(); - assert(data.vifcode0().kind == VifCode::Kind::NOP); - assert(data.vifcode1().kind == VifCode::Kind::DIRECT); - assert(data.vifcode1().immediate == data.size_bytes / 16); + ASSERT(data.vifcode0().kind == VifCode::Kind::NOP); + ASSERT(data.vifcode1().kind == VifCode::Kind::DIRECT); + ASSERT(data.vifcode1().immediate == data.size_bytes / 16); if (m_enabled) { m_direct_renderer.render_gif(data.data, data.size_bytes, render_state, prof); } @@ -169,17 +169,17 @@ void SkyRenderer::render(DmaFollower& dma, } auto empty = dma.read_and_advance(); - assert(empty.size_bytes == 0); - assert(empty.vif0() == 0); - assert(empty.vif1() == 0); + ASSERT(empty.size_bytes == 0); + ASSERT(empty.vif0() == 0); + ASSERT(empty.vif1() == 0); - assert(dma.current_tag().kind == DmaTag::Kind::CALL); + ASSERT(dma.current_tag().kind == DmaTag::Kind::CALL); dma.read_and_advance(); dma.read_and_advance(); // cnt - assert(dma.current_tag().kind == DmaTag::Kind::RET); + ASSERT(dma.current_tag().kind == DmaTag::Kind::RET); dma.read_and_advance(); // ret dma.read_and_advance(); // ret - assert(dma.current_tag_offset() == render_state->next_bucket); + ASSERT(dma.current_tag_offset() == render_state->next_bucket); } else { while (dma.current_tag_offset() != render_state->next_bucket) { auto data = dma.read_and_advance(); @@ -190,7 +190,7 @@ void SkyRenderer::render(DmaFollower& dma, if (dma.current_tag_offset() == render_state->default_regs_buffer) { dma.read_and_advance(); // cnt - assert(dma.current_tag().kind == DmaTag::Kind::RET); + ASSERT(dma.current_tag().kind == DmaTag::Kind::RET); dma.read_and_advance(); // ret } } diff --git a/game/graphics/opengl_renderer/Sprite3.cpp b/game/graphics/opengl_renderer/Sprite3.cpp index 59a58d25a1..88d82f1e3a 100644 --- a/game/graphics/opengl_renderer/Sprite3.cpp +++ b/game/graphics/opengl_renderer/Sprite3.cpp @@ -26,10 +26,10 @@ u32 process_sprite_chunk_header(DmaFollower& dma) { // note that flg = true, this should use double buffering bool ok = verify_unpack_with_stcycl(transfer, VifCode::Kind::UNPACK_V4_32, 4, 4, 1, SpriteDataMem::Header, false, true); - assert(ok); + ASSERT(ok); u32 header[4]; memcpy(header, transfer.data, 16); - assert(header[0] <= Sprite3::SPRITES_PER_CHUNK); + ASSERT(header[0] <= Sprite3::SPRITES_PER_CHUNK); return header[0]; } } // namespace @@ -132,18 +132,18 @@ void Sprite3::render_distorter(DmaFollower& dma, } // m_direct_renderer.flush_pending(render_state, prof); auto sprite_distorter_direct_setup = dma.read_and_advance(); - assert(sprite_distorter_direct_setup.vifcode0().kind == VifCode::Kind::NOP); - assert(sprite_distorter_direct_setup.vifcode1().kind == VifCode::Kind::DIRECT); - assert(sprite_distorter_direct_setup.vifcode1().immediate == 7); + ASSERT(sprite_distorter_direct_setup.vifcode0().kind == VifCode::Kind::NOP); + ASSERT(sprite_distorter_direct_setup.vifcode1().kind == VifCode::Kind::DIRECT); + ASSERT(sprite_distorter_direct_setup.vifcode1().immediate == 7); memcpy(m_sprite_distorter_setup, sprite_distorter_direct_setup.data, 7 * 16); // Next thing should be the sprite-distorter tables auto sprite_distorter_tables = dma.read_and_advance(); - assert(sprite_distorter_tables.size_bytes == 0x8b * 16); - assert(sprite_distorter_tables.vifcode0().kind == VifCode::Kind::STCYCL); + ASSERT(sprite_distorter_tables.size_bytes == 0x8b * 16); + ASSERT(sprite_distorter_tables.vifcode0().kind == VifCode::Kind::STCYCL); VifCodeStcycl distorter_table_transfer(sprite_distorter_tables.vifcode0()); - assert(distorter_table_transfer.cl == 4); - assert(distorter_table_transfer.wl == 4); + ASSERT(distorter_table_transfer.cl == 4); + ASSERT(distorter_table_transfer.wl == 4); // TODO: check unpack cmd (vif1) // TODO: do something with the table @@ -161,48 +161,48 @@ void Sprite3::render_distorter(DmaFollower& dma, void Sprite3::handle_sprite_frame_setup(DmaFollower& dma) { // first is some direct data auto direct_data = dma.read_and_advance(); - assert(direct_data.size_bytes == 3 * 16); + ASSERT(direct_data.size_bytes == 3 * 16); memcpy(m_sprite_direct_setup, direct_data.data, 3 * 16); // next would be the program, but it's 0 size on the PC and isn't sent. // next is the "frame data" auto frame_data = dma.read_and_advance(); - assert(frame_data.size_bytes == (int)sizeof(SpriteFrameData)); // very cool - assert(frame_data.vifcode0().kind == VifCode::Kind::STCYCL); + ASSERT(frame_data.size_bytes == (int)sizeof(SpriteFrameData)); // very cool + ASSERT(frame_data.vifcode0().kind == VifCode::Kind::STCYCL); VifCodeStcycl frame_data_stcycl(frame_data.vifcode0()); - assert(frame_data_stcycl.cl == 4); - assert(frame_data_stcycl.wl == 4); - assert(frame_data.vifcode1().kind == VifCode::Kind::UNPACK_V4_32); + ASSERT(frame_data_stcycl.cl == 4); + ASSERT(frame_data_stcycl.wl == 4); + ASSERT(frame_data.vifcode1().kind == VifCode::Kind::UNPACK_V4_32); VifCodeUnpack frame_data_unpack(frame_data.vifcode1()); - assert(frame_data_unpack.addr_qw == SpriteDataMem::FrameData); - assert(frame_data_unpack.use_tops_flag == false); + ASSERT(frame_data_unpack.addr_qw == SpriteDataMem::FrameData); + ASSERT(frame_data_unpack.use_tops_flag == false); memcpy(&m_frame_data, frame_data.data, sizeof(SpriteFrameData)); // next, a MSCALF. auto mscalf = dma.read_and_advance(); - assert(mscalf.size_bytes == 0); - assert(mscalf.vifcode0().kind == VifCode::Kind::MSCALF); - assert(mscalf.vifcode0().immediate == SpriteProgMem::Init); - assert(mscalf.vifcode1().kind == VifCode::Kind::FLUSHE); + ASSERT(mscalf.size_bytes == 0); + ASSERT(mscalf.vifcode0().kind == VifCode::Kind::MSCALF); + ASSERT(mscalf.vifcode0().immediate == SpriteProgMem::Init); + ASSERT(mscalf.vifcode1().kind == VifCode::Kind::FLUSHE); // next base and offset auto base_offset = dma.read_and_advance(); - assert(base_offset.size_bytes == 0); - assert(base_offset.vifcode0().kind == VifCode::Kind::BASE); - assert(base_offset.vifcode0().immediate == SpriteDataMem::Buffer0); - assert(base_offset.vifcode1().kind == VifCode::Kind::OFFSET); - assert(base_offset.vifcode1().immediate == SpriteDataMem::Buffer1); + ASSERT(base_offset.size_bytes == 0); + ASSERT(base_offset.vifcode0().kind == VifCode::Kind::BASE); + ASSERT(base_offset.vifcode0().immediate == SpriteDataMem::Buffer0); + ASSERT(base_offset.vifcode1().kind == VifCode::Kind::OFFSET); + ASSERT(base_offset.vifcode1().immediate == SpriteDataMem::Buffer1); } void Sprite3::render_3d(DmaFollower& dma) { // one time matrix data auto matrix_data = dma.read_and_advance(); - assert(matrix_data.size_bytes == sizeof(Sprite3DMatrixData)); + ASSERT(matrix_data.size_bytes == sizeof(Sprite3DMatrixData)); bool unpack_ok = verify_unpack_with_stcycl(matrix_data, VifCode::Kind::UNPACK_V4_32, 4, 4, 5, SpriteDataMem::Matrix, false, false); - assert(unpack_ok); + ASSERT(unpack_ok); static_assert(sizeof(m_3d_matrix_data) == 5 * 16); memcpy(&m_3d_matrix_data, matrix_data.data, sizeof(m_3d_matrix_data)); // TODO @@ -254,21 +254,21 @@ void Sprite3::render_2d_group0(DmaFollower& dma, // second is the vector data u32 expected_vec_size = sizeof(SpriteVecData2d) * sprite_count; auto vec_data = dma.read_and_advance(); - assert(expected_vec_size <= sizeof(m_vec_data_2d)); + ASSERT(expected_vec_size <= sizeof(m_vec_data_2d)); unpack_to_no_stcycl(&m_vec_data_2d, vec_data, VifCode::Kind::UNPACK_V4_32, expected_vec_size, SpriteDataMem::Vector, false, true); // third is the adgif data u32 expected_adgif_size = sizeof(AdGifData) * sprite_count; auto adgif_data = dma.read_and_advance(); - assert(expected_adgif_size <= sizeof(m_adgif)); + ASSERT(expected_adgif_size <= sizeof(m_adgif)); unpack_to_no_stcycl(&m_adgif, adgif_data, VifCode::Kind::UNPACK_V4_32, expected_adgif_size, SpriteDataMem::Adgif, false, true); // fourth is the actual run!!!!! auto run = dma.read_and_advance(); - assert(run.vifcode0().kind == VifCode::Kind::NOP); - assert(run.vifcode1().kind == VifCode::Kind::MSCAL); + ASSERT(run.vifcode0().kind == VifCode::Kind::NOP); + ASSERT(run.vifcode1().kind == VifCode::Kind::MSCAL); if (m_enabled) { if (run.vifcode1().immediate != last_prog) { @@ -294,8 +294,8 @@ void Sprite3::render_fake_shadow(DmaFollower& dma) { // TODO // nop + flushe auto nop_flushe = dma.read_and_advance(); - assert(nop_flushe.vifcode0().kind == VifCode::Kind::NOP); - assert(nop_flushe.vifcode1().kind == VifCode::Kind::FLUSHE); + ASSERT(nop_flushe.vifcode0().kind == VifCode::Kind::NOP); + ASSERT(nop_flushe.vifcode1().kind == VifCode::Kind::FLUSHE); } /*! @@ -308,8 +308,8 @@ void Sprite3::render_2d_group1(DmaFollower& dma, auto mat_upload = dma.read_and_advance(); bool mat_ok = verify_unpack_with_stcycl(mat_upload, VifCode::Kind::UNPACK_V4_32, 4, 4, 80, SpriteDataMem::Matrix, false, false); - assert(mat_ok); - assert(mat_upload.size_bytes == sizeof(m_hud_matrix_data)); + ASSERT(mat_ok); + ASSERT(mat_upload.size_bytes == sizeof(m_hud_matrix_data)); memcpy(&m_hud_matrix_data, mat_upload.data, sizeof(m_hud_matrix_data)); // opengl sprite frame setup @@ -334,22 +334,22 @@ void Sprite3::render_2d_group1(DmaFollower& dma, // second is the vector data u32 expected_vec_size = sizeof(SpriteVecData2d) * sprite_count; auto vec_data = dma.read_and_advance(); - assert(expected_vec_size <= sizeof(m_vec_data_2d)); + ASSERT(expected_vec_size <= sizeof(m_vec_data_2d)); unpack_to_no_stcycl(&m_vec_data_2d, vec_data, VifCode::Kind::UNPACK_V4_32, expected_vec_size, SpriteDataMem::Vector, false, true); // third is the adgif data u32 expected_adgif_size = sizeof(AdGifData) * sprite_count; auto adgif_data = dma.read_and_advance(); - assert(expected_adgif_size <= sizeof(m_adgif)); + ASSERT(expected_adgif_size <= sizeof(m_adgif)); unpack_to_no_stcycl(&m_adgif, adgif_data, VifCode::Kind::UNPACK_V4_32, expected_adgif_size, SpriteDataMem::Adgif, false, true); // fourth is the actual run!!!!! auto run = dma.read_and_advance(); - assert(run.vifcode0().kind == VifCode::Kind::NOP); - assert(run.vifcode1().kind == VifCode::Kind::MSCAL); - assert(run.vifcode1().immediate == SpriteProgMem::Sprites2dHud); + ASSERT(run.vifcode0().kind == VifCode::Kind::NOP); + ASSERT(run.vifcode1().kind == VifCode::Kind::MSCAL); + ASSERT(run.vifcode1().immediate == SpriteProgMem::Sprites2dHud); if (m_enabled && m_2d_enable) { do_block_common(SpriteMode::ModeHUD, sprite_count, render_state, prof); } @@ -360,16 +360,16 @@ void Sprite3::render(DmaFollower& dma, SharedRenderState* render_state, ScopedPr m_debug_stats = {}; // First thing should be a NEXT with two nops. this is a jump from buckets to sprite data auto data0 = dma.read_and_advance(); - assert(data0.vif1() == 0); - assert(data0.vif0() == 0); - assert(data0.size_bytes == 0); + ASSERT(data0.vif1() == 0); + ASSERT(data0.vif0() == 0); + ASSERT(data0.size_bytes == 0); if (dma.current_tag().kind == DmaTag::Kind::CALL) { // sprite renderer didn't run, let's just get out of here. for (int i = 0; i < 4; i++) { dma.read_and_advance(); } - assert(dma.current_tag_offset() == render_state->next_bucket); + ASSERT(dma.current_tag_offset() == render_state->next_bucket); return; } @@ -478,7 +478,7 @@ void Sprite3::flush_sprites(SharedRenderState* render_state, fmt::print("Failed to find texture at {}, using random\n", tbp); tex = render_state->texture_pool->get_random_texture(); } - assert(tex); + ASSERT(tex); // first: do we need to load the texture? if (!tex->on_gpu) { @@ -520,7 +520,7 @@ void Sprite3::flush_sprites(SharedRenderState* render_state, (void*)(kv.second.offset_in_idx_buffer * sizeof(u32))); break; default: - assert(false); + ASSERT(false); } } } @@ -546,8 +546,8 @@ void Sprite3::handle_tex0(u64 val, // tw: assume they got it right // th: assume they got it right - assert(reg.tfx() == GsTex0::TextureFunction::MODULATE); - assert(reg.psm() != GsTex0::PSM::PSMT4HH); + ASSERT(reg.tfx() == GsTex0::TextureFunction::MODULATE); + ASSERT(reg.psm() != GsTex0::PSM::PSMT4HH); // cbp: assume they got it right // cpsm: assume they got it right @@ -567,8 +567,8 @@ void Sprite3::handle_zbuf(u64 val, // note: we can basically ignore this. There's a single z buffer that's always configured the same // way - 24-bit, at offset 448. GsZbuf x(val); - assert(x.psm() == TextureFormat::PSMZ24); - assert(x.zbp() == 448); + ASSERT(x.psm() == TextureFormat::PSMZ24); + ASSERT(x.zbp() == 448); m_current_mode.set_depth_write_enable(!x.zmsk()); } @@ -578,7 +578,7 @@ void Sprite3::handle_clamp(u64 val, ScopedProfilerNode& /*prof*/) { if (!(val == 0b101 || val == 0 || val == 1 || val == 0b100)) { fmt::print("clamp: 0x{:x}\n", val); - assert(false); + ASSERT(false); } m_current_mode.set_clamp_s_enable(val & 0b001); @@ -604,7 +604,7 @@ void update_mode_from_alpha1(u64 val, DrawMode& mode) { reg.b_mode() == GsAlpha::BlendMode::ZERO_OR_FIXED && reg.c_mode() == GsAlpha::BlendMode::ZERO_OR_FIXED && reg.d_mode() == GsAlpha::BlendMode::DEST) { - assert(reg.fix() == 128); + ASSERT(reg.fix() == 128); // Cv = (Cs - 0) * FIX + Cd // if fix = 128, it works out to 1.0 mode.set_alpha_blend(DrawMode::AlphaBlend::SRC_0_FIX_DST); @@ -614,7 +614,7 @@ void update_mode_from_alpha1(u64 val, DrawMode& mode) { reg.c_mode() == GsAlpha::BlendMode::ZERO_OR_FIXED && reg.d_mode() == GsAlpha::BlendMode::DEST) { // Cv = (Cs - Cd) * FIX + Cd - assert(reg.fix() == 64); + ASSERT(reg.fix() == 64); mode.set_alpha_blend(DrawMode::AlphaBlend::SRC_DST_FIX_DST); } @@ -622,7 +622,7 @@ void update_mode_from_alpha1(u64 val, DrawMode& mode) { fmt::print("unsupported blend: a {} b {} c {} d {}\n", (int)reg.a_mode(), (int)reg.b_mode(), (int)reg.c_mode(), (int)reg.d_mode()); mode.set_alpha_blend(DrawMode::AlphaBlend::SRC_DST_SRC_DST); - assert(false); + ASSERT(false); } } diff --git a/game/graphics/opengl_renderer/SpriteRenderer.cpp b/game/graphics/opengl_renderer/SpriteRenderer.cpp index 779368341b..e5eac633b2 100644 --- a/game/graphics/opengl_renderer/SpriteRenderer.cpp +++ b/game/graphics/opengl_renderer/SpriteRenderer.cpp @@ -23,10 +23,10 @@ u32 process_sprite_chunk_header(DmaFollower& dma) { // note that flg = true, this should use double buffering bool ok = verify_unpack_with_stcycl(transfer, VifCode::Kind::UNPACK_V4_32, 4, 4, 1, SpriteDataMem::Header, false, true); - assert(ok); + ASSERT(ok); u32 header[4]; memcpy(header, transfer.data, 16); - assert(header[0] <= SpriteRenderer::SPRITES_PER_CHUNK); + ASSERT(header[0] <= SpriteRenderer::SPRITES_PER_CHUNK); return header[0]; } } // namespace @@ -111,18 +111,18 @@ void SpriteRenderer::render_distorter(DmaFollower& dma, } // m_direct_renderer.flush_pending(render_state, prof); auto sprite_distorter_direct_setup = dma.read_and_advance(); - assert(sprite_distorter_direct_setup.vifcode0().kind == VifCode::Kind::NOP); - assert(sprite_distorter_direct_setup.vifcode1().kind == VifCode::Kind::DIRECT); - assert(sprite_distorter_direct_setup.vifcode1().immediate == 7); + ASSERT(sprite_distorter_direct_setup.vifcode0().kind == VifCode::Kind::NOP); + ASSERT(sprite_distorter_direct_setup.vifcode1().kind == VifCode::Kind::DIRECT); + ASSERT(sprite_distorter_direct_setup.vifcode1().immediate == 7); memcpy(m_sprite_distorter_setup, sprite_distorter_direct_setup.data, 7 * 16); // Next thing should be the sprite-distorter tables auto sprite_distorter_tables = dma.read_and_advance(); - assert(sprite_distorter_tables.size_bytes == 0x8b * 16); - assert(sprite_distorter_tables.vifcode0().kind == VifCode::Kind::STCYCL); + ASSERT(sprite_distorter_tables.size_bytes == 0x8b * 16); + ASSERT(sprite_distorter_tables.vifcode0().kind == VifCode::Kind::STCYCL); VifCodeStcycl distorter_table_transfer(sprite_distorter_tables.vifcode0()); - assert(distorter_table_transfer.cl == 4); - assert(distorter_table_transfer.wl == 4); + ASSERT(distorter_table_transfer.cl == 4); + ASSERT(distorter_table_transfer.wl == 4); // TODO: check unpack cmd (vif1) // TODO: do something with the table @@ -140,48 +140,48 @@ void SpriteRenderer::render_distorter(DmaFollower& dma, void SpriteRenderer::handle_sprite_frame_setup(DmaFollower& dma) { // first is some direct data auto direct_data = dma.read_and_advance(); - assert(direct_data.size_bytes == 3 * 16); + ASSERT(direct_data.size_bytes == 3 * 16); memcpy(m_sprite_direct_setup, direct_data.data, 3 * 16); // next would be the program, but it's 0 size on the PC and isn't sent. // next is the "frame data" auto frame_data = dma.read_and_advance(); - assert(frame_data.size_bytes == (int)sizeof(SpriteFrameData)); // very cool - assert(frame_data.vifcode0().kind == VifCode::Kind::STCYCL); + ASSERT(frame_data.size_bytes == (int)sizeof(SpriteFrameData)); // very cool + ASSERT(frame_data.vifcode0().kind == VifCode::Kind::STCYCL); VifCodeStcycl frame_data_stcycl(frame_data.vifcode0()); - assert(frame_data_stcycl.cl == 4); - assert(frame_data_stcycl.wl == 4); - assert(frame_data.vifcode1().kind == VifCode::Kind::UNPACK_V4_32); + ASSERT(frame_data_stcycl.cl == 4); + ASSERT(frame_data_stcycl.wl == 4); + ASSERT(frame_data.vifcode1().kind == VifCode::Kind::UNPACK_V4_32); VifCodeUnpack frame_data_unpack(frame_data.vifcode1()); - assert(frame_data_unpack.addr_qw == SpriteDataMem::FrameData); - assert(frame_data_unpack.use_tops_flag == false); + ASSERT(frame_data_unpack.addr_qw == SpriteDataMem::FrameData); + ASSERT(frame_data_unpack.use_tops_flag == false); memcpy(&m_frame_data, frame_data.data, sizeof(SpriteFrameData)); // next, a MSCALF. auto mscalf = dma.read_and_advance(); - assert(mscalf.size_bytes == 0); - assert(mscalf.vifcode0().kind == VifCode::Kind::MSCALF); - assert(mscalf.vifcode0().immediate == SpriteProgMem::Init); - assert(mscalf.vifcode1().kind == VifCode::Kind::FLUSHE); + ASSERT(mscalf.size_bytes == 0); + ASSERT(mscalf.vifcode0().kind == VifCode::Kind::MSCALF); + ASSERT(mscalf.vifcode0().immediate == SpriteProgMem::Init); + ASSERT(mscalf.vifcode1().kind == VifCode::Kind::FLUSHE); // next base and offset auto base_offset = dma.read_and_advance(); - assert(base_offset.size_bytes == 0); - assert(base_offset.vifcode0().kind == VifCode::Kind::BASE); - assert(base_offset.vifcode0().immediate == SpriteDataMem::Buffer0); - assert(base_offset.vifcode1().kind == VifCode::Kind::OFFSET); - assert(base_offset.vifcode1().immediate == SpriteDataMem::Buffer1); + ASSERT(base_offset.size_bytes == 0); + ASSERT(base_offset.vifcode0().kind == VifCode::Kind::BASE); + ASSERT(base_offset.vifcode0().immediate == SpriteDataMem::Buffer0); + ASSERT(base_offset.vifcode1().kind == VifCode::Kind::OFFSET); + ASSERT(base_offset.vifcode1().immediate == SpriteDataMem::Buffer1); } void SpriteRenderer::render_3d(DmaFollower& dma) { // one time matrix data auto matrix_data = dma.read_and_advance(); - assert(matrix_data.size_bytes == sizeof(Sprite3DMatrixData)); + ASSERT(matrix_data.size_bytes == sizeof(Sprite3DMatrixData)); bool unpack_ok = verify_unpack_with_stcycl(matrix_data, VifCode::Kind::UNPACK_V4_32, 4, 4, 5, SpriteDataMem::Matrix, false, false); - assert(unpack_ok); + ASSERT(unpack_ok); static_assert(sizeof(m_3d_matrix_data) == 5 * 16); memcpy(&m_3d_matrix_data, matrix_data.data, sizeof(m_3d_matrix_data)); // TODO @@ -233,21 +233,21 @@ void SpriteRenderer::render_2d_group0(DmaFollower& dma, // second is the vector data u32 expected_vec_size = sizeof(SpriteVecData2d) * sprite_count; auto vec_data = dma.read_and_advance(); - assert(expected_vec_size <= sizeof(m_vec_data_2d)); + ASSERT(expected_vec_size <= sizeof(m_vec_data_2d)); unpack_to_no_stcycl(&m_vec_data_2d, vec_data, VifCode::Kind::UNPACK_V4_32, expected_vec_size, SpriteDataMem::Vector, false, true); // third is the adgif data u32 expected_adgif_size = sizeof(AdGifData) * sprite_count; auto adgif_data = dma.read_and_advance(); - assert(expected_adgif_size <= sizeof(m_adgif)); + ASSERT(expected_adgif_size <= sizeof(m_adgif)); unpack_to_no_stcycl(&m_adgif, adgif_data, VifCode::Kind::UNPACK_V4_32, expected_adgif_size, SpriteDataMem::Adgif, false, true); // fourth is the actual run!!!!! auto run = dma.read_and_advance(); - assert(run.vifcode0().kind == VifCode::Kind::NOP); - assert(run.vifcode1().kind == VifCode::Kind::MSCAL); + ASSERT(run.vifcode0().kind == VifCode::Kind::NOP); + ASSERT(run.vifcode1().kind == VifCode::Kind::MSCAL); if (m_enabled) { if (run.vifcode1().immediate != last_prog) { @@ -279,8 +279,8 @@ void SpriteRenderer::render_fake_shadow(DmaFollower& dma) { // TODO // nop + flushe auto nop_flushe = dma.read_and_advance(); - assert(nop_flushe.vifcode0().kind == VifCode::Kind::NOP); - assert(nop_flushe.vifcode1().kind == VifCode::Kind::FLUSHE); + ASSERT(nop_flushe.vifcode0().kind == VifCode::Kind::NOP); + ASSERT(nop_flushe.vifcode1().kind == VifCode::Kind::FLUSHE); } /*! @@ -293,8 +293,8 @@ void SpriteRenderer::render_2d_group1(DmaFollower& dma, auto mat_upload = dma.read_and_advance(); bool mat_ok = verify_unpack_with_stcycl(mat_upload, VifCode::Kind::UNPACK_V4_32, 4, 4, 80, SpriteDataMem::Matrix, false, false); - assert(mat_ok); - assert(mat_upload.size_bytes == sizeof(m_hud_matrix_data)); + ASSERT(mat_ok); + ASSERT(mat_upload.size_bytes == sizeof(m_hud_matrix_data)); memcpy(&m_hud_matrix_data, mat_upload.data, sizeof(m_hud_matrix_data)); // opengl sprite frame setup @@ -321,22 +321,22 @@ void SpriteRenderer::render_2d_group1(DmaFollower& dma, // second is the vector data u32 expected_vec_size = sizeof(SpriteVecData2d) * sprite_count; auto vec_data = dma.read_and_advance(); - assert(expected_vec_size <= sizeof(m_vec_data_2d)); + ASSERT(expected_vec_size <= sizeof(m_vec_data_2d)); unpack_to_no_stcycl(&m_vec_data_2d, vec_data, VifCode::Kind::UNPACK_V4_32, expected_vec_size, SpriteDataMem::Vector, false, true); // third is the adgif data u32 expected_adgif_size = sizeof(AdGifData) * sprite_count; auto adgif_data = dma.read_and_advance(); - assert(expected_adgif_size <= sizeof(m_adgif)); + ASSERT(expected_adgif_size <= sizeof(m_adgif)); unpack_to_no_stcycl(&m_adgif, adgif_data, VifCode::Kind::UNPACK_V4_32, expected_adgif_size, SpriteDataMem::Adgif, false, true); // fourth is the actual run!!!!! auto run = dma.read_and_advance(); - assert(run.vifcode0().kind == VifCode::Kind::NOP); - assert(run.vifcode1().kind == VifCode::Kind::MSCAL); - assert(run.vifcode1().immediate == SpriteProgMem::Sprites2dHud); + ASSERT(run.vifcode0().kind == VifCode::Kind::NOP); + ASSERT(run.vifcode1().kind == VifCode::Kind::MSCAL); + ASSERT(run.vifcode1().immediate == SpriteProgMem::Sprites2dHud); if (m_enabled && m_2d_enable) { do_block_common(SpriteMode::ModeHUD, sprite_count, render_state, prof); } @@ -349,16 +349,16 @@ void SpriteRenderer::render(DmaFollower& dma, m_debug_stats = {}; // First thing should be a NEXT with two nops. this is a jump from buckets to sprite data auto data0 = dma.read_and_advance(); - assert(data0.vif1() == 0); - assert(data0.vif0() == 0); - assert(data0.size_bytes == 0); + ASSERT(data0.vif1() == 0); + ASSERT(data0.vif0() == 0); + ASSERT(data0.size_bytes == 0); if (dma.current_tag().kind == DmaTag::Kind::CALL) { // sprite renderer didn't run, let's just get out of here. for (int i = 0; i < 4; i++) { dma.read_and_advance(); } - assert(dma.current_tag_offset() == render_state->next_bucket); + ASSERT(dma.current_tag_offset() == render_state->next_bucket); return; } @@ -482,7 +482,7 @@ void SpriteRenderer::handle_tex0(u64 val, // tw: assume they got it right // th: assume they got it right - assert(reg.tfx() == GsTex0::TextureFunction::MODULATE); + ASSERT(reg.tfx() == GsTex0::TextureFunction::MODULATE); // cbp: assume they got it right // cpsm: assume they got it right @@ -494,13 +494,13 @@ void SpriteRenderer::handle_tex1(u64 val, ScopedProfilerNode& /*prof*/) { GsTex1 reg(val); // for now, we aren't going to handle mipmapping. I don't think it's used with direct. - // assert(reg.mxl() == 0); + // ASSERT(reg.mxl() == 0); // if that's true, we can ignore LCM, MTBA, L, K m_adgif_state.enable_tex_filt = reg.mmag(); // MMAG/MMIN specify texture filtering. For now, assume always linear - // assert(reg.mmag() == true); + // ASSERT(reg.mmag() == true); // if (!(reg.mmin() == 1 || reg.mmin() == 4)) { // with mipmap off, both of these are linear // // lg::error("unsupported mmin"); // } @@ -512,8 +512,8 @@ void SpriteRenderer::handle_zbuf(u64 val, // note: we can basically ignore this. There's a single z buffer that's always configured the same // way - 24-bit, at offset 448. GsZbuf x(val); - assert(x.psm() == TextureFormat::PSMZ24); - assert(x.zbp() == 448); + ASSERT(x.psm() == TextureFormat::PSMZ24); + ASSERT(x.zbp() == 448); m_adgif_state.z_write = !x.zmsk(); } @@ -523,7 +523,7 @@ void SpriteRenderer::handle_clamp(u64 val, ScopedProfilerNode& /*prof*/) { if (!(val == 0b101 || val == 0 || val == 1 || val == 0b100)) { fmt::print("clamp: 0x{:x}\n", val); - assert(false); + ASSERT(false); } m_adgif_state.reg_clamp = val; @@ -563,7 +563,7 @@ void SpriteRenderer::update_gl_blend(AdGifState& state) { // unsupported blend: a 0 b 2 c 2 d 1 lg::error("unsupported blend: a {} b {} c {} d {} NOTE THIS DOWN IMMEDIATELY!!", (int)state.a, (int)state.b, (int)state.c, (int)state.d); - assert(false); + ASSERT(false); } } } @@ -580,19 +580,19 @@ void SpriteRenderer::update_gl_prim(SharedRenderState* /*render_state*/) { // currently gouraud is handled in setup. const auto& state = m_prim_gl_state; if (state.fogging_enable) { - // assert(false); + // ASSERT(false); } if (state.aa_enable) { - assert(false); + ASSERT(false); } if (state.use_uv) { - assert(false); + ASSERT(false); } if (state.ctxt) { - assert(false); + ASSERT(false); } if (state.fix) { - assert(false); + ASSERT(false); } } @@ -617,7 +617,7 @@ void SpriteRenderer::update_gl_texture(SharedRenderState* render_state, int unit // fmt::print("Successful texture lookup! {} {}\n", tex->page_name, tex->name); } } - assert(tex); + ASSERT(tex); // first: do we need to load the texture? if (!tex->on_gpu) { diff --git a/game/graphics/opengl_renderer/SpriteRenderer.h b/game/graphics/opengl_renderer/SpriteRenderer.h index dd0199b5ab..e3e0371dfc 100644 --- a/game/graphics/opengl_renderer/SpriteRenderer.h +++ b/game/graphics/opengl_renderer/SpriteRenderer.h @@ -137,7 +137,7 @@ class SpriteRenderer : public BucketRenderer { d = reg.d_mode(); fix = reg.fix(); - assert(fix == 0); + ASSERT(fix == 0); } bool z_write = false; diff --git a/game/graphics/opengl_renderer/TextureUploadHandler.cpp b/game/graphics/opengl_renderer/TextureUploadHandler.cpp index f81f9e9f65..caed759a84 100644 --- a/game/graphics/opengl_renderer/TextureUploadHandler.cpp +++ b/game/graphics/opengl_renderer/TextureUploadHandler.cpp @@ -42,7 +42,7 @@ void TextureUploadHandler::render(DmaFollower& dma, dma.read_and_advance(); // cnt dma.read_and_advance(); // ret // on next - assert(dma.current_tag_offset() == render_state->next_bucket); + ASSERT(dma.current_tag_offset() == render_state->next_bucket); } } @@ -72,7 +72,7 @@ void TextureUploadHandler::render(DmaFollower& dma, render_state); // after conversion, we should be able to populate the texture pool. bool ok = try_to_populate_from_cache(uploads[0].page, has_segment, render_state); - assert(ok); + ASSERT(ok); } } else if (uploads.size() == 1 && uploads[0].mode == -1) { @@ -83,7 +83,7 @@ void TextureUploadHandler::render(DmaFollower& dma, ee_mem + uploads[0].page, -1, ee_mem, render_state->offset_of_s7), render_state); bool ok = try_to_populate_from_cache(uploads[0].page, has_segment, render_state); - assert(ok); + ASSERT(ok); } } else if (uploads.size() == 1 && uploads[0].mode == -2) { @@ -93,7 +93,7 @@ void TextureUploadHandler::render(DmaFollower& dma, ee_mem + uploads[0].page, -2, ee_mem, render_state->offset_of_s7), render_state); bool ok = try_to_populate_from_cache(uploads[0].page, has_segment, render_state); - assert(ok); + ASSERT(ok); } } else if (uploads.size() == 1 && uploads[0].mode == 0) { @@ -103,7 +103,7 @@ void TextureUploadHandler::render(DmaFollower& dma, ee_mem + uploads[0].page, 0, ee_mem, render_state->offset_of_s7), render_state); bool ok = try_to_populate_from_cache(uploads[0].page, has_segment, render_state); - assert(ok); + ASSERT(ok); } } @@ -114,7 +114,7 @@ void TextureUploadHandler::render(DmaFollower& dma, for (auto& upload : uploads) { fmt::print(" page: 0x{:x} mode: {}\n", upload.page, upload.mode); } - assert(false); + ASSERT(false); } } @@ -127,7 +127,7 @@ void TextureUploadHandler::draw_debug_window() { namespace { const char* goal_string(u32 ptr, const u8* memory_base) { if (ptr == 0) { - assert(false); + ASSERT(false); } return (const char*)(memory_base + ptr + 4); } diff --git a/game/graphics/opengl_renderer/dma_helpers.cpp b/game/graphics/opengl_renderer/dma_helpers.cpp index 2869a8b474..b698f00ac7 100644 --- a/game/graphics/opengl_renderer/dma_helpers.cpp +++ b/game/graphics/opengl_renderer/dma_helpers.cpp @@ -66,8 +66,8 @@ void unpack_to_stcycl(void* dst, bool flg) { bool ok = verify_unpack_with_stcycl(transfer, unpack_kind, cl, wl, size_bytes / 16, addr, usn, flg); - assert(ok); - assert((size_bytes & 0xf) == 0); + ASSERT(ok); + ASSERT((size_bytes & 0xf) == 0); memcpy(dst, transfer.data, size_bytes); } @@ -124,14 +124,14 @@ void unpack_to_no_stcycl(void* dst, bool usn, bool flg) { bool ok = verify_unpack_no_stcycl(transfer, unpack_kind, size_bytes / 16, addr, usn, flg); - assert(ok); - assert((size_bytes & 0xf) == 0); + ASSERT(ok); + ASSERT((size_bytes & 0xf) == 0); memcpy(dst, transfer.data, size_bytes); } void verify_mscal(const DmaTransfer& transfer, int address) { - assert(transfer.size_bytes == 0); - assert(transfer.vif0() == 0); - assert(transfer.vifcode1().kind == VifCode::Kind::MSCAL); - assert(transfer.vifcode1().immediate == address); + ASSERT(transfer.size_bytes == 0); + ASSERT(transfer.vif0() == 0); + ASSERT(transfer.vifcode1().kind == VifCode::Kind::MSCAL); + ASSERT(transfer.vifcode1().immediate == address); } \ No newline at end of file diff --git a/game/graphics/opengl_renderer/tfrag/TFragment.cpp b/game/graphics/opengl_renderer/tfrag/TFragment.cpp index 15c25af4f3..c6c4015fc4 100644 --- a/game/graphics/opengl_renderer/tfrag/TFragment.cpp +++ b/game/graphics/opengl_renderer/tfrag/TFragment.cpp @@ -51,9 +51,9 @@ void TFragment::render(DmaFollower& dma, // unless we are a child, in which case our parent took this already. if (!m_child_mode) { auto data0 = dma.read_and_advance(); - assert(data0.vif1() == 0); - assert(data0.vif0() == 0); - assert(data0.size_bytes == 0); + ASSERT(data0.vif1() == 0); + ASSERT(data0.vif0() == 0); + ASSERT(data0.size_bytes == 0); } if (dma.current_tag().kind == DmaTag::Kind::CALL) { @@ -61,7 +61,7 @@ void TFragment::render(DmaFollower& dma, for (int i = 0; i < 4; i++) { dma.read_and_advance(); } - assert(dma.current_tag_offset() == render_state->next_bucket); + ASSERT(dma.current_tag_offset() == render_state->next_bucket); return; } @@ -70,10 +70,10 @@ void TFragment::render(DmaFollower& dma, transfers[0] = dma.read_and_advance(); auto next0 = dma.read_and_advance(); - assert(next0.size_bytes == 0); + ASSERT(next0.size_bytes == 0); transfers[1] = dma.read_and_advance(); auto next1 = dma.read_and_advance(); - assert(next1.size_bytes == 0); + ASSERT(next1.size_bytes == 0); for (int i = 0; i < 2; i++) { if (transfers[i].size_bytes == 128 * 16) { @@ -82,7 +82,7 @@ void TFragment::render(DmaFollower& dma, memcpy(render_state->occlusion_vis[i].data, transfers[i].data, 128 * 16); } } else { - assert(transfers[i].size_bytes == 16); + ASSERT(transfers[i].size_bytes == 16); } } } @@ -92,7 +92,7 @@ void TFragment::render(DmaFollower& dma, for (int i = 0; i < 4; i++) { dma.read_and_advance(); } - assert(dma.current_tag_offset() == render_state->next_bucket); + ASSERT(dma.current_tag_offset() == render_state->next_bucket); return; } @@ -102,7 +102,7 @@ void TFragment::render(DmaFollower& dma, if (level_name.empty()) { level_name = m_pc_port_data.level_name; } else if (level_name != m_pc_port_data.level_name) { - assert(false); + ASSERT(false); } while (looks_like_tfragment_dma(dma)) { @@ -114,7 +114,7 @@ void TFragment::render(DmaFollower& dma, dma.read_and_advance(); } - assert(!level_name.empty()); + ASSERT(!level_name.empty()); { m_tfrag3.setup_for_level(m_tree_kinds, level_name, render_state); TfragRenderSettings settings; @@ -225,10 +225,10 @@ void TFragment::draw_debug_window() { void TFragment::handle_initialization(DmaFollower& dma) { // Set up test (different between different renderers) auto setup_test = dma.read_and_advance(); - assert(setup_test.vif0() == 0); - assert(setup_test.vifcode1().kind == VifCode::Kind::DIRECT); - assert(setup_test.vifcode1().immediate == 2); - assert(setup_test.size_bytes == 32); + ASSERT(setup_test.vif0() == 0); + ASSERT(setup_test.vifcode1().kind == VifCode::Kind::DIRECT); + ASSERT(setup_test.vifcode1().immediate == 2); + ASSERT(setup_test.size_bytes == 32); memcpy(m_test_setup, setup_test.data, 32); // matrix 0 @@ -252,7 +252,7 @@ void TFragment::handle_initialization(DmaFollower& dma) { verify_mscal(mscal_setup, TFragProgMem::TFragSetup); auto pc_port_data = dma.read_and_advance(); - assert(pc_port_data.size_bytes == sizeof(TfragPcPortData)); + ASSERT(pc_port_data.size_bytes == sizeof(TfragPcPortData)); memcpy(&m_pc_port_data, pc_port_data.data, sizeof(TfragPcPortData)); m_pc_port_data.level_name[11] = '\0'; @@ -271,10 +271,10 @@ void TFragment::handle_initialization(DmaFollower& dma) { // setup double buffering. auto db_setup = dma.read_and_advance(); - assert(db_setup.size_bytes == 0); - assert(db_setup.vifcode0().kind == VifCode::Kind::BASE && + ASSERT(db_setup.size_bytes == 0); + ASSERT(db_setup.vifcode0().kind == VifCode::Kind::BASE && db_setup.vifcode0().immediate == Buffer0_Start); - assert(db_setup.vifcode1().kind == VifCode::Kind::OFFSET && + ASSERT(db_setup.vifcode1().kind == VifCode::Kind::OFFSET && db_setup.vifcode1().immediate == (Buffer1_Start - Buffer0_Start)); } diff --git a/game/graphics/opengl_renderer/tfrag/Tfrag3.cpp b/game/graphics/opengl_renderer/tfrag/Tfrag3.cpp index 0a44e28a75..d92bf0e0bc 100644 --- a/game/graphics/opengl_renderer/tfrag/Tfrag3.cpp +++ b/game/graphics/opengl_renderer/tfrag/Tfrag3.cpp @@ -131,7 +131,7 @@ bool Tfrag3::update_load(const std::vector& tree_kind m_cache.vis_temp.resize(vis_temp_len); m_cache.draw_idx_temp.resize(max_draw); - assert(time_of_day_count <= TIME_OF_DAY_COLOR_COUNT); + ASSERT(time_of_day_count <= TIME_OF_DAY_COLOR_COUNT); m_load_state.state = UPLOAD_VERTS; m_load_state.vert = 0; } break; @@ -164,7 +164,7 @@ bool Tfrag3::update_load(const std::vector& tree_kind } } break; default: - assert(false); + ASSERT(false); } return false; @@ -218,7 +218,7 @@ void Tfrag3::render_tree(const TfragRenderSettings& settings, return; } auto& tree = m_cached_trees.at(settings.tree_idx); - assert(tree.kind != tfrag3::TFragmentTreeKind::INVALID); + ASSERT(tree.kind != tfrag3::TFragmentTreeKind::INVALID); if (m_color_result.size() < tree.colors->size()) { m_color_result.resize(tree.colors->size()); @@ -285,7 +285,7 @@ void Tfrag3::render_tree(const TfragRenderSettings& settings, glDrawElements(GL_TRIANGLE_STRIP, draw_size, GL_UNSIGNED_INT, (void*)offset); break; default: - assert(false); + ASSERT(false); } } glBindVertexArray(0); @@ -402,7 +402,7 @@ void debug_vis_draw(int first_root, std::vector& verts_out) { for (int ki = 0; ki < num; ki++) { auto& node = nodes.at(ki + tree - first_root); - assert(node.child_id != 0xffff); + ASSERT(node.child_id != 0xffff); math::Vector4f rgba{frac(0.4 * depth), frac(0.7 * depth), frac(0.2 * depth), 0.06}; math::Vector3f center = node.bsphere.xyz(); float rad = node.bsphere.w(); diff --git a/game/graphics/opengl_renderer/tfrag/Tie3.cpp b/game/graphics/opengl_renderer/tfrag/Tie3.cpp index d92d398ad6..ea1c2bd20d 100644 --- a/game/graphics/opengl_renderer/tfrag/Tie3.cpp +++ b/game/graphics/opengl_renderer/tfrag/Tie3.cpp @@ -140,7 +140,7 @@ bool Tie3::update_load(const tfrag3::Level* lev_data) { fmt::print("wind: {}\n", max_wind_idx); m_wind_vectors.resize(4 * max_wind_idx + 4); // 4x u32's per wind. fmt::print("level max time of day: {}\n", time_of_day_count); - assert(time_of_day_count <= TIME_OF_DAY_COLOR_COUNT); + ASSERT(time_of_day_count <= TIME_OF_DAY_COLOR_COUNT); } m_load_state.state = UPLOAD_VERTS; m_load_state.vert = 0; @@ -172,7 +172,7 @@ bool Tie3::update_load(const tfrag3::Level* lev_data) { } break; default: - assert(false); + ASSERT(false); } return false; @@ -358,41 +358,41 @@ void Tie3::render(DmaFollower& dma, SharedRenderState* render_state, ScopedProfi } auto data0 = dma.read_and_advance(); - assert(data0.vif1() == 0); - assert(data0.vif0() == 0); - assert(data0.size_bytes == 0); + ASSERT(data0.vif1() == 0); + ASSERT(data0.vif0() == 0); + ASSERT(data0.size_bytes == 0); if (dma.current_tag().kind == DmaTag::Kind::CALL) { // renderer didn't run, let's just get out of here. for (int i = 0; i < 4; i++) { dma.read_and_advance(); } - assert(dma.current_tag_offset() == render_state->next_bucket); + ASSERT(dma.current_tag_offset() == render_state->next_bucket); return; } auto gs_test = dma.read_and_advance(); - assert(gs_test.size_bytes == 32); + ASSERT(gs_test.size_bytes == 32); auto tie_consts = dma.read_and_advance(); - assert(tie_consts.size_bytes == 9 * 16); + ASSERT(tie_consts.size_bytes == 9 * 16); auto mscalf = dma.read_and_advance(); - assert(mscalf.size_bytes == 0); + ASSERT(mscalf.size_bytes == 0); auto row = dma.read_and_advance(); - assert(row.size_bytes == 32); + ASSERT(row.size_bytes == 32); auto next = dma.read_and_advance(); - assert(next.size_bytes == 0); + ASSERT(next.size_bytes == 0); auto pc_port_data = dma.read_and_advance(); - assert(pc_port_data.size_bytes == sizeof(TfragPcPortData)); + ASSERT(pc_port_data.size_bytes == sizeof(TfragPcPortData)); memcpy(&m_pc_port_data, pc_port_data.data, sizeof(TfragPcPortData)); m_pc_port_data.level_name[11] = '\0'; auto wind_data = dma.read_and_advance(); - assert(wind_data.size_bytes == sizeof(WindWork)); + ASSERT(wind_data.size_bytes == sizeof(WindWork)); memcpy(&m_wind_data, wind_data.data, sizeof(WindWork)); while (dma.current_tag_offset() != render_state->next_bucket) { @@ -473,7 +473,7 @@ void Tie3::render_tree_wind(int idx, // auto& mat = tree.instance_info->operator[](inst_id).matrix; auto mat = info.matrix; - assert(info.wind_idx * 4 <= m_wind_vectors.size()); + ASSERT(info.wind_idx * 4 <= m_wind_vectors.size()); do_wind_math(info.wind_idx, m_wind_vectors.data(), m_wind_data, info.stiffness * m_wind_multiplier, mat); @@ -553,7 +553,7 @@ void Tie3::render_tree_wind(int idx, (void*)0); break; default: - assert(false); + ASSERT(false); } } } @@ -677,7 +677,7 @@ void Tie3::render_tree(int idx, glDrawElements(GL_TRIANGLE_STRIP, draw_size, GL_UNSIGNED_INT, (void*)offset); break; default: - assert(false); + ASSERT(false); } if (m_debug_wireframe) { diff --git a/game/graphics/opengl_renderer/tfrag/tfrag_common.cpp b/game/graphics/opengl_renderer/tfrag/tfrag_common.cpp index fe82b62153..3a98f17ebc 100644 --- a/game/graphics/opengl_renderer/tfrag/tfrag_common.cpp +++ b/game/graphics/opengl_renderer/tfrag/tfrag_common.cpp @@ -25,7 +25,7 @@ DoubleDraw setup_opengl_from_draw_mode(DrawMode mode, u32 tex_unit, bool mipmap) glDepthFunc(GL_GREATER); break; default: - assert(false); + ASSERT(false); } } else { glDisable(GL_DEPTH_TEST); @@ -51,7 +51,7 @@ DoubleDraw setup_opengl_from_draw_mode(DrawMode mode, u32 tex_unit, bool mipmap) glBlendColor(0.5, 0.5, 0.5, 0.5); break; default: - assert(false); + ASSERT(false); } } else { glDisable(GL_BLEND); @@ -99,18 +99,18 @@ DoubleDraw setup_opengl_from_draw_mode(DrawMode mode, u32 tex_unit, bool mipmap) double_draw.aref_second = alpha_min; break; default: - assert(false); + ASSERT(false); } break; case DrawMode::AlphaTest::NEVER: if (mode.get_alpha_fail() == GsTest::AlphaFail::FB_ONLY) { alpha_hack_to_disable_z_write = true; } else { - assert(false); + ASSERT(false); } break; default: - assert(false); + ASSERT(false); } } diff --git a/game/graphics/sceGraphicsInterface.cpp b/game/graphics/sceGraphicsInterface.cpp index 26b07e1d6f..d291f90b1e 100644 --- a/game/graphics/sceGraphicsInterface.cpp +++ b/game/graphics/sceGraphicsInterface.cpp @@ -1,7 +1,7 @@ #include "game/graphics/sceGraphicsInterface.h" #include "game/graphics/gfx.h" #include -#include "common/util/assert.h" +#include "common/util/Assert.h" /*! * Wait for rendering to complete. @@ -19,7 +19,7 @@ * */ u32 sceGsSyncPath(u32 mode, u32 timeout) { - assert(mode == 0 && timeout == 0); + ASSERT(mode == 0 && timeout == 0); return Gfx::sync_path(); } @@ -27,6 +27,6 @@ u32 sceGsSyncPath(u32 mode, u32 timeout) { * Actual vsync. */ u32 sceGsSyncV(u32 mode) { - assert(mode == 0); + ASSERT(mode == 0); return Gfx::vsync(); } diff --git a/game/graphics/sceGraphicsInterface.h b/game/graphics/sceGraphicsInterface.h index fe3cacf90c..407041a932 100644 --- a/game/graphics/sceGraphicsInterface.h +++ b/game/graphics/sceGraphicsInterface.h @@ -1,7 +1,7 @@ #pragma once #include "common/common_types.h" -#include "common/util/assert.h" +#include "common/util/Assert.h" /*! * @file sceGraphicInterface.h diff --git a/game/graphics/texture/TextureConverter.cpp b/game/graphics/texture/TextureConverter.cpp index 644baf2c34..00db9ca831 100644 --- a/game/graphics/texture/TextureConverter.cpp +++ b/game/graphics/texture/TextureConverter.cpp @@ -2,7 +2,7 @@ #include "third-party/fmt/core.h" #include "common/util/FileUtil.h" #include "common/texture/texture_conversion.h" -#include "common/util/assert.h" +#include "common/util/Assert.h" TextureConverter::TextureConverter() { m_vram.resize(4 * 1024 * 1024); @@ -192,10 +192,10 @@ void TextureConverter::download_rgba8888(u8* result, } else { - assert(false); + ASSERT(false); } - assert(out_offset == expected_size_bytes); + ASSERT(out_offset == expected_size_bytes); } void TextureConverter::serialize(Serializer& ser) { diff --git a/game/graphics/texture/TexturePool.cpp b/game/graphics/texture/TexturePool.cpp index 9672b3be88..d183b095d4 100644 --- a/game/graphics/texture/TexturePool.cpp +++ b/game/graphics/texture/TexturePool.cpp @@ -8,7 +8,7 @@ #include "common/util/Timer.h" #include "common/log/log.h" #include "game/graphics/pipelines/opengl.h" -#include "common/util/assert.h" +#include "common/util/Assert.h" //////////////////////////////// // Extraction of textures @@ -37,7 +37,7 @@ std::string GoalTexturePage::print() const { void TextureRecord::serialize(Serializer& ser) { if (only_on_gpu) { - assert(on_gpu); + ASSERT(on_gpu); if (ser.is_saving()) { // we should download the texture and save it. data.resize(w * h * 4); @@ -130,7 +130,7 @@ void TexturePool::unload_all_textures() { } void TextureRecord::unload_from_gpu() { - assert(on_gpu); + ASSERT(on_gpu); GLuint tex_id = gpu_texture; glBindTexture(GL_TEXTURE_2D, tex_id); glDeleteTextures(1, &tex_id); @@ -310,7 +310,7 @@ void TexturePool::set_texture(u32 location, std::shared_ptr recor */ void TexturePool::relocate(u32 destination, u32 source, u32 format) { auto& src = m_textures.at(source).normal_texture; - assert(src); + ASSERT(src); if (format == 44) { m_textures.at(destination).mt4hh_texture = std::move(src); } else { @@ -389,7 +389,7 @@ void TexturePool::draw_debug_for_tex(const std::string& name, TextureRecord& tex } void TexturePool::upload_to_gpu(TextureRecord* tex) { - assert(!tex->on_gpu); + ASSERT(!tex->on_gpu); GLuint tex_id; glGenTextures(1, &tex_id); tex->gpu_texture = tex_id; @@ -435,7 +435,7 @@ void TexturePool::remove_garbage_textures() { } void TexturePool::discard(std::shared_ptr tex) { - assert(!tex->do_gc); + ASSERT(!tex->do_gc); fmt::print("discard {}\n", tex->name); m_garbage_textures.push_back(tex); } diff --git a/game/kernel/Ptr.h b/game/kernel/Ptr.h index 3883affa72..2e99ae000e 100644 --- a/game/kernel/Ptr.h +++ b/game/kernel/Ptr.h @@ -7,7 +7,7 @@ #include "game/runtime.h" #include "common/common_types.h" -#include "common/util/assert.h" +#include "common/util/Assert.h" /*! * GOAL pointer to a T. Represented as a 32-bit unsigned offset from g_ee_main_mem. @@ -36,7 +36,7 @@ struct Ptr { * Dereference a pointer. Will error if you do this on a null pointer. */ T* operator->() { - assert(offset); + ASSERT(offset); return (T*)(g_ee_main_mem + offset); } @@ -44,7 +44,7 @@ struct Ptr { * Dereference a pointer. Will error if you do this on a null pointer. */ T& operator*() { - assert(offset); + ASSERT(offset); return *(T*)(g_ee_main_mem + offset); } diff --git a/game/kernel/fileio.cpp b/game/kernel/fileio.cpp index a0c44ba144..ff22618798 100644 --- a/game/kernel/fileio.cpp +++ b/game/kernel/fileio.cpp @@ -10,7 +10,7 @@ #include "fileio.h" #include "kprint.h" #include "common/versions.h" -#include "common/util/assert.h" +#include "common/util/Assert.h" namespace { // buffer for file paths. This might be static char buffer[512]. Maybe 633 is the line number? @@ -66,7 +66,7 @@ u32 ReadHufWord(u8** loc_ptr) { break; default: - assert(false); + ASSERT(false); } // update location pointer diff --git a/game/kernel/kdsnetm.cpp b/game/kernel/kdsnetm.cpp index 77bcfaf84a..eacc7de04f 100644 --- a/game/kernel/kdsnetm.cpp +++ b/game/kernel/kdsnetm.cpp @@ -10,7 +10,7 @@ #include "game/system/deci_common.h" // todo, reorganize to avoid this include #include "kdsnetm.h" #include "kprint.h" -#include "common/util/assert.h" +#include "common/util/Assert.h" using namespace ee; @@ -115,7 +115,7 @@ void GoalProtoHandler(int event, int param, void* opt) { case DECI2_WRITE: { // note that we should not attempt to send more than 0xffff bytes at a time, or this will be // wrong. This is correctly checked for prints, but not for outputs. - assert(pb->send_remaining < 0xffff); + ASSERT(pb->send_remaining < 0xffff); // why and it with 0xffff? Seems like saturation would be better. Either way some data // will be lost, so I guess it doesn't matter. s32 sent = sceDeci2ExSend(pb->socket, (void*)pb->send_ptr, pb->send_remaining & 0xffff); diff --git a/game/kernel/klink.cpp b/game/kernel/klink.cpp index 4306b84d2a..fe4b307ac7 100644 --- a/game/kernel/klink.cpp +++ b/game/kernel/klink.cpp @@ -17,7 +17,7 @@ #include "common/symbols.h" #include "common/goal_constants.h" #include "game/mips2c/mips2c_table.h" -#include "common/util/assert.h" +#include "common/util/Assert.h" namespace { // turn on printf's for debugging linking issues. @@ -83,7 +83,7 @@ void link_control::begin(Ptr object_file, "VERSION ERROR: C Kernel built from GOAL %d.%d, but object file %s is from GOAL %d.%d\n", versions::GOAL_VERSION_MAJOR, versions::GOAL_VERSION_MINOR, name, ofh->goal_version_major, ofh->goal_version_minor); - assert(false); + ASSERT(false); } if (link_debug_printfs) { printf("Object file header:\n"); @@ -144,7 +144,7 @@ void link_control::begin(Ptr object_file, } } else { printf("UNHANDLED OBJECT FILE VERSION\n"); - assert(false); + ASSERT(false); } if ((m_flags & LINK_FLAG_FORCE_DEBUG) && MasterDebug && !DiskBoot) { @@ -248,14 +248,14 @@ uint32_t link_control::work() { uint32_t rv; if (m_version == 3) { - assert(m_opengoal); + ASSERT(m_opengoal); rv = work_v3(); } else if (m_version == 2 || m_version == 4) { - assert(!m_opengoal); + ASSERT(!m_opengoal); rv = work_v2(); } else { printf("UNHANDLED OBJECT FILE VERSION %d IN WORK!\n", m_version); - assert(false); + ASSERT(false); return 0; } @@ -274,7 +274,7 @@ uint32_t typelink_v3(Ptr link, Ptr data) { while (link.c()[seek]) { sym_name[seek] = link.c()[seek]; seek++; - assert(seek < 256); + ASSERT(seek < 256); } sym_name[seek] = 0; seek++; @@ -311,7 +311,7 @@ uint32_t symlink_v3(Ptr link, Ptr data) { while (link.c()[seek]) { sym_name[seek] = link.c()[seek]; seek++; - assert(seek < 256); + ASSERT(seek < 256); } sym_name[seek] = 0; seek++; @@ -353,7 +353,7 @@ uint32_t cross_seg_dist_link_v3(Ptr link, int size) { // target seg, dist into mine, dist into target, patch loc in mine uint8_t target_seg = *link; - assert(target_seg < ofh->segment_count); + ASSERT(target_seg < ofh->segment_count); uint32_t* link_data = (link + 1).cast().c(); int32_t mine = link_data[0] + ofh->code_infos[current_seg].offset; @@ -378,7 +378,7 @@ uint32_t cross_seg_dist_link_v3(Ptr link, } else if (size == 8) { *Ptr(offset_of_patch).c() = diff; } else { - assert(false); + ASSERT(false); } return 1 + 3 * 4; @@ -503,7 +503,7 @@ uint32_t link_control::work_v3() { break; default: printf("unknown link table thing %d\n", *lp); - assert(false); + ASSERT(false); break; } } @@ -554,7 +554,7 @@ Ptr c_symlink2(Ptr objData, Ptr linkObj, Ptr relocTable) { *(objPtr.cast()) = linkObj.offset; } else { // I don't think we should hit this ever. - assert(false); + ASSERT(false); } } while (*relocPtr); @@ -581,7 +581,7 @@ uint32_t link_control::work_v2() { m_heap_gap = m_object_data - m_heap->current; // distance between end of heap and start of object if (m_object_data.offset < m_heap->current.offset) { - assert(false); + ASSERT(false); } } @@ -677,7 +677,7 @@ uint32_t link_control::work_v2() { } else { // offset mode for (u32 i = 0; i < count; i++) { if (m_loc_ptr.offset % 4) { - assert(false); + ASSERT(false); } u32 code = *(m_loc_ptr.cast()); code += m_base_ptr.offset; diff --git a/game/kernel/kmachine.cpp b/game/kernel/kmachine.cpp index aa3cce78df..38d4202f25 100644 --- a/game/kernel/kmachine.cpp +++ b/game/kernel/kmachine.cpp @@ -37,7 +37,7 @@ #include "game/system/vm/vm.h" #include "game/system/newpad.h" #include "game/sce/libscf.h" -#include "common/util/assert.h" +#include "common/util/Assert.h" #include "game/discord.h" using namespace ee; @@ -537,12 +537,12 @@ u64 CPadGetData(u64 cpad_info) { // TODO InstallHandler void InstallHandler(u32 handler_idx, u32 handler_func) { - assert(handler_idx == 5); // vif1 + ASSERT(handler_idx == 5); // vif1 vif1_interrupt_handler = handler_func; } // TODO InstallDebugHandler void InstallDebugHandler() { - assert(false); + ASSERT(false); } void send_gfx_dma_chain(u32 /*bank*/, u32 chain) { @@ -665,7 +665,7 @@ u64 kclose(u64 fs) { // TODO dma_to_iop void dma_to_iop() { - assert(false); + ASSERT(false); } u64 DecodeLanguage() { @@ -701,7 +701,7 @@ void DecodeTime(u32 ptr) { // TODO PutDisplayEnv void PutDisplayEnv() { - // assert(false); + // ASSERT(false); } /*! diff --git a/game/kernel/kmemcard.cpp b/game/kernel/kmemcard.cpp index 2526335cc6..8c9ea62698 100644 --- a/game/kernel/kmemcard.cpp +++ b/game/kernel/kmemcard.cpp @@ -14,7 +14,7 @@ #include "game/kernel/kdgo.h" #include "game/common/ramdisk_rpc_types.h" #include "game/kernel/fileio.h" -#include "common/util/assert.h" +#include "common/util/Assert.h" constexpr static bool memcard_debug = false; diff --git a/game/kernel/kprint.cpp b/game/kernel/kprint.cpp index 9f9ce2337e..6f98418d1d 100644 --- a/game/kernel/kprint.cpp +++ b/game/kernel/kprint.cpp @@ -22,7 +22,7 @@ #include "klisten.h" #include "klink.h" #include "common/symbols.h" -#include "common/util/assert.h" +#include "common/util/Assert.h" /////////// // SDATA @@ -356,7 +356,7 @@ s32 cvt_float(float x, s32 precision, s32* lead_char, char* buff_start, char* bu value = (char)rounder; } else if (!(ru32 >> 31)) { // sign bit value = 0; - // assert(false); // not sure what happens here. + // ASSERT(false); // not sure what happens here. } else { value = -1; // happens on NaN's } @@ -403,7 +403,7 @@ s32 cvt_float(float x, s32 precision, s32* lead_char, char* buff_start, char* bu value = (char)next_int; } else if (!(ru32 >> 0x1f)) { value = 0; - // assert(false); // not sure what happens here. + // ASSERT(false); // not sure what happens here. } else { value = -1; // happens on NaN's } @@ -417,7 +417,7 @@ s32 cvt_float(float x, s32 precision, s32* lead_char, char* buff_start, char* bu // however, the rounding flag is always disabled and the rounding code doesn't work. if ((fraction_part != 0.f) && ((flags & 1) != 0)) { start_ptr = round(fraction_part, nullptr, start_ptr, count_chrp - 1, 0, lead_char); - assert(false); + ASSERT(false); } } @@ -569,7 +569,7 @@ char* kitoa(char* buffer, s64 value, u64 base, s32 length, char pad, u32 flag) { * uses C varags, but 128-bit varags don't work, so "format" always passes 0 for quadword printing. */ void kqtoa() { - assert(false); + ASSERT(false); } struct format_struct { @@ -807,7 +807,7 @@ s32 format_impl(uint64_t* args) { } kstrinsert(output_ptr, pad, desired_length - print_len); } else { - assert(false); + ASSERT(false); // output_ptr = strend(output_ptr); // while(0 < (desired_length - print_len)) { // char pad = ' '; @@ -858,7 +858,7 @@ s32 format_impl(uint64_t* args) { kstrinsert(output_ptr, pad, desired_length - print_len); } else { - assert(false); + ASSERT(false); // output_ptr = strend(output_ptr); // u32 l140 = 0; // while(l140 < (desired_length - print_len)) { @@ -899,7 +899,7 @@ s32 format_impl(uint64_t* args) { call_method_of_type(in, type, GOAL_PRINT_METHOD); } } else { - assert(false); // bad type. + ASSERT(false); // bad type. } } output_ptr = strend(output_ptr); @@ -920,7 +920,7 @@ s32 format_impl(uint64_t* args) { call_method_of_type(in, type, GOAL_INSPECT_METHOD); } } else { - assert(false); // bad type + ASSERT(false); // bad type } } output_ptr = strend(output_ptr); @@ -928,7 +928,7 @@ s32 format_impl(uint64_t* args) { case 'Q': // not yet implemented. hopefully andy gavin finishes this one soon. case 'q': - assert(false); + ASSERT(false); break; case 'X': // hex, 64 bit, pad padchar @@ -1025,7 +1025,7 @@ s32 format_impl(uint64_t* args) { precision = 4; float value; if (in < 0) { - assert(false); // i don't get this one + ASSERT(false); // i don't get this one } else { value = in; } @@ -1041,7 +1041,7 @@ s32 format_impl(uint64_t* args) { default: MsgErr("format: unknown code 0x%02x\n", format_ptr[1]); - assert(false); + ASSERT(false); break; } format_ptr++; @@ -1092,10 +1092,10 @@ s32 format_impl(uint64_t* args) { return 0; } } - assert(false); // unknown destination + ASSERT(false); // unknown destination return 0; } - assert(false); // ?????? + ASSERT(false); // ?????? return 7; } diff --git a/game/kernel/kscheme.cpp b/game/kernel/kscheme.cpp index 029f6f647e..4dc4fc1b44 100644 --- a/game/kernel/kscheme.cpp +++ b/game/kernel/kscheme.cpp @@ -23,7 +23,7 @@ #include "common/log/log.h" #include "common/util/Timer.h" #include "game/mips2c/mips2c_table.h" -#include "common/util/assert.h" +#include "common/util/Assert.h" //! Controls link mode when EnableMethodSet = 0, MasterDebug = 1, DiskBoot = 0. Will enable a //! warning message if EnableMethodSet = 1 @@ -88,7 +88,7 @@ u32 crc32(const u8* data, s32 size) { if ((~crc) == 0) { // if this happens, I think the hash table implementation breaks. - assert(false); + ASSERT(false); } return ~crc; } @@ -132,7 +132,7 @@ u64 goal_malloc(u32 heap, u32 size, u32 flags, u32 name) { * UNKNOWN_PROCESS (UINT32_MAX). */ u64 alloc_from_heap(u32 heapSymbol, u32 type, s32 size, u32 pp) { - assert(size > 0); + ASSERT(size > 0); // align to 16 bytes (part one) s32 alignedSize = size + 0xf; @@ -174,13 +174,13 @@ u64 alloc_from_heap(u32 heapSymbol, u32 type, s32 size, u32 pp) { MsgErr( "Attempted to do a process allocation, but pp was UNKNOWN_PP. This is not yet supported " "by kscheme.cpp.\n"); - assert(false); + ASSERT(false); } if (pp == 0) { // added MsgErr("Attempted to do a process allocation, but pp was 0.\n"); - assert(false); + ASSERT(false); } // allocate on current process heap @@ -198,7 +198,7 @@ u64 alloc_from_heap(u32 heapSymbol, u32 type, s32 size, u32 pp) { return 0; } } else if (heapOffset == FIX_SYM_SCRATCH) { - assert(false); // nyi, I think unused. + ASSERT(false); // nyi, I think unused. return 0; } else { memset(Ptr(heapSymbol).c(), 0, (size_t)alignedSize); // treat it as a stack address @@ -844,7 +844,7 @@ Ptr intern_type_from_c(const char* name, u64 methods) { "dkernel: trying to redefine a type '%s' with %d methods when it had %d, try " "restarting\n", name, (u32)methods, type->num_methods); - assert(false); + ASSERT(false); } return type; } @@ -929,7 +929,7 @@ u64 new_type(u32 symbol, u32 parent, u64 flags) { n_methods = DEFAULT_METHOD_COUNT; } - assert(n_methods < 127); // will cause issues. + ASSERT(n_methods < 127); // will cause issues. auto new_type = Ptr(intern_type(info(Ptr(symbol))->str.offset, n_methods)); @@ -940,7 +940,7 @@ u64 new_type(u32 symbol, u32 parent, u64 flags) { // printf("%s %d %d\n", info(Ptr(symbol))->str.c()->data(), // Ptr(parent)->num_methods, // n_methods); - // assert(false); + // ASSERT(false); // } // BUG! This uses the child method count, but should probably use the parent method count. @@ -1213,7 +1213,7 @@ u64 call_method_of_type_arg2(u32 arg, Ptr type, u32 method_id, u32 a1, u32 } } printf("[ERROR] call_method_of_type_arg2 failed!\n"); - assert(false); + ASSERT(false); return arg; } diff --git a/game/mips2c/functions/collide_cache.cpp b/game/mips2c/functions/collide_cache.cpp index a6fda43c0f..6b27e26c77 100644 --- a/game/mips2c/functions/collide_cache.cpp +++ b/game/mips2c/functions/collide_cache.cpp @@ -34,8 +34,8 @@ u64 execute(void* ctxt) { int qw_to_write = c->sgpr64(a2); const u16* data_in = (const u16*)(g_ee_main_mem + c->sgpr64(a0)); // I don't quite get why this is wrong sometimes. - // assert(qw_to_write * 3 == qw_in_source * 8); - assert(qw_to_write <= 128); + // ASSERT(qw_to_write * 3 == qw_in_source * 8); + ASSERT(qw_to_write <= 128); int in_idx = 0; int out_idx = 0; @@ -96,7 +96,7 @@ u64 execute(void* ctxt) { c->vfs[vf13].du32[3] = 0; c->vmove(DEST::xyzw, vf2, vf0); // vmove.xyzw vf2, vf0 c->lbu(a0, 24, a1); // lbu a0, 24(a1) - assert(c->sgpr64(a3) == 0); + ASSERT(c->sgpr64(a3) == 0); vi1 = 0; // Unknown instr: ctc2.i vi1, a3 c->vmove(DEST::xyzw, vf3, vf0); // vmove.xyzw vf3, vf0 @@ -409,7 +409,7 @@ u64 execute(void* ctxt) { c->vmove(DEST::xyzw, vf2, vf0); // vmove.xyzw vf2, vf0 c->lbu(a0, 24, a1); // lbu a0, 24(a1) // Unknown instr: ctc2.i vi1, a3 - assert(c->sgpr64(a3) == 0); + ASSERT(c->sgpr64(a3) == 0); vi1 = c->sgpr64(a3); c->vmove(DEST::xyzw, vf3, vf0); // vmove.xyzw vf3, vf0 c->vitof0(DEST::xyzw, vf14, vf14); // vitof0.xyzw vf14, vf14 diff --git a/game/mips2c/functions/joint.cpp b/game/mips2c/functions/joint.cpp index 3e8217e994..bc7f0e0266 100644 --- a/game/mips2c/functions/joint.cpp +++ b/game/mips2c/functions/joint.cpp @@ -165,7 +165,7 @@ u64 execute(void* ctxt) { // nop // sll r0, r0, 0 // nop // sll r0, r0, 0 next_block = 0x4d7666d9 ^ c->gprs[t3].du32[0]; // jr t3 - assert(next_block < 33); + ASSERT(next_block < 33); break; // nop // sll r0, r0, 0 @@ -936,7 +936,7 @@ u64 execute(void* ctxt) { // nop // sll r0, r0, 0 // nop // sll r0, r0, 0 next_block = 0x7b2191d ^ c->gprs[t3].du32[0]; // jr t3 - assert(next_block < 33); + ASSERT(next_block < 33); break; // nop // sll r0, r0, 0 @@ -1552,7 +1552,7 @@ u64 execute(void* ctxt) { // nop // sll r0, r0, 0 // nop // sll r0, r0, 0 next_block = 0x3ee6b6f0 ^ c->gprs[t3].du32[0]; // jr t3 - assert(next_block < 33); + ASSERT(next_block < 33); break; // nop // sll r0, r0, 0 diff --git a/game/mips2c/mips2c_private.h b/game/mips2c/mips2c_private.h index 2d659eb308..6799108626 100644 --- a/game/mips2c/mips2c_private.h +++ b/game/mips2c/mips2c_private.h @@ -7,7 +7,7 @@ #include "game/mips2c/mips2c_table.h" #include "common/util/BitUtils.h" #include "third-party/fmt/core.h" -#include "common/util/assert.h" +#include "common/util/Assert.h" #include "common/dma/dma.h" // This file contains utility functions for code generated by the mips2c pass. @@ -307,13 +307,13 @@ struct ExecutionContext { void sq(int src, int offset, int addr) { auto s = gpr_src(src); - assert((offset & 15) == 0); + ASSERT((offset & 15) == 0); memcpy(g_ee_main_mem + gpr_addr(addr) + offset, &s.du32[0], 16); } void sqc2(int src, int offset, int addr) { auto s = vf_src(src); - assert(((gpr_addr(addr) + offset) & 0xf) == 0); + ASSERT(((gpr_addr(addr) + offset) & 0xf) == 0); memcpy(g_ee_main_mem + gpr_addr(addr) + offset, &s.du32[0], 16); } @@ -486,7 +486,7 @@ struct ExecutionContext { } void pmulth(int rd, int rs, int rt) { - // assert(rd == 0); + // ASSERT(rd == 0); s32 temp; auto s = gpr_src(rs); @@ -1060,7 +1060,7 @@ struct ExecutionContext { void adds(int dst, int src0, int src1) { fprs[dst] = fprs[src0] + fprs[src1]; } void subs(int dst, int src0, int src1) { fprs[dst] = fprs[src0] - fprs[src1]; } void divs(int dst, int src0, int src1) { - // assert(fprs[src1] != 0); + // ASSERT(fprs[src1] != 0); fprs[dst] = fprs[src0] / fprs[src1]; } void negs(int dst, int src) { @@ -1125,11 +1125,11 @@ inline void spad_to_dma(void* spad_sym_addr, u32 madr, u32 sadr, u32 qwc) { memcpy(&spad_addr_goal, spad_sym_addr, 4); sadr -= spad_addr_goal; - assert((madr & 0xf) == 0); - assert((sadr & 0xf) == 0); - assert(sadr < 0x4000); - assert((sadr + 16 * qwc) <= 0x4000); - assert(qwc <= 0x4000); + ASSERT((madr & 0xf) == 0); + ASSERT((sadr & 0xf) == 0); + ASSERT(sadr < 0x4000); + ASSERT((sadr + 16 * qwc) <= 0x4000); + ASSERT(qwc <= 0x4000); void* spad_addr_c = g_ee_main_mem + spad_addr_goal + sadr; @@ -1140,11 +1140,11 @@ inline void spad_to_dma_no_sadr_off(void* spad_sym_addr, u32 madr, u32 sadr, u32 u32 spad_addr_goal; memcpy(&spad_addr_goal, spad_sym_addr, 4); - assert((madr & 0xf) == 0); - assert((sadr & 0xf) == 0); - assert(sadr < 0x4000); - assert((sadr + 16 * qwc) <= 0x4000); - assert(qwc <= 0x4000); + ASSERT((madr & 0xf) == 0); + ASSERT((sadr & 0xf) == 0); + ASSERT(sadr < 0x4000); + ASSERT((sadr + 16 * qwc) <= 0x4000); + ASSERT(qwc <= 0x4000); void* spad_addr_c = g_ee_main_mem + spad_addr_goal + sadr; @@ -1158,15 +1158,15 @@ inline void spad_to_dma_no_sadr_off_bones_interleave(void* spad_sym_addr, u32 spad_addr_goal; memcpy(&spad_addr_goal, spad_sym_addr, 4); - assert((madr & 0xf) == 0); - assert((sadr & 0xf) == 0); - assert(sadr < 0x4000); - assert((sadr + 16 * qwc) <= 0x4000); - assert(qwc <= 0x4000); + ASSERT((madr & 0xf) == 0); + ASSERT((sadr & 0xf) == 0); + ASSERT(sadr < 0x4000); + ASSERT((sadr + 16 * qwc) <= 0x4000); + ASSERT(qwc <= 0x4000); u8* spad_addr_c = g_ee_main_mem + spad_addr_goal + sadr; const u8* mem_addr = g_ee_main_mem + madr; - assert((qwc & 3) == 0); + ASSERT((qwc & 3) == 0); while (qwc > 0) { // transfer 4. memcpy(spad_addr_c, mem_addr, 4 * 16); @@ -1182,11 +1182,11 @@ inline void spad_from_dma(void* spad_sym_addr, u32 madr, u32 sadr, u32 qwc) { u32 spad_addr_goal; memcpy(&spad_addr_goal, spad_sym_addr, 4); sadr -= spad_addr_goal; - assert((madr & 0xf) == 0); - assert((sadr & 0xf) == 0); - assert(sadr < 0x4000); - assert((sadr + 16 * qwc) <= 0x4000); - assert(qwc <= 0x4000); + ASSERT((madr & 0xf) == 0); + ASSERT((sadr & 0xf) == 0); + ASSERT(sadr < 0x4000); + ASSERT((sadr + 16 * qwc) <= 0x4000); + ASSERT(qwc <= 0x4000); void* spad_addr_c = g_ee_main_mem + spad_addr_goal + sadr; @@ -1196,11 +1196,11 @@ inline void spad_from_dma(void* spad_sym_addr, u32 madr, u32 sadr, u32 qwc) { inline void spad_from_dma_no_sadr_off(void* spad_sym_addr, u32 madr, u32 sadr, u32 qwc) { u32 spad_addr_goal; memcpy(&spad_addr_goal, spad_sym_addr, 4); - assert((madr & 0xf) == 0); - assert((sadr & 0xf) == 0); - assert(sadr < 0x4000); - assert((sadr + 16 * qwc) <= 0x4000); - assert(qwc <= 0x4000); + ASSERT((madr & 0xf) == 0); + ASSERT((sadr & 0xf) == 0); + ASSERT(sadr < 0x4000); + ASSERT((sadr + 16 * qwc) <= 0x4000); + ASSERT(qwc <= 0x4000); void* spad_addr_c = g_ee_main_mem + spad_addr_goal + sadr; diff --git a/game/mips2c/mips2c_table.cpp b/game/mips2c/mips2c_table.cpp index a9f8bce0eb..1dcacc92e6 100644 --- a/game/mips2c/mips2c_table.cpp +++ b/game/mips2c/mips2c_table.cpp @@ -324,7 +324,7 @@ void LinkedFunctionTable::reg(const std::string& name, u64 (*exec)(void*), u32 s u32 LinkedFunctionTable::get(const std::string& name) { auto it = m_executes.find(name); if (it == m_executes.end()) { - assert(false); + ASSERT(false); } return it->second.goal_trampoline.offset; } diff --git a/game/mips2c/mips2c_table.h b/game/mips2c/mips2c_table.h index 6d74893bd8..b2cb64fe82 100644 --- a/game/mips2c/mips2c_table.h +++ b/game/mips2c/mips2c_table.h @@ -8,7 +8,7 @@ #include "game/kernel/Ptr.h" #include "common/common_types.h" -#include "common/util/assert.h" +#include "common/util/Assert.h" namespace Mips2C { diff --git a/game/overlord/fake_iso.cpp b/game/overlord/fake_iso.cpp index e21b11664e..48ba13ac50 100644 --- a/game/overlord/fake_iso.cpp +++ b/game/overlord/fake_iso.cpp @@ -17,7 +17,7 @@ #include "overlord.h" #include "common/util/FileUtil.h" #include "common/log/log.h" -#include "common/util/assert.h" +#include "common/util/Assert.h" using namespace iop; @@ -82,10 +82,10 @@ int FS_Init(u8* buffer) { for (const auto& f : std::filesystem::directory_iterator(file_util::get_file_path({"out/iso"}))) { if (f.is_regular_file()) { - assert(fake_iso_entry_count < MAX_ISO_FILES); + ASSERT(fake_iso_entry_count < MAX_ISO_FILES); FakeIsoEntry* e = &fake_iso_entries[fake_iso_entry_count]; std::string file_name = f.path().filename().string(); - assert(file_name.length() < 16); // should be 8.3. + ASSERT(file_name.length() < 16); // should be 8.3. strcpy(e->iso_name, file_name.c_str()); strcpy(e->file_path, fmt::format("out/iso/{}", file_name).c_str()); fake_iso_entry_count++; @@ -140,7 +140,7 @@ FileRecord* FS_FindIN(const char* iso_name) { * Build a full file path for a FileRecord. */ static const char* get_file_path(FileRecord* fr) { - assert(fr->location < fake_iso_entry_count); + ASSERT(fr->location < fake_iso_entry_count); static char path_buffer[1024]; strcpy(path_buffer, file_util::get_project_path().c_str()); strcat(path_buffer, "/"); @@ -156,7 +156,7 @@ uint32_t FS_GetLength(FileRecord* fr) { const char* path = get_file_path(fr); file_util::assert_file_exists(path, "fake_iso FS_GetLength"); FILE* fp = fopen(path, "rb"); - assert(fp); + ASSERT(fp); fseek(fp, 0, SEEK_END); uint32_t len = ftell(fp); rewind(fp); @@ -229,7 +229,7 @@ void FS_Close(LoadStackEntry* fd) { * Idea: do the fopen in FS_Open and keep the file open? It would be faster. */ uint32_t FS_BeginRead(LoadStackEntry* fd, void* buffer, int32_t len) { - assert(fd->fr->location < fake_iso_entry_count); + ASSERT(fd->fr->location < fake_iso_entry_count); int32_t real_size = len; if (len < 0) { @@ -247,7 +247,7 @@ uint32_t FS_BeginRead(LoadStackEntry* fd, void* buffer, int32_t len) { if (!fp) { lg::error("[OVERLORD] fake iso could not open the file \"{}\"", path); } - assert(fp); + ASSERT(fp); fseek(fp, 0, SEEK_END); uint32_t file_len = ftell(fp); rewind(fp); @@ -262,7 +262,7 @@ uint32_t FS_BeginRead(LoadStackEntry* fd, void* buffer, int32_t len) { } if (fread(buffer, real_size, 1, fp) != 1) { - assert(false); + ASSERT(false); } } @@ -300,7 +300,7 @@ void FS_PollDrive() {} uint32_t FS_LoadMusic(char* name, void* buffer) { (void)name; (void)buffer; - assert(false); + ASSERT(false); return 0; } @@ -308,6 +308,6 @@ uint32_t FS_LoadMusic(char* name, void* buffer) { uint32_t FS_LoadSoundBank(char* name, void* buffer) { (void)name; (void)buffer; - assert(false); + ASSERT(false); return 0; } diff --git a/game/overlord/iso.cpp b/game/overlord/iso.cpp index 80e1d51da2..8faa776514 100644 --- a/game/overlord/iso.cpp +++ b/game/overlord/iso.cpp @@ -16,7 +16,7 @@ #include "dma.h" #include "fake_iso.h" #include "game/common/dgo_rpc_types.h" -#include "common/util/assert.h" +#include "common/util/Assert.h" using namespace iop; @@ -323,7 +323,7 @@ u32 ISOThread() { if (load_single_cmd->length_to_copy == 0) { // if we get zero for some reason, use the commanded length. - assert(false); + ASSERT(false); load_single_cmd->length_to_copy = load_single_cmd->length; } else if (load_single_cmd->length < load_single_cmd->length_to_copy) { // if we ask for less than the full length, use the smaller value. @@ -780,7 +780,7 @@ u32 bswap(u32 in) { u32 ProcessVAGData(IsoMessage* _cmd, IsoBufferHeader* buffer_header) { (void)_cmd; (void)buffer_header; - assert(false); + ASSERT(false); return 0; } diff --git a/game/overlord/iso_api.cpp b/game/overlord/iso_api.cpp index d1b19c3c2b..2949669e02 100644 --- a/game/overlord/iso_api.cpp +++ b/game/overlord/iso_api.cpp @@ -2,7 +2,7 @@ #include "game/sce/iop.h" #include "common/log/log.h" #include "sbank.h" -#include "common/util/assert.h" +#include "common/util/Assert.h" using namespace iop; @@ -74,7 +74,7 @@ s32 LoadISOFileChunkToEE(FileRecord* file, uint32_t dest_addr, uint32_t length, */ void LoadSoundBank(const char* bank_name, SoundBank* bank) { (void)bank; - assert(strlen(bank_name) < 16); + ASSERT(strlen(bank_name) < 16); SoundBankLoadCommand cmd; cmd.cmd_id = LOAD_SOUND_BANK; cmd.messagebox_to_reply = 0; diff --git a/game/overlord/iso_queue.cpp b/game/overlord/iso_queue.cpp index d1bd2da27d..d23239b831 100644 --- a/game/overlord/iso_queue.cpp +++ b/game/overlord/iso_queue.cpp @@ -4,7 +4,7 @@ #include "game/sce/iop.h" #include "iso_queue.h" #include "isocommon.h" -#include "common/util/assert.h" +#include "common/util/Assert.h" using namespace iop; @@ -212,7 +212,7 @@ void UnqueueMessage(IsoMessage* cmd) { lg::warn("[OVERLORD ISO QUEUE] Failed to unqueue!"); found: - assert(gPriStack[pri].cmds[idx] == cmd); + ASSERT(gPriStack[pri].cmds[idx] == cmd); // pop gPriStack[pri].n--; diff --git a/game/overlord/isocommon.cpp b/game/overlord/isocommon.cpp index 2e2911d048..07399584eb 100644 --- a/game/overlord/isocommon.cpp +++ b/game/overlord/isocommon.cpp @@ -6,7 +6,7 @@ #include "common/common_types.h" #include #include "isocommon.h" -#include "common/util/assert.h" +#include "common/util/Assert.h" /*! * Convert file name to "ISO Name" diff --git a/game/overlord/ramdisk.cpp b/game/overlord/ramdisk.cpp index c3a7794c69..2697e3c1b8 100644 --- a/game/overlord/ramdisk.cpp +++ b/game/overlord/ramdisk.cpp @@ -12,7 +12,7 @@ #include "iso.h" #include "iso_api.h" #include "game/sce/iop.h" -#include "common/util/assert.h" +#include "common/util/Assert.h" // Note - the RAMDISK code supports having multiple files, but it appears only one file can ever be // used at a time. @@ -130,7 +130,7 @@ void* RPC_Ramdisk(unsigned int fno, void* data, int size) { if ((file_length + gMemUsed <= gMemSize) && (gNumFiles != RAMDISK_MAX_FILES)) { // Create the new file record gFiles[gNumFiles].size = (file_length + 0xf) & 0xfffffff0; - assert(gFiles[gNumFiles].size + gMemUsed < + ASSERT(gFiles[gNumFiles].size + gMemUsed < gMemSize); // ADDED! this checks for a real bug in the code. gFiles[gNumFiles].additional_offset = 0; gFiles[gNumFiles].file_id = cmd->file_id_or_ee_addr; diff --git a/game/overlord/soundcommon.cpp b/game/overlord/soundcommon.cpp index 11456cd27c..a61feb2a96 100644 --- a/game/overlord/soundcommon.cpp +++ b/game/overlord/soundcommon.cpp @@ -1,7 +1,7 @@ #include "soundcommon.h" -#include "common/util/assert.h" +#include "common/util/Assert.h" void PrintBankInfo(void* buffer) { (void)buffer; - assert(false); + ASSERT(false); } diff --git a/game/overlord/srpc.cpp b/game/overlord/srpc.cpp index 78d8308658..9be87796a8 100644 --- a/game/overlord/srpc.cpp +++ b/game/overlord/srpc.cpp @@ -7,7 +7,7 @@ #include "common/versions.h" #include "sbank.h" #include "iso_api.h" -#include "common/util/assert.h" +#include "common/util/Assert.h" using namespace iop; @@ -55,7 +55,7 @@ void* RPC_Loader(unsigned int /*fno*/, void* data, int size) { if (gSoundEnable) { // I don't think it should be possible to have > 1 message here - the buffer isn't big enough. if (n_messages > 1) { - assert(false); + ASSERT(false); } while (n_messages > 0) { switch (cmd->command) { @@ -93,7 +93,7 @@ void* RPC_Loader(unsigned int /*fno*/, void* data, int size) { break; default: printf("Unhandled RPC Loader command %d\n", (int)cmd->command); - assert(false); + ASSERT(false); } n_messages--; cmd++; diff --git a/game/overlord/stream.cpp b/game/overlord/stream.cpp index b18e4ad6d0..01e6fe4752 100644 --- a/game/overlord/stream.cpp +++ b/game/overlord/stream.cpp @@ -11,7 +11,7 @@ #include "game/common/play_rpc_types.h" #include "game/overlord/isocommon.h" #include "game/overlord/iso_api.h" -#include "common/util/assert.h" +#include "common/util/Assert.h" using namespace iop; diff --git a/game/runtime.cpp b/game/runtime.cpp index 2d88296421..e7d87be7d1 100644 --- a/game/runtime.cpp +++ b/game/runtime.cpp @@ -84,7 +84,7 @@ void deci2_runner(SystemThreadInterface& iface) { server.wait_for_protos_ready(); // then allow the server to accept connections if (!server.init()) { - assert(false); + ASSERT(false); } lg::debug("[DECI2] Waiting for listener..."); diff --git a/game/sce/deci2.cpp b/game/sce/deci2.cpp index 8e99207135..9a5c39835a 100644 --- a/game/sce/deci2.cpp +++ b/game/sce/deci2.cpp @@ -8,7 +8,7 @@ #include "common/log/log.h" #include "deci2.h" #include "game/system/Deci2Server.h" -#include "common/util/assert.h" +#include "common/util/Assert.h" namespace ee { @@ -86,7 +86,7 @@ s32 sceDeci2Open(u16 protocol, void* opt, void (*handler)(s32 event, s32 param, * Deactivate a DECI2 protocol by socket descriptor. */ s32 sceDeci2Close(s32 s) { - assert(s - 1 < protocol_count); + ASSERT(s - 1 < protocol_count); protocols[s - 1].active = false; return 1; } @@ -95,7 +95,7 @@ s32 sceDeci2Close(s32 s) { * Start a send. */ s32 sceDeci2ReqSend(s32 s, char dest) { - assert(s - 1 < protocol_count); + ASSERT(s - 1 < protocol_count); auto& proto = protocols[s - 1]; proto.pending_send = dest; return 0; @@ -106,7 +106,7 @@ s32 sceDeci2ReqSend(s32 s, char dest) { * Returns after data is copied. */ s32 sceDeci2ExRecv(s32 s, void* buf, u16 len) { - assert(s - 1 < protocol_count); + ASSERT(s - 1 < protocol_count); protocols[s - 1].recv_size = len; auto avail = protocols[s - 1].available_to_receive; if (len <= avail) { @@ -122,7 +122,7 @@ s32 sceDeci2ExRecv(s32 s, void* buf, u16 len) { * Do a send. */ s32 sceDeci2ExSend(s32 s, void* buf, u16 len) { - assert(s - 1 < protocol_count); + ASSERT(s - 1 < protocol_count); if (!sending_driver) { printf("sceDeci2ExSend called at illegal time!\n"); } diff --git a/game/sce/iop.cpp b/game/sce/iop.cpp index b4c1c82f6a..99e9f05740 100644 --- a/game/sce/iop.cpp +++ b/game/sce/iop.cpp @@ -1,7 +1,7 @@ #include #include "iop.h" #include "game/system/iop_thread.h" -#include "common/util/assert.h" +#include "common/util/Assert.h" namespace iop { /*! @@ -24,7 +24,7 @@ void sceSifInit() { * Initialize RPC */ void sceSifInitRpc(int mode) { - assert(mode == 0); + ASSERT(mode == 0); } /*! @@ -74,8 +74,8 @@ int QueryTotalFreeMemSize() { * Allocate memory. */ void* AllocSysMemory(int type, unsigned long size, void* addr) { - assert(type == SMEM_Low); - assert(addr == nullptr); + ASSERT(type == SMEM_Low); + ASSERT(addr == nullptr); return iop->iop_alloc(size); } @@ -95,7 +95,7 @@ s32 CreateMbx(MbxParam* param) { } s32 StartThread(s32 thid, u32 arg) { - assert(!arg); + ASSERT(!arg); iop->kernel.StartThread(thid); return 0; } @@ -121,8 +121,8 @@ void sceSifRegisterRpc(sceSifServeData* serve, serve->buff = buff; (void)cfunc; (void)cbuff; - assert(!cfunc); - assert(!cbuff); + ASSERT(!cfunc); + ASSERT(!cbuff); qd->serve_data = serve; } @@ -169,8 +169,8 @@ int sceCdDiskReady(int mode) { } u32 sceSifSetDma(sceSifDmaData* sdd, int len) { - assert(len == 1); - assert(len <= 0xc000); + ASSERT(len == 1); + ASSERT(len <= 0xc000); // todo - sanity check the destination address. memcpy(iop->ee_main_mem + (u64)(sdd->addr), sdd->data, sdd->size); return 1; @@ -203,13 +203,13 @@ s32 CreateSema(SemaParam* param) { s32 WaitSema(s32 sema) { (void)sema; - assert(false); // nyi + ASSERT(false); // nyi return 0; } s32 SignalSema(s32 sema) { (void)sema; - assert(false); // nyi + ASSERT(false); // nyi return 0; } diff --git a/game/sce/libcdvd_ee.cpp b/game/sce/libcdvd_ee.cpp index defd226a58..5e4182d7f0 100644 --- a/game/sce/libcdvd_ee.cpp +++ b/game/sce/libcdvd_ee.cpp @@ -4,7 +4,7 @@ */ #include "libcdvd_ee.h" -#include "common/util/assert.h" +#include "common/util/Assert.h" namespace ee { @@ -22,7 +22,7 @@ void LIBRARY_INIT_sceCd() { * init_mode should be SCECdINIT */ int sceCdInit(int init_mode) { - assert(init_mode == SCECdINIT); + ASSERT(init_mode == SCECdINIT); return 1; // Initialization was performed normally } diff --git a/game/sce/libpad.cpp b/game/sce/libpad.cpp index a80deea8e5..c2c1e9ac36 100644 --- a/game/sce/libpad.cpp +++ b/game/sce/libpad.cpp @@ -2,7 +2,7 @@ #include "game/kernel/kmachine.h" #include "game/graphics/gfx.h" -#include "common/util/assert.h" +#include "common/util/Assert.h" /*! * @file libpad.cpp @@ -15,7 +15,7 @@ int scePadPortOpen(int port, int slot, void*) { // we are expected to return a non-zero file descriptor. // we return the port + 1 and succeed always. // the game just opens this once at the beginning, we don't have to implement closing/reopening. - assert(slot == 0); + ASSERT(slot == 0); return port + 1; } diff --git a/game/sce/sif_ee.cpp b/game/sce/sif_ee.cpp index a9fdef0ea1..104c0747ff 100644 --- a/game/sce/sif_ee.cpp +++ b/game/sce/sif_ee.cpp @@ -5,7 +5,7 @@ #include "sif_ee.h" #include "game/system/iop_thread.h" #include "game/runtime.h" -#include "common/util/assert.h" +#include "common/util/Assert.h" namespace ee { @@ -77,9 +77,9 @@ s32 sceSifCallRpc(sceSifClientData* bd, s32 rsize, void* end_func, void* end_para) { - assert(!end_func); - assert(!end_para); - assert(mode == 1); // async + ASSERT(!end_func); + ASSERT(!end_para); + ASSERT(mode == 1); // async iop->kernel.sif_rpc(bd->rpcd.id, fno, mode, send, ssize, recv, rsize); iop->signal_run_iop(); return 0; @@ -91,7 +91,7 @@ s32 sceSifCheckStatRpc(sceSifRpcData* bd) { } s32 sceSifBindRpc(sceSifClientData* bd, u32 request, u32 mode) { - assert(mode == 1); // async + ASSERT(mode == 1); // async bd->rpcd.id = request; bd->serve = (sceSifServeData*)1; return 0; @@ -148,7 +148,7 @@ s32 sceRead(s32 fd, void* buf, s32 nbyte) { s32 sceWrite(s32 fd, const void* buf, s32 nbyte) { auto kv = sce_fds.find(fd); if (kv == sce_fds.end()) { - assert(false); + ASSERT(false); return -1; } else { return fwrite(buf, 1, nbyte, kv->second); @@ -171,7 +171,7 @@ s32 sceLseek(s32 fd, s32 offset, s32 where) { fseek(kv->second, offset, SEEK_SET); return ftell(kv->second); default: - assert(false); + ASSERT(false); return -1; } } diff --git a/game/sce/sif_ee_memcard.cpp b/game/sce/sif_ee_memcard.cpp index ee6591875b..1c6a822c8b 100644 --- a/game/sce/sif_ee_memcard.cpp +++ b/game/sce/sif_ee_memcard.cpp @@ -8,7 +8,7 @@ #include "game/sce/sif_ee.h" #include "common/util/Serializer.h" #include "common/util/FileUtil.h" -#include "common/util/assert.h" +#include "common/util/Assert.h" namespace ee { /*! @@ -54,7 +54,7 @@ void CardData::load_from_file(const std::string& name) { ser.from_pod_vector(&file_entry.data); ser.from_ptr(&file_entry.is_directory); } - assert(ser.get_load_finished()); + ASSERT(ser.get_load_finished()); } std::string get_memory_card_path() { @@ -89,8 +89,8 @@ int sceMcInit() { } s32 sceMcMkdir(s32 port, s32 slot, const char* name) { - assert(port == 0); - assert(slot == 0); + ASSERT(port == 0); + ASSERT(slot == 0); auto& file = g_mc_state.data.files[name]; file.data.clear(); file.is_directory = true; @@ -99,7 +99,7 @@ s32 sceMcMkdir(s32 port, s32 slot, const char* name) { s32 sceMcSync(s32 mode, s32* cmd, s32* result) { // don't care about the mode, all memory card ops are instant. - assert(mode == 1 || mode == 0); + ASSERT(mode == 1 || mode == 0); if (g_mc_state.current_function == -1) { return sceMcExecIdle; } else { @@ -111,14 +111,14 @@ s32 sceMcSync(s32 mode, s32* cmd, s32* result) { } s32 sceMcOpen(s32 port, s32 slot, const char* name, s32 mode) { - assert(port == 0); - assert(slot == 0); - assert(g_mc_state.current_function == -1); + ASSERT(port == 0); + ASSERT(slot == 0); + ASSERT(g_mc_state.current_function == -1); // add existing file, if it does not exist. auto existing_file = g_mc_state.data.files.find(name); if (existing_file == g_mc_state.data.files.end()) { - assert(mode & SCE_CREAT); + ASSERT(mode & SCE_CREAT); g_mc_state.data.files[name] = {}; } @@ -137,15 +137,15 @@ s32 sceMcOpen(s32 port, s32 slot, const char* name, s32 mode) { } s32 sceMcWrite(s32 fd, const void* buff, s32 size) { - assert(g_mc_state.current_function == -1); + ASSERT(g_mc_state.current_function == -1); - assert(size >= 0 && size < (1024 * 1024 * 1024)); + ASSERT(size >= 0 && size < (1024 * 1024 * 1024)); auto hand = g_mc_state.handles.find(fd); - assert(hand != g_mc_state.handles.end()); // make sure fd is valid - assert(hand->second.mode & SCE_WRONLY); // make sure we're allowed to write + ASSERT(hand != g_mc_state.handles.end()); // make sure fd is valid + ASSERT(hand->second.mode & SCE_WRONLY); // make sure we're allowed to write const auto& file = g_mc_state.data.files.find(hand->second.name); - assert(file != g_mc_state.data.files.end()); + ASSERT(file != g_mc_state.data.files.end()); file->second.data.resize(size + hand->second.seek); memcpy(file->second.data.data() + hand->second.seek, buff, size); @@ -159,9 +159,9 @@ s32 sceMcWrite(s32 fd, const void* buff, s32 size) { } s32 sceMcClose(s32 fd) { - assert(g_mc_state.current_function == -1); + ASSERT(g_mc_state.current_function == -1); auto hand = g_mc_state.handles.find(fd); - assert(hand != g_mc_state.handles.end()); // make sure fd is valid + ASSERT(hand != g_mc_state.handles.end()); // make sure fd is valid g_mc_state.handles.erase(fd); g_mc_state.current_function = sceMcFuncNoClose; g_mc_state.current_function_result = sceMcResSucceed; @@ -169,9 +169,9 @@ s32 sceMcClose(s32 fd) { } s32 sceMcGetInfo(s32 port, s32 slot, s32* type, s32* free, s32* format) { - assert(g_mc_state.current_function == -1); - assert(port == 0 || port == 1); - assert(slot == 0); + ASSERT(g_mc_state.current_function == -1); + ASSERT(port == 0 || port == 1); + ASSERT(slot == 0); if (port == 0) { if (type) { @@ -200,9 +200,9 @@ s32 sceMcGetInfo(s32 port, s32 slot, s32* type, s32* free, s32* format) { } s32 sceMcFormat(s32 port, s32 slot) { - assert(g_mc_state.current_function == -1); - assert(port == 0); - assert(slot == 0); + ASSERT(g_mc_state.current_function == -1); + ASSERT(port == 0); + ASSERT(slot == 0); g_mc_state.data.is_formatted = true; g_mc_state.current_function_result = sceMcResSucceed; g_mc_state.current_function = sceMcFuncNoFormat; @@ -210,9 +210,9 @@ s32 sceMcFormat(s32 port, s32 slot) { } s32 sceMcUnformat(s32 port, s32 slot) { - assert(g_mc_state.current_function == -1); - assert(port == 0); - assert(slot == 0); + ASSERT(g_mc_state.current_function == -1); + ASSERT(port == 0); + ASSERT(slot == 0); g_mc_state.data.is_formatted = false; g_mc_state.current_function_result = sceMcResSucceed; g_mc_state.current_function = sceMcFuncNoUnformat; @@ -220,9 +220,9 @@ s32 sceMcUnformat(s32 port, s32 slot) { } s32 sceMcDelete(s32 port, s32 slot, const char* name) { - assert(g_mc_state.current_function == -1); - assert(port == 0); - assert(slot == 0); + ASSERT(g_mc_state.current_function == -1); + ASSERT(port == 0); + ASSERT(slot == 0); g_mc_state.current_function = sceMcFuncNoDelete; if (!g_mc_state.data.is_formatted) { @@ -252,12 +252,12 @@ sceMcStDateTime make_fake_date_time() { } s32 sceMcGetDir(s32 port, int slot, const char* name, u32 mode, s32 maxent, sceMcTblGetDir* table) { - assert(g_mc_state.current_function == -1); - assert(port == 0); - assert(slot == 0); - assert(maxent == 1); - assert(mode == 0); - assert(g_mc_state.data.is_formatted); + ASSERT(g_mc_state.current_function == -1); + ASSERT(port == 0); + ASSERT(slot == 0); + ASSERT(maxent == 1); + ASSERT(mode == 0); + ASSERT(g_mc_state.data.is_formatted); g_mc_state.current_function = sceMcFuncNoGetDir; auto file_it = g_mc_state.data.files.find(name); @@ -266,7 +266,7 @@ s32 sceMcGetDir(s32 port, int slot, const char* name, u32 mode, s32 maxent, sceM return 0; } else { g_mc_state.current_function_result = 1; - // assert(strlen(name) < 32); + // ASSERT(strlen(name) < 32); strcpy(table[0].name, "blah"); table[0].file_size = file_it->second.data.size(); table[0].created = make_fake_date_time(); @@ -276,14 +276,14 @@ s32 sceMcGetDir(s32 port, int slot, const char* name, u32 mode, s32 maxent, sceM } s32 sceMcRead(s32 fd, void* buff, s32 size) { - assert(g_mc_state.current_function == -1); - assert(g_mc_state.data.is_formatted); + ASSERT(g_mc_state.current_function == -1); + ASSERT(g_mc_state.data.is_formatted); auto it = g_mc_state.handles.find(fd); - assert(it != g_mc_state.handles.end()); + ASSERT(it != g_mc_state.handles.end()); auto file_it = g_mc_state.data.files.find(it->second.name); // todo check read/write mode - assert(file_it != g_mc_state.data.files.end()); - assert(size + it->second.seek <= file_it->second.data.size()); + ASSERT(file_it != g_mc_state.data.files.end()); + ASSERT(size + it->second.seek <= file_it->second.data.size()); memcpy(buff, file_it->second.data.data() + it->second.seek, size); it->second.seek += size; diff --git a/game/sce/stubs.cpp b/game/sce/stubs.cpp index 164d72e21d..1e3dbb3e86 100644 --- a/game/sce/stubs.cpp +++ b/game/sce/stubs.cpp @@ -1,23 +1,23 @@ #include #include "stubs.h" -#include "common/util/assert.h" +#include "common/util/Assert.h" namespace ee { void sceGsResetGraph() { - assert(false); + ASSERT(false); } void sceGsPutIMR() { - assert(false); + ASSERT(false); } void sceGsGetIMR() { - assert(false); + ASSERT(false); } void sceGsExecStoreImage() { - assert(false); + ASSERT(false); } void FlushCache() {} @@ -28,17 +28,17 @@ namespace iop { u32 snd_BankLoadByLoc(u32 sector, u32 unk) { (void)sector; (void)unk; - assert(false); + ASSERT(false); return 0; } u32 snd_GetLastLoadError() { - assert(false); + ASSERT(false); return 0; } void snd_ResolveBankXREFS() { - assert(false); + ASSERT(false); } } // namespace iop diff --git a/game/system/Deci2Server.cpp b/game/system/Deci2Server.cpp index 49b19b5426..87b66f50cd 100644 --- a/game/system/Deci2Server.cpp +++ b/game/system/Deci2Server.cpp @@ -23,7 +23,7 @@ #include "common/listener_common.h" #include "common/versions.h" #include "Deci2Server.h" -#include "common/util/assert.h" +#include "common/util/Assert.h" Deci2Server::Deci2Server(std::function shutdown_callback) { buffer = new char[BUFFER_SIZE]; @@ -185,7 +185,7 @@ void Deci2Server::run() { int got = 0; while (got < desired_size) { - assert(got + desired_size < BUFFER_SIZE); + ASSERT(got + desired_size < BUFFER_SIZE); auto x = read_from_socket(new_sock, buffer + got, desired_size - got); if (want_exit()) { return; diff --git a/game/system/IOP_Kernel.cpp b/game/system/IOP_Kernel.cpp index b4f878d403..4e76470c63 100644 --- a/game/system/IOP_Kernel.cpp +++ b/game/system/IOP_Kernel.cpp @@ -1,16 +1,16 @@ #include #include "IOP_Kernel.h" #include "game/sce/iop.h" -#include "common/util/assert.h" +#include "common/util/Assert.h" /*! * Create a new thread. Will not run the thread. */ s32 IOP_Kernel::CreateThread(std::string name, u32 (*func)()) { - assert(_currentThread == -1); // can only create thread from kernel thread. + ASSERT(_currentThread == -1); // can only create thread from kernel thread. u32 ID = (u32)_nextThID++; - assert(ID == threads.size()); + ASSERT(ID == threads.size()); // add entry threads.emplace_back(name, func, ID, this); @@ -47,7 +47,7 @@ void IOP_Kernel::setupThread(s32 id) { returnToKernel(); threads.at(id).waitForDispatch(); // printf("[IOP Kernel] Thread %s first dispatch!\n", threads.at(id).name.c_str()); - assert(_currentThread == id); // should run in the thread. + ASSERT(_currentThread == id); // should run in the thread. (threads.at(id).function)(); // printf("Thread %s has returned!\n", threads.at(id).name.c_str()); threads.at(id).done = true; @@ -58,7 +58,7 @@ void IOP_Kernel::setupThread(s32 id) { * Run a thread (call from kernel) */ void IOP_Kernel::runThread(s32 id) { - assert(_currentThread == -1); // should run in the kernel thread + ASSERT(_currentThread == -1); // should run in the kernel thread _currentThread = id; threads.at(id).dispatch(); threads.at(id).waitForReturnToKernel(); @@ -75,7 +75,7 @@ void IOP_Kernel::SuspendThread() { threads.at(oldThread).returnToKernel(); threads.at(oldThread).waitForDispatch(); // check kernel resumed us correctly - assert(_currentThread == oldThread); + ASSERT(_currentThread == oldThread); } /*! @@ -127,7 +127,7 @@ void IOP_Kernel::dispatchAll() { void IopThreadRecord::returnToKernel() { runThreadReady = false; // should be called from the correct thread - assert(kernel->getCurrentThread() == thID); + ASSERT(kernel->getCurrentThread() == thID); { std::lock_guard lck(*threadToKernelMutex); @@ -141,7 +141,7 @@ void IopThreadRecord::returnToKernel() { */ void IopThreadRecord::dispatch() { syscallReady = false; - assert(kernel->getCurrentThread() == thID); + ASSERT(kernel->getCurrentThread() == thID); { std::lock_guard lck(*kernelToThreadMutex); @@ -168,7 +168,7 @@ void IopThreadRecord::waitForDispatch() { void IOP_Kernel::set_rpc_queue(iop::sceSifQueueData* qd, u32 thread) { for (const auto& r : sif_records) { - assert(!(r.qd == qd || r.thread_to_wake == thread)); + ASSERT(!(r.qd == qd || r.thread_to_wake == thread)); } SifRecord rec; rec.thread_to_wake = thread; @@ -189,7 +189,7 @@ bool IOP_Kernel::sif_busy(u32 id) { break; } } - assert(found); + ASSERT(found); sif_mtx.unlock(); return rv; } @@ -201,7 +201,7 @@ void IOP_Kernel::sif_rpc(s32 rpcChannel, s32 sendSize, void* recvBuff, s32 recvSize) { - assert(async); + ASSERT(async); sif_mtx.lock(); // step 1 - find entry SifRecord* rec = nullptr; @@ -213,10 +213,10 @@ void IOP_Kernel::sif_rpc(s32 rpcChannel, if (!rec) { printf("Failed to find handler for sif channel 0x%x\n", rpcChannel); } - assert(rec); + ASSERT(rec); // step 2 - check entry is safe to give command to - assert(rec->cmd.finished && rec->cmd.started); + ASSERT(rec->cmd.finished && rec->cmd.started); // step 3 - memcpy! memcpy(rec->qd->serve_data->buff, sendBuff, sendSize); @@ -259,7 +259,7 @@ void IOP_Kernel::rpc_loop(iop::sceSifQueueData* qd) { if (!cmd.started) { // cf - assert(func); + ASSERT(func); auto data = func(cmd.fno, cmd.buff, cmd.size); if (cmd.copy_back_buff && cmd.copy_back_size) { memcpy(cmd.copy_back_buff, data, cmd.copy_back_size); @@ -268,7 +268,7 @@ void IOP_Kernel::rpc_loop(iop::sceSifQueueData* qd) { sif_mtx.lock(); for (auto& r : sif_records) { if (r.qd == qd) { - assert(r.cmd.started); + ASSERT(r.cmd.started); r.cmd.finished = true; } } @@ -284,12 +284,12 @@ void IOP_Kernel::read_disc_sectors(u32 sector, u32 sectors, void* buffer) { iso_disc_file = fopen("./disc.iso", "rb"); } - assert(iso_disc_file); + ASSERT(iso_disc_file); if (fseek(iso_disc_file, sector * 0x800, SEEK_SET)) { - assert(false); + ASSERT(false); } auto rv = fread(buffer, sectors * 0x800, 1, iso_disc_file); - assert(rv == 1); + ASSERT(rv == 1); } void IOP_Kernel::shutdown() { diff --git a/game/system/IOP_Kernel.h b/game/system/IOP_Kernel.h index 2eb586a311..567b8de4f7 100644 --- a/game/system/IOP_Kernel.h +++ b/game/system/IOP_Kernel.h @@ -11,7 +11,7 @@ #include #include #include "common/common_types.h" -#include "common/util/assert.h" +#include "common/util/Assert.h" class IOP_Kernel; namespace iop { @@ -99,7 +99,7 @@ class IOP_Kernel { * Resume the kernel. */ void returnToKernel() { - assert(_currentThread >= 0); // must be in a thread + ASSERT(_currentThread >= 0); // must be in a thread threads[_currentThread].returnToKernel(); } @@ -127,7 +127,7 @@ class IOP_Kernel { return -0x1a9; } - assert(mbx < (s32)mbxs.size()); + ASSERT(mbx < (s32)mbxs.size()); s32 gotSomething = mbxs[mbx].empty() ? 0 : 1; if (gotSomething) { void* thing = mbxs[mbx].front(); @@ -146,7 +146,7 @@ class IOP_Kernel { * Push something into a mbx */ s32 SendMbx(s32 mbx, void* value) { - assert(mbx < (s32)mbxs.size()); + ASSERT(mbx < (s32)mbxs.size()); mbxs[mbx].push(value); return 0; } diff --git a/game/system/SystemThread.cpp b/game/system/SystemThread.cpp index 3b2c3dc5d2..86daaab03b 100644 --- a/game/system/SystemThread.cpp +++ b/game/system/SystemThread.cpp @@ -15,7 +15,7 @@ SystemThread& SystemThreadManager::create_thread(const std::string& name) { if (thread_count >= MAX_SYSTEM_THREADS) { lg::die("Out of System Threads! MAX_SYSTEM_THREADS is ", MAX_SYSTEM_THREADS); - assert(false); + ASSERT(false); } auto& thread = threads[thread_count]; diff --git a/goal_src/engine/draw/process-drawable.gc b/goal_src/engine/draw/process-drawable.gc index 5deed9dc76..cc7c857487 100644 --- a/goal_src/engine/draw/process-drawable.gc +++ b/goal_src/engine/draw/process-drawable.gc @@ -85,6 +85,7 @@ ) (defmethod lod-set! draw-control ((obj draw-control) (arg0 int)) + ;; note: good spot to mess with lods here. (let ((v1-1 (max 0 (min arg0 (-> obj lod-set max-lod))))) (set! (-> obj desired-lod) v1-1) (when (!= (-> obj cur-lod) v1-1) diff --git a/goal_src/engine/sound/gsound.gc b/goal_src/engine/sound/gsound.gc index b6202ddd02..28dee07bb9 100644 --- a/goal_src/engine/sound/gsound.gc +++ b/goal_src/engine/sound/gsound.gc @@ -44,6 +44,11 @@ (define *sound-iop-info* (new 'global 'sound-iop-info)) +;; HACK +(#unless PC_DEBUG_SOUND_ENABLE + (set! (-> *sound-iop-info* strpos) -1) + ) + (defun str-is-playing? () "Return #t if an audio stream is playing" diff --git a/goal_src/engine/target/logic-target.gc b/goal_src/engine/target/logic-target.gc index c1e1da5b38..faf4bd805b 100644 --- a/goal_src/engine/target/logic-target.gc +++ b/goal_src/engine/target/logic-target.gc @@ -2092,7 +2092,7 @@ (let* ((s5-0 (get-process *target-dead-pool* target #x4000)) (v1-3 (when s5-0 (let ((t9-2 (method-of-type target activate))) - (t9-2 (the-as target s5-0) *target-pool* 'target (&-> *dram-stack* 14336)) + (t9-2 (the-as target s5-0) *target-pool* 'target (&-> *dram-stack* DPROCESS_STACK_SIZE)) ) (run-now-in-process s5-0 init-target arg1) (-> s5-0 ppointer) diff --git a/goal_src/kernel/gkernel.gc b/goal_src/kernel/gkernel.gc index 9eaf63353f..45a1f4637e 100644 --- a/goal_src/kernel/gkernel.gc +++ b/goal_src/kernel/gkernel.gc @@ -120,8 +120,8 @@ (#cond (PC_PORT - ;; make sure the scratchpad is 16kb aligned - (let* ((mem (new 'global 'array 'uint8 (* (+ 16 16) 1024))) + ;; make sure the scratchpad is 16kb aligned, and make it 32 kB so we can big stacks on it. + (let* ((mem (new 'global 'array 'uint8 (* (+ 16 32) 1024))) ) (define *fake-scratchpad-data* (the pointer (align-n mem (* 16 1024)))) ) @@ -2184,7 +2184,7 @@ (#when PC_PORT (when (= stack-top *scratch-memory-top*) ;; (format #t "Process ~A requested a stack on the scratchpad, moving to fake scratch~%") - (set! stack-top (&+ *fake-scratchpad-stack* (* 16 1024))) + (set! stack-top (&+ *fake-scratchpad-stack* (* 32 1024))) ) ) diff --git a/goalc/compiler/CodeGenerator.cpp b/goalc/compiler/CodeGenerator.cpp index 3f29724b10..50eee36f19 100644 --- a/goalc/compiler/CodeGenerator.cpp +++ b/goalc/compiler/CodeGenerator.cpp @@ -149,7 +149,7 @@ void CodeGenerator::do_goal_function(const std::shared_ptr& env, in stack_offset += 8; } - assert(stack_offset & 15); + ASSERT(stack_offset & 15); // do manual stack offset. if (manually_added_stack_offset) { @@ -185,7 +185,7 @@ void CodeGenerator::do_goal_function(const std::shared_ptr& env, in op.reg, RSP, allocs.get_slot_for_spill(op.slot) * GPR_SIZE), i_rec); } else { - assert(false); + ASSERT(false); } } } @@ -212,7 +212,7 @@ void CodeGenerator::do_goal_function(const std::shared_ptr& env, in RSP, op.reg, allocs.get_slot_for_spill(op.slot) * GPR_SIZE), i_rec); } else { - assert(false); + ASSERT(false); } } } @@ -227,7 +227,7 @@ void CodeGenerator::do_goal_function(const std::shared_ptr& env, in } if (bonus_push) { - assert(!manually_added_stack_offset); + ASSERT(!manually_added_stack_offset); m_gen.add_instr_no_ir(f_rec, IGen::pop_gpr64(ri.get_saved_gpr(0)), InstructionInfo::Kind::EPILOGUE); } @@ -252,7 +252,7 @@ void CodeGenerator::do_goal_function(const std::shared_ptr& env, in InstructionInfo::Kind::EPILOGUE); } } - assert(j == 0); + ASSERT(j == 0); m_gen.add_instr_no_ir(f_rec, IGen::add_gpr64_imm(RSP, xmm_backup_stack_offset), InstructionInfo::Kind::EPILOGUE); } diff --git a/goalc/compiler/Compiler.cpp b/goalc/compiler/Compiler.cpp index 2166d704d8..bad1535937 100644 --- a/goalc/compiler/Compiler.cpp +++ b/goalc/compiler/Compiler.cpp @@ -330,7 +330,7 @@ void Compiler::compile_and_send_from_string(const std::string& source_code) { auto code = m_goos.reader.read_from_string(source_code); auto compiled = compile_object_file("test-code", code, true); - assert(!compiled->is_empty()); + ASSERT(!compiled->is_empty()); color_object_file(compiled); auto data = codegen_object_file(compiled); m_listener.send_code(data); diff --git a/goalc/compiler/ConstantValue.h b/goalc/compiler/ConstantValue.h index a18937e37f..44a1c5071e 100644 --- a/goalc/compiler/ConstantValue.h +++ b/goalc/compiler/ConstantValue.h @@ -4,7 +4,7 @@ #include "common/common_types.h" #include "common/util/BitUtils.h" #include "third-party/fmt/core.h" -#include "common/util/assert.h" +#include "common/util/Assert.h" struct U128 { U128() = default; @@ -16,7 +16,7 @@ struct U128 { class ConstantValue { public: ConstantValue(const void* data, int size) : m_size(size) { - assert(size == 8 || size == 16); + ASSERT(size == 8 || size == 16); memcpy(m_value, data, size); } @@ -29,21 +29,21 @@ class ConstantValue { } s64 value_64() const { - assert(m_size == 8); + ASSERT(m_size == 8); s64 result; memcpy(&result, m_value, sizeof(s64)); return result; } u64 value_128_lo() const { - assert(m_size == 16); + ASSERT(m_size == 16); s64 result; memcpy(&result, m_value, sizeof(s64)); return result; } u64 value_128_hi() const { - assert(m_size == 16); + ASSERT(m_size == 16); s64 result; memcpy(&result, m_value + sizeof(s64), sizeof(s64)); return result; @@ -76,7 +76,7 @@ class ConstantValue { memcpy(destination, m_value, 16); return true; } else { - assert(false); + ASSERT(false); } return false; } diff --git a/goalc/compiler/Env.cpp b/goalc/compiler/Env.cpp index 35935f4749..a157cf7127 100644 --- a/goalc/compiler/Env.cpp +++ b/goalc/compiler/Env.cpp @@ -51,7 +51,7 @@ std::unordered_map& Env::get_label_map() { void Env::emit(const goos::Object& form, std::unique_ptr ir) { auto e = function_env(); - assert(e); + ASSERT(e); e->emit(form, std::move(ir), this); } @@ -134,9 +134,9 @@ std::string FileEnv::print() { } void FileEnv::add_function(std::unique_ptr fe) { - assert(fe->idx_in_file == -1); + ASSERT(fe->idx_in_file == -1); fe->idx_in_file = m_functions.size(); - assert(!fe->name().empty()); + ASSERT(!fe->name().empty()); m_functions.push_back(std::move(fe)); } @@ -233,7 +233,7 @@ RegVal* FunctionEnv::make_ireg(const TypeSpec& ts, RegClass reg_class) { ireg.id = m_iregs.size(); auto rv = std::make_unique(ireg, coerce_to_reg_type(ts)); m_iregs.push_back(std::move(rv)); - assert(reg_class != RegClass::INVALID); + ASSERT(reg_class != RegClass::INVALID); return m_iregs.back().get(); } @@ -265,7 +265,7 @@ RegVal* FunctionEnv::lexical_lookup(goos::Object sym) { FunctionEnv::StackSpace FunctionEnv::allocate_aligned_stack_space(int size_bytes, int align_bytes) { require_aligned_stack(); - assert(align_bytes <= 16); + ASSERT(align_bytes <= 16); int align_slots = (align_bytes + emitter::GPR_SIZE - 1) / emitter::GPR_SIZE; while (m_stack_var_slots_used % align_slots) { m_stack_var_slots_used++; diff --git a/goalc/compiler/Env.h b/goalc/compiler/Env.h index 9311bf081d..2ef9cbcd76 100644 --- a/goalc/compiler/Env.h +++ b/goalc/compiler/Env.h @@ -103,7 +103,7 @@ class FileEnv : public Env { return "anon-function-" + std::to_string(m_anon_func_counter++); } const FunctionEnv& top_level_function() { - assert(m_top_level_func); + ASSERT(m_top_level_func); return *m_top_level_func; } const std::string& name() { return m_name; } diff --git a/goalc/compiler/IR.cpp b/goalc/compiler/IR.cpp index dba52c3fbd..9c908f810c 100644 --- a/goalc/compiler/IR.cpp +++ b/goalc/compiler/IR.cpp @@ -16,20 +16,20 @@ Register get_reg(const RegVal* rv, const AllocationResult& allocs, emitter::IR_R if (lr.has_info_at(irec.ir_id)) { auto ass_reg = range.at(rv->ireg().id).get(irec.ir_id); if (ass_reg.kind == Assignment::Kind::REGISTER) { - assert(ass_reg.reg == reg); + ASSERT(ass_reg.reg == reg); } else { - assert(false); + ASSERT(false); } } else { - assert(false); + ASSERT(false); } } else { - assert(false); + ASSERT(false); } return reg; } else { auto& ass = allocs.ass_as_ranges.at(rv->ireg().id).get(irec.ir_id); - assert(ass.kind == Assignment::Kind::REGISTER); + ASSERT(ass.kind == Assignment::Kind::REGISTER); return ass.reg; } } @@ -37,12 +37,12 @@ Register get_reg(const RegVal* rv, const AllocationResult& allocs, emitter::IR_R int get_stack_offset(const RegVal* rv, const AllocationResult& allocs) { if (rv->rlet_constraint().has_value()) { // should be impossible. Can't take the address of an inline assembly form register. - assert(false); + ASSERT(false); } else { - assert(rv->forced_on_stack()); + ASSERT(rv->forced_on_stack()); auto& ass = allocs.ass_as_ranges.at(rv->ireg().id); auto stack_slot = allocs.get_slot_for_spill(ass.stack_slot()); - assert(stack_slot >= 0); + ASSERT(stack_slot >= 0); return stack_slot * 8; } } @@ -141,7 +141,7 @@ void regset_common(emitter::ObjectGenerator* gen, } else if (src_is_xmm128 && dst_class == RegClass::GPR_64) { gen->add_instr(IGen::movq_gpr64_xmm64(dst_reg, src_reg), irec); } else { - assert(false); // unhandled move. + ASSERT(false); // unhandled move. } } } // namespace @@ -356,7 +356,7 @@ std::string IR_GotoLabel::print() { } RegAllocInstr IR_GotoLabel::to_rai() { - assert(m_resolved); + ASSERT(m_resolved); RegAllocInstr rai; rai.jumps.push_back(m_dest->idx); rai.fallthrough = false; @@ -372,7 +372,7 @@ void IR_GotoLabel::do_codegen(emitter::ObjectGenerator* gen, } void IR_GotoLabel::resolve(const Label* dest) { - assert(!m_resolved); + ASSERT(!m_resolved); m_dest = dest; m_resolved = true; } @@ -621,19 +621,19 @@ void IR_IntegerMath::do_codegen(emitter::ObjectGenerator* gen, break; case IntegerMathKind::NOT_64: gen->add_instr(IGen::not_gpr64(get_reg(m_dest, allocs, irec)), irec); - assert(!m_arg); + ASSERT(!m_arg); break; case IntegerMathKind::SHLV_64: gen->add_instr(IGen::shl_gpr64_cl(get_reg(m_dest, allocs, irec)), irec); - assert(get_reg(m_arg, allocs, irec) == emitter::RCX); + ASSERT(get_reg(m_arg, allocs, irec) == emitter::RCX); break; case IntegerMathKind::SHRV_64: gen->add_instr(IGen::shr_gpr64_cl(get_reg(m_dest, allocs, irec)), irec); - assert(get_reg(m_arg, allocs, irec) == emitter::RCX); + ASSERT(get_reg(m_arg, allocs, irec) == emitter::RCX); break; case IntegerMathKind::SARV_64: gen->add_instr(IGen::sar_gpr64_cl(get_reg(m_dest, allocs, irec)), irec); - assert(get_reg(m_arg, allocs, irec) == emitter::RCX); + ASSERT(get_reg(m_arg, allocs, irec) == emitter::RCX); break; case IntegerMathKind::SHL_64: gen->add_instr(IGen::shl_gpr64_u8(get_reg(m_dest, allocs, irec), m_shift_amount), irec); @@ -671,7 +671,7 @@ void IR_IntegerMath::do_codegen(emitter::ObjectGenerator* gen, } break; default: - assert(false); + ASSERT(false); } } @@ -746,7 +746,7 @@ void IR_FloatMath::do_codegen(emitter::ObjectGenerator* gen, irec); break; default: - assert(false); + ASSERT(false); } } @@ -771,12 +771,12 @@ void IR_StaticVarLoad::do_codegen(emitter::ObjectGenerator* gen, const AllocationResult& allocs, emitter::IR_Record irec) { auto load_info = m_src->get_load_info(); - assert(m_src->get_addr_offset() == 0); + ASSERT(m_src->get_addr_offset() == 0); if (m_dest->ireg().reg_class == RegClass::FLOAT) { - assert(load_info.load_signed == false); - assert(load_info.load_size == 4); - assert(load_info.requires_load == true); + ASSERT(load_info.load_signed == false); + ASSERT(load_info.load_size == 4); + ASSERT(load_info.requires_load == true); auto instr = gen->add_instr(IGen::static_load_xmm32(get_reg(m_dest, allocs, irec), 0), irec); gen->link_instruction_static(instr, m_src->rec, 0); @@ -786,7 +786,7 @@ void IR_StaticVarLoad::do_codegen(emitter::ObjectGenerator* gen, auto instr = gen->add_instr(IGen::loadvf_rip_plus_s32(get_reg(m_dest, allocs, irec), 0), irec); gen->link_instruction_static(instr, m_src->rec, 0); } else { - assert(false); + ASSERT(false); } } @@ -830,7 +830,7 @@ std::string IR_ConditionalBranch::print() { RegAllocInstr IR_ConditionalBranch::to_rai() { auto rai = condition.to_rai(); - assert(m_resolved); + ASSERT(m_resolved); rai.jumps.push_back(label.idx); return rai; } @@ -839,7 +839,7 @@ void IR_ConditionalBranch::do_codegen(emitter::ObjectGenerator* gen, const AllocationResult& allocs, emitter::IR_Record irec) { Instruction jump_instr(0); - assert(m_resolved); + ASSERT(m_resolved); switch (condition.kind) { case ConditionKind::EQUAL: jump_instr = IGen::je_32(); @@ -877,7 +877,7 @@ void IR_ConditionalBranch::do_codegen(emitter::ObjectGenerator* gen, } break; default: - assert(false); + ASSERT(false); } if (condition.is_float) { @@ -1463,7 +1463,7 @@ std::string IR_VFMath3Asm::print() { function = ".div.vf"; break; default: - assert(false); + ASSERT(false); } return fmt::format("{}{} {}, {}, {}", function, get_color_suffix_string(), m_dst->print(), m_src1->print(), m_src2->print()); @@ -1509,7 +1509,7 @@ void IR_VFMath3Asm::do_codegen(emitter::ObjectGenerator* gen, gen->add_instr(IGen::div_vf(dst, src1, src2), irec); break; default: - assert(false); + ASSERT(false); } } @@ -1582,7 +1582,7 @@ std::string IR_Int128Math3Asm::print() { function = ".pand"; break; default: - assert(false); + ASSERT(false); } return fmt::format("{}{} {}, {}, {}", function, get_color_suffix_string(), m_dst->print(), m_src1->print(), m_src2->print()); @@ -1669,7 +1669,7 @@ void IR_Int128Math3Asm::do_codegen(emitter::ObjectGenerator* gen, gen->add_instr(IGen::parallel_bitwise_and(dst, src2, src1), irec); break; default: - assert(false); + ASSERT(false); } } @@ -1690,7 +1690,7 @@ std::string IR_VFMath2Asm::print() { function = ".ftoi.vf"; break; default: - assert(false); + ASSERT(false); } return fmt::format("{}{} {}, {}", function, get_color_suffix_string(), m_dst->print(), @@ -1720,7 +1720,7 @@ void IR_VFMath2Asm::do_codegen(emitter::ObjectGenerator* gen, gen->add_instr(IGen::ftoi_vf(dst, src), irec); break; default: - assert(false); + ASSERT(false); } } @@ -1768,11 +1768,11 @@ std::string IR_Int128Math2Asm::print() { function = ".VPSHUFHW"; break; default: - assert(false); + ASSERT(false); } if (use_imm) { - assert(m_imm.has_value()); + ASSERT(m_imm.has_value()); return fmt::format("{}{} {}, {}, {}", function, get_color_suffix_string(), m_dst->print(), m_src->print(), *m_imm); } else { @@ -1799,49 +1799,49 @@ void IR_Int128Math2Asm::do_codegen(emitter::ObjectGenerator* gen, switch (m_kind) { case Kind::PW_SLL: // you are technically allowed to put values > 32 in here. - assert(m_imm.has_value()); - assert(*m_imm >= 0); - assert(*m_imm <= 255); + ASSERT(m_imm.has_value()); + ASSERT(*m_imm >= 0); + ASSERT(*m_imm <= 255); gen->add_instr(IGen::pw_sll(dst, src, *m_imm), irec); break; case Kind::PW_SRL: - assert(m_imm.has_value()); - assert(*m_imm >= 0); - assert(*m_imm <= 255); + ASSERT(m_imm.has_value()); + ASSERT(*m_imm >= 0); + ASSERT(*m_imm <= 255); gen->add_instr(IGen::pw_srl(dst, src, *m_imm), irec); break; case Kind::PW_SRA: - assert(m_imm.has_value()); - assert(*m_imm >= 0); - assert(*m_imm <= 255); + ASSERT(m_imm.has_value()); + ASSERT(*m_imm >= 0); + ASSERT(*m_imm <= 255); gen->add_instr(IGen::pw_sra(dst, src, *m_imm), irec); break; case Kind::VPSRLDQ: - assert(m_imm.has_value()); - assert(*m_imm >= 0); - assert(*m_imm <= 255); + ASSERT(m_imm.has_value()); + ASSERT(*m_imm >= 0); + ASSERT(*m_imm <= 255); gen->add_instr(IGen::vpsrldq(dst, src, *m_imm), irec); break; case Kind::VPSLLDQ: - assert(m_imm.has_value()); - assert(*m_imm >= 0); - assert(*m_imm <= 255); + ASSERT(m_imm.has_value()); + ASSERT(*m_imm >= 0); + ASSERT(*m_imm <= 255); gen->add_instr(IGen::vpslldq(dst, src, *m_imm), irec); break; case Kind::VPSHUFLW: - assert(m_imm.has_value()); - assert(*m_imm >= 0); - assert(*m_imm <= 255); + ASSERT(m_imm.has_value()); + ASSERT(*m_imm >= 0); + ASSERT(*m_imm <= 255); gen->add_instr(IGen::vpshuflw(dst, src, *m_imm), irec); break; case Kind::VPSHUFHW: - assert(m_imm.has_value()); - assert(*m_imm >= 0); - assert(*m_imm <= 255); + ASSERT(m_imm.has_value()); + ASSERT(*m_imm >= 0); + ASSERT(*m_imm <= 255); gen->add_instr(IGen::vpshufhw(dst, src, *m_imm), irec); break; default: - assert(false); + ASSERT(false); } } diff --git a/goalc/compiler/StaticObject.h b/goalc/compiler/StaticObject.h index 73281997fd..95a19ce501 100644 --- a/goalc/compiler/StaticObject.h +++ b/goalc/compiler/StaticObject.h @@ -123,38 +123,38 @@ class StaticResult { bool is_func() const { return m_kind == Kind::FUNCTION_REFERENCE; } StaticStructure* reference() const { - assert(is_reference()); + ASSERT(is_reference()); return m_struct; } s32 constant_s32() const { - assert(is_constant_data() && m_constant_data && m_constant_data->size() == 8 && + ASSERT(is_constant_data() && m_constant_data && m_constant_data->size() == 8 && integer_fits(m_constant_data->value_64(), 4, true)); return (s32)m_constant_data->value_64(); } const std::string& symbol_name() const { - assert(is_symbol() || is_type()); + ASSERT(is_symbol() || is_type()); return m_symbol; } const FunctionEnv* function() const { - assert(is_func()); + ASSERT(is_func()); return m_func; } int method_count() const { - assert(is_type()); + ASSERT(is_type()); return m_method_count; } u64 constant_u64() const { - assert(is_constant_data() && m_constant_data && m_constant_data->size() == 8); + ASSERT(is_constant_data() && m_constant_data && m_constant_data->size() == 8); return m_constant_data->value_64(); } const ConstantValue& constant() const { - assert(m_constant_data.has_value()); + ASSERT(m_constant_data.has_value()); return *m_constant_data; } diff --git a/goalc/compiler/SymbolInfo.h b/goalc/compiler/SymbolInfo.h index 86f61d4ead..ca66c1320d 100644 --- a/goalc/compiler/SymbolInfo.h +++ b/goalc/compiler/SymbolInfo.h @@ -5,7 +5,7 @@ #include #include "common/util/Trie.h" #include "common/goos/Object.h" -#include "common/util/assert.h" +#include "common/util/Assert.h" /*! * Info about a single symbol, representing one of: diff --git a/goalc/compiler/Util.cpp b/goalc/compiler/Util.cpp index 47e0e3bafb..80be666c99 100644 --- a/goalc/compiler/Util.cpp +++ b/goalc/compiler/Util.cpp @@ -284,7 +284,7 @@ void Compiler::compile_constant_product(const goos::Object& form, int stride, Env* env) { // todo - support imul with an imm. - assert(stride); + ASSERT(stride); bool is_power_of_two = (stride & (stride - 1)) == 0; if (stride == 1) { @@ -297,7 +297,7 @@ void Compiler::compile_constant_product(const goos::Object& form, return; } } - assert(false); + ASSERT(false); } else { // get the multiplier env->emit_ir(form, dest, stride); diff --git a/goalc/compiler/Val.cpp b/goalc/compiler/Val.cpp index 8a3cb5fce5..3a15a1c924 100644 --- a/goalc/compiler/Val.cpp +++ b/goalc/compiler/Val.cpp @@ -149,7 +149,7 @@ RegVal* StaticVal::to_reg(const goos::Object& form, Env* fe) { RegVal* LambdaVal::to_reg(const goos::Object& form, Env* fe) { auto re = fe->make_gpr(coerce_to_reg_type(m_ts)); - assert(func); + ASSERT(func); fe->emit(form, std::make_unique(re, func)); return re; } @@ -292,7 +292,7 @@ RegVal* BitFieldVal::to_reg(const goos::Object& form, Env* env) { } else { // we need to get the value as a 128-bit integer auto xmm = m_parent->to_reg(form, env); - assert(xmm->ireg().reg_class == RegClass::INT_128); + ASSERT(xmm->ireg().reg_class == RegClass::INT_128); auto xmm_temp = fe->make_ireg(TypeSpec("object"), RegClass::INT_128); env->emit_ir(form, true, xmm_temp, xmm, xmm, IR_Int128Math3Asm::Kind::PCPYUD); @@ -302,9 +302,9 @@ RegVal* BitFieldVal::to_reg(const goos::Object& form, Env* env) { // this second step does up to 2 shifts to extract the bitfield and sign extend as needed. int end_bit = start_bit + m_size; - assert(end_bit <= 64); // should be checked by the type system. + ASSERT(end_bit <= 64); // should be checked by the type system. int epad = 64 - end_bit; - assert(epad >= 0); + ASSERT(epad >= 0); int spad = start_bit; // shift left as much as possible to kill upper bits @@ -313,8 +313,8 @@ RegVal* BitFieldVal::to_reg(const goos::Object& form, Env* env) { } int next_shift = epad + spad; - assert(next_shift + m_size == 64); - assert(next_shift >= 0); + ASSERT(next_shift + m_size == 64); + ASSERT(next_shift >= 0); if (next_shift > 0) { if (m_sign_extend) { diff --git a/goalc/compiler/Val.h b/goalc/compiler/Val.h index fd0af54e6a..94a19c8b90 100644 --- a/goalc/compiler/Val.h +++ b/goalc/compiler/Val.h @@ -154,8 +154,8 @@ class StaticVal : public Val { struct MemLoadInfo { MemLoadInfo() = default; explicit MemLoadInfo(const DerefInfo& di) { - assert(di.can_deref); - assert(di.mem_deref); + ASSERT(di.can_deref); + ASSERT(di.mem_deref); sign_extend = di.sign_extend; size = di.load_size; reg = di.reg; @@ -245,7 +245,7 @@ class IntegerConstantVal : public Val { public: IntegerConstantVal(TypeSpec ts, const void* data, int size) : Val(std::move(ts)), m_value(data, size) { - assert(size == 8 || size == 16); + ASSERT(size == 8 || size == 16); } std::string print() const override { return std::string("integer-constant-") + m_value.print(); } diff --git a/goalc/compiler/compilation/Atoms.cpp b/goalc/compiler/compilation/Atoms.cpp index 7b56aaa160..dc85c2af11 100644 --- a/goalc/compiler/compilation/Atoms.cpp +++ b/goalc/compiler/compilation/Atoms.cpp @@ -330,12 +330,12 @@ Val* Compiler::compile_pair(const goos::Object& code, Env* env) { * The type is always int. */ Val* Compiler::compile_integer(const goos::Object& code, Env* env) { - assert(code.is_int()); + ASSERT(code.is_int()); return compile_integer(code.integer_obj.value, env); } Val* Compiler::compile_char(const goos::Object& code, Env* env) { - assert(code.is_char()); + ASSERT(code.is_char()); return compile_integer(uint8_t(code.char_obj.value), env); } @@ -460,7 +460,7 @@ Val* Compiler::compile_string(const std::string& str, Env* env, int seg) { * of the code, at least in Jak 1. */ Val* Compiler::compile_float(const goos::Object& code, Env* env) { - assert(code.is_float()); + ASSERT(code.is_float()); // TODO: this will put top-level only floats in main. Which is conservative because I // don't think we can take the address of a float constant. return compile_float(code.float_obj.value, env, env->function_env()->segment_for_static_data()); diff --git a/goalc/compiler/compilation/CompilerControl.cpp b/goalc/compiler/compilation/CompilerControl.cpp index 41deefb0a2..d693206935 100644 --- a/goalc/compiler/compilation/CompilerControl.cpp +++ b/goalc/compiler/compilation/CompilerControl.cpp @@ -407,7 +407,7 @@ std::string Compiler::make_symbol_info_description(const SymbolInfo& info) { return fmt::format("[Forward-Declared] Name: {} Defined: {}", info.name(), m_goos.reader.db.get_info_for(info.src_form())); default: - assert(false); + ASSERT(false); return {}; } } diff --git a/goalc/compiler/compilation/Debug.cpp b/goalc/compiler/compilation/Debug.cpp index 923d6fd722..ef5cd8e2d6 100644 --- a/goalc/compiler/compilation/Debug.cpp +++ b/goalc/compiler/compilation/Debug.cpp @@ -194,7 +194,7 @@ void mem_print(T* data, int count, u32 start_addr, PrintMode mode) { format_string = "{:8.4f} "; // todo, is this what we want? break; default: - assert(false); + ASSERT(false); } // loop over elts @@ -314,7 +314,7 @@ Val* Compiler::compile_pm(const goos::Object& form, const goos::Object& rest, En } break; default: - assert(false); + ASSERT(false); } return get_none(); diff --git a/goalc/compiler/compilation/Define.cpp b/goalc/compiler/compilation/Define.cpp index f3f781e94c..d3cb1fdc75 100644 --- a/goalc/compiler/compilation/Define.cpp +++ b/goalc/compiler/compilation/Define.cpp @@ -125,7 +125,7 @@ void Compiler::set_bits_in_bitfield(const goos::Object& form, // to shift us all the way to the left and clear upper bits int left_shift_amnt = 64 - size; int right_shift_amnt = (64 - size) - offset; - assert(right_shift_amnt >= 0); + ASSERT(right_shift_amnt >= 0); if (left_shift_amnt > 0) { env->emit_ir(form, IntegerMathKind::SHL_64, temp, left_shift_amnt); @@ -163,7 +163,7 @@ void Compiler::set_bitfield_128(const goos::Object& form, BitFieldVal* dst, RegV bool get_top = dst->offset() >= 64; // first, get the value we want to modify: - assert(m_ts.lookup_type(dst->parent()->type())->get_preferred_reg_class() == RegClass::INT_128); + ASSERT(m_ts.lookup_type(dst->parent()->type())->get_preferred_reg_class() == RegClass::INT_128); RegVal* original_original = dst->parent()->to_xmm128(form, env); // next, get the 64-bit part we want to modify in the lower 64 bits of an XMM diff --git a/goalc/compiler/compilation/Function.cpp b/goalc/compiler/compilation/Function.cpp index 8387842a29..bdf1d77e09 100644 --- a/goalc/compiler/compilation/Function.cpp +++ b/goalc/compiler/compilation/Function.cpp @@ -20,7 +20,7 @@ const goos::Object& get_lambda_body(const goos::Object& def) { iter = &iter->as_pair()->cdr; iter = &iter->as_pair()->cdr; } else { - assert(car.is_list()); + ASSERT(car.is_list()); return iter->as_pair()->cdr; } } @@ -135,7 +135,7 @@ Val* Compiler::compile_lambda(const goos::Object& form, const goos::Object& rest lambda_ts.add_arg(parm.type); } }); - assert(lambda.params.size() == lambda_ts.arg_count()); + ASSERT(lambda.params.size() == lambda_ts.arg_count()); // optional name for debugging (defun sets this) if (args.has_named("name")) { @@ -295,7 +295,7 @@ Val* Compiler::compile_lambda(const goos::Object& form, const goos::Object& rest new_func_env->finish(); // save our code for possible inlining - assert(obj_env); + ASSERT(obj_env); if (new_func_env->settings.save_code) { obj_env->add_function(std::move(new_func_env)); } @@ -552,7 +552,7 @@ Val* Compiler::compile_function_or_method_call(const goos::Object& form, Env* en } } - assert(false); + ASSERT(false); return get_none(); } diff --git a/goalc/compiler/compilation/Math.cpp b/goalc/compiler/compilation/Math.cpp index c30582d03d..8105200720 100644 --- a/goalc/compiler/compilation/Math.cpp +++ b/goalc/compiler/compilation/Math.cpp @@ -147,9 +147,9 @@ Val* Compiler::compile_add(const goos::Object& form, const goos::Object& rest, E throw_compiler_error(form, "Cannot do math on a {}.", first_type.print()); break; default: - assert(false); + ASSERT(false); } - assert(false); + ASSERT(false); return get_none(); } @@ -204,9 +204,9 @@ Val* Compiler::compile_mul(const goos::Object& form, const goos::Object& rest, E throw_compiler_error(form, "Cannot do math on a {}.", first_type.print()); break; default: - assert(false); + ASSERT(false); } - assert(false); + ASSERT(false); return get_none(); } @@ -298,9 +298,9 @@ Val* Compiler::compile_imul64(const goos::Object& form, const goos::Object& rest throw_compiler_error(form, "Cannot do imul64 on a {}.", first_type.print()); break; default: - assert(false); + ASSERT(false); } - assert(false); + ASSERT(false); return get_none(); } @@ -366,9 +366,9 @@ Val* Compiler::compile_sub(const goos::Object& form, const goos::Object& rest, E throw_compiler_error(form, "Cannot do math on a {}.", first_type.print()); break; default: - assert(false); + ASSERT(false); } - assert(false); + ASSERT(false); return get_none(); } @@ -493,9 +493,9 @@ Val* Compiler::compile_div(const goos::Object& form, const goos::Object& rest, E throw_compiler_error(form, "Cannot do math on a {}.", first_type.print()); break; default: - assert(false); + ASSERT(false); } - assert(false); + ASSERT(false); return get_none(); } diff --git a/goalc/compiler/compilation/Static.cpp b/goalc/compiler/compilation/Static.cpp index ac350b16ee..0be48714d5 100644 --- a/goalc/compiler/compilation/Static.cpp +++ b/goalc/compiler/compilation/Static.cpp @@ -20,7 +20,7 @@ void Compiler::compile_static_structure_inline(const goos::Object& form, int offset, Env* env) { auto type_info = dynamic_cast(m_ts.lookup_type(type)); - assert(type_info); + ASSERT(type_info); // make sure we have enough space if (int(structure->data.size()) < offset + type_info->get_size_in_memory()) { @@ -121,10 +121,10 @@ void Compiler::compile_static_structure_inline(const goos::Object& form, } } else if (is_integer(field_info.type)) { - assert(field_info.needs_deref); // for now... + ASSERT(field_info.needs_deref); // for now... auto deref_info = m_ts.get_deref_info(m_ts.make_pointer_typespec(field_info.type)); - assert(field_offset + deref_info.load_size <= int(structure->data.size())); - assert(!field_info.field.is_inline()); + ASSERT(field_offset + deref_info.load_size <= int(structure->data.size())); + ASSERT(!field_info.field.is_inline()); auto sr = compile_static(field_value, env); if (!sr.is_constant_data()) { throw_compiler_error(form, "Could not use {} for an integer field", field_value.print()); @@ -144,7 +144,7 @@ void Compiler::compile_static_structure_inline(const goos::Object& form, } else if (is_structure(field_info.type) || is_pair(field_info.type)) { if (is_pair(field_info.type)) { - assert(!field_info.field.is_inline()); + ASSERT(!field_info.field.is_inline()); } if (field_info.field.is_inline()) { @@ -184,19 +184,19 @@ void Compiler::compile_static_structure_inline(const goos::Object& form, } } else { - assert(field_info.needs_deref); + ASSERT(field_info.needs_deref); auto deref_info = m_ts.get_deref_info(m_ts.make_pointer_typespec(field_info.type)); auto field_size = deref_info.load_size; - assert(field_offset + field_size <= int(structure->data.size())); + ASSERT(field_offset + field_size <= int(structure->data.size())); auto sr = compile_static(field_value, env); if (sr.is_symbol()) { if (sr.symbol_name() != "#f" && sr.symbol_name() != "_empty_") { typecheck(form, field_info.type, sr.typespec()); } structure->add_symbol_record(sr.symbol_name(), field_offset); - assert(deref_info.mem_deref); - assert(deref_info.can_deref); - assert(deref_info.load_size == 4); + ASSERT(deref_info.mem_deref); + ASSERT(deref_info.can_deref); + ASSERT(deref_info.load_size == 4); // the linker needs to see a -1 in order to know to insert a symbol pointer // instead of just the symbol table offset. u32 linker_val = 0xffffffff; @@ -218,11 +218,11 @@ void Compiler::compile_static_structure_inline(const goos::Object& form, } } } else if (is_float(field_info.type)) { - assert(field_info.needs_deref); + ASSERT(field_info.needs_deref); auto deref_info = m_ts.get_deref_info(m_ts.make_pointer_typespec(field_info.type)); auto field_size = deref_info.load_size; - assert(field_offset + field_size <= int(structure->data.size())); - assert(!field_info.field.is_inline()); + ASSERT(field_offset + field_size <= int(structure->data.size())); + ASSERT(!field_info.field.is_inline()); auto sr = compile_static(field_value, env); if (!sr.is_constant_data()) { throw_compiler_error(form, "Could not use {} for a float field", field_value.print()); @@ -236,7 +236,7 @@ void Compiler::compile_static_structure_inline(const goos::Object& form, throw_compiler_error(form, "Invalid definition of field {}", field_info.field.name()); } typecheck(form, field_info.type, sr.typespec()); - assert(sr.reference()->get_addr_offset() == 0); + ASSERT(sr.reference()->get_addr_offset() == 0); structure->add_pointer_record(field_offset, sr.reference(), sr.reference()->get_addr_offset()); } else if (field_info.type.base_type() == "pointer") { @@ -245,9 +245,9 @@ void Compiler::compile_static_structure_inline(const goos::Object& form, // allow #f to be used for a pointer. structure->add_symbol_record(sr.symbol_name(), field_offset); auto deref_info = m_ts.get_deref_info(m_ts.make_pointer_typespec(field_info.type)); - assert(deref_info.mem_deref); - assert(deref_info.can_deref); - assert(deref_info.load_size == 4); + ASSERT(deref_info.mem_deref); + ASSERT(deref_info.can_deref); + ASSERT(deref_info.load_size == 4); // the linker needs to see a -1 in order to know to insert a symbol pointer // instead of just the symbol table offset. u32 linker_val = 0xffffffff; @@ -257,7 +257,7 @@ void Compiler::compile_static_structure_inline(const goos::Object& form, throw_compiler_error(form, "Invalid definition of field {}", field_info.field.name()); } typecheck(form, field_info.type, sr.typespec()); - assert(sr.reference()->get_addr_offset() == 0); + ASSERT(sr.reference()->get_addr_offset() == 0); structure->add_pointer_record(field_offset, sr.reference(), sr.reference()->get_addr_offset()); } @@ -265,7 +265,7 @@ void Compiler::compile_static_structure_inline(const goos::Object& form, } else { - assert(false); // for now + ASSERT(false); // for now } } } @@ -285,7 +285,7 @@ StaticResult Compiler::compile_new_static_structure(const goos::Object& form, } auto type_info = dynamic_cast(m_ts.lookup_type(type)); - assert(type_info); + ASSERT(type_info); obj->data.resize(type_info->get_size_in_memory()); compile_static_structure_inline(form, type, _field_defs, obj.get(), 0, env); @@ -312,7 +312,7 @@ Val* Compiler::compile_bitfield_definition(const goos::Object& form, // look up the bitfield type we're working with. For now, make sure it's under 8 bytes. auto type_info = dynamic_cast(m_ts.lookup_type(type)); - assert(type_info); + ASSERT(type_info); bool use_128 = type_info->get_load_size() == 16; // We will construct this bitfield in two passes. @@ -347,7 +347,7 @@ Val* Compiler::compile_bitfield_definition(const goos::Object& form, auto field_offset = field_info.offset; auto field_size = field_info.size; - assert(field_offset + field_size <= type_info->get_load_size() * 8); + ASSERT(field_offset + field_size <= type_info->get_load_size() * 8); if (is_integer(field_info.result_type) || field_info.result_type.base_type() == "pointer") { // first, try as a constant @@ -375,7 +375,7 @@ Val* Compiler::compile_bitfield_definition(const goos::Object& form, } else { u64 unsigned_value = value; u64 or_value = unsigned_value; - assert(field_size <= 64); + ASSERT(field_size <= 64); // shift us all the way left to clear upper bits. or_value <<= (64 - field_size); // and back right. @@ -386,7 +386,7 @@ Val* Compiler::compile_bitfield_definition(const goos::Object& form, bool start_lo = field_offset < 64; bool end_lo = (field_offset + field_size) <= 64; - assert(start_lo == end_lo); + ASSERT(start_lo == end_lo); if (end_lo) { constant_integer_part.lo |= (or_value << field_offset); } else { @@ -422,7 +422,7 @@ Val* Compiler::compile_bitfield_definition(const goos::Object& form, u64 float_value = float_as_u32(value); bool start_lo = field_offset < 64; bool end_lo = (field_offset + field_size) <= 64; - assert(start_lo == end_lo); + ASSERT(start_lo == end_lo); if (end_lo) { constant_integer_part.lo |= (float_value << field_offset); } else { @@ -467,7 +467,7 @@ Val* Compiler::compile_bitfield_definition(const goos::Object& form, integer = compile_integer(constant_integer_part, env); } else { integer = compile_integer(constant_integer_part.lo, env); - assert(constant_integer_part.hi == 0); + ASSERT(constant_integer_part.hi == 0); } integer->set_type(type); @@ -475,7 +475,7 @@ Val* Compiler::compile_bitfield_definition(const goos::Object& form, if (dynamic_defs.empty()) { return integer; } else { - assert(allow_dynamic_construction); + ASSERT(allow_dynamic_construction); if (use_128) { auto integer_lo = compile_integer(constant_integer_part.lo, env)->to_gpr(form, env); @@ -496,8 +496,8 @@ Val* Compiler::compile_bitfield_definition(const goos::Object& form, bool start_lo = def.field_offset < 64; bool end_lo = def.field_offset + def.field_size <= 64; - assert(start_lo == end_lo); - assert(def.field_size <= 64); + ASSERT(start_lo == end_lo); + ASSERT(def.field_size <= 64); int corrected_offset = def.field_offset; if (!start_lo) { @@ -506,7 +506,7 @@ Val* Compiler::compile_bitfield_definition(const goos::Object& form, int left_shift_amnt = 64 - def.field_size; int right_shift_amnt = (64 - def.field_size) - corrected_offset; - assert(right_shift_amnt >= 0); + ASSERT(right_shift_amnt >= 0); if (left_shift_amnt > 0) { env->emit_ir(form, IntegerMathKind::SHL_64, field_val, left_shift_amnt); @@ -537,7 +537,7 @@ Val* Compiler::compile_bitfield_definition(const goos::Object& form, } int left_shift_amnt = 64 - def.field_size; int right_shift_amnt = (64 - def.field_size) - def.field_offset; - assert(right_shift_amnt >= 0); + ASSERT(right_shift_amnt >= 0); if (left_shift_amnt > 0) { env->emit_ir(form, IntegerMathKind::SHL_64, field_val, left_shift_amnt); @@ -802,7 +802,7 @@ StaticResult Compiler::compile_static(const goos::Object& form_before_macro, Env return StaticResult::make_type_ref(type_name, method_count); } else if (first.is_symbol("lambda")) { auto lambda = dynamic_cast(compile_lambda(form, rest, env)); - assert(lambda); + ASSERT(lambda); if (!lambda->func) { throw_compiler_error(form, "Static lambda cannot be inline."); } @@ -829,8 +829,8 @@ void Compiler::fill_static_array_inline(const goos::Object& form, Env* env) { auto pointer_type = m_ts.make_pointer_typespec(content_type); auto deref_info = m_ts.get_deref_info(pointer_type); - assert(deref_info.can_deref); - assert(deref_info.mem_deref); + ASSERT(deref_info.can_deref); + ASSERT(deref_info.mem_deref); for (int arg_idx = 0; arg_idx < args_array_length; arg_idx++) { int elt_offset = offset + arg_idx * deref_info.stride; auto sr = compile_static(args_array[arg_idx], env); @@ -840,12 +840,12 @@ void Compiler::fill_static_array_inline(const goos::Object& form, typecheck(form, content_type, sr.typespec()); } if (sr.is_symbol()) { - assert(deref_info.stride == 4); + ASSERT(deref_info.stride == 4); structure->add_symbol_record(sr.symbol_name(), elt_offset); u32 symbol_placeholder = 0xffffffff; memcpy(structure->data.data() + elt_offset, &symbol_placeholder, 4); } else if (sr.is_reference()) { - assert(deref_info.stride == 4); + ASSERT(deref_info.stride == 4); structure->add_pointer_record(elt_offset, sr.reference(), sr.reference()->get_addr_offset()); } else if (sr.is_constant_data()) { if (!sr.constant().copy_to(structure->data.data() + elt_offset, deref_info.load_size, @@ -854,7 +854,7 @@ void Compiler::fill_static_array_inline(const goos::Object& form, sr.constant().print(), arg_idx, content_type.print()); } } else { - assert(false); + ASSERT(false); } } } @@ -879,8 +879,8 @@ StaticResult Compiler::fill_static_array(const goos::Object& form, // todo - generalize this array stuff if we ever need other types of static arrays. auto pointer_type = m_ts.make_pointer_typespec(content_type); auto deref_info = m_ts.get_deref_info(pointer_type); - assert(deref_info.can_deref); - assert(deref_info.mem_deref); + ASSERT(deref_info.can_deref); + ASSERT(deref_info.mem_deref); auto array_data_size_bytes = length * deref_info.stride; std::unique_ptr obj; @@ -949,8 +949,8 @@ StaticResult Compiler::fill_static_boxed_array(const goos::Object& form, // todo - generalize this array stuff if we ever need other types of static arrays. auto pointer_type = m_ts.make_pointer_typespec(content_type); auto deref_info = m_ts.get_deref_info(pointer_type); - assert(deref_info.can_deref); - assert(deref_info.mem_deref); + ASSERT(deref_info.can_deref); + ASSERT(deref_info.mem_deref); auto array_data_size_bytes = allocated_length * deref_info.stride; // todo, segments std::unique_ptr obj; @@ -989,8 +989,8 @@ void Compiler::fill_static_inline_array_inline(const goos::Object& form, Env* env) { auto inline_array_type = m_ts.make_inline_array_typespec(content_type); auto deref_info = m_ts.get_deref_info(inline_array_type); - assert(deref_info.can_deref); - assert(!deref_info.mem_deref); + ASSERT(deref_info.can_deref); + ASSERT(!deref_info.mem_deref); for (size_t i = 4; i < args.size(); i++) { auto arg_idx = i - 4; @@ -1051,8 +1051,8 @@ StaticResult Compiler::fill_static_inline_array(const goos::Object& form, auto inline_array_type = m_ts.make_inline_array_typespec(content_type); auto deref_info = m_ts.get_deref_info(inline_array_type); - assert(deref_info.can_deref); - assert(!deref_info.mem_deref); + ASSERT(deref_info.can_deref); + ASSERT(!deref_info.mem_deref); auto obj = std::make_unique(seg); obj->set_offset(is_basic(content_type) ? 4 : 0); obj->data.resize(length * deref_info.stride); @@ -1067,9 +1067,9 @@ StaticResult Compiler::fill_static_inline_array(const goos::Object& form, } Val* Compiler::compile_static_pair(const goos::Object& form, Env* env, int seg) { - assert(form.is_pair()); // (quote PAIR) + ASSERT(form.is_pair()); // (quote PAIR) auto result = compile_static_no_eval_for_pairs(form, env, seg, true); - assert(result.is_reference()); + ASSERT(result.is_reference()); auto fe = env->function_env(); auto static_result = fe->alloc_val(result.reference(), result.typespec()); return static_result; diff --git a/goalc/compiler/compilation/Type.cpp b/goalc/compiler/compilation/Type.cpp index 3c372ac72b..420ff9861e 100644 --- a/goalc/compiler/compilation/Type.cpp +++ b/goalc/compiler/compilation/Type.cpp @@ -31,7 +31,7 @@ RegVal* Compiler::compile_get_method_of_type(const goos::Object& form, auto info = m_ts.lookup_method(compile_time_type.base_type(), method_name); info.type = info.type.substitute_for_method_call(compile_time_type.base_type()); auto offset_of_method = get_offset_of_method(info.id); - assert(type->type() == TypeSpec("type")); + ASSERT(type->type() == TypeSpec("type")); auto fe = env->function_env(); @@ -42,10 +42,10 @@ RegVal* Compiler::compile_get_method_of_type(const goos::Object& form, auto loc_type = m_ts.make_pointer_typespec(info.type); auto loc = fe->alloc_val(loc_type, type, offset_of_method); auto di = m_ts.get_deref_info(loc_type); - assert(di.can_deref); - assert(di.mem_deref); - assert(di.sign_extend == false); - assert(di.load_size == 4); + ASSERT(di.can_deref); + ASSERT(di.mem_deref); + ASSERT(di.sign_extend == false); + ASSERT(di.load_size == 4); auto deref = fe->alloc_val(di.result_type, loc, MemLoadInfo(di)); return deref->to_reg(form, env); @@ -111,10 +111,10 @@ RegVal* Compiler::compile_get_method_of_object(const goos::Object& form, auto loc_type = m_ts.make_pointer_typespec(method_info.type); auto loc = fe->alloc_val(loc_type, runtime_type, offset_of_method); auto di = m_ts.get_deref_info(loc_type); - assert(di.can_deref); - assert(di.mem_deref); - assert(di.sign_extend == false); - assert(di.load_size == 4); + ASSERT(di.can_deref); + ASSERT(di.mem_deref); + ASSERT(di.sign_extend == false); + ASSERT(di.load_size == 4); auto deref = fe->alloc_val(di.result_type, loc, MemLoadInfo(di)); return deref->to_reg(form, env); @@ -472,7 +472,7 @@ Val* Compiler::compile_defmethod(const goos::Object& form, const goos::Object& _ lambda.params.push_back(parm); } }); - assert(lambda.params.size() == lambda_ts.arg_count()); + ASSERT(lambda.params.size() == lambda_ts.arg_count()); // todo, verify argument list types (check that first arg is _type_ for methods that aren't "new") lambda.debug_name = fmt::format("(method {} {})", method_name.print(), type_name.print()); @@ -602,7 +602,7 @@ Val* Compiler::compile_defmethod(const goos::Object& form, const goos::Object& _ new_func_env->finish(); auto obj_env = new_func_env->file_env(); - assert(obj_env); + ASSERT(obj_env); if (new_func_env->settings.save_code) { obj_env->add_function(std::move(new_func_env)); } @@ -634,8 +634,8 @@ Val* Compiler::get_field_of_structure(const StructureType* type, auto loc = fe->alloc_val(loc_type, object, field.field.offset() + offset); auto di = m_ts.get_deref_info(loc_type); - assert(di.can_deref); - assert(di.mem_deref); + ASSERT(di.can_deref); + ASSERT(di.mem_deref); result = fe->alloc_val(di.result_type, loc, MemLoadInfo(di)); result->mark_as_settable(); } else { @@ -701,7 +701,7 @@ Val* Compiler::compile_deref(const goos::Object& form, const goos::Object& _rest fe->alloc_val(deref_info.result_type, result, MemLoadInfo(deref_info)); result->mark_as_settable(); } else { - assert(false); + ASSERT(false); } return result; } @@ -770,7 +770,7 @@ Val* Compiler::compile_deref(const goos::Object& form, const goos::Object& _rest } auto di = m_ts.get_deref_info(result->type()); auto base_type = di.result_type; - assert(di.can_deref); + ASSERT(di.can_deref); if (has_constant_idx) { result = fe->alloc_val(di.result_type, result, di.stride * constant_index_value); @@ -787,8 +787,8 @@ Val* Compiler::compile_deref(const goos::Object& form, const goos::Object& _rest } auto di = m_ts.get_deref_info(result->type()); auto base_type = di.result_type; - assert(di.mem_deref); - assert(di.can_deref); + ASSERT(di.mem_deref); + ASSERT(di.can_deref); Val* loc = nullptr; if (has_constant_idx) { loc = fe->alloc_val(result->type(), result, @@ -812,9 +812,9 @@ Val* Compiler::compile_deref(const goos::Object& form, const goos::Object& _rest auto di = m_ts.get_deref_info(loc_type); // and the result auto base_type = di.result_type; - assert(base_type == result->type().get_single_arg()); - assert(di.mem_deref); - assert(di.can_deref); + ASSERT(base_type == result->type().get_single_arg()); + ASSERT(di.mem_deref); + ASSERT(di.can_deref); Val* loc = nullptr; if (has_constant_idx) { @@ -1135,7 +1135,7 @@ Val* Compiler::compile_stack_new(const goos::Object& form, int stride = align(type_info->get_size_in_memory(), type_info->get_inline_array_stride_alignment()); - assert(stride == info.stride); + ASSERT(stride == info.stride); int size_in_bytes = info.stride * constant_count; auto addr = fe->allocate_aligned_stack_variable(ts, size_in_bytes, 16); @@ -1148,7 +1148,7 @@ Val* Compiler::compile_stack_new(const goos::Object& form, type_of_object.print()); } auto ti_as_struct = dynamic_cast(ti); - assert(ti_as_struct); + ASSERT(ti_as_struct); if (ti_as_struct->is_dynamic()) { throw_compiler_error(form, "Cannot stack allocate the dynamic type {}.", @@ -1395,7 +1395,7 @@ Val* Compiler::compile_enum_lookup(const goos::Object& form, Env* env) { bool success; u64 value = enum_lookup(form, e, rest, true, &success); - assert(success); + ASSERT(success); auto result = compile_integer(value, env); result->set_type(TypeSpec(e->get_name())); return result; diff --git a/goalc/data_compiler/DataObjectGenerator.cpp b/goalc/data_compiler/DataObjectGenerator.cpp index ac3db7681b..a05f7a55ef 100644 --- a/goalc/data_compiler/DataObjectGenerator.cpp +++ b/goalc/data_compiler/DataObjectGenerator.cpp @@ -2,7 +2,7 @@ #include #include "DataObjectGenerator.h" #include "common/link_types.h" -#include "common/util/assert.h" +#include "common/util/Assert.h" namespace { template @@ -171,7 +171,7 @@ std::vector DataObjectGenerator::generate_link_table() { auto& entry = m_ptr_links.at(i); int diff = int(entry.source_word) - int(last_word); last_word = entry.source_word + 1; - assert(diff >= 0); + ASSERT(diff >= 0); push_variable_length_integer(diff, &link); m_words.at(entry.source_word) = entry.target_byte; @@ -205,7 +205,7 @@ std::vector DataObjectGenerator::generate_link_table() { for (auto& x : sl.second) { int diff = x - prev; - assert(diff >= 0); + ASSERT(diff >= 0); push_better_variable_length_integer(diff * 4, &link); m_words.at(x) = 0xffffffff; prev = x; @@ -226,7 +226,7 @@ std::vector DataObjectGenerator::generate_link_table() { for (auto& x : tl.second) { int diff = x - prev; - assert(diff >= 0); + ASSERT(diff >= 0); push_better_variable_length_integer(diff * 4, &link); m_words.at(x) = 0xffffffff; prev = x; diff --git a/goalc/debugger/DebugInfo.h b/goalc/debugger/DebugInfo.h index 7524ed32e7..98640f3d54 100644 --- a/goalc/debugger/DebugInfo.h +++ b/goalc/debugger/DebugInfo.h @@ -8,7 +8,7 @@ #include "common/common_types.h" #include "goalc/emitter/Instruction.h" #include "goalc/debugger/disassemble.h" -#include "common/util/assert.h" +#include "common/util/Assert.h" class FunctionEnv; @@ -40,7 +40,7 @@ class DebugInfo { FunctionDebugInfo& add_function(const std::string& name, const std::string& obj_name) { if (m_functions.find(name) != m_functions.end()) { - assert(false); + ASSERT(false); } auto& result = m_functions[name]; result.name = name; diff --git a/goalc/debugger/Debugger.cpp b/goalc/debugger/Debugger.cpp index 790b5ae9af..84fbf4e17c 100644 --- a/goalc/debugger/Debugger.cpp +++ b/goalc/debugger/Debugger.cpp @@ -12,7 +12,7 @@ #include "goalc/emitter/Register.h" #include "goalc/listener/Listener.h" #include "third-party/fmt/core.h" -#include "common/util/assert.h" +#include "common/util/Assert.h" /*! * Is the target halted? If we don't know or aren't connected, returns false. @@ -208,7 +208,7 @@ InstructionPointerInfo Debugger::get_rip_info(u64 rip) { result.function_offset = obj_offset - info->offset_in_seg; result.func_debug = info; - assert(!info->instructions.empty()); + ASSERT(!info->instructions.empty()); } } } @@ -369,7 +369,7 @@ Disassembly Debugger::disassemble_at_rip(const InstructionPointerInfo& info) { FunctionDebugInfo* func_info = info.func_debug; std::string name = func_info->name; auto continue_info = get_continue_info(rip); - assert(!func_info->instructions.empty()); + ASSERT(!func_info->instructions.empty()); std::vector function_mem; function_mem.resize(func_info->instructions.back().offset + @@ -438,7 +438,7 @@ void Debugger::update_break_info() { * Waits for break to be acknowledged and reads break info. */ bool Debugger::do_break() { - assert(is_valid() && is_attached() && is_running()); + ASSERT(is_valid() && is_attached() && is_running()); m_expecting_immeidate_break = true; m_continue_info.valid = false; clear_signal_queue(); @@ -446,7 +446,7 @@ bool Debugger::do_break() { return false; } else { auto info = pop_signal(); - assert(info.kind == xdbg::SignalInfo::BREAK); + ASSERT(info.kind == xdbg::SignalInfo::BREAK); update_break_info(); m_running = false; return true; @@ -457,22 +457,22 @@ bool Debugger::do_break() { * Continue the target, must be attached and stopped. */ bool Debugger::do_continue() { - assert(is_valid() && is_attached() && is_halted()); + ASSERT(is_valid() && is_attached() && is_halted()); if (!m_regs_valid) { update_break_info(); } - assert(regs_valid()); + ASSERT(regs_valid()); if (!m_continue_info.valid) { update_continue_info(); } - assert(m_continue_info.valid); + ASSERT(m_continue_info.valid); m_regs_valid = false; if (m_continue_info.subtract_1) { m_regs_at_break.rip--; auto result = xdbg::set_regs_now(m_debug_context.tid, m_regs_at_break); - assert(result); + ASSERT(result); } m_expecting_immeidate_break = false; @@ -488,12 +488,12 @@ bool Debugger::do_continue() { * Read memory from an attached and halted target. */ bool Debugger::read_memory(u8* dest_buffer, int size, u32 goal_addr) const { - assert(is_valid() && is_attached() && is_halted()); + ASSERT(is_valid() && is_attached() && is_halted()); return xdbg::read_goal_memory(dest_buffer, size, goal_addr, m_debug_context, m_memory_handle); } bool Debugger::read_memory_if_safe(u8* dest_buffer, int size, u32 goal_addr) const { - assert(is_valid() && is_attached() && is_halted()); + ASSERT(is_valid() && is_attached() && is_halted()); if (goal_addr >= EE_MAIN_MEM_LOW_PROTECT && goal_addr + size < EE_MAIN_MEM_SIZE) { return read_memory(dest_buffer, size, goal_addr); } @@ -504,7 +504,7 @@ bool Debugger::read_memory_if_safe(u8* dest_buffer, int size, u32 goal_addr) con * Write the memory of an attached and halted target. */ bool Debugger::write_memory(const u8* src_buffer, int size, u32 goal_addr) { - assert(is_valid() && is_attached() && is_halted()); + ASSERT(is_valid() && is_attached() && is_halted()); return xdbg::write_goal_memory(src_buffer, size, goal_addr, m_debug_context, m_memory_handle); } @@ -512,7 +512,7 @@ bool Debugger::write_memory(const u8* src_buffer, int size, u32 goal_addr) { * Read the GOAL Symbol table from an attached and halted target. */ void Debugger::read_symbol_table() { - assert(is_valid() && is_attached() && is_halted()); + ASSERT(is_valid() && is_attached() && is_halted()); u32 bytes_read = 0; u32 reads = 0; Timer timer; @@ -581,8 +581,8 @@ void Debugger::read_symbol_table() { // GOAL sym - s7 auto sym_offset = s32(offset + st_base + BASIC_OFFSET) - s32(m_debug_context.s7); - assert(sym_offset >= INT16_MIN); - assert(sym_offset <= INT16_MAX); + ASSERT(sym_offset >= INT16_MIN); + ASSERT(sym_offset <= INT16_MAX); std::string str(str_buff); if (str.length() >= 50) { @@ -601,7 +601,7 @@ void Debugger::read_symbol_table() { } else { fmt::print("Symbol {} (#x{:x}) appears multiple times!\n", str, sym_offset); continue; - // assert(false); + // ASSERT(false); } } @@ -611,7 +611,7 @@ void Debugger::read_symbol_table() { } } - assert(m_symbol_offset_to_name_map.size() == m_symbol_name_to_offset_map.size()); + ASSERT(m_symbol_offset_to_name_map.size() == m_symbol_name_to_offset_map.size()); fmt::print("Read symbol table ({} bytes, {} reads, {} symbols, {:.2f} ms)\n", bytes_read, reads, m_symbol_name_to_offset_map.size(), timer.getMs()); } @@ -621,7 +621,7 @@ void Debugger::read_symbol_table() { * Returns 0 if the symbol doesn't exist. */ u32 Debugger::get_symbol_address(const std::string& sym_name) { - assert(is_valid()); + ASSERT(is_valid()); auto kv = m_symbol_name_to_offset_map.find(sym_name); if (kv != m_symbol_name_to_offset_map.end()) { return m_debug_context.s7 + kv->second; @@ -633,7 +633,7 @@ u32 Debugger::get_symbol_address(const std::string& sym_name) { * Get the value of a symbol by name. Returns if the symbol exists and populates output if it does. */ bool Debugger::get_symbol_value(const std::string& sym_name, u32* output) { - assert(is_valid()); + ASSERT(is_valid()); auto kv = m_symbol_name_to_value_map.find(sym_name); if (kv != m_symbol_name_to_value_map.end()) { *output = kv->second; @@ -646,7 +646,7 @@ bool Debugger::get_symbol_value(const std::string& sym_name, u32* output) { * Get the value of a symbol by name. Returns NULL if symbol does not exist. */ const char* Debugger::get_symbol_name_from_offset(s32 ofs) const { - assert(is_valid()); + ASSERT(is_valid()); auto kv = m_symbol_offset_to_name_map.find(ofs); if (kv != m_symbol_offset_to_name_map.end()) { return kv->second.c_str(); @@ -682,7 +682,7 @@ void Debugger::start_watcher() { if (m_watcher_running) { stop_watcher(); } - assert(!m_watcher_running); + ASSERT(!m_watcher_running); m_watcher_running = true; m_watcher_should_stop = false; { @@ -696,7 +696,7 @@ void Debugger::start_watcher() { * Stops the debugger watch thread (waits for it to end) */ void Debugger::stop_watcher() { - assert(m_watcher_running); + ASSERT(m_watcher_running); m_watcher_running = false; m_watcher_should_stop = true; m_watcher_thread.join(); @@ -762,7 +762,7 @@ void Debugger::watcher() { #endif default: printf("[Debugger] unhandled signal in watcher: %d\n", int(signal_info.kind)); - assert(false); + ASSERT(false); } { @@ -802,7 +802,7 @@ Debugger::SignalInfo Debugger::pop_signal() { Debugger::SignalInfo result; if (!try_pop_signal(&result)) { - assert(false); + ASSERT(false); } return result; } @@ -962,7 +962,7 @@ std::string Debugger::disassemble_x86_with_symbols(int len, u64 base_addr) const result.replace(pos + 1, read + sym_val_string.length() - 1, sym_str); // the [ is ignored (result is something like: [identity]) pos += sym_str.length() + 1; - assert(result.at(pos) == ']'); // maybe? + ASSERT(result.at(pos) == ']'); // maybe? } else { // symbol not found for whatever reason, just use regular disassembly and skip over pos += 1; diff --git a/goalc/debugger/Debugger.h b/goalc/debugger/Debugger.h index c8f0cfb5ec..5fc8df3fb9 100644 --- a/goalc/debugger/Debugger.h +++ b/goalc/debugger/Debugger.h @@ -107,7 +107,7 @@ class Debugger { * Get the x86 address of GOAL memory */ u64 get_x86_base_addr() const { - assert(m_context_valid); + ASSERT(m_context_valid); return m_debug_context.base; } @@ -115,7 +115,7 @@ class Debugger { * Get the thread being debugged. */ const xdbg::ThreadID& get_thread_id() const { - assert(m_context_valid); + ASSERT(m_context_valid); return m_debug_context.tid; } @@ -141,7 +141,7 @@ class Debugger { } const xdbg::Regs& get_regs() { - assert(m_regs_valid); + ASSERT(m_regs_valid); return m_regs_at_break; } diff --git a/goalc/debugger/disassemble.cpp b/goalc/debugger/disassemble.cpp index 10b63960e3..ae3b39daee 100644 --- a/goalc/debugger/disassemble.cpp +++ b/goalc/debugger/disassemble.cpp @@ -47,7 +47,7 @@ std::string disassemble_x86(u8* data, int len, u64 base_addr, u64 highlight_addr char print_buff[print_buff_size]; int offset = 0; - assert(highlight_addr >= base_addr); + ASSERT(highlight_addr >= base_addr); int mark_offset = int(highlight_addr - base_addr); while (offset < len) { char prefix = (offset == mark_offset) ? '-' : ' '; @@ -107,7 +107,7 @@ std::string disassemble_x86_function(u8* data, std::vector> lines; - assert(highlight_addr >= base_addr); + ASSERT(highlight_addr >= base_addr); int mark_offset = int(highlight_addr - base_addr); while (offset < len) { char prefix = (offset == mark_offset) ? '-' : ' '; diff --git a/goalc/emitter/CallingConvention.cpp b/goalc/emitter/CallingConvention.cpp index b9013a6493..4228a39588 100644 --- a/goalc/emitter/CallingConvention.cpp +++ b/goalc/emitter/CallingConvention.cpp @@ -1,11 +1,11 @@ #include "CallingConvention.h" -#include "common/util/assert.h" +#include "common/util/Assert.h" CallingConvention get_function_calling_convention(const TypeSpec& function_type, const TypeSystem& type_system) { - assert(function_type.base_type() == "function"); - assert(function_type.arg_count() > 0); - assert(function_type.arg_count() <= 9); + ASSERT(function_type.base_type() == "function"); + ASSERT(function_type.arg_count() > 0); + ASSERT(function_type.arg_count() <= 9); int gpr_idx = 0; int xmm_idx = 0; diff --git a/goalc/emitter/CodeTester.cpp b/goalc/emitter/CodeTester.cpp index d88288e697..225a289ca0 100644 --- a/goalc/emitter/CodeTester.cpp +++ b/goalc/emitter/CodeTester.cpp @@ -48,7 +48,7 @@ std::string CodeTester::dump_to_hex_string(bool nospace) { */ void CodeTester::emit(const Instruction& instr) { code_buffer_size += instr.emit(code_buffer + code_buffer_size); - assert(code_buffer_size <= code_buffer_capacity); + ASSERT(code_buffer_size <= code_buffer_capacity); } /*! @@ -134,7 +134,7 @@ void CodeTester::init_code_buffer(int capacity) { MAP_ANONYMOUS | MAP_PRIVATE, 0, 0); if (code_buffer == (u8*)(-1)) { printf("[CodeTester] Failed to map memory!\n"); - assert(false); + ASSERT(false); } code_buffer_capacity = capacity; diff --git a/goalc/emitter/CodeTester.h b/goalc/emitter/CodeTester.h index 103df5840e..3a087c20ef 100644 --- a/goalc/emitter/CodeTester.h +++ b/goalc/emitter/CodeTester.h @@ -49,7 +49,7 @@ class CodeTester { template int emit_data(T x) { auto ret = code_buffer_size; - assert(int(sizeof(T)) + code_buffer_size <= code_buffer_capacity); + ASSERT(int(sizeof(T)) + code_buffer_size <= code_buffer_capacity); memcpy(code_buffer + code_buffer_size, &x, sizeof(T)); code_buffer_size += sizeof(T); return ret; @@ -104,8 +104,8 @@ class CodeTester { */ template void write(T x, int at) { - assert(at >= 0); - assert(int(sizeof(T)) + at <= code_buffer_capacity); + ASSERT(at >= 0); + ASSERT(int(sizeof(T)) + at <= code_buffer_capacity); memcpy(code_buffer + at, &x, sizeof(T)); } @@ -114,8 +114,8 @@ class CodeTester { */ template T read(int at) { - assert(at >= 0); - assert(int(sizeof(T)) + at <= code_buffer_capacity); + ASSERT(at >= 0); + ASSERT(int(sizeof(T)) + at <= code_buffer_capacity); T result; memcpy(&result, code_buffer + at, sizeof(T)); return result; diff --git a/goalc/emitter/IGen.h b/goalc/emitter/IGen.h index 787d17dc4c..261bab823c 100644 --- a/goalc/emitter/IGen.h +++ b/goalc/emitter/IGen.h @@ -3,7 +3,7 @@ #include "Register.h" #include "Instruction.h" #include -#include "common/util/assert.h" +#include "common/util/Assert.h" namespace emitter { class IGen { @@ -15,8 +15,8 @@ class IGen { * Move data from src to dst. Moves all 64-bits of the GPR. */ static Instruction mov_gpr64_gpr64(Register dst, Register src) { - assert(dst.is_gpr()); - assert(src.is_gpr()); + ASSERT(dst.is_gpr()); + ASSERT(src.is_gpr()); Instruction instr(0x89); instr.set_modrm_and_rex(src.hw_id(), dst.hw_id(), 3, true); return instr; @@ -26,7 +26,7 @@ class IGen { * Move a 64-bit constant into a register. */ static Instruction mov_gpr64_u64(Register dst, uint64_t val) { - assert(dst.is_gpr()); + ASSERT(dst.is_gpr()); bool rex_b = false; auto dst_hw_id = dst.hw_id(); if (dst_hw_id >= 8) { @@ -43,8 +43,8 @@ class IGen { * Move a 32-bit constant into a register. Zeros the upper 32 bits. */ static Instruction mov_gpr64_u32(Register dst, uint64_t val) { - assert(val <= UINT32_MAX); - assert(dst.is_gpr()); + ASSERT(val <= UINT32_MAX); + ASSERT(dst.is_gpr()); auto dst_hw_id = dst.hw_id(); bool rex_b = false; if (dst_hw_id >= 8) { @@ -66,8 +66,8 @@ class IGen { * This is always bigger than mov_gpr64_u32, but smaller than a mov_gpr_u64. */ static Instruction mov_gpr64_s32(Register dst, int64_t val) { - assert(val >= INT32_MIN && val <= INT32_MAX); - assert(dst.is_gpr()); + ASSERT(val >= INT32_MIN && val <= INT32_MAX); + ASSERT(dst.is_gpr()); Instruction instr(0xc7); instr.set_modrm_and_rex(0, dst.hw_id(), 3, true); instr.set(Imm(4, val)); @@ -78,8 +78,8 @@ class IGen { * Move 32-bits of xmm to 32 bits of gpr (no sign extension). */ static Instruction movd_gpr32_xmm32(Register dst, Register src) { - assert(dst.is_gpr()); - assert(src.is_xmm()); + ASSERT(dst.is_gpr()); + ASSERT(src.is_xmm()); Instruction instr(0x66); instr.set_op2(0x0f); instr.set_op3(0x7e); @@ -92,8 +92,8 @@ class IGen { * Move 32-bits of gpr to 32-bits of xmm (no sign extension) */ static Instruction movd_xmm32_gpr32(Register dst, Register src) { - assert(dst.is_xmm()); - assert(src.is_gpr()); + ASSERT(dst.is_xmm()); + ASSERT(src.is_gpr()); Instruction instr(0x66); instr.set_op2(0x0f); instr.set_op3(0x6e); @@ -106,8 +106,8 @@ class IGen { * Move 64-bits of xmm to 64 bits of gpr (no sign extension). */ static Instruction movq_gpr64_xmm64(Register dst, Register src) { - assert(dst.is_gpr()); - assert(src.is_xmm()); + ASSERT(dst.is_gpr()); + ASSERT(src.is_xmm()); Instruction instr(0x66); instr.set_op2(0x0f); instr.set_op3(0x7e); @@ -120,8 +120,8 @@ class IGen { * Move 64-bits of gpr to 64-bits of xmm (no sign extension) */ static Instruction movq_xmm64_gpr64(Register dst, Register src) { - assert(dst.is_xmm()); - assert(src.is_gpr()); + ASSERT(dst.is_xmm()); + ASSERT(src.is_gpr()); Instruction instr(0x66); instr.set_op2(0x0f); instr.set_op3(0x6e); @@ -134,8 +134,8 @@ class IGen { * Move 32-bits between xmm's */ static Instruction mov_xmm32_xmm32(Register dst, Register src) { - assert(dst.is_xmm()); - assert(src.is_xmm()); + ASSERT(dst.is_xmm()); + ASSERT(src.is_xmm()); Instruction instr(0xf3); instr.set_op2(0x0f); instr.set_op3(0x10); @@ -157,12 +157,12 @@ class IGen { * Cannot use rsp. */ static Instruction load8s_gpr64_gpr64_plus_gpr64(Register dst, Register addr1, Register addr2) { - assert(dst.is_gpr()); - assert(addr1.is_gpr()); - assert(addr2.is_gpr()); - assert(addr1 != addr2); - assert(addr1 != RSP); - assert(addr2 != RSP); + ASSERT(dst.is_gpr()); + ASSERT(addr1.is_gpr()); + ASSERT(addr2.is_gpr()); + ASSERT(addr1 != addr2); + ASSERT(addr1 != RSP); + ASSERT(addr2 != RSP); Instruction instr(0xf); instr.set_op2(0xbe); instr.set_modrm_and_rex_for_reg_plus_reg_addr(dst.hw_id(), addr1.hw_id(), addr2.hw_id(), true, @@ -171,12 +171,12 @@ class IGen { } static Instruction store8_gpr64_gpr64_plus_gpr64(Register addr1, Register addr2, Register value) { - assert(value.is_gpr()); - assert(addr1.is_gpr()); - assert(addr2.is_gpr()); - assert(addr1 != addr2); - assert(addr1 != RSP); - assert(addr2 != RSP); + ASSERT(value.is_gpr()); + ASSERT(addr1.is_gpr()); + ASSERT(addr2.is_gpr()); + ASSERT(addr1 != addr2); + ASSERT(addr1 != RSP); + ASSERT(addr2 != RSP); Instruction instr(0x88); instr.set_modrm_and_rex_for_reg_plus_reg_addr(value.hw_id(), addr1.hw_id(), addr2.hw_id()); if (value.id() > RBX) { @@ -189,13 +189,13 @@ class IGen { Register addr1, Register addr2, s64 offset) { - assert(dst.is_gpr()); - assert(addr1.is_gpr()); - assert(addr2.is_gpr()); - assert(addr1 != addr2); - assert(addr1 != RSP); - assert(addr2 != RSP); - assert(offset >= INT8_MIN && offset <= INT8_MAX); + ASSERT(dst.is_gpr()); + ASSERT(addr1.is_gpr()); + ASSERT(addr2.is_gpr()); + ASSERT(addr1 != addr2); + ASSERT(addr1 != RSP); + ASSERT(addr2 != RSP); + ASSERT(offset >= INT8_MIN && offset <= INT8_MAX); Instruction instr(0xf); instr.set_op2(0xbe); instr.set_modrm_and_rex_for_reg_plus_reg_plus_s8(dst.hw_id(), addr1.hw_id(), addr2.hw_id(), @@ -207,13 +207,13 @@ class IGen { Register addr2, Register value, s64 offset) { - assert(value.is_gpr()); - assert(addr1.is_gpr()); - assert(addr2.is_gpr()); - assert(addr1 != addr2); - assert(addr1 != RSP); - assert(addr2 != RSP); - assert(offset >= INT8_MIN && offset <= INT8_MAX); + ASSERT(value.is_gpr()); + ASSERT(addr1.is_gpr()); + ASSERT(addr2.is_gpr()); + ASSERT(addr1 != addr2); + ASSERT(addr1 != RSP); + ASSERT(addr2 != RSP); + ASSERT(offset >= INT8_MIN && offset <= INT8_MAX); Instruction instr(0x88); instr.set_modrm_and_rex_for_reg_plus_reg_plus_s8(value.hw_id(), addr1.hw_id(), addr2.hw_id(), offset, false); @@ -227,13 +227,13 @@ class IGen { Register addr1, Register addr2, s64 offset) { - assert(dst.is_gpr()); - assert(addr1.is_gpr()); - assert(addr2.is_gpr()); - assert(addr1 != addr2); - assert(addr1 != RSP); - assert(addr2 != RSP); - assert(offset >= INT32_MIN && offset <= INT32_MAX); + ASSERT(dst.is_gpr()); + ASSERT(addr1.is_gpr()); + ASSERT(addr2.is_gpr()); + ASSERT(addr1 != addr2); + ASSERT(addr1 != RSP); + ASSERT(addr2 != RSP); + ASSERT(offset >= INT32_MIN && offset <= INT32_MAX); Instruction instr(0xf); instr.set_op2(0xbe); instr.set_modrm_and_rex_for_reg_plus_reg_plus_s32(dst.hw_id(), addr1.hw_id(), addr2.hw_id(), @@ -245,13 +245,13 @@ class IGen { Register addr2, Register value, s64 offset) { - assert(value.is_gpr()); - assert(addr1.is_gpr()); - assert(addr2.is_gpr()); - assert(addr1 != addr2); - assert(addr1 != RSP); - assert(addr2 != RSP); - assert(offset >= INT32_MIN && offset <= INT32_MAX); + ASSERT(value.is_gpr()); + ASSERT(addr1.is_gpr()); + ASSERT(addr2.is_gpr()); + ASSERT(addr1 != addr2); + ASSERT(addr1 != RSP); + ASSERT(addr2 != RSP); + ASSERT(offset >= INT32_MIN && offset <= INT32_MAX); Instruction instr(0x88); instr.set_modrm_and_rex_for_reg_plus_reg_plus_s32(value.hw_id(), addr1.hw_id(), addr2.hw_id(), offset, false); @@ -267,12 +267,12 @@ class IGen { * Cannot use rsp. */ static Instruction load8u_gpr64_gpr64_plus_gpr64(Register dst, Register addr1, Register addr2) { - assert(dst.is_gpr()); - assert(addr1.is_gpr()); - assert(addr2.is_gpr()); - assert(addr1 != addr2); - assert(addr1 != RSP); - assert(addr2 != RSP); + ASSERT(dst.is_gpr()); + ASSERT(addr1.is_gpr()); + ASSERT(addr2.is_gpr()); + ASSERT(addr1 != addr2); + ASSERT(addr1 != RSP); + ASSERT(addr2 != RSP); Instruction instr(0xf); instr.set_op2(0xb6); instr.set_modrm_and_rex_for_reg_plus_reg_addr(dst.hw_id(), addr1.hw_id(), addr2.hw_id(), true, @@ -284,13 +284,13 @@ class IGen { Register addr1, Register addr2, s64 offset) { - assert(dst.is_gpr()); - assert(addr1.is_gpr()); - assert(addr2.is_gpr()); - assert(addr1 != addr2); - assert(addr1 != RSP); - assert(addr2 != RSP); - assert(offset >= INT8_MIN && offset <= INT8_MAX); + ASSERT(dst.is_gpr()); + ASSERT(addr1.is_gpr()); + ASSERT(addr2.is_gpr()); + ASSERT(addr1 != addr2); + ASSERT(addr1 != RSP); + ASSERT(addr2 != RSP); + ASSERT(offset >= INT8_MIN && offset <= INT8_MAX); Instruction instr(0xf); instr.set_op2(0xb6); instr.set_modrm_and_rex_for_reg_plus_reg_plus_s8(dst.hw_id(), addr1.hw_id(), addr2.hw_id(), @@ -302,13 +302,13 @@ class IGen { Register addr1, Register addr2, s64 offset) { - assert(dst.is_gpr()); - assert(addr1.is_gpr()); - assert(addr2.is_gpr()); - assert(addr1 != addr2); - assert(addr1 != RSP); - assert(addr2 != RSP); - assert(offset >= INT32_MIN && offset <= INT32_MAX); + ASSERT(dst.is_gpr()); + ASSERT(addr1.is_gpr()); + ASSERT(addr2.is_gpr()); + ASSERT(addr1 != addr2); + ASSERT(addr1 != RSP); + ASSERT(addr2 != RSP); + ASSERT(offset >= INT32_MIN && offset <= INT32_MAX); Instruction instr(0xf); instr.set_op2(0xb6); instr.set_modrm_and_rex_for_reg_plus_reg_plus_s32(dst.hw_id(), addr1.hw_id(), addr2.hw_id(), @@ -322,12 +322,12 @@ class IGen { * Cannot use rsp. */ static Instruction load16s_gpr64_gpr64_plus_gpr64(Register dst, Register addr1, Register addr2) { - assert(dst.is_gpr()); - assert(addr1.is_gpr()); - assert(addr2.is_gpr()); - assert(addr1 != addr2); - assert(addr1 != RSP); - assert(addr2 != RSP); + ASSERT(dst.is_gpr()); + ASSERT(addr1.is_gpr()); + ASSERT(addr2.is_gpr()); + ASSERT(addr1 != addr2); + ASSERT(addr1 != RSP); + ASSERT(addr2 != RSP); Instruction instr(0xf); instr.set_op2(0xbf); instr.set_modrm_and_rex_for_reg_plus_reg_addr(dst.hw_id(), addr1.hw_id(), addr2.hw_id(), true, @@ -338,12 +338,12 @@ class IGen { static Instruction store16_gpr64_gpr64_plus_gpr64(Register addr1, Register addr2, Register value) { - assert(value.is_gpr()); - assert(addr1.is_gpr()); - assert(addr2.is_gpr()); - assert(addr1 != addr2); - assert(addr1 != RSP); - assert(addr2 != RSP); + ASSERT(value.is_gpr()); + ASSERT(addr1.is_gpr()); + ASSERT(addr2.is_gpr()); + ASSERT(addr1 != addr2); + ASSERT(addr1 != RSP); + ASSERT(addr2 != RSP); Instruction instr(0x66); instr.set_op2(0x89); instr.set_modrm_and_rex_for_reg_plus_reg_addr(value.hw_id(), addr1.hw_id(), addr2.hw_id()); @@ -355,13 +355,13 @@ class IGen { Register addr2, Register value, s64 offset) { - assert(value.is_gpr()); - assert(addr1.is_gpr()); - assert(addr2.is_gpr()); - assert(addr1 != addr2); - assert(addr1 != RSP); - assert(addr2 != RSP); - assert(offset >= INT8_MIN && offset <= INT8_MAX); + ASSERT(value.is_gpr()); + ASSERT(addr1.is_gpr()); + ASSERT(addr2.is_gpr()); + ASSERT(addr1 != addr2); + ASSERT(addr1 != RSP); + ASSERT(addr2 != RSP); + ASSERT(offset >= INT8_MIN && offset <= INT8_MAX); Instruction instr(0x66); instr.set_op2(0x89); instr.set_modrm_and_rex_for_reg_plus_reg_plus_s8(value.hw_id(), addr1.hw_id(), addr2.hw_id(), @@ -374,13 +374,13 @@ class IGen { Register addr2, Register value, s64 offset) { - assert(value.is_gpr()); - assert(addr1.is_gpr()); - assert(addr2.is_gpr()); - assert(addr1 != addr2); - assert(addr1 != RSP); - assert(addr2 != RSP); - assert(offset >= INT32_MIN && offset <= INT32_MAX); + ASSERT(value.is_gpr()); + ASSERT(addr1.is_gpr()); + ASSERT(addr2.is_gpr()); + ASSERT(addr1 != addr2); + ASSERT(addr1 != RSP); + ASSERT(addr2 != RSP); + ASSERT(offset >= INT32_MIN && offset <= INT32_MAX); Instruction instr(0x66); instr.set_op2(0x89); instr.set_modrm_and_rex_for_reg_plus_reg_plus_s32(value.hw_id(), addr1.hw_id(), addr2.hw_id(), @@ -393,13 +393,13 @@ class IGen { Register addr1, Register addr2, s64 offset) { - assert(dst.is_gpr()); - assert(addr1.is_gpr()); - assert(addr2.is_gpr()); - assert(addr1 != addr2); - assert(addr1 != RSP); - assert(addr2 != RSP); - assert(offset >= INT8_MIN && offset <= INT8_MAX); + ASSERT(dst.is_gpr()); + ASSERT(addr1.is_gpr()); + ASSERT(addr2.is_gpr()); + ASSERT(addr1 != addr2); + ASSERT(addr1 != RSP); + ASSERT(addr2 != RSP); + ASSERT(offset >= INT8_MIN && offset <= INT8_MAX); Instruction instr(0xf); instr.set_op2(0xbf); instr.set_modrm_and_rex_for_reg_plus_reg_plus_s8(dst.hw_id(), addr1.hw_id(), addr2.hw_id(), @@ -411,13 +411,13 @@ class IGen { Register addr1, Register addr2, s64 offset) { - assert(dst.is_gpr()); - assert(addr1.is_gpr()); - assert(addr2.is_gpr()); - assert(addr1 != addr2); - assert(addr1 != RSP); - assert(addr2 != RSP); - assert(offset >= INT32_MIN && offset <= INT32_MAX); + ASSERT(dst.is_gpr()); + ASSERT(addr1.is_gpr()); + ASSERT(addr2.is_gpr()); + ASSERT(addr1 != addr2); + ASSERT(addr1 != RSP); + ASSERT(addr2 != RSP); + ASSERT(offset >= INT32_MIN && offset <= INT32_MAX); Instruction instr(0xf); instr.set_op2(0xbf); instr.set_modrm_and_rex_for_reg_plus_reg_plus_s32(dst.hw_id(), addr1.hw_id(), addr2.hw_id(), @@ -431,12 +431,12 @@ class IGen { * Cannot use rsp. */ static Instruction load16u_gpr64_gpr64_plus_gpr64(Register dst, Register addr1, Register addr2) { - assert(dst.is_gpr()); - assert(addr1.is_gpr()); - assert(addr2.is_gpr()); - assert(addr1 != addr2); - assert(addr1 != RSP); - assert(addr2 != RSP); + ASSERT(dst.is_gpr()); + ASSERT(addr1.is_gpr()); + ASSERT(addr2.is_gpr()); + ASSERT(addr1 != addr2); + ASSERT(addr1 != RSP); + ASSERT(addr2 != RSP); Instruction instr(0xf); instr.set_op2(0xb7); instr.set_modrm_and_rex_for_reg_plus_reg_addr(dst.hw_id(), addr1.hw_id(), addr2.hw_id(), true, @@ -448,13 +448,13 @@ class IGen { Register addr1, Register addr2, s64 offset) { - assert(dst.is_gpr()); - assert(addr1.is_gpr()); - assert(addr2.is_gpr()); - assert(addr1 != addr2); - assert(addr1 != RSP); - assert(addr2 != RSP); - assert(offset >= INT8_MIN && offset <= INT8_MAX); + ASSERT(dst.is_gpr()); + ASSERT(addr1.is_gpr()); + ASSERT(addr2.is_gpr()); + ASSERT(addr1 != addr2); + ASSERT(addr1 != RSP); + ASSERT(addr2 != RSP); + ASSERT(offset >= INT8_MIN && offset <= INT8_MAX); Instruction instr(0xf); instr.set_op2(0xb7); instr.set_modrm_and_rex_for_reg_plus_reg_plus_s8(dst.hw_id(), addr1.hw_id(), addr2.hw_id(), @@ -466,13 +466,13 @@ class IGen { Register addr1, Register addr2, s64 offset) { - assert(dst.is_gpr()); - assert(addr1.is_gpr()); - assert(addr2.is_gpr()); - assert(addr1 != addr2); - assert(addr1 != RSP); - assert(addr2 != RSP); - assert(offset >= INT32_MIN && offset <= INT32_MAX); + ASSERT(dst.is_gpr()); + ASSERT(addr1.is_gpr()); + ASSERT(addr2.is_gpr()); + ASSERT(addr1 != addr2); + ASSERT(addr1 != RSP); + ASSERT(addr2 != RSP); + ASSERT(offset >= INT32_MIN && offset <= INT32_MAX); Instruction instr(0xf); instr.set_op2(0xb7); instr.set_modrm_and_rex_for_reg_plus_reg_plus_s32(dst.hw_id(), addr1.hw_id(), addr2.hw_id(), @@ -486,12 +486,12 @@ class IGen { * Cannot use rsp. */ static Instruction load32s_gpr64_gpr64_plus_gpr64(Register dst, Register addr1, Register addr2) { - assert(dst.is_gpr()); - assert(addr1.is_gpr()); - assert(addr2.is_gpr()); - assert(addr1 != addr2); - assert(addr1 != RSP); - assert(addr2 != RSP); + ASSERT(dst.is_gpr()); + ASSERT(addr1.is_gpr()); + ASSERT(addr2.is_gpr()); + ASSERT(addr1 != addr2); + ASSERT(addr1 != RSP); + ASSERT(addr2 != RSP); Instruction instr(0x63); instr.set_modrm_and_rex_for_reg_plus_reg_addr(dst.hw_id(), addr1.hw_id(), addr2.hw_id(), true); return instr; @@ -500,12 +500,12 @@ class IGen { static Instruction store32_gpr64_gpr64_plus_gpr64(Register addr1, Register addr2, Register value) { - assert(value.is_gpr()); - assert(addr1.is_gpr()); - assert(addr2.is_gpr()); - assert(addr1 != addr2); - assert(addr1 != RSP); - assert(addr2 != RSP); + ASSERT(value.is_gpr()); + ASSERT(addr1.is_gpr()); + ASSERT(addr2.is_gpr()); + ASSERT(addr1 != addr2); + ASSERT(addr1 != RSP); + ASSERT(addr2 != RSP); Instruction instr(0x89); instr.set_modrm_and_rex_for_reg_plus_reg_addr(value.hw_id(), addr1.hw_id(), addr2.hw_id()); return instr; @@ -515,13 +515,13 @@ class IGen { Register addr1, Register addr2, s64 offset) { - assert(dst.is_gpr()); - assert(addr1.is_gpr()); - assert(addr2.is_gpr()); - assert(addr1 != addr2); - assert(addr1 != RSP); - assert(addr2 != RSP); - assert(offset >= INT8_MIN && offset <= INT8_MAX); + ASSERT(dst.is_gpr()); + ASSERT(addr1.is_gpr()); + ASSERT(addr2.is_gpr()); + ASSERT(addr1 != addr2); + ASSERT(addr1 != RSP); + ASSERT(addr2 != RSP); + ASSERT(offset >= INT8_MIN && offset <= INT8_MAX); Instruction instr(0x63); instr.set_modrm_and_rex_for_reg_plus_reg_plus_s8(dst.hw_id(), addr1.hw_id(), addr2.hw_id(), offset, true); @@ -532,13 +532,13 @@ class IGen { Register addr2, Register value, s64 offset) { - assert(value.is_gpr()); - assert(addr1.is_gpr()); - assert(addr2.is_gpr()); - assert(addr1 != addr2); - assert(addr1 != RSP); - assert(addr2 != RSP); - assert(offset >= INT8_MIN && offset <= INT8_MAX); + ASSERT(value.is_gpr()); + ASSERT(addr1.is_gpr()); + ASSERT(addr2.is_gpr()); + ASSERT(addr1 != addr2); + ASSERT(addr1 != RSP); + ASSERT(addr2 != RSP); + ASSERT(offset >= INT8_MIN && offset <= INT8_MAX); Instruction instr(0x89); instr.set_modrm_and_rex_for_reg_plus_reg_plus_s8(value.hw_id(), addr1.hw_id(), addr2.hw_id(), offset, false); @@ -549,13 +549,13 @@ class IGen { Register addr1, Register addr2, s64 offset) { - assert(dst.is_gpr()); - assert(addr1.is_gpr()); - assert(addr2.is_gpr()); - assert(addr1 != addr2); - assert(addr1 != RSP); - assert(addr2 != RSP); - assert(offset >= INT32_MIN && offset <= INT32_MAX); + ASSERT(dst.is_gpr()); + ASSERT(addr1.is_gpr()); + ASSERT(addr2.is_gpr()); + ASSERT(addr1 != addr2); + ASSERT(addr1 != RSP); + ASSERT(addr2 != RSP); + ASSERT(offset >= INT32_MIN && offset <= INT32_MAX); Instruction instr(0x63); instr.set_modrm_and_rex_for_reg_plus_reg_plus_s32(dst.hw_id(), addr1.hw_id(), addr2.hw_id(), offset, true); @@ -566,13 +566,13 @@ class IGen { Register addr2, Register value, s64 offset) { - assert(value.is_gpr()); - assert(addr1.is_gpr()); - assert(addr2.is_gpr()); - assert(addr1 != addr2); - assert(addr1 != RSP); - assert(addr2 != RSP); - assert(offset >= INT32_MIN && offset <= INT32_MAX); + ASSERT(value.is_gpr()); + ASSERT(addr1.is_gpr()); + ASSERT(addr2.is_gpr()); + ASSERT(addr1 != addr2); + ASSERT(addr1 != RSP); + ASSERT(addr2 != RSP); + ASSERT(offset >= INT32_MIN && offset <= INT32_MAX); Instruction instr(0x89); instr.set_modrm_and_rex_for_reg_plus_reg_plus_s32(value.hw_id(), addr1.hw_id(), addr2.hw_id(), offset, false); @@ -585,12 +585,12 @@ class IGen { * Cannot use rsp. */ static Instruction load32u_gpr64_gpr64_plus_gpr64(Register dst, Register addr1, Register addr2) { - assert(dst.is_gpr()); - assert(addr1.is_gpr()); - assert(addr2.is_gpr()); - assert(addr1 != addr2); - assert(addr1 != RSP); - assert(addr2 != RSP); + ASSERT(dst.is_gpr()); + ASSERT(addr1.is_gpr()); + ASSERT(addr2.is_gpr()); + ASSERT(addr1 != addr2); + ASSERT(addr1 != RSP); + ASSERT(addr2 != RSP); Instruction instr(0x8b); instr.set_modrm_and_rex_for_reg_plus_reg_addr(dst.hw_id(), addr1.hw_id(), addr2.hw_id()); return instr; @@ -600,13 +600,13 @@ class IGen { Register addr1, Register addr2, s64 offset) { - assert(dst.is_gpr()); - assert(addr1.is_gpr()); - assert(addr2.is_gpr()); - assert(addr1 != addr2); - assert(addr1 != RSP); - assert(addr2 != RSP); - assert(offset >= INT8_MIN && offset <= INT8_MAX); + ASSERT(dst.is_gpr()); + ASSERT(addr1.is_gpr()); + ASSERT(addr2.is_gpr()); + ASSERT(addr1 != addr2); + ASSERT(addr1 != RSP); + ASSERT(addr2 != RSP); + ASSERT(offset >= INT8_MIN && offset <= INT8_MAX); Instruction instr(0x8b); instr.set_modrm_and_rex_for_reg_plus_reg_plus_s8(dst.hw_id(), addr1.hw_id(), addr2.hw_id(), offset, false); @@ -617,13 +617,13 @@ class IGen { Register addr1, Register addr2, s64 offset) { - assert(dst.is_gpr()); - assert(addr1.is_gpr()); - assert(addr2.is_gpr()); - assert(addr1 != addr2); - assert(addr1 != RSP); - assert(addr2 != RSP); - assert(offset >= INT32_MIN && offset <= INT32_MAX); + ASSERT(dst.is_gpr()); + ASSERT(addr1.is_gpr()); + ASSERT(addr2.is_gpr()); + ASSERT(addr1 != addr2); + ASSERT(addr1 != RSP); + ASSERT(addr2 != RSP); + ASSERT(offset >= INT32_MIN && offset <= INT32_MAX); Instruction instr(0x8b); instr.set_modrm_and_rex_for_reg_plus_reg_plus_s32(dst.hw_id(), addr1.hw_id(), addr2.hw_id(), offset, false); @@ -636,12 +636,12 @@ class IGen { * Cannot use rsp. */ static Instruction load64_gpr64_gpr64_plus_gpr64(Register dst, Register addr1, Register addr2) { - assert(dst.is_gpr()); - assert(addr1.is_gpr()); - assert(addr2.is_gpr()); - assert(addr1 != addr2); - assert(addr1 != RSP); - assert(addr2 != RSP); + ASSERT(dst.is_gpr()); + ASSERT(addr1.is_gpr()); + ASSERT(addr2.is_gpr()); + ASSERT(addr1 != addr2); + ASSERT(addr1 != RSP); + ASSERT(addr2 != RSP); Instruction instr(0x8b); instr.set_modrm_and_rex_for_reg_plus_reg_addr(dst.hw_id(), addr1.hw_id(), addr2.hw_id(), true); return instr; @@ -650,12 +650,12 @@ class IGen { static Instruction store64_gpr64_gpr64_plus_gpr64(Register addr1, Register addr2, Register value) { - assert(value.is_gpr()); - assert(addr1.is_gpr()); - assert(addr2.is_gpr()); - assert(addr1 != addr2); - assert(addr1 != RSP); - assert(addr2 != RSP); + ASSERT(value.is_gpr()); + ASSERT(addr1.is_gpr()); + ASSERT(addr2.is_gpr()); + ASSERT(addr1 != addr2); + ASSERT(addr1 != RSP); + ASSERT(addr2 != RSP); Instruction instr(0x89); instr.set_modrm_and_rex_for_reg_plus_reg_addr(value.hw_id(), addr1.hw_id(), addr2.hw_id(), true); @@ -666,13 +666,13 @@ class IGen { Register addr1, Register addr2, s64 offset) { - assert(dst.is_gpr()); - assert(addr1.is_gpr()); - assert(addr2.is_gpr()); - assert(addr1 != addr2); - assert(addr1 != RSP); - assert(addr2 != RSP); - assert(offset >= INT8_MIN && offset <= INT8_MAX); + ASSERT(dst.is_gpr()); + ASSERT(addr1.is_gpr()); + ASSERT(addr2.is_gpr()); + ASSERT(addr1 != addr2); + ASSERT(addr1 != RSP); + ASSERT(addr2 != RSP); + ASSERT(offset >= INT8_MIN && offset <= INT8_MAX); Instruction instr(0x8b); instr.set_modrm_and_rex_for_reg_plus_reg_plus_s8(dst.hw_id(), addr1.hw_id(), addr2.hw_id(), offset, true); @@ -683,13 +683,13 @@ class IGen { Register addr2, Register value, s64 offset) { - assert(value.is_gpr()); - assert(addr1.is_gpr()); - assert(addr2.is_gpr()); - assert(addr1 != addr2); - assert(addr1 != RSP); - assert(addr2 != RSP); - assert(offset >= INT8_MIN && offset <= INT8_MAX); + ASSERT(value.is_gpr()); + ASSERT(addr1.is_gpr()); + ASSERT(addr2.is_gpr()); + ASSERT(addr1 != addr2); + ASSERT(addr1 != RSP); + ASSERT(addr2 != RSP); + ASSERT(offset >= INT8_MIN && offset <= INT8_MAX); Instruction instr(0x89); instr.set_modrm_and_rex_for_reg_plus_reg_plus_s8(value.hw_id(), addr1.hw_id(), addr2.hw_id(), offset, true); @@ -700,13 +700,13 @@ class IGen { Register addr1, Register addr2, s64 offset) { - assert(dst.is_gpr()); - assert(addr1.is_gpr()); - assert(addr2.is_gpr()); - assert(addr1 != addr2); - assert(addr1 != RSP); - assert(addr2 != RSP); - assert(offset >= INT32_MIN && offset <= INT32_MAX); + ASSERT(dst.is_gpr()); + ASSERT(addr1.is_gpr()); + ASSERT(addr2.is_gpr()); + ASSERT(addr1 != addr2); + ASSERT(addr1 != RSP); + ASSERT(addr2 != RSP); + ASSERT(offset >= INT32_MIN && offset <= INT32_MAX); Instruction instr(0x8b); instr.set_modrm_and_rex_for_reg_plus_reg_plus_s32(dst.hw_id(), addr1.hw_id(), addr2.hw_id(), offset, true); @@ -717,13 +717,13 @@ class IGen { Register addr2, Register value, s64 offset) { - assert(value.is_gpr()); - assert(addr1.is_gpr()); - assert(addr2.is_gpr()); - assert(addr1 != addr2); - assert(addr1 != RSP); - assert(addr2 != RSP); - assert(offset >= INT32_MIN && offset <= INT32_MAX); + ASSERT(value.is_gpr()); + ASSERT(addr1.is_gpr()); + ASSERT(addr2.is_gpr()); + ASSERT(addr1 != addr2); + ASSERT(addr1 != RSP); + ASSERT(addr2 != RSP); + ASSERT(offset >= INT32_MIN && offset <= INT32_MAX); Instruction instr(0x89); instr.set_modrm_and_rex_for_reg_plus_reg_plus_s32(value.hw_id(), addr1.hw_id(), addr2.hw_id(), offset, true); @@ -738,7 +738,7 @@ class IGen { } else if (offset >= INT32_MIN && offset <= INT32_MAX) { return storevf_gpr64_plus_gpr64_plus_s32(value, addr, off, offset); } - assert(false); + ASSERT(false); return {0}; } @@ -756,7 +756,7 @@ class IGen { } else if (offset >= INT32_MIN && offset <= INT32_MAX) { return store8_gpr64_gpr64_plus_gpr64_plus_s32(addr, off, value, offset); } else { - assert(false); + ASSERT(false); } case 2: if (offset == 0) { @@ -766,7 +766,7 @@ class IGen { } else if (offset >= INT32_MIN && offset <= INT32_MAX) { return store16_gpr64_gpr64_plus_gpr64_plus_s32(addr, off, value, offset); } else { - assert(false); + ASSERT(false); } case 4: if (offset == 0) { @@ -776,7 +776,7 @@ class IGen { } else if (offset >= INT32_MIN && offset <= INT32_MAX) { return store32_gpr64_gpr64_plus_gpr64_plus_s32(addr, off, value, offset); } else { - assert(false); + ASSERT(false); } case 8: if (offset == 0) { @@ -786,10 +786,10 @@ class IGen { } else if (offset >= INT32_MIN && offset <= INT32_MAX) { return store64_gpr64_gpr64_plus_gpr64_plus_s32(addr, off, value, offset); } else { - assert(false); + ASSERT(false); } default: - assert(false); + ASSERT(false); return {0}; } } @@ -802,7 +802,7 @@ class IGen { } else if (offset >= INT32_MIN && offset <= INT32_MAX) { return loadvf_gpr64_plus_gpr64_plus_s32(dst, addr, off, offset); } else { - assert(false); + ASSERT(false); return {0}; } } @@ -838,7 +838,7 @@ class IGen { return load8u_gpr64_gpr64_plus_gpr64_plus_s32(dst, addr, off, offset); } } else { - assert(false); + ASSERT(false); } case 2: if (offset == 0) { @@ -860,7 +860,7 @@ class IGen { return load16u_gpr64_gpr64_plus_gpr64_plus_s32(dst, addr, off, offset); } } else { - assert(false); + ASSERT(false); } case 4: if (offset == 0) { @@ -882,7 +882,7 @@ class IGen { return load32u_gpr64_gpr64_plus_gpr64_plus_s32(dst, addr, off, offset); } } else { - assert(false); + ASSERT(false); } case 8: if (offset == 0) { @@ -895,10 +895,10 @@ class IGen { return load64_gpr64_gpr64_plus_gpr64_plus_s32(dst, addr, off, offset); } else { - assert(false); + ASSERT(false); } default: - assert(false); + ASSERT(false); return {0}; } } @@ -909,9 +909,9 @@ class IGen { static Instruction store32_xmm32_gpr64_plus_gpr64(Register addr1, Register addr2, Register xmm_value) { - assert(xmm_value.is_xmm()); - assert(addr1.is_gpr()); - assert(addr2.is_gpr()); + ASSERT(xmm_value.is_xmm()); + ASSERT(addr1.is_gpr()); + ASSERT(addr2.is_gpr()); Instruction instr(0xf3); instr.set_op2(0x0f); @@ -925,9 +925,9 @@ class IGen { static Instruction load32_xmm32_gpr64_plus_gpr64(Register xmm_dest, Register addr1, Register addr2) { - assert(xmm_dest.is_xmm()); - assert(addr1.is_gpr()); - assert(addr2.is_gpr()); + ASSERT(xmm_dest.is_xmm()); + ASSERT(addr1.is_gpr()); + ASSERT(addr2.is_gpr()); Instruction instr(0xf3); instr.set_op2(0x0f); @@ -942,10 +942,10 @@ class IGen { Register addr2, Register xmm_value, s64 offset) { - assert(xmm_value.is_xmm()); - assert(addr1.is_gpr()); - assert(addr2.is_gpr()); - assert(offset >= INT8_MIN && offset <= INT8_MAX); + ASSERT(xmm_value.is_xmm()); + ASSERT(addr1.is_gpr()); + ASSERT(addr2.is_gpr()); + ASSERT(offset >= INT8_MIN && offset <= INT8_MAX); Instruction instr(0xf3); instr.set_op2(0x0f); @@ -961,10 +961,10 @@ class IGen { Register addr1, Register addr2, s64 offset) { - assert(xmm_dest.is_xmm()); - assert(addr1.is_gpr()); - assert(addr2.is_gpr()); - assert(offset >= INT8_MIN && offset <= INT8_MAX); + ASSERT(xmm_dest.is_xmm()); + ASSERT(addr1.is_gpr()); + ASSERT(addr2.is_gpr()); + ASSERT(offset >= INT8_MIN && offset <= INT8_MAX); Instruction instr(0xf3); instr.set_op2(0x0f); @@ -980,10 +980,10 @@ class IGen { Register addr2, Register xmm_value, s64 offset) { - assert(xmm_value.is_xmm()); - assert(addr1.is_gpr()); - assert(addr2.is_gpr()); - assert(offset >= INT32_MIN && offset <= INT32_MAX); + ASSERT(xmm_value.is_xmm()); + ASSERT(addr1.is_gpr()); + ASSERT(addr2.is_gpr()); + ASSERT(offset >= INT32_MIN && offset <= INT32_MAX); Instruction instr(0xf3); instr.set_op2(0x0f); @@ -996,9 +996,9 @@ class IGen { } static Instruction lea_reg_plus_off32(Register dest, Register base, s64 offset) { - assert(dest.is_gpr()); - assert(base.is_gpr()); - assert(offset >= INT32_MIN && offset <= INT32_MAX); + ASSERT(dest.is_gpr()); + ASSERT(base.is_gpr()); + ASSERT(offset >= INT32_MIN && offset <= INT32_MAX); Instruction instr(0x8d); instr.set_modrm_rex_sib_for_reg_reg_disp(dest.hw_id(), 2, base.hw_id(), true); instr.set(Imm(4, offset)); @@ -1006,9 +1006,9 @@ class IGen { } static Instruction lea_reg_plus_off8(Register dest, Register base, s64 offset) { - assert(dest.is_gpr()); - assert(base.is_gpr()); - assert(offset >= INT8_MIN && offset <= INT8_MAX); + ASSERT(dest.is_gpr()); + ASSERT(base.is_gpr()); + ASSERT(offset >= INT8_MIN && offset <= INT8_MAX); Instruction instr(0x8d); instr.set_modrm_rex_sib_for_reg_reg_disp(dest.hw_id(), 1, base.hw_id(), true); instr.set(Imm(1, offset)); @@ -1021,15 +1021,15 @@ class IGen { } else if (offset >= INT32_MIN && offset <= INT32_MAX) { return lea_reg_plus_off32(dest, base, offset); } else { - assert(false); + ASSERT(false); return {0}; } } static Instruction store32_xmm32_gpr64_plus_s32(Register base, Register xmm_value, s64 offset) { - assert(xmm_value.is_xmm()); - assert(base.is_gpr()); - assert(offset >= INT32_MIN && offset <= INT32_MAX); + ASSERT(xmm_value.is_xmm()); + ASSERT(base.is_gpr()); + ASSERT(offset >= INT32_MIN && offset <= INT32_MAX); Instruction instr(0xf3); instr.set_op2(0x0f); instr.set_op3(0x11); @@ -1040,9 +1040,9 @@ class IGen { } static Instruction store32_xmm32_gpr64_plus_s8(Register base, Register xmm_value, s64 offset) { - assert(xmm_value.is_xmm()); - assert(base.is_gpr()); - assert(offset >= INT8_MIN && offset <= INT8_MAX); + ASSERT(xmm_value.is_xmm()); + ASSERT(base.is_gpr()); + ASSERT(offset >= INT8_MIN && offset <= INT8_MAX); Instruction instr(0xf3); instr.set_op2(0x0f); instr.set_op3(0x11); @@ -1056,10 +1056,10 @@ class IGen { Register addr1, Register addr2, s64 offset) { - assert(xmm_dest.is_xmm()); - assert(addr1.is_gpr()); - assert(addr2.is_gpr()); - assert(offset >= INT32_MIN && offset <= INT32_MAX); + ASSERT(xmm_dest.is_xmm()); + ASSERT(addr1.is_gpr()); + ASSERT(addr2.is_gpr()); + ASSERT(offset >= INT32_MIN && offset <= INT32_MAX); Instruction instr(0xf3); instr.set_op2(0x0f); @@ -1072,9 +1072,9 @@ class IGen { } static Instruction load32_xmm32_gpr64_plus_s32(Register xmm_dest, Register base, s64 offset) { - assert(xmm_dest.is_xmm()); - assert(base.is_gpr()); - assert(offset >= INT32_MIN && offset <= INT32_MAX); + ASSERT(xmm_dest.is_xmm()); + ASSERT(base.is_gpr()); + ASSERT(offset >= INT32_MIN && offset <= INT32_MAX); Instruction instr(0xf3); instr.set_op2(0x0f); instr.set_op3(0x10); @@ -1085,9 +1085,9 @@ class IGen { } static Instruction load32_xmm32_gpr64_plus_s8(Register xmm_dest, Register base, s64 offset) { - assert(xmm_dest.is_xmm()); - assert(base.is_gpr()); - assert(offset >= INT8_MIN && offset <= INT8_MAX); + ASSERT(xmm_dest.is_xmm()); + ASSERT(base.is_gpr()); + ASSERT(offset >= INT8_MIN && offset <= INT8_MAX); Instruction instr(0xf3); instr.set_op2(0x0f); instr.set_op3(0x10); @@ -1105,7 +1105,7 @@ class IGen { } else if (offset >= INT32_MIN && offset <= INT32_MAX) { return load32_xmm32_gpr64_plus_gpr64_plus_s32(xmm_dest, addr, off, offset); } else { - assert(false); + ASSERT(false); return {0}; } } @@ -1118,33 +1118,33 @@ class IGen { } else if (offset >= INT32_MIN && offset <= INT32_MAX) { return store32_xmm32_gpr64_plus_gpr64_plus_s32(addr, off, xmm_value, offset); } else { - assert(false); + ASSERT(false); return {0}; } } static Instruction store_reg_offset_xmm32(Register base, Register xmm_value, s64 offset) { - assert(base.is_gpr()); - assert(xmm_value.is_xmm()); + ASSERT(base.is_gpr()); + ASSERT(xmm_value.is_xmm()); if (offset >= INT8_MIN && offset <= INT8_MAX) { return store32_xmm32_gpr64_plus_s8(base, xmm_value, offset); } else if (offset >= INT32_MIN && offset <= INT32_MAX) { return store32_xmm32_gpr64_plus_s32(base, xmm_value, offset); } else { - assert(false); + ASSERT(false); return {0}; } } static Instruction load_reg_offset_xmm32(Register xmm_dest, Register base, s64 offset) { - assert(base.is_gpr()); - assert(xmm_dest.is_xmm()); + ASSERT(base.is_gpr()); + ASSERT(xmm_dest.is_xmm()); if (offset >= INT8_MIN && offset <= INT8_MAX) { return load32_xmm32_gpr64_plus_s8(xmm_dest, base, offset); } else if (offset >= INT32_MIN && offset <= INT32_MAX) { return load32_xmm32_gpr64_plus_s32(xmm_dest, base, offset); } else { - assert(false); + ASSERT(false); return {0}; } } @@ -1157,8 +1157,8 @@ class IGen { * Store a 128-bit xmm into an address stored in a register, no offset */ static Instruction store128_gpr64_xmm128(Register gpr_addr, Register xmm_value) { - assert(gpr_addr.is_gpr()); - assert(xmm_value.is_xmm()); + ASSERT(gpr_addr.is_gpr()); + ASSERT(xmm_value.is_xmm()); Instruction instr(0x66); // Instruction instr(0xf3); instr.set_op2(0x0f); @@ -1169,9 +1169,9 @@ class IGen { } static Instruction store128_gpr64_xmm128_s32(Register gpr_addr, Register xmm_value, s64 offset) { - assert(gpr_addr.is_gpr()); - assert(xmm_value.is_xmm()); - assert(offset >= INT32_MIN && offset <= INT32_MAX); + ASSERT(gpr_addr.is_gpr()); + ASSERT(xmm_value.is_xmm()); + ASSERT(offset >= INT32_MIN && offset <= INT32_MAX); Instruction instr(0x66); // Instruction instr(0xf3); instr.set_op2(0x0f); @@ -1183,9 +1183,9 @@ class IGen { } static Instruction store128_gpr64_xmm128_s8(Register gpr_addr, Register xmm_value, s64 offset) { - assert(gpr_addr.is_gpr()); - assert(xmm_value.is_xmm()); - assert(offset >= INT8_MIN && offset <= INT8_MAX); + ASSERT(gpr_addr.is_gpr()); + ASSERT(xmm_value.is_xmm()); + ASSERT(offset >= INT8_MIN && offset <= INT8_MAX); Instruction instr(0x66); // Instruction instr(0xf3); instr.set_op2(0x0f); @@ -1197,8 +1197,8 @@ class IGen { } static Instruction load128_xmm128_gpr64(Register xmm_dest, Register gpr_addr) { - assert(gpr_addr.is_gpr()); - assert(xmm_dest.is_xmm()); + ASSERT(gpr_addr.is_gpr()); + ASSERT(xmm_dest.is_xmm()); Instruction instr(0x66); // Instruction instr(0xf3); instr.set_op2(0x0f); @@ -1209,9 +1209,9 @@ class IGen { } static Instruction load128_xmm128_gpr64_s32(Register xmm_dest, Register gpr_addr, s64 offset) { - assert(gpr_addr.is_gpr()); - assert(xmm_dest.is_xmm()); - assert(offset >= INT32_MIN && offset <= INT32_MAX); + ASSERT(gpr_addr.is_gpr()); + ASSERT(xmm_dest.is_xmm()); + ASSERT(offset >= INT32_MIN && offset <= INT32_MAX); Instruction instr(0x66); // Instruction instr(0xf3); instr.set_op2(0x0f); @@ -1223,9 +1223,9 @@ class IGen { } static Instruction load128_xmm128_gpr64_s8(Register xmm_dest, Register gpr_addr, s64 offset) { - assert(gpr_addr.is_gpr()); - assert(xmm_dest.is_xmm()); - assert(offset >= INT8_MIN && offset <= INT8_MAX); + ASSERT(gpr_addr.is_gpr()); + ASSERT(xmm_dest.is_xmm()); + ASSERT(offset >= INT8_MIN && offset <= INT8_MAX); Instruction instr(0x66); // Instruction instr(0xf3); instr.set_op2(0x0f); @@ -1244,7 +1244,7 @@ class IGen { } else if (offset >= INT32_MIN && offset <= INT32_MAX) { return load128_xmm128_gpr64_s32(xmm_dest, base, offset); } else { - assert(false); + ASSERT(false); return {0}; } } @@ -1257,7 +1257,7 @@ class IGen { } else if (offset >= INT32_MIN && offset <= INT32_MAX) { return store128_gpr64_xmm128_s32(base, xmm_val, offset); } else { - assert(false); + ASSERT(false); return {0}; } } @@ -1267,32 +1267,32 @@ class IGen { //;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; static Instruction load64_rip_s32(Register dest, s64 offset) { - assert(dest.is_gpr()); - assert(offset >= INT32_MIN && offset <= INT32_MAX); + ASSERT(dest.is_gpr()); + ASSERT(offset >= INT32_MIN && offset <= INT32_MAX); Instruction instr(0x8b); instr.set_modrm_and_rex_for_rip_plus_s32(dest.hw_id(), offset, true); return instr; } static Instruction load32s_rip_s32(Register dest, s64 offset) { - assert(dest.is_gpr()); - assert(offset >= INT32_MIN && offset <= INT32_MAX); + ASSERT(dest.is_gpr()); + ASSERT(offset >= INT32_MIN && offset <= INT32_MAX); Instruction instr(0x63); instr.set_modrm_and_rex_for_rip_plus_s32(dest.hw_id(), offset, true); return instr; } static Instruction load32u_rip_s32(Register dest, s64 offset) { - assert(dest.is_gpr()); - assert(offset >= INT32_MIN && offset <= INT32_MAX); + ASSERT(dest.is_gpr()); + ASSERT(offset >= INT32_MIN && offset <= INT32_MAX); Instruction instr(0x8b); instr.set_modrm_and_rex_for_rip_plus_s32(dest.hw_id(), offset, false); return instr; } static Instruction load16u_rip_s32(Register dest, s64 offset) { - assert(dest.is_gpr()); - assert(offset >= INT32_MIN && offset <= INT32_MAX); + ASSERT(dest.is_gpr()); + ASSERT(offset >= INT32_MIN && offset <= INT32_MAX); Instruction instr(0xf); instr.set_op2(0xb7); instr.set_modrm_and_rex_for_rip_plus_s32(dest.hw_id(), offset, true); @@ -1300,8 +1300,8 @@ class IGen { } static Instruction load16s_rip_s32(Register dest, s64 offset) { - assert(dest.is_gpr()); - assert(offset >= INT32_MIN && offset <= INT32_MAX); + ASSERT(dest.is_gpr()); + ASSERT(offset >= INT32_MIN && offset <= INT32_MAX); Instruction instr(0xf); instr.set_op2(0xbf); instr.set_modrm_and_rex_for_rip_plus_s32(dest.hw_id(), offset, true); @@ -1309,8 +1309,8 @@ class IGen { } static Instruction load8u_rip_s32(Register dest, s64 offset) { - assert(dest.is_gpr()); - assert(offset >= INT32_MIN && offset <= INT32_MAX); + ASSERT(dest.is_gpr()); + ASSERT(offset >= INT32_MIN && offset <= INT32_MAX); Instruction instr(0xf); instr.set_op2(0xb6); instr.set_modrm_and_rex_for_rip_plus_s32(dest.hw_id(), offset, true); @@ -1318,8 +1318,8 @@ class IGen { } static Instruction load8s_rip_s32(Register dest, s64 offset) { - assert(dest.is_gpr()); - assert(offset >= INT32_MIN && offset <= INT32_MAX); + ASSERT(dest.is_gpr()); + ASSERT(offset >= INT32_MIN && offset <= INT32_MAX); Instruction instr(0xf); instr.set_op2(0xbe); instr.set_modrm_and_rex_for_rip_plus_s32(dest.hw_id(), offset, true); @@ -1352,32 +1352,32 @@ class IGen { case 8: return load64_rip_s32(dest, offset); default: - assert(false); + ASSERT(false); } } static Instruction store64_rip_s32(Register src, s64 offset) { - assert(src.is_gpr()); - assert(offset >= INT32_MIN && offset <= INT32_MAX); - assert(offset >= INT32_MIN && offset <= INT32_MAX); + ASSERT(src.is_gpr()); + ASSERT(offset >= INT32_MIN && offset <= INT32_MAX); + ASSERT(offset >= INT32_MIN && offset <= INT32_MAX); Instruction instr(0x89); instr.set_modrm_and_rex_for_rip_plus_s32(src.hw_id(), offset, true); return instr; } static Instruction store32_rip_s32(Register src, s64 offset) { - assert(src.is_gpr()); - assert(offset >= INT32_MIN && offset <= INT32_MAX); - assert(offset >= INT32_MIN && offset <= INT32_MAX); + ASSERT(src.is_gpr()); + ASSERT(offset >= INT32_MIN && offset <= INT32_MAX); + ASSERT(offset >= INT32_MIN && offset <= INT32_MAX); Instruction instr(0x89); instr.set_modrm_and_rex_for_rip_plus_s32(src.hw_id(), offset, false); return instr; } static Instruction store16_rip_s32(Register src, s64 offset) { - assert(src.is_gpr()); - assert(offset >= INT32_MIN && offset <= INT32_MAX); - assert(offset >= INT32_MIN && offset <= INT32_MAX); + ASSERT(src.is_gpr()); + ASSERT(offset >= INT32_MIN && offset <= INT32_MAX); + ASSERT(offset >= INT32_MIN && offset <= INT32_MAX); Instruction instr(0x66); instr.set_op2(0x89); instr.set_modrm_and_rex_for_rip_plus_s32(src.hw_id(), offset, false); @@ -1386,9 +1386,9 @@ class IGen { } static Instruction store8_rip_s32(Register src, s64 offset) { - assert(src.is_gpr()); - assert(offset >= INT32_MIN && offset <= INT32_MAX); - assert(offset >= INT32_MIN && offset <= INT32_MAX); + ASSERT(src.is_gpr()); + ASSERT(offset >= INT32_MIN && offset <= INT32_MAX); + ASSERT(offset >= INT32_MIN && offset <= INT32_MAX); Instruction instr(0x88); instr.set_modrm_and_rex_for_rip_plus_s32(src.hw_id(), offset, false); if (src.id() > RBX) { @@ -1408,21 +1408,21 @@ class IGen { case 8: return store64_rip_s32(value, offset); default: - assert(false); + ASSERT(false); } } static Instruction static_addr(Register dst, s64 offset) { - assert(dst.is_gpr()); - assert(offset >= INT32_MIN && offset <= INT32_MAX); + ASSERT(dst.is_gpr()); + ASSERT(offset >= INT32_MIN && offset <= INT32_MAX); Instruction instr(0x8d); instr.set_modrm_and_rex_for_rip_plus_s32(dst.hw_id(), offset, true); return instr; } static Instruction static_load_xmm32(Register xmm_dest, s64 offset) { - assert(xmm_dest.is_xmm()); - assert(offset >= INT32_MIN && offset <= INT32_MAX); + ASSERT(xmm_dest.is_xmm()); + ASSERT(offset >= INT32_MIN && offset <= INT32_MAX); Instruction instr(0xf3); instr.set_op2(0x0f); @@ -1434,8 +1434,8 @@ class IGen { } static Instruction static_store_xmm32(Register xmm_value, s64 offset) { - assert(xmm_value.is_xmm()); - assert(offset >= INT32_MIN && offset <= INT32_MAX); + ASSERT(xmm_value.is_xmm()); + ASSERT(offset >= INT32_MIN && offset <= INT32_MAX); Instruction instr(0xf3); instr.set_op2(0x0f); @@ -1450,8 +1450,8 @@ class IGen { // TODO, consider specialized stack loads and stores? static Instruction load64_gpr64_plus_s32(Register dst_reg, int32_t offset, Register src_reg) { - assert(dst_reg.is_gpr()); - assert(src_reg.is_gpr()); + ASSERT(dst_reg.is_gpr()); + ASSERT(src_reg.is_gpr()); Instruction instr(0x8b); instr.set_modrm_rex_sib_for_reg_reg_disp(dst_reg.hw_id(), 2, src_reg.hw_id(), true); instr.set_disp(Imm(4, offset)); @@ -1462,8 +1462,8 @@ class IGen { * Store 64-bits from gpr into memory located at 64-bit reg + 32-bit signed offset. */ static Instruction store64_gpr64_plus_s32(Register addr, int32_t offset, Register value) { - assert(addr.is_gpr()); - assert(value.is_gpr()); + ASSERT(addr.is_gpr()); + ASSERT(value.is_gpr()); Instruction instr(0x89); instr.set_modrm_rex_sib_for_reg_reg_disp(value.hw_id(), 2, addr.hw_id(), true); instr.set_disp(Imm(4, offset)); @@ -1482,7 +1482,7 @@ class IGen { * Instruction to push gpr (64-bits) onto the stack */ static Instruction push_gpr64(Register reg) { - assert(reg.is_gpr()); + ASSERT(reg.is_gpr()); if (reg.hw_id() >= 8) { auto i = Instruction(0x50 + reg.hw_id() - 8); i.set(REX(false, false, false, true)); @@ -1495,7 +1495,7 @@ class IGen { * Instruction to pop 64 bit gpr from the stack */ static Instruction pop_gpr64(Register reg) { - assert(reg.is_gpr()); + ASSERT(reg.is_gpr()); if (reg.hw_id() >= 8) { auto i = Instruction(0x58 + reg.hw_id() - 8); i.set(REX(false, false, false, true)); @@ -1508,14 +1508,14 @@ class IGen { * Call a function stored in a 64-bit gpr */ static Instruction call_r64(Register reg_) { - assert(reg_.is_gpr()); + ASSERT(reg_.is_gpr()); auto reg = reg_.hw_id(); Instruction instr(0xff); if (reg >= 8) { instr.set(REX(false, false, false, true)); reg -= 8; } - assert(reg < 8); + ASSERT(reg < 8); ModRM mrm; mrm.rm = reg; mrm.reg_op = 2; @@ -1528,14 +1528,14 @@ class IGen { * Jump to an x86-64 address stored in a 64-bit gpr. */ static Instruction jmp_r64(Register reg_) { - assert(reg_.is_gpr()); + ASSERT(reg_.is_gpr()); auto reg = reg_.hw_id(); Instruction instr(0xff); if (reg >= 8) { instr.set(REX(false, false, false, true)); reg -= 8; } - assert(reg < 8); + ASSERT(reg < 8); ModRM mrm; mrm.rm = reg; mrm.reg_op = 4; @@ -1548,8 +1548,8 @@ class IGen { // INTEGER MATH //;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; static Instruction sub_gpr64_imm8s(Register reg, int64_t imm) { - assert(reg.is_gpr()); - assert(imm >= INT8_MIN && imm <= INT8_MAX); + ASSERT(reg.is_gpr()); + ASSERT(imm >= INT8_MIN && imm <= INT8_MAX); // SUB r/m64, imm8 : REX.W + 83 /5 ib Instruction instr(0x83); instr.set_modrm_and_rex(5, reg.hw_id(), 3, true); @@ -1558,8 +1558,8 @@ class IGen { } static Instruction sub_gpr64_imm32s(Register reg, int64_t imm) { - assert(reg.is_gpr()); - assert(imm >= INT32_MIN && imm <= INT32_MAX); + ASSERT(reg.is_gpr()); + ASSERT(imm >= INT32_MIN && imm <= INT32_MAX); Instruction instr(0x81); instr.set_modrm_and_rex(5, reg.hw_id(), 3, true); instr.set(Imm(4, imm)); @@ -1567,7 +1567,7 @@ class IGen { } static Instruction add_gpr64_imm8s(Register reg, int64_t v) { - assert(v >= INT8_MIN && v <= INT8_MAX); + ASSERT(v >= INT8_MIN && v <= INT8_MAX); Instruction instr(0x83); instr.set_modrm_and_rex(0, reg.hw_id(), 3, true); instr.set(Imm(1, v)); @@ -1575,7 +1575,7 @@ class IGen { } static Instruction add_gpr64_imm32s(Register reg, int64_t v) { - assert(v >= INT32_MIN && v <= INT32_MAX); + ASSERT(v >= INT32_MIN && v <= INT32_MAX); Instruction instr(0x81); instr.set_modrm_and_rex(0, reg.hw_id(), 3, true); instr.set(Imm(4, v)); @@ -1606,16 +1606,16 @@ class IGen { static Instruction add_gpr64_gpr64(Register dst, Register src) { Instruction instr(0x01); - assert(dst.is_gpr()); - assert(src.is_gpr()); + ASSERT(dst.is_gpr()); + ASSERT(src.is_gpr()); instr.set_modrm_and_rex(src.hw_id(), dst.hw_id(), 3, true); return instr; } static Instruction sub_gpr64_gpr64(Register dst, Register src) { Instruction instr(0x29); - assert(dst.is_gpr()); - assert(src.is_gpr()); + ASSERT(dst.is_gpr()); + ASSERT(src.is_gpr()); instr.set_modrm_and_rex(src.hw_id(), dst.hw_id(), 3, true); return instr; } @@ -1627,8 +1627,8 @@ class IGen { static Instruction imul_gpr32_gpr32(Register dst, Register src) { Instruction instr(0xf); instr.set_op2(0xaf); - assert(dst.is_gpr()); - assert(src.is_gpr()); + ASSERT(dst.is_gpr()); + ASSERT(src.is_gpr()); instr.set_modrm_and_rex(dst.hw_id(), src.hw_id(), 3, false); return instr; } @@ -1640,8 +1640,8 @@ class IGen { static Instruction imul_gpr64_gpr64(Register dst, Register src) { Instruction instr(0xf); instr.set_op2(0xaf); - assert(dst.is_gpr()); - assert(src.is_gpr()); + ASSERT(dst.is_gpr()); + ASSERT(src.is_gpr()); instr.set_modrm_and_rex(dst.hw_id(), src.hw_id(), 3, true); return instr; } @@ -1651,14 +1651,14 @@ class IGen { */ static Instruction idiv_gpr32(Register reg) { Instruction instr(0xf7); - assert(reg.is_gpr()); + ASSERT(reg.is_gpr()); instr.set_modrm_and_rex(7, reg.hw_id(), 3, false); return instr; } static Instruction unsigned_div_gpr32(Register reg) { Instruction instr(0xf7); - assert(reg.is_gpr()); + ASSERT(reg.is_gpr()); instr.set_modrm_and_rex(6, reg.hw_id(), 3, false); return instr; } @@ -1677,8 +1677,8 @@ class IGen { */ static Instruction movsx_r64_r32(Register dst, Register src) { Instruction instr(0x63); - assert(dst.is_gpr()); - assert(src.is_gpr()); + ASSERT(dst.is_gpr()); + ASSERT(src.is_gpr()); instr.set_modrm_and_rex(dst.hw_id(), src.hw_id(), 3, true); return instr; } @@ -1689,8 +1689,8 @@ class IGen { */ static Instruction cmp_gpr64_gpr64(Register a, Register b) { Instruction instr(0x3b); - assert(a.is_gpr()); - assert(b.is_gpr()); + ASSERT(a.is_gpr()); + ASSERT(b.is_gpr()); instr.set_modrm_and_rex(a.hw_id(), b.hw_id(), 3, true); return instr; } @@ -1704,8 +1704,8 @@ class IGen { */ static Instruction or_gpr64_gpr64(Register dst, Register src) { Instruction instr(0x0b); - assert(dst.is_gpr()); - assert(src.is_gpr()); + ASSERT(dst.is_gpr()); + ASSERT(src.is_gpr()); instr.set_modrm_and_rex(dst.hw_id(), src.hw_id(), 3, true); return instr; } @@ -1715,8 +1715,8 @@ class IGen { */ static Instruction and_gpr64_gpr64(Register dst, Register src) { Instruction instr(0x23); - assert(dst.is_gpr()); - assert(src.is_gpr()); + ASSERT(dst.is_gpr()); + ASSERT(src.is_gpr()); instr.set_modrm_and_rex(dst.hw_id(), src.hw_id(), 3, true); return instr; } @@ -1726,8 +1726,8 @@ class IGen { */ static Instruction xor_gpr64_gpr64(Register dst, Register src) { Instruction instr(0x33); - assert(dst.is_gpr()); - assert(src.is_gpr()); + ASSERT(dst.is_gpr()); + ASSERT(src.is_gpr()); instr.set_modrm_and_rex(dst.hw_id(), src.hw_id(), 3, true); return instr; } @@ -1737,7 +1737,7 @@ class IGen { */ static Instruction not_gpr64(Register reg) { Instruction instr(0xf7); - assert(reg.is_gpr()); + ASSERT(reg.is_gpr()); instr.set_modrm_and_rex(2, reg.hw_id(), 3, true); return instr; } @@ -1750,7 +1750,7 @@ class IGen { * Shift 64-bit gpr left by CL register */ static Instruction shl_gpr64_cl(Register reg) { - assert(reg.is_gpr()); + ASSERT(reg.is_gpr()); Instruction instr(0xd3); instr.set_modrm_and_rex(4, reg.hw_id(), 3, true); return instr; @@ -1760,7 +1760,7 @@ class IGen { * Shift 64-bit gpr right (logical) by CL register */ static Instruction shr_gpr64_cl(Register reg) { - assert(reg.is_gpr()); + ASSERT(reg.is_gpr()); Instruction instr(0xd3); instr.set_modrm_and_rex(5, reg.hw_id(), 3, true); return instr; @@ -1770,7 +1770,7 @@ class IGen { * Shift 64-bit gpr right (arithmetic) by CL register */ static Instruction sar_gpr64_cl(Register reg) { - assert(reg.is_gpr()); + ASSERT(reg.is_gpr()); Instruction instr(0xd3); instr.set_modrm_and_rex(7, reg.hw_id(), 3, true); return instr; @@ -1780,7 +1780,7 @@ class IGen { * Shift 64-ptr left (logical) by the constant shift amount "sa". */ static Instruction shl_gpr64_u8(Register reg, uint8_t sa) { - assert(reg.is_gpr()); + ASSERT(reg.is_gpr()); Instruction instr(0xc1); instr.set_modrm_and_rex(4, reg.hw_id(), 3, true); instr.set(Imm(1, sa)); @@ -1791,7 +1791,7 @@ class IGen { * Shift 64-ptr right (logical) by the constant shift amount "sa". */ static Instruction shr_gpr64_u8(Register reg, uint8_t sa) { - assert(reg.is_gpr()); + ASSERT(reg.is_gpr()); Instruction instr(0xc1); instr.set_modrm_and_rex(5, reg.hw_id(), 3, true); instr.set(Imm(1, sa)); @@ -1802,7 +1802,7 @@ class IGen { * Shift 64-ptr right (arithmetic) by the constant shift amount "sa". */ static Instruction sar_gpr64_u8(Register reg, uint8_t sa) { - assert(reg.is_gpr()); + ASSERT(reg.is_gpr()); Instruction instr(0xc1); instr.set_modrm_and_rex(7, reg.hw_id(), 3, true); instr.set(Imm(1, sa)); @@ -1930,8 +1930,8 @@ class IGen { * Compare two floats and set flag register for jump (ucomiss) */ static Instruction cmp_flt_flt(Register a, Register b) { - assert(a.is_xmm()); - assert(b.is_xmm()); + ASSERT(a.is_xmm()); + ASSERT(b.is_xmm()); Instruction instr(0x0f); instr.set_op2(0x2e); instr.set_modrm_and_rex(a.hw_id(), b.hw_id(), 3, false); @@ -1939,8 +1939,8 @@ class IGen { } static Instruction sqrts_xmm(Register dst, Register src) { - assert(dst.is_xmm()); - assert(src.is_xmm()); + ASSERT(dst.is_xmm()); + ASSERT(src.is_xmm()); Instruction instr(0xf3); instr.set_op2(0x0f); instr.set_op3(0x51); @@ -1953,8 +1953,8 @@ class IGen { * Multiply two floats in xmm's */ static Instruction mulss_xmm_xmm(Register dst, Register src) { - assert(dst.is_xmm()); - assert(src.is_xmm()); + ASSERT(dst.is_xmm()); + ASSERT(src.is_xmm()); Instruction instr(0xf3); instr.set_op2(0x0f); instr.set_op3(0x59); @@ -1967,8 +1967,8 @@ class IGen { * Divide two floats in xmm's */ static Instruction divss_xmm_xmm(Register dst, Register src) { - assert(dst.is_xmm()); - assert(src.is_xmm()); + ASSERT(dst.is_xmm()); + ASSERT(src.is_xmm()); Instruction instr(0xf3); instr.set_op2(0x0f); instr.set_op3(0x5e); @@ -1981,8 +1981,8 @@ class IGen { * Subtract two floats in xmm's */ static Instruction subss_xmm_xmm(Register dst, Register src) { - assert(dst.is_xmm()); - assert(src.is_xmm()); + ASSERT(dst.is_xmm()); + ASSERT(src.is_xmm()); Instruction instr(0xf3); instr.set_op2(0x0f); instr.set_op3(0x5c); @@ -1995,8 +1995,8 @@ class IGen { * Add two floats in xmm's */ static Instruction addss_xmm_xmm(Register dst, Register src) { - assert(dst.is_xmm()); - assert(src.is_xmm()); + ASSERT(dst.is_xmm()); + ASSERT(src.is_xmm()); Instruction instr(0xf3); instr.set_op2(0x0f); instr.set_op3(0x58); @@ -2009,8 +2009,8 @@ class IGen { * Floating point minimum. */ static Instruction minss_xmm_xmm(Register dst, Register src) { - assert(dst.is_xmm()); - assert(src.is_xmm()); + ASSERT(dst.is_xmm()); + ASSERT(src.is_xmm()); Instruction instr(0xf3); instr.set_op2(0x0f); instr.set_op3(0x5d); @@ -2023,8 +2023,8 @@ class IGen { * Floating point maximum. */ static Instruction maxss_xmm_xmm(Register dst, Register src) { - assert(dst.is_xmm()); - assert(src.is_xmm()); + ASSERT(dst.is_xmm()); + ASSERT(src.is_xmm()); Instruction instr(0xf3); instr.set_op2(0x0f); instr.set_op3(0x5f); @@ -2037,8 +2037,8 @@ class IGen { * Convert GPR int32 to XMM float (single precision) */ static Instruction int32_to_float(Register dst, Register src) { - assert(dst.is_xmm()); - assert(src.is_gpr()); + ASSERT(dst.is_xmm()); + ASSERT(src.is_gpr()); Instruction instr(0xf3); instr.set_op2(0x0f); instr.set_op3(0x2a); @@ -2051,8 +2051,8 @@ class IGen { * Convert XMM float to GPR int32(single precision) (truncate) */ static Instruction float_to_int32(Register dst, Register src) { - assert(dst.is_gpr()); - assert(src.is_xmm()); + ASSERT(dst.is_gpr()); + ASSERT(src.is_xmm()); Instruction instr(0xf3); instr.set_op2(0x0f); instr.set_op3(0x2c); @@ -2100,8 +2100,8 @@ class IGen { } static Instruction mov_vf_vf(Register dst, Register src) { - assert(dst.is_xmm()); - assert(src.is_xmm()); + ASSERT(dst.is_xmm()); + ASSERT(src.is_xmm()); if (src.hw_id() >= 8 && dst.hw_id() < 8) { // in this case, we can use the 0x29 encoding, which swaps src and dst, in order to use the @@ -2118,12 +2118,12 @@ class IGen { } static Instruction loadvf_gpr64_plus_gpr64(Register dst, Register addr1, Register addr2) { - assert(dst.is_xmm()); - assert(addr1.is_gpr()); - assert(addr2.is_gpr()); - assert(addr1 != addr2); - assert(addr1 != RSP); - assert(addr2 != RSP); + ASSERT(dst.is_xmm()); + ASSERT(addr1.is_gpr()); + ASSERT(addr2.is_gpr()); + ASSERT(addr1 != addr2); + ASSERT(addr1 != RSP); + ASSERT(addr2 != RSP); Instruction instr(0x28); instr.set_vex_modrm_and_rex_for_reg_plus_reg_addr(dst.hw_id(), addr1.hw_id(), addr2.hw_id(), VEX3::LeadingBytes::P_0F, false); @@ -2134,13 +2134,13 @@ class IGen { Register addr1, Register addr2, s64 offset) { - assert(dst.is_xmm()); - assert(addr1.is_gpr()); - assert(addr2.is_gpr()); - assert(addr1 != addr2); - assert(addr1 != RSP); - assert(addr2 != RSP); - assert(offset >= INT8_MIN && offset <= INT8_MAX); + ASSERT(dst.is_xmm()); + ASSERT(addr1.is_gpr()); + ASSERT(addr2.is_gpr()); + ASSERT(addr1 != addr2); + ASSERT(addr1 != RSP); + ASSERT(addr2 != RSP); + ASSERT(offset >= INT8_MIN && offset <= INT8_MAX); Instruction instr(0x28); instr.set_vex_modrm_and_rex_for_reg_plus_reg_plus_s8(dst.hw_id(), addr1.hw_id(), addr2.hw_id(), offset, VEX3::LeadingBytes::P_0F, false); @@ -2151,13 +2151,13 @@ class IGen { Register addr1, Register addr2, s64 offset) { - assert(dst.is_xmm()); - assert(addr1.is_gpr()); - assert(addr2.is_gpr()); - assert(addr1 != addr2); - assert(addr1 != RSP); - assert(addr2 != RSP); - assert(offset >= INT32_MIN && offset <= INT32_MAX); + ASSERT(dst.is_xmm()); + ASSERT(addr1.is_gpr()); + ASSERT(addr2.is_gpr()); + ASSERT(addr1 != addr2); + ASSERT(addr1 != RSP); + ASSERT(addr2 != RSP); + ASSERT(offset >= INT32_MIN && offset <= INT32_MAX); Instruction instr(0x28); instr.set_vex_modrm_and_rex_for_reg_plus_reg_plus_s32(dst.hw_id(), addr1.hw_id(), addr2.hw_id(), offset, VEX3::LeadingBytes::P_0F, false); @@ -2165,12 +2165,12 @@ class IGen { } static Instruction storevf_gpr64_plus_gpr64(Register value, Register addr1, Register addr2) { - assert(value.is_xmm()); - assert(addr1.is_gpr()); - assert(addr2.is_gpr()); - assert(addr1 != addr2); - assert(addr1 != RSP); - assert(addr2 != RSP); + ASSERT(value.is_xmm()); + ASSERT(addr1.is_gpr()); + ASSERT(addr2.is_gpr()); + ASSERT(addr1 != addr2); + ASSERT(addr1 != RSP); + ASSERT(addr2 != RSP); Instruction instr(0x29); instr.set_vex_modrm_and_rex_for_reg_plus_reg_addr(value.hw_id(), addr1.hw_id(), addr2.hw_id(), VEX3::LeadingBytes::P_0F, false); @@ -2181,13 +2181,13 @@ class IGen { Register addr1, Register addr2, s64 offset) { - assert(value.is_xmm()); - assert(addr1.is_gpr()); - assert(addr2.is_gpr()); - assert(addr1 != addr2); - assert(addr1 != RSP); - assert(addr2 != RSP); - assert(offset >= INT8_MIN && offset <= INT8_MAX); + ASSERT(value.is_xmm()); + ASSERT(addr1.is_gpr()); + ASSERT(addr2.is_gpr()); + ASSERT(addr1 != addr2); + ASSERT(addr1 != RSP); + ASSERT(addr2 != RSP); + ASSERT(offset >= INT8_MIN && offset <= INT8_MAX); Instruction instr(0x29); instr.set_vex_modrm_and_rex_for_reg_plus_reg_plus_s8( value.hw_id(), addr1.hw_id(), addr2.hw_id(), offset, VEX3::LeadingBytes::P_0F, false); @@ -2198,13 +2198,13 @@ class IGen { Register addr1, Register addr2, s64 offset) { - assert(value.is_xmm()); - assert(addr1.is_gpr()); - assert(addr2.is_gpr()); - assert(addr1 != addr2); - assert(addr1 != RSP); - assert(addr2 != RSP); - assert(offset >= INT32_MIN && offset <= INT32_MAX); + ASSERT(value.is_xmm()); + ASSERT(addr1.is_gpr()); + ASSERT(addr2.is_gpr()); + ASSERT(addr1 != addr2); + ASSERT(addr1 != RSP); + ASSERT(addr2 != RSP); + ASSERT(offset >= INT32_MIN && offset <= INT32_MAX); Instruction instr(0x29); instr.set_vex_modrm_and_rex_for_reg_plus_reg_plus_s32( value.hw_id(), addr1.hw_id(), addr2.hw_id(), offset, VEX3::LeadingBytes::P_0F, false); @@ -2212,9 +2212,9 @@ class IGen { } static Instruction loadvf_rip_plus_s32(Register dest, s64 offset) { - assert(dest.is_xmm()); - assert(offset >= INT32_MIN); - assert(offset <= INT32_MAX); + ASSERT(dest.is_xmm()); + ASSERT(offset >= INT32_MIN); + ASSERT(offset <= INT32_MAX); Instruction instr(0x28); instr.set_vex_modrm_and_rex_for_rip_plus_s32(dest.hw_id(), offset); return instr; @@ -2223,10 +2223,10 @@ class IGen { // TODO - rip relative loads and stores. static Instruction blend_vf(Register dst, Register src1, Register src2, u8 mask) { - assert(!(mask & 0b11110000)); - assert(dst.is_xmm()); - assert(src1.is_xmm()); - assert(src2.is_xmm()); + ASSERT(!(mask & 0b11110000)); + ASSERT(dst.is_xmm()); + ASSERT(src1.is_xmm()); + ASSERT(src2.is_xmm()); Instruction instr(0x0c); // VBLENDPS instr.set_vex_modrm_and_rex(dst.hw_id(), src2.hw_id(), VEX3::LeadingBytes::P_0F_3A, src1.hw_id(), false, VexPrefix::P_66); @@ -2235,12 +2235,12 @@ class IGen { } static Instruction shuffle_vf(Register dst, Register src, u8 dx, u8 dy, u8 dz, u8 dw) { - assert(dst.is_xmm()); - assert(src.is_xmm()); - assert(dx < 4); - assert(dy < 4); - assert(dz < 4); - assert(dw < 4); + ASSERT(dst.is_xmm()); + ASSERT(src.is_xmm()); + ASSERT(dx < 4); + ASSERT(dy < 4); + ASSERT(dz < 4); + ASSERT(dw < 4); u8 imm = dx + (dy << 2) + (dz << 4) + (dw << 6); return swizzle_vf(dst, src, imm); @@ -2271,8 +2271,8 @@ class IGen { > (4.5, 1.5, 2.5, 3.5) */ static Instruction swizzle_vf(Register dst, Register src, u8 controlBytes) { - assert(dst.is_xmm()); - assert(src.is_xmm()); + ASSERT(dst.is_xmm()); + ASSERT(src.is_xmm()); Instruction instr(0xC6); // VSHUFPS // we use the AVX "VEX" encoding here. This is a three-operand form, @@ -2306,93 +2306,93 @@ class IGen { return swizzle_vf(dst, src, 0b11111111); break; default: - assert(false); + ASSERT(false); return {0}; } } static Instruction xor_vf(Register dst, Register src1, Register src2) { - assert(dst.is_xmm()); - assert(src1.is_xmm()); - assert(src2.is_xmm()); + ASSERT(dst.is_xmm()); + ASSERT(src1.is_xmm()); + ASSERT(src2.is_xmm()); Instruction instr(0x57); // VXORPS instr.set_vex_modrm_and_rex(dst.hw_id(), src2.hw_id(), VEX3::LeadingBytes::P_0F, src1.hw_id()); return instr; } static Instruction sub_vf(Register dst, Register src1, Register src2) { - assert(dst.is_xmm()); - assert(src1.is_xmm()); - assert(src2.is_xmm()); + ASSERT(dst.is_xmm()); + ASSERT(src1.is_xmm()); + ASSERT(src2.is_xmm()); Instruction instr(0x5c); // VSUBPS instr.set_vex_modrm_and_rex(dst.hw_id(), src2.hw_id(), VEX3::LeadingBytes::P_0F, src1.hw_id()); return instr; } static Instruction add_vf(Register dst, Register src1, Register src2) { - assert(dst.is_xmm()); - assert(src1.is_xmm()); - assert(src2.is_xmm()); + ASSERT(dst.is_xmm()); + ASSERT(src1.is_xmm()); + ASSERT(src2.is_xmm()); Instruction instr(0x58); // VADDPS instr.set_vex_modrm_and_rex(dst.hw_id(), src2.hw_id(), VEX3::LeadingBytes::P_0F, src1.hw_id()); return instr; } static Instruction mul_vf(Register dst, Register src1, Register src2) { - assert(dst.is_xmm()); - assert(src1.is_xmm()); - assert(src2.is_xmm()); + ASSERT(dst.is_xmm()); + ASSERT(src1.is_xmm()); + ASSERT(src2.is_xmm()); Instruction instr(0x59); // VMULPS instr.set_vex_modrm_and_rex(dst.hw_id(), src2.hw_id(), VEX3::LeadingBytes::P_0F, src1.hw_id()); return instr; } static Instruction max_vf(Register dst, Register src1, Register src2) { - assert(dst.is_xmm()); - assert(src1.is_xmm()); - assert(src2.is_xmm()); + ASSERT(dst.is_xmm()); + ASSERT(src1.is_xmm()); + ASSERT(src2.is_xmm()); Instruction instr(0x5F); // VMAXPS instr.set_vex_modrm_and_rex(dst.hw_id(), src2.hw_id(), VEX3::LeadingBytes::P_0F, src1.hw_id()); return instr; } static Instruction min_vf(Register dst, Register src1, Register src2) { - assert(dst.is_xmm()); - assert(src1.is_xmm()); - assert(src2.is_xmm()); + ASSERT(dst.is_xmm()); + ASSERT(src1.is_xmm()); + ASSERT(src2.is_xmm()); Instruction instr(0x5D); // VMINPS instr.set_vex_modrm_and_rex(dst.hw_id(), src2.hw_id(), VEX3::LeadingBytes::P_0F, src1.hw_id()); return instr; } static Instruction div_vf(Register dst, Register src1, Register src2) { - assert(dst.is_xmm()); - assert(src1.is_xmm()); - assert(src2.is_xmm()); + ASSERT(dst.is_xmm()); + ASSERT(src1.is_xmm()); + ASSERT(src2.is_xmm()); Instruction instr(0x5E); // VDIVPS instr.set_vex_modrm_and_rex(dst.hw_id(), src2.hw_id(), VEX3::LeadingBytes::P_0F, src1.hw_id()); return instr; } static Instruction sqrt_vf(Register dst, Register src) { - assert(dst.is_xmm()); - assert(src.is_xmm()); + ASSERT(dst.is_xmm()); + ASSERT(src.is_xmm()); Instruction instr(0x51); // VSQRTPS instr.set_vex_modrm_and_rex(dst.hw_id(), src.hw_id(), VEX3::LeadingBytes::P_0F, 0b0); return instr; } static Instruction itof_vf(Register dst, Register src) { - assert(dst.is_xmm()); - assert(src.is_xmm()); + ASSERT(dst.is_xmm()); + ASSERT(src.is_xmm()); Instruction instr(0x5b); // VCVTDQ2PS instr.set_vex_modrm_and_rex(dst.hw_id(), src.hw_id(), VEX3::LeadingBytes::P_0F, 0); return instr; } static Instruction ftoi_vf(Register dst, Register src) { - assert(dst.is_xmm()); - assert(src.is_xmm()); + ASSERT(dst.is_xmm()); + ASSERT(src.is_xmm()); // VEX.128.F3.0F.WIG 5B /r VCVTTPS2DQ xmm1, xmm2/m128 Instruction instr(0x5b); // VCVTTPS2DQ instr.set_vex_modrm_and_rex(dst.hw_id(), src.hw_id(), VEX3::LeadingBytes::P_0F, 0, false, @@ -2401,8 +2401,8 @@ class IGen { } static Instruction pw_sra(Register dst, Register src, u8 imm) { - assert(dst.is_xmm()); - assert(src.is_xmm()); + ASSERT(dst.is_xmm()); + ASSERT(src.is_xmm()); // VEX.128.66.0F.WIG 72 /4 ib VPSRAD xmm1, xmm2, imm8 Instruction instr(0x72); instr.set_vex_modrm_and_rex(4, src.hw_id(), VEX3::LeadingBytes::P_0F, dst.hw_id(), false, @@ -2412,8 +2412,8 @@ class IGen { } static Instruction pw_srl(Register dst, Register src, u8 imm) { - assert(dst.is_xmm()); - assert(src.is_xmm()); + ASSERT(dst.is_xmm()); + ASSERT(src.is_xmm()); // VEX.128.66.0F.WIG 72 /2 ib VPSRLD xmm1, xmm2, imm8 Instruction instr(0x72); instr.set_vex_modrm_and_rex(2, src.hw_id(), VEX3::LeadingBytes::P_0F, dst.hw_id(), false, @@ -2423,8 +2423,8 @@ class IGen { } static Instruction pw_sll(Register dst, Register src, u8 imm) { - assert(dst.is_xmm()); - assert(src.is_xmm()); + ASSERT(dst.is_xmm()); + ASSERT(src.is_xmm()); // VEX.128.66.0F.WIG 72 /6 ib VPSLLD xmm1, xmm2, imm8 Instruction instr(0x72); instr.set_vex_modrm_and_rex(6, src.hw_id(), VEX3::LeadingBytes::P_0F, dst.hw_id(), false, @@ -2434,9 +2434,9 @@ class IGen { } static Instruction parallel_bitwise_or(Register dst, Register src0, Register src1) { - assert(dst.is_xmm()); - assert(src0.is_xmm()); - assert(src1.is_xmm()); + ASSERT(dst.is_xmm()); + ASSERT(src0.is_xmm()); + ASSERT(src1.is_xmm()); // VEX.128.66.0F.WIG EB /r VPOR xmm1, xmm2, xmm3/m128 // reg, vex, r/m Instruction instr(0xEB); @@ -2446,9 +2446,9 @@ class IGen { } static Instruction parallel_bitwise_xor(Register dst, Register src0, Register src1) { - assert(dst.is_xmm()); - assert(src0.is_xmm()); - assert(src1.is_xmm()); + ASSERT(dst.is_xmm()); + ASSERT(src0.is_xmm()); + ASSERT(src1.is_xmm()); // VEX.128.66.0F.WIG EF /r VPXOR xmm1, xmm2, xmm3/m128 // reg, vex, r/m Instruction instr(0xEF); @@ -2458,9 +2458,9 @@ class IGen { } static Instruction parallel_bitwise_and(Register dst, Register src0, Register src1) { - assert(dst.is_xmm()); - assert(src0.is_xmm()); - assert(src1.is_xmm()); + ASSERT(dst.is_xmm()); + ASSERT(src0.is_xmm()); + ASSERT(src1.is_xmm()); // VEX.128.66.0F.WIG DB /r VPAND xmm1, xmm2, xmm3/m128 // reg, vex, r/m Instruction instr(0xDB); @@ -2479,9 +2479,9 @@ class IGen { // -- Unpack High Data Instructions static Instruction pextub_swapped(Register dst, Register src0, Register src1) { - assert(dst.is_xmm()); - assert(src0.is_xmm()); - assert(src1.is_xmm()); + ASSERT(dst.is_xmm()); + ASSERT(src0.is_xmm()); + ASSERT(src1.is_xmm()); // VEX.128.66.0F.WIG 68/r VPUNPCKHBW xmm1,xmm2, xmm3/m128 // reg, vex, r/m Instruction instr(0x68); @@ -2491,9 +2491,9 @@ class IGen { } static Instruction pextuh_swapped(Register dst, Register src0, Register src1) { - assert(dst.is_xmm()); - assert(src0.is_xmm()); - assert(src1.is_xmm()); + ASSERT(dst.is_xmm()); + ASSERT(src0.is_xmm()); + ASSERT(src1.is_xmm()); // VEX.128.66.0F.WIG 69/r VPUNPCKHWD xmm1,xmm2, xmm3/m128 // reg, vex, r/m Instruction instr(0x69); @@ -2503,9 +2503,9 @@ class IGen { } static Instruction pextuw_swapped(Register dst, Register src0, Register src1) { - assert(dst.is_xmm()); - assert(src0.is_xmm()); - assert(src1.is_xmm()); + ASSERT(dst.is_xmm()); + ASSERT(src0.is_xmm()); + ASSERT(src1.is_xmm()); // VEX.128.66.0F.WIG 6A/r VPUNPCKHDQ xmm1, xmm2, xmm3/m128 // reg, vex, r/m Instruction instr(0x6a); @@ -2516,9 +2516,9 @@ class IGen { // -- Unpack Low Data Instructions static Instruction pextlb_swapped(Register dst, Register src0, Register src1) { - assert(dst.is_xmm()); - assert(src0.is_xmm()); - assert(src1.is_xmm()); + ASSERT(dst.is_xmm()); + ASSERT(src0.is_xmm()); + ASSERT(src1.is_xmm()); // VEX.128.66.0F.WIG 60/r VPUNPCKLBW xmm1,xmm2, xmm3/m128 // reg, vex, r/m Instruction instr(0x60); @@ -2528,9 +2528,9 @@ class IGen { } static Instruction pextlh_swapped(Register dst, Register src0, Register src1) { - assert(dst.is_xmm()); - assert(src0.is_xmm()); - assert(src1.is_xmm()); + ASSERT(dst.is_xmm()); + ASSERT(src0.is_xmm()); + ASSERT(src1.is_xmm()); // VEX.128.66.0F.WIG 61/r VPUNPCKLWD xmm1,xmm2, xmm3/m128 // reg, vex, r/m Instruction instr(0x61); @@ -2540,9 +2540,9 @@ class IGen { } static Instruction pextlw_swapped(Register dst, Register src0, Register src1) { - assert(dst.is_xmm()); - assert(src0.is_xmm()); - assert(src1.is_xmm()); + ASSERT(dst.is_xmm()); + ASSERT(src0.is_xmm()); + ASSERT(src1.is_xmm()); // VEX.128.66.0F.WIG 62/r VPUNPCKLDQ xmm1, xmm2, xmm3/m128 // reg, vex, r/m Instruction instr(0x62); @@ -2553,9 +2553,9 @@ class IGen { // Equal to than comparison as 16 bytes (8 bits) static Instruction parallel_compare_e_b(Register dst, Register src0, Register src1) { - assert(dst.is_xmm()); - assert(src0.is_xmm()); - assert(src1.is_xmm()); + ASSERT(dst.is_xmm()); + ASSERT(src0.is_xmm()); + ASSERT(src1.is_xmm()); // VEX.128.66.0F.WIG 74 /r VPCMPEQB xmm1, xmm2, xmm3/m128 // reg, vex, r/m Instruction instr(0x74); @@ -2566,9 +2566,9 @@ class IGen { // Equal to than comparison as 8 halfwords (16 bits) static Instruction parallel_compare_e_h(Register dst, Register src0, Register src1) { - assert(dst.is_xmm()); - assert(src0.is_xmm()); - assert(src1.is_xmm()); + ASSERT(dst.is_xmm()); + ASSERT(src0.is_xmm()); + ASSERT(src1.is_xmm()); // VEX.128.66.0F.WIG 75 /r VPCMPEQW xmm1, xmm2, xmm3/m128 // reg, vex, r/m Instruction instr(0x75); @@ -2579,9 +2579,9 @@ class IGen { // Equal to than comparison as 4 words (32 bits) static Instruction parallel_compare_e_w(Register dst, Register src0, Register src1) { - assert(dst.is_xmm()); - assert(src0.is_xmm()); - assert(src1.is_xmm()); + ASSERT(dst.is_xmm()); + ASSERT(src0.is_xmm()); + ASSERT(src1.is_xmm()); // VEX.128.66.0F.WIG 76 /r VPCMPEQD xmm1, xmm2, xmm3/m128 // reg, vex, r/m Instruction instr(0x76); @@ -2592,9 +2592,9 @@ class IGen { // Greater than comparison as 16 bytes (8 bits) static Instruction parallel_compare_gt_b(Register dst, Register src0, Register src1) { - assert(dst.is_xmm()); - assert(src0.is_xmm()); - assert(src1.is_xmm()); + ASSERT(dst.is_xmm()); + ASSERT(src0.is_xmm()); + ASSERT(src1.is_xmm()); // VEX.128.66.0F.WIG 64 /r VPCMPGTB xmm1, xmm2, xmm3/m128 // reg, vex, r/m Instruction instr(0x64); @@ -2605,9 +2605,9 @@ class IGen { // Greater than comparison as 8 halfwords (16 bits) static Instruction parallel_compare_gt_h(Register dst, Register src0, Register src1) { - assert(dst.is_xmm()); - assert(src0.is_xmm()); - assert(src1.is_xmm()); + ASSERT(dst.is_xmm()); + ASSERT(src0.is_xmm()); + ASSERT(src1.is_xmm()); // VEX.128.66.0F.WIG 65 /r VPCMPGTW xmm1, xmm2, xmm3/m128 // reg, vex, r/m Instruction instr(0x65); @@ -2618,9 +2618,9 @@ class IGen { // Greater than comparison as 4 words (32 bits) static Instruction parallel_compare_gt_w(Register dst, Register src0, Register src1) { - assert(dst.is_xmm()); - assert(src0.is_xmm()); - assert(src1.is_xmm()); + ASSERT(dst.is_xmm()); + ASSERT(src0.is_xmm()); + ASSERT(src1.is_xmm()); // VEX.128.66.0F.WIG 66 /r VPCMPGTD xmm1, xmm2, xmm3/m128 // reg, vex, r/m Instruction instr(0x66); @@ -2630,9 +2630,9 @@ class IGen { } static Instruction vpunpcklqdq(Register dst, Register src0, Register src1) { - assert(dst.is_xmm()); - assert(src0.is_xmm()); - assert(src1.is_xmm()); + ASSERT(dst.is_xmm()); + ASSERT(src0.is_xmm()); + ASSERT(src1.is_xmm()); // VEX.128.66.0F.WIG 6C/r VPUNPCKLQDQ xmm1, xmm2, xmm3/m128 // reg, vex, r/m Instruction instr(0x6c); @@ -2646,9 +2646,9 @@ class IGen { } static Instruction pcpyud(Register dst, Register src0, Register src1) { - assert(dst.is_xmm()); - assert(src0.is_xmm()); - assert(src1.is_xmm()); + ASSERT(dst.is_xmm()); + ASSERT(src0.is_xmm()); + ASSERT(src1.is_xmm()); // VEX.128.66.0F.WIG 6D/r VPUNPCKHQDQ xmm1, xmm2, xmm3/m128 // reg, vex, r/m Instruction instr(0x6d); @@ -2658,9 +2658,9 @@ class IGen { } static Instruction vpsubd(Register dst, Register src0, Register src1) { - assert(dst.is_xmm()); - assert(src0.is_xmm()); - assert(src1.is_xmm()); + ASSERT(dst.is_xmm()); + ASSERT(src0.is_xmm()); + ASSERT(src1.is_xmm()); // VEX.128.66.0F.WIG FA /r VPSUBD xmm1, xmm2, xmm3/m128 // reg, vec, r/m Instruction instr(0xfa); @@ -2670,8 +2670,8 @@ class IGen { } static Instruction vpsrldq(Register dst, Register src, u8 imm) { - assert(dst.is_xmm()); - assert(src.is_xmm()); + ASSERT(dst.is_xmm()); + ASSERT(src.is_xmm()); // VEX.128.66.0F.WIG 73 /3 ib VPSRLDQ xmm1, xmm2, imm8 Instruction instr(0x73); instr.set_vex_modrm_and_rex(3, src.hw_id(), VEX3::LeadingBytes::P_0F, dst.hw_id(), false, @@ -2681,8 +2681,8 @@ class IGen { } static Instruction vpslldq(Register dst, Register src, u8 imm) { - assert(dst.is_xmm()); - assert(src.is_xmm()); + ASSERT(dst.is_xmm()); + ASSERT(src.is_xmm()); // VEX.128.66.0F.WIG 73 /7 ib VPSLLDQ xmm1, xmm2, imm8 Instruction instr(0x73); instr.set_vex_modrm_and_rex(7, src.hw_id(), VEX3::LeadingBytes::P_0F, dst.hw_id(), false, @@ -2692,8 +2692,8 @@ class IGen { } static Instruction vpshuflw(Register dst, Register src, u8 imm) { - assert(dst.is_xmm()); - assert(src.is_xmm()); + ASSERT(dst.is_xmm()); + ASSERT(src.is_xmm()); // VEX.128.F2.0F.WIG 70 /r ib VPSHUFLW xmm1, xmm2/m128, imm8 Instruction instr(0x70); instr.set_vex_modrm_and_rex(dst.hw_id(), src.hw_id(), VEX3::LeadingBytes::P_0F, 0, false, @@ -2703,8 +2703,8 @@ class IGen { } static Instruction vpshufhw(Register dst, Register src, u8 imm) { - assert(dst.is_xmm()); - assert(src.is_xmm()); + ASSERT(dst.is_xmm()); + ASSERT(src.is_xmm()); // VEX.128.F3.0F.WIG 70 /r ib VPSHUFHW xmm1, xmm2/m128, imm8 Instruction instr(0x70); instr.set_vex_modrm_and_rex(dst.hw_id(), src.hw_id(), VEX3::LeadingBytes::P_0F, 0, false, diff --git a/goalc/emitter/Instruction.h b/goalc/emitter/Instruction.h index 9c00f26887..7a75da5cb3 100644 --- a/goalc/emitter/Instruction.h +++ b/goalc/emitter/Instruction.h @@ -4,7 +4,7 @@ #define JAK_INSTRUCTION_H #include "common/common_types.h" -#include "common/util/assert.h" +#include "common/util/Assert.h" namespace emitter { /*! @@ -84,7 +84,7 @@ struct VEX3 { result |= (u8(prefix) & 0b11); return result; } else { - assert(false); + ASSERT(false); return -1; } } @@ -124,7 +124,7 @@ struct VEX2 { result |= (u8(prefix) & 0b11); return result; } else { - assert(false); + ASSERT(false); return -1; } } @@ -307,9 +307,9 @@ struct Instruction { // need three byte version set(VEX3(rex_w, rex_r, false, rex_b, lb, vex_reg, prefix)); } else { - assert(lb == VEX3::LeadingBytes::P_0F); // vex2 implies 0x0f - assert(!rex_b); - assert(!rex_w); + ASSERT(lb == VEX3::LeadingBytes::P_0F); // vex2 implies 0x0f + ASSERT(!rex_b); + ASSERT(!rex_w); set(VEX2(rex_r, vex_reg, prefix)); } } @@ -344,9 +344,9 @@ struct Instruction { set(VEX3(rex_w, rex_r, false, rex_b, lb)); } else { // can get away with two byte version - assert(lb == VEX3::LeadingBytes::P_0F); // vex2 implies 0x0f - assert(!rex_b); - assert(!rex_w); + ASSERT(lb == VEX3::LeadingBytes::P_0F); // vex2 implies 0x0f + ASSERT(!rex_b); + ASSERT(!rex_w); set(VEX2(rex_r)); } } @@ -398,7 +398,7 @@ struct Instruction { rex_x = addr1_ext; rex_b = addr2_ext; } - assert(sib.index != 4); + ASSERT(sib.index != 4); if (rex_b || rex_w || rex_r || rex_x) { set(REX(rex_w, rex_r, rex_x, rex_b)); @@ -457,16 +457,16 @@ struct Instruction { rex_x = addr1_ext; rex_b = addr2_ext; } - assert(sib.index != 4); + ASSERT(sib.index != 4); if (rex_b || rex_w || rex_x || lb != VEX3::LeadingBytes::P_0F) { // need three byte version set(VEX3(rex_w, rex_r, rex_x, rex_b, lb)); } else { - assert(lb == VEX3::LeadingBytes::P_0F); // vex2 implies 0x0f - assert(!rex_b); - assert(!rex_w); - assert(!rex_x); + ASSERT(lb == VEX3::LeadingBytes::P_0F); // vex2 implies 0x0f + ASSERT(!rex_b); + ASSERT(!rex_w); + ASSERT(!rex_x); set(VEX2(rex_r)); } @@ -522,7 +522,7 @@ struct Instruction { rex_x = addr1_ext; rex_b = addr2_ext; } - assert(sib.index != 4); + ASSERT(sib.index != 4); if (rex_b || rex_w || rex_r || rex_x) { set(REX(rex_w, rex_r, rex_x, rex_b)); @@ -581,16 +581,16 @@ struct Instruction { rex_x = addr1_ext; rex_b = addr2_ext; } - assert(sib.index != 4); + ASSERT(sib.index != 4); if (rex_b || rex_w || rex_x || lb != VEX3::LeadingBytes::P_0F) { // need three byte version set(VEX3(rex_w, rex_r, rex_x, rex_b, lb)); } else { - assert(lb == VEX3::LeadingBytes::P_0F); // vex2 implies 0x0f - assert(!rex_b); - assert(!rex_w); - assert(!rex_x); + ASSERT(lb == VEX3::LeadingBytes::P_0F); // vex2 implies 0x0f + ASSERT(!rex_b); + ASSERT(!rex_w); + ASSERT(!rex_x); set(VEX2(rex_r)); } @@ -655,8 +655,8 @@ struct Instruction { rex_x = addr1_ext; rex_b = addr2_ext; } - assert(sib.base != 5); - assert(sib.index != 4); + ASSERT(sib.base != 5); + ASSERT(sib.index != 4); } if (rex_b || rex_w || rex_r || rex_x || rex_always) { @@ -723,18 +723,18 @@ struct Instruction { rex_x = addr1_ext; rex_b = addr2_ext; } - assert(sib.base != 5); - assert(sib.index != 4); + ASSERT(sib.base != 5); + ASSERT(sib.index != 4); } if (rex_b || rex_w || rex_x || lb != VEX3::LeadingBytes::P_0F) { // need three byte version set(VEX3(rex_w, rex_r, rex_x, rex_b, lb)); } else { - assert(lb == VEX3::LeadingBytes::P_0F); // vex2 implies 0x0f - assert(!rex_b); - assert(!rex_w); - assert(!rex_x); + ASSERT(lb == VEX3::LeadingBytes::P_0F); // vex2 implies 0x0f + ASSERT(!rex_b); + ASSERT(!rex_w); + ASSERT(!rex_x); set(VEX2(rex_r)); } @@ -832,8 +832,8 @@ struct Instruction { // need three byte version set(VEX3(rex_w, rex_r, false, false, lb)); } else { - assert(lb == VEX3::LeadingBytes::P_0F); // vex2 implies 0x0f - assert(!rex_w); + ASSERT(lb == VEX3::LeadingBytes::P_0F); // vex2 implies 0x0f + ASSERT(!rex_w); set(VEX2(rex_r)); } @@ -882,7 +882,7 @@ struct Instruction { int offset_of_disp() const { if (is_null) return 0; - assert(set_disp_imm); + ASSERT(set_disp_imm); int offset = 0; offset += n_vex; if (set_rex) @@ -905,7 +905,7 @@ struct Instruction { int offset_of_imm() const { if (is_null) return 0; - assert(set_imm); + ASSERT(set_imm); int offset = 0; offset += n_vex; if (set_rex) diff --git a/goalc/emitter/ObjectGenerator.cpp b/goalc/emitter/ObjectGenerator.cpp index 4bb2a83198..538a6b43ca 100644 --- a/goalc/emitter/ObjectGenerator.cpp +++ b/goalc/emitter/ObjectGenerator.cpp @@ -56,7 +56,7 @@ ObjectFileData ObjectGenerator::generate_data_v3(const TypeSystem* ts) { const auto& instr = function.instructions[instr_idx]; u8 temp[128]; auto count = instr.emit(temp); - assert(count < 128); + ASSERT(count < 128); function.instruction_to_byte_in_data.push_back(data.size()); function.debug->instructions.at(instr_idx).offset = data.size() - function.debug->offset_in_seg; @@ -158,7 +158,7 @@ IR_Record ObjectGenerator::add_ir(const FunctionRecord& func) { * jumps forward to things we haven't seen yet. */ IR_Record ObjectGenerator::get_future_ir_record(const FunctionRecord& func, int ir_id) { - assert(func.func_id == int(m_function_data_by_seg.at(func.seg).size()) - 1); + ASSERT(func.func_id == int(m_function_data_by_seg.at(func.seg).size()) - 1); IR_Record rec; rec.seg = func.seg; rec.func_id = func.func_id; @@ -179,7 +179,7 @@ IR_Record ObjectGenerator::get_future_ir_record_in_same_func(const IR_Record& ir */ InstructionRecord ObjectGenerator::add_instr(Instruction inst, IR_Record ir) { // only this second condition is an actual error. - assert(ir.ir_id == + ASSERT(ir.ir_id == int(m_function_data_by_seg.at(ir.seg).at(ir.func_id).ir_to_instruction.size()) - 1); InstructionRecord rec; @@ -239,8 +239,8 @@ void ObjectGenerator::link_static_type_ptr(StaticRecord rec, */ void ObjectGenerator::link_instruction_jump(InstructionRecord jump_instr, IR_Record destination) { // must jump within our own function. - assert(jump_instr.seg == destination.seg); - assert(jump_instr.func_id == destination.func_id); + ASSERT(jump_instr.seg == destination.seg); + ASSERT(jump_instr.func_id == destination.func_id); m_jump_temp_links_by_seg.at(jump_instr.seg).push_back({jump_instr, destination}); } @@ -286,7 +286,7 @@ void ObjectGenerator::link_static_pointer_to_data(const StaticRecord& source, link.dest = dest; link.offset_in_source = source_offset; link.offset_in_dest = dest_offset; - assert(link.source.seg == link.dest.seg); + ASSERT(link.source.seg == link.dest.seg); m_static_data_temp_ptr_links_by_seg.at(source.seg).push_back(link); } @@ -301,7 +301,7 @@ void ObjectGenerator::link_static_pointer_to_function(const StaticRecord& source link.source = source; link.offset_in_source = source_offset; link.dest = target_func; - assert(target_func.seg == source.seg); + ASSERT(target_func.seg == source.seg); m_static_function_temp_ptr_links_by_seg.at(source.seg).push_back(link); } @@ -325,7 +325,7 @@ void ObjectGenerator::handle_temp_static_type_links(int seg) { for (const auto& type_links : m_static_type_temp_links_by_seg.at(seg)) { const auto& type_name = type_links.first; for (const auto& link : type_links.second) { - assert(seg == link.rec.seg); + ASSERT(seg == link.rec.seg); const auto& static_object = m_static_data_by_seg.at(seg).at(link.rec.static_id); int total_offset = static_object.location + link.offset; m_type_ptr_links_by_seg.at(seg)[type_name].push_back(total_offset); @@ -342,7 +342,7 @@ void ObjectGenerator::handle_temp_static_sym_links(int seg) { for (const auto& sym_links : m_static_sym_temp_links_by_seg.at(seg)) { const auto& sym_name = sym_links.first; for (const auto& link : sym_links.second) { - assert(seg == link.rec.seg); + ASSERT(seg == link.rec.seg); const auto& static_object = m_static_data_by_seg.at(seg).at(link.rec.static_id); int total_offset = static_object.location + link.offset; m_sym_links_by_seg.at(seg)[sym_name].push_back(total_offset); @@ -367,7 +367,7 @@ void ObjectGenerator::handle_temp_static_ptr_links(int seg) { for (const auto& link : m_static_function_temp_ptr_links_by_seg.at(seg)) { const auto& source_object = m_static_data_by_seg.at(seg).at(link.source.static_id); const auto& dest_function = m_function_data_by_seg.at(seg).at(link.dest.func_id); - assert(link.dest.seg == seg); + ASSERT(link.dest.seg == seg); int loc = dest_function.instruction_to_byte_in_data.at(0); PointerLink result_link; result_link.segment = seg; @@ -387,11 +387,11 @@ void ObjectGenerator::handle_temp_jump_links(int seg) { // 2). the value of RIP at the jump (the instruction after the jump, on x86) // 3). the value of RIP we want const auto& function = m_function_data_by_seg.at(seg).at(link.jump_instr.func_id); - assert(link.jump_instr.func_id == link.dest.func_id); - assert(link.jump_instr.seg == seg); - assert(link.dest.seg == seg); + ASSERT(link.jump_instr.func_id == link.dest.func_id); + ASSERT(link.jump_instr.seg == seg); + ASSERT(link.dest.seg == seg); const auto& jump_instr = function.instructions.at(link.jump_instr.instr_id); - assert(jump_instr.get_imm_size() == 4); + ASSERT(jump_instr.get_imm_size() == 4); // 1). patch = instruction location + location of imm in instruction. int patch_location = function.instruction_to_byte_in_data.at(link.jump_instr.instr_id) + @@ -417,16 +417,16 @@ void ObjectGenerator::handle_temp_instr_sym_links(int seg) { for (const auto& links : m_symbol_instr_temp_links_by_seg.at(seg)) { const auto& sym_name = links.first; for (const auto& link : links.second) { - assert(seg == link.rec.seg); + ASSERT(seg == link.rec.seg); const auto& function = m_function_data_by_seg.at(seg).at(link.rec.func_id); const auto& instruction = function.instructions.at(link.rec.instr_id); int offset_of_instruction = function.instruction_to_byte_in_data.at(link.rec.instr_id); int offset_in_instruction = link.is_mem_access ? instruction.offset_of_disp() : instruction.offset_of_imm(); if (link.is_mem_access) { - assert(instruction.get_disp_size() == 4); + ASSERT(instruction.get_disp_size() == 4); } else { - assert(instruction.get_imm_size() == 4); + ASSERT(instruction.get_imm_size() == 4); } m_sym_links_by_seg.at(seg)[sym_name].push_back(offset_of_instruction + offset_in_instruction); } @@ -516,8 +516,8 @@ void ObjectGenerator::emit_link_ptr(int seg) { auto& out = m_link_by_seg.at(seg); for (auto& rec : m_pointer_links_by_seg.at(seg)) { out.push_back(LINK_PTR); - assert(rec.dest >= 0); - assert(rec.source >= 0); + ASSERT(rec.dest >= 0); + ASSERT(rec.source >= 0); push_data(rec.source, out); push_data(rec.dest, out); } @@ -540,11 +540,11 @@ void ObjectGenerator::emit_link_rip(int seg) { const auto& src_func = m_function_data_by_seg.at(rec.instr.seg).at(rec.instr.func_id); push_data(src_func.instruction_to_byte_in_data.at(rec.instr.instr_id + 1), out); // offset into target - assert(rec.offset_in_segment >= 0); + ASSERT(rec.offset_in_segment >= 0); push_data(rec.offset_in_segment, out); // patch location const auto& src_instr = src_func.instructions.at(rec.instr.instr_id); - assert(src_instr.get_disp_size() == 4); + ASSERT(src_instr.get_disp_size() == 4); push_data( src_func.instruction_to_byte_in_data.at(rec.instr.instr_id) + src_instr.offset_of_disp(), out); diff --git a/goalc/emitter/ObjectGenerator.h b/goalc/emitter/ObjectGenerator.h index e9d03f596f..11cb400e1b 100644 --- a/goalc/emitter/ObjectGenerator.h +++ b/goalc/emitter/ObjectGenerator.h @@ -122,8 +122,8 @@ class ObjectGenerator { template void patch_data(int seg, int offset, const T& x) { auto& data = m_data_by_seg.at(seg); - assert(offset >= 0); - assert(offset + sizeof(T) <= data.size()); + ASSERT(offset >= 0); + ASSERT(offset + sizeof(T) <= data.size()); memcpy(data.data() + offset, &x, sizeof(T)); } diff --git a/goalc/emitter/Register.cpp b/goalc/emitter/Register.cpp index e2fa146fe3..57ac46e8ff 100644 --- a/goalc/emitter/Register.cpp +++ b/goalc/emitter/Register.cpp @@ -93,7 +93,7 @@ HWRegKind reg_class_to_hw(RegClass reg_class) { case RegClass::GPR_64: return HWRegKind::GPR; default: - assert(false); + ASSERT(false); return HWRegKind::INVALID; } } diff --git a/goalc/emitter/Register.h b/goalc/emitter/Register.h index 6baa2a33da..4edce8b644 100644 --- a/goalc/emitter/Register.h +++ b/goalc/emitter/Register.h @@ -10,7 +10,7 @@ #include #include "common/common_types.h" #include "common/goal_constants.h" -#include "common/util/assert.h" +#include "common/util/Assert.h" namespace emitter { @@ -76,7 +76,7 @@ class Register { } else if (is_gpr()) { return m_id - RAX; } else { - assert(false); + ASSERT(false); } return 0xff; } diff --git a/goalc/listener/Listener.cpp b/goalc/listener/Listener.cpp index f9a2e298f4..8f89db149d 100644 --- a/goalc/listener/Listener.cpp +++ b/goalc/listener/Listener.cpp @@ -29,7 +29,7 @@ #include "common/versions.h" #include "third-party/fmt/core.h" -#include "common/util/assert.h" +#include "common/util/Assert.h" using namespace versions; constexpr bool debug_listener = false; @@ -244,7 +244,7 @@ void Listener::receive_func() { ack_recv_prog += got; } ack_recv_buff[ack_recv_prog] = '\0'; - assert(ack_recv_prog < 512); + ASSERT(ack_recv_prog < 512); got_ack = true; last_recvd_id = hdr->msg_id; if (last_recvd_id > last_sent_id) { @@ -262,7 +262,7 @@ void Listener::receive_func() { case ListenerMessageKind::MSG_PRINT: { auto* str_buff = new char[hdr->msg_size + 1]; // plus one for the null terminator int msg_prog = 0; - assert(hdr->msg_id == 0); + ASSERT(hdr->msg_id == 0); while (rcvd < hdr->deci2_header.len) { if (!m_connected) { return; @@ -495,17 +495,17 @@ void Listener::handle_output_message(const char* msg) { auto x = str.find(' '); auto kind = str.substr(0, x); if (kind == "reset") { - assert(x + 1 < str.length()); + ASSERT(x + 1 < str.length()); auto next = str.find(' ', x + 1); auto s7_str = str.substr(x, next - x); x = next; - assert(x + 1 < str.length()); + ASSERT(x + 1 < str.length()); next = str.find(' ', x + 1); auto base_str = str.substr(x, next - x); x = next; - assert(x + 1 < str.length()); + ASSERT(x + 1 < str.length()); next = str.find(' ', x + 1); auto tid_str = str.substr(x, next - x); @@ -516,12 +516,12 @@ void Listener::handle_output_message(const char* msg) { } } else if (kind == "load") { - assert(x + 1 < str.length()); + ASSERT(x + 1 < str.length()); auto next = str.find(' ', x + 1); auto name_str = str.substr(x, next - x); x = next; - assert(x + 1 < str.length()); + ASSERT(x + 1 < str.length()); next = str.find(' ', x + 1); auto load_kind_str = str.substr(x, next - x); x = next; @@ -529,7 +529,7 @@ void Listener::handle_output_message(const char* msg) { std::string seg_strings[6]; for (auto& seg_string : seg_strings) { - assert(x + 1 < str.length()); + ASSERT(x + 1 < str.length()); next = str.find(' ', x + 1); seg_string = str.substr(x, next - x); x = next; diff --git a/goalc/listener/MemoryMap.cpp b/goalc/listener/MemoryMap.cpp index a7442ac53a..7750c42cde 100644 --- a/goalc/listener/MemoryMap.cpp +++ b/goalc/listener/MemoryMap.cpp @@ -4,7 +4,7 @@ #include "third-party/fmt/core.h" #include "common/link_types.h" #include "common/util/BitUtils.h" -#include "common/util/assert.h" +#include "common/util/Assert.h" namespace listener { std::string LoadEntry::print() const { @@ -60,7 +60,7 @@ MemoryMap::MemoryMap(const std::unordered_map& load_entr printf("%s\n", temp.print().c_str()); printf("Can't add %s\n", entry.print().c_str()); - assert(false); // todo, handle this more gracefully + ASSERT(false); // todo, handle this more gracefully } else if (entry.start_addr > last_addr) { // this is fine, there's just a gap. MemoryMapEntry gap; @@ -107,7 +107,7 @@ const MemoryMapEntry& MemoryMap::lookup(u32 addr) { return entry; } } - assert(false); + ASSERT(false); throw std::runtime_error("MemoryMap::lookup failed"); } diff --git a/goalc/make/MakeSystem.cpp b/goalc/make/MakeSystem.cpp index eee4cf6851..c07a21e735 100644 --- a/goalc/make/MakeSystem.cpp +++ b/goalc/make/MakeSystem.cpp @@ -198,7 +198,7 @@ std::vector MakeSystem::get_dependencies(const std::string& target) void MakeSystem::add_tool(std::shared_ptr tool) { auto& name = tool->name(); - assert(m_tools.find(name) == m_tools.end()); + ASSERT(m_tools.find(name) == m_tools.end()); m_tools[name] = tool; } diff --git a/goalc/regalloc/Allocator.cpp b/goalc/regalloc/Allocator.cpp index addae2ae09..986247d1a2 100644 --- a/goalc/regalloc/Allocator.cpp +++ b/goalc/regalloc/Allocator.cpp @@ -39,7 +39,7 @@ void compute_live_ranges(RegAllocCache* cache, const AllocationInput& in) { } // and liveliness analysis - assert(block.live.size() == block.instr_idx.size()); + ASSERT(block.live.size() == block.instr_idx.size()); for (uint32_t i = 0; i < block.live.size(); i++) { for (int j = 0; j < block.live[i].size(); j++) { if (block.live[i][j]) { @@ -416,7 +416,7 @@ int get_stack_slot_for_var(int var, RegAllocCache* cache) { slot_size = 1; break; default: - assert(false); + ASSERT(false); } auto kv = cache->var_to_stack_slot.find(var); if (kv == cache->var_to_stack_slot.end()) { @@ -435,7 +435,7 @@ int get_stack_slot_for_var(int var, RegAllocCache* cache) { const std::vector& get_default_alloc_order_for_var_spill(int v, RegAllocCache* cache) { auto& info = cache->iregs.at(v); - assert(info.reg_class != RegClass::INVALID); + ASSERT(info.reg_class != RegClass::INVALID); auto hw_kind = emitter::reg_class_to_hw(info.reg_class); if (hw_kind == emitter::HWRegKind::GPR) { return emitter::gRegInfo.get_gpr_spill_alloc_order(); @@ -450,7 +450,7 @@ const std::vector& get_default_alloc_order_for_var(int v, RegAllocCache* cache, bool get_all) { auto& info = cache->iregs.at(v); - assert(info.reg_class != RegClass::INVALID); + ASSERT(info.reg_class != RegClass::INVALID); auto hw_kind = emitter::reg_class_to_hw(info.reg_class); if (hw_kind == emitter::HWRegKind::GPR || hw_kind == emitter::HWRegKind::INVALID) { if (!get_all && cache->is_asm_func) { @@ -507,7 +507,7 @@ bool try_spill_coloring(int var, RegAllocCache* cache, const AllocationInput& in // this shouldn't be possible with feasible constraints printf("-- SPILL FAILED -- IMPOSSIBLE CONSTRAINT @ %d %s. This is likely a RegAlloc bug!\n", instr, current_assignment.to_string().c_str()); - assert(false); + ASSERT(false); return false; } @@ -570,7 +570,7 @@ bool try_spill_coloring(int var, RegAllocCache* cache, const AllocationInput& in if (spill_assignment.reg == -1) { printf("SPILLING FAILED BECAUSE WE COULDN'T FIND A TEMP REGISTER!\n"); - assert(false); + ASSERT(false); return false; } diff --git a/goalc/regalloc/Allocator.h b/goalc/regalloc/Allocator.h index f86d246fbe..7f18b3b098 100644 --- a/goalc/regalloc/Allocator.h +++ b/goalc/regalloc/Allocator.h @@ -46,7 +46,7 @@ struct LiveInfo { * Add an instruction id where this variable is live. */ void add_live_instruction(int value) { - assert(value >= 0); + ASSERT(value >= 0); if (value > max) max = value; if (value < min) @@ -79,7 +79,7 @@ struct LiveInfo { return true; if (idx < min || idx > max) return false; - assert(idx > min); + ASSERT(idx > min); return is_alive.at(idx - min) && !is_alive.at(idx - min - 1); } else { return idx == min; @@ -95,7 +95,7 @@ struct LiveInfo { return true; if (idx < min || idx > max) return false; - assert(idx < max); + ASSERT(idx < max); return is_alive.at(idx - min) && !is_alive.at(idx - min + 1); } else { return idx == max; @@ -109,7 +109,7 @@ struct LiveInfo { var = id; if (!seen) return; // don't do any prep for a variable which isn't used. - assert(max - min >= 0); + ASSERT(max - min >= 0); assignment.resize(max - min + 1); is_alive.resize(max - min + 1); for (auto& x : indices_of_alive) { @@ -123,7 +123,7 @@ struct LiveInfo { * Will set best_hint to this assignment. */ void constrain_at_one(int id, emitter::Register reg) { - assert(id >= min && id <= max); + ASSERT(id >= min && id <= max); Assignment ass; ass.reg = reg; ass.kind = Assignment::Kind::REGISTER; @@ -150,7 +150,7 @@ struct LiveInfo { * At the given instruction, does the given assignment conflict with this one? */ bool conflicts_at(int id, Assignment ass) { - assert(id >= min && id <= max); + ASSERT(id >= min && id <= max); return assignment.at(id - min).occupies_same_reg(ass); } @@ -158,7 +158,7 @@ struct LiveInfo { * At the given instruction, does the given assignment conflict with this one? */ bool conflicts_at(int id, emitter::Register reg) { - assert(id >= min && id <= max); + ASSERT(id >= min && id <= max); Assignment ass; ass.reg = reg; ass.kind = Assignment::Kind::REGISTER; @@ -170,8 +170,8 @@ struct LiveInfo { * Throws if this would require modifying a currently set assignment. */ void assign_no_overwrite(Assignment ass) { - assert(seen); - assert(ass.is_assigned()); + ASSERT(seen); + ASSERT(ass.is_assigned()); for (int i = min; i <= max; i++) { auto& a = assignment.at(i - min); if (a.is_assigned() && !(a.occupies_same_reg(ass))) { @@ -186,7 +186,7 @@ struct LiveInfo { * Get the assignment at the given instruction. */ const Assignment& get(int id) const { - assert(id >= min && id <= max); + ASSERT(id >= min && id <= max); return assignment.at(id - min); } diff --git a/goalc/regalloc/Allocator_v2.cpp b/goalc/regalloc/Allocator_v2.cpp index 7d929ec283..9674278db9 100644 --- a/goalc/regalloc/Allocator_v2.cpp +++ b/goalc/regalloc/Allocator_v2.cpp @@ -117,7 +117,7 @@ class VarAssignment { // get the register that this variable is assigned to. Must be assigned_to_reg() emitter::Register reg() const { - assert(assigned_to_reg()); + ASSERT(assigned_to_reg()); return m_assigned_register; } @@ -136,21 +136,21 @@ class VarAssignment { // put this variable in the given register and constrain it there (prevent spilling) void constrain_to_register(const emitter::Register& reg) { - assert(unassigned()); + ASSERT(unassigned()); m_kind = Kind::REGISTER; m_locked = true; m_assigned_register = reg; } void assign_to_register(const emitter::Register& reg) { - assert(unassigned()); + ASSERT(unassigned()); m_kind = Kind::REGISTER; m_locked = false; m_assigned_register = reg; } void assign_to_stack(int slot) { - assert(unassigned()); + ASSERT(unassigned()); m_kind = Kind::STACK; m_locked = false; m_stack_temp_regs.resize(m_live.size()); @@ -158,7 +158,7 @@ class VarAssignment { } void demote_to_stack(int slot) { - assert(assigned_to_reg()); + ASSERT(assigned_to_reg()); m_kind = Kind::STACK; m_locked = false; m_stack_temp_regs.resize(m_live.size()); @@ -166,8 +166,8 @@ class VarAssignment { } void set_stack_slot_reg(const emitter::Register& reg, int instr_idx) { - assert(assigned_to_stack()); - assert(!m_stack_temp_regs.at(instr_idx - first_live())); + ASSERT(assigned_to_stack()); + ASSERT(!m_stack_temp_regs.at(instr_idx - first_live())); m_stack_temp_regs.at(instr_idx - first_live()) = reg; } @@ -178,13 +178,13 @@ class VarAssignment { } emitter::Register get_stack_slot_reg(int instr_idx) const { - assert(assigned_to_stack()); - assert(m_stack_temp_regs.at(instr_idx - first_live())); + ASSERT(assigned_to_stack()); + ASSERT(m_stack_temp_regs.at(instr_idx - first_live())); return *m_stack_temp_regs.at(instr_idx - first_live()); } bool stack_bonus_op_needs_reg(const emitter::Register& reg, int instr_idx) const { - assert(assigned_to_stack()); + ASSERT(assigned_to_stack()); auto& stack_reg = m_stack_temp_regs.at(instr_idx - m_first_live); return stack_reg && (*stack_reg == reg); } @@ -215,7 +215,7 @@ class VarAssignment { } return asses; } else { - assert(false); + ASSERT(false); } } @@ -356,7 +356,7 @@ std::vector> find_live_range_instr(const AllocationInput& input, } } - assert(block.live.size() == block.instr_idx.size()); + ASSERT(block.live.size() == block.instr_idx.size()); for (uint32_t i = 0; i < block.live.size(); i++) { for (int j = 0; j < block.live[i].size(); j++) { if (block.live[i][j]) { @@ -388,7 +388,7 @@ std::vector initialize_unassigned(const std::vector>& // allocate std::vector result; result.reserve(input.max_vars); - assert(input.max_vars == (int)live_ranges.size()); + ASSERT(input.max_vars == (int)live_ranges.size()); int var_idx = 0; for (auto lr : live_ranges) { result.emplace_back(lr.first(), lr.last(), var_idx++); @@ -408,7 +408,7 @@ std::vector initialize_unassigned(const std::vector>& } // and liveliness analysis - assert(block.live.size() == block.instr_idx.size()); + ASSERT(block.live.size() == block.instr_idx.size()); for (uint32_t instr = 0; instr < block.live.size(); instr++) { for (int var = 0; var < block.live[instr].size(); var++) { if (block.live[instr][var]) { @@ -800,7 +800,7 @@ int get_stack_slot_for_var(int var, RACache* cache) { slot_size = 1; break; default: - assert(false); + ASSERT(false); } auto kv = cache->var_to_stack_slot.find(var); if (kv == cache->var_to_stack_slot.end()) { diff --git a/goalc/regalloc/IRegSet.h b/goalc/regalloc/IRegSet.h index 1f7d692d20..5da9d86730 100644 --- a/goalc/regalloc/IRegSet.h +++ b/goalc/regalloc/IRegSet.h @@ -15,7 +15,7 @@ */ #include #include "common/common_types.h" -#include "common/util/assert.h" +#include "common/util/Assert.h" class IRegSet { public: @@ -27,7 +27,7 @@ class IRegSet { */ void insert(int x) { resize(x + 1); - assert(m_bits > x); + ASSERT(m_bits > x); auto word = x / 64; auto bit = x % 64; m_data.at(word) |= (1ll << bit); diff --git a/goalc/regalloc/IRegister.cpp b/goalc/regalloc/IRegister.cpp index 3750465456..2b994dad6b 100644 --- a/goalc/regalloc/IRegister.cpp +++ b/goalc/regalloc/IRegister.cpp @@ -1,6 +1,6 @@ #include "third-party/fmt/core.h" #include "IRegister.h" -#include "common/util/assert.h" +#include "common/util/Assert.h" std::string IRegister::to_string() const { // if (with_constraints) { @@ -21,7 +21,7 @@ std::string IRegister::to_string() const { case RegClass::VECTOR_FLOAT: return fmt::format("ivf-{}", id); default: - assert(false); + ASSERT(false); return {}; } } diff --git a/goalc/regalloc/allocator_interface.cpp b/goalc/regalloc/allocator_interface.cpp index bb96f885f7..e5be037464 100644 --- a/goalc/regalloc/allocator_interface.cpp +++ b/goalc/regalloc/allocator_interface.cpp @@ -81,7 +81,7 @@ std::string Assignment::to_string() const { result += "unassigned"; break; default: - assert(false); + ASSERT(false); } return result; @@ -134,7 +134,7 @@ void find_basic_blocks(ControlFlowAnalysisCache* cache, const AllocationInput& i for (uint32_t i = 0; i < cache->basic_blocks.size(); i++) { if (!cache->basic_blocks[i].instr_idx.empty() && cache->basic_blocks[i].instr_idx.front() == instr) { - assert(!found); + ASSERT(!found); found = true; result = i; } @@ -143,13 +143,13 @@ void find_basic_blocks(ControlFlowAnalysisCache* cache, const AllocationInput& i printf("[RegAlloc Error] couldn't find basic block beginning with instr %d of %d\n", instr, int(in.instructions.size())); } - assert(found); + ASSERT(found); return result; }; // link blocks for (auto& block : cache->basic_blocks) { - assert(!block.instr_idx.empty()); + ASSERT(!block.instr_idx.empty()); auto& last_instr = in.instructions.at(block.instr_idx.back()); if (last_instr.fallthrough) { // try to link to next block: diff --git a/goalc/regalloc/allocator_interface.h b/goalc/regalloc/allocator_interface.h index b011096d5f..4b8092a450 100644 --- a/goalc/regalloc/allocator_interface.h +++ b/goalc/regalloc/allocator_interface.h @@ -102,7 +102,7 @@ class AssignmentRange { const std::vector& assignments) : m_start(start_instr), m_live(live), m_ass(assignments) { m_end = start_instr + live.size() - 1; - assert(m_live.size() == m_ass.size()); + ASSERT(m_live.size() == m_ass.size()); } bool is_live_at_instr(int instr) const { return has_info_at(instr) && m_live.at(instr - m_start); @@ -139,12 +139,12 @@ struct AllocationResult { int total_stack_slots() const { return stack_slots_for_spills + stack_slots_for_vars; } int get_slot_for_var(int slot) const { - assert(slot < stack_slots_for_vars); + ASSERT(slot < stack_slots_for_vars); return slot; } int get_slot_for_spill(int slot) const { - assert(slot < stack_slots_for_spills); + ASSERT(slot < stack_slots_for_spills); return slot + stack_slots_for_vars; } }; diff --git a/test/offline/offline_test_main.cpp b/test/offline/offline_test_main.cpp index 673127a27a..dcdf1ad7f1 100644 --- a/test/offline/offline_test_main.cpp +++ b/test/offline/offline_test_main.cpp @@ -253,7 +253,7 @@ decompiler::ObjectFileData& get_data(Decompiler& dc, auto it = std::find_if(files.begin(), files.end(), [&](const decompiler::ObjectFileData& data) { return data.to_unique_name() == unique_name; }); - assert(it != files.end()); + ASSERT(it != files.end()); return *it; } diff --git a/test/test_common_util.cpp b/test/test_common_util.cpp index 94c8c2a62b..c65b9353b6 100644 --- a/test/test_common_util.cpp +++ b/test/test_common_util.cpp @@ -387,5 +387,8 @@ TEST(SmallVector, Construction) { EXPECT_FALSE(one.empty()); } +TEST(Assert, Death) { + EXPECT_DEATH(private_assert_failed("foo", "bar", 12, "aaa"), ""); +} } // namespace test } // namespace cu \ No newline at end of file diff --git a/tools/MemoryDumpTool/main.cpp b/tools/MemoryDumpTool/main.cpp index ddd6bec722..65a0179c86 100644 --- a/tools/MemoryDumpTool/main.cpp +++ b/tools/MemoryDumpTool/main.cpp @@ -11,7 +11,7 @@ #include "common/type_system/TypeSystem.h" #include "decompiler/util/DecompilerTypeSystem.h" -#include "common/util/assert.h" +#include "common/util/Assert.h" namespace fs = std::filesystem; @@ -23,7 +23,7 @@ struct Ram { template T read(u32 addr) const { - assert(in_memory(addr)); + ASSERT(in_memory(addr)); T result; memcpy(&result, data + addr, sizeof(T)); return result; @@ -41,7 +41,7 @@ struct Ram { std::string string(u32 addr) const { std::string result; while (true) { - assert(in_memory(addr)); + ASSERT(in_memory(addr)); auto next = read(addr++); if (next) { result.push_back(next); @@ -134,7 +134,7 @@ SymbolMap build_symbol_map(const Ram& ram, u32 s7) { if (str) { auto name = ram.string(str + 4); if (name != "asize-of-basic-func") { - assert(map.name_to_addr.find(name) == map.name_to_addr.end()); + ASSERT(map.name_to_addr.find(name) == map.name_to_addr.end()); map.name_to_addr[name] = sym; map.addr_to_name[sym] = name; map.name_to_value[name] = ram.word(sym); @@ -142,7 +142,7 @@ SymbolMap build_symbol_map(const Ram& ram, u32 s7) { } } - assert(map.name_to_addr.size() == map.addr_to_name.size()); + ASSERT(map.name_to_addr.size() == map.addr_to_name.size()); fmt::print("found {} symbols.\n", map.name_to_addr.size()); return map; } @@ -153,7 +153,7 @@ std::unordered_map build_type_map(const Ram& ram, std::unordered_map result; fmt::print("finding types...\n"); u32 type_of_type = ram.word(s7 + FIX_SYM_TYPE_TYPE); - assert(type_of_type == ram.word(symbols.name_to_addr.at("type"))); + ASSERT(type_of_type == ram.word(symbols.name_to_addr.at("type"))); for (const auto& [name, addr] : symbols.name_to_addr) { u32 value = ram.word(addr); @@ -588,7 +588,7 @@ int main(int argc, char** argv) { } else if (data.size() == 127 * one_mb) { fmt::print("Got a 127MB file. Assuming this is a dump with the first 1 MB missing.\n"); data.insert(data.begin(), one_mb, 0); - assert(data.size() == 128 * one_mb); + ASSERT(data.size() == 128 * one_mb); } else { fmt::print("Invalid size: {} bytes\n", data.size()); } diff --git a/tools/level_tools/level_dump/main.cpp b/tools/level_tools/level_dump/main.cpp index 93c56ededc..b40ba26d5f 100644 --- a/tools/level_tools/level_dump/main.cpp +++ b/tools/level_tools/level_dump/main.cpp @@ -7,7 +7,7 @@ #include "decompiler/util/goal_data_reader.h" #include "decompiler/level_extractor/BspHeader.h" -#include "common/util/assert.h" +#include "common/util/Assert.h" /*! * Get the level data from a DGO File. @@ -21,7 +21,7 @@ decompiler::LinkedObjectFile load_bsp_from_dgo(const std::string& file_name, auto dgo = DgoReader(short_name, dgo_file_data); auto entries = dgo.entries(); - assert(entries.size() > 0); + ASSERT(entries.size() > 0); const auto& level_file = entries.back();