From 9074a35b9b3ea6e6d8ca86efc4db48e903c3f612 Mon Sep 17 00:00:00 2001 From: water111 <48171810+water111@users.noreply.github.com> Date: Sun, 7 Mar 2021 12:01:59 -0500 Subject: [PATCH] [Decompiler] Fix printing of lets (#314) * fix let prints and windows warnings * missing include for windows * windows again --- common/goos/PrettyPrinter.cpp | 47 ++++++++-- common/goos/TextDB.cpp | 2 +- common/type_system/TypeFieldLookup.cpp | 1 + decompiler/Disasm/Instruction.cpp | 1 + decompiler/Disasm/InstructionParser.cpp | 2 + decompiler/Function/Warnings.h | 1 + decompiler/IR/BasicOpBuilder.cpp | 1 + decompiler/IR/IR.cpp | 4 + decompiler/IR2/AtomicOp.cpp | 8 ++ decompiler/IR2/AtomicOpForm.cpp | 1 + decompiler/IR2/AtomicOpTypeAnalysis.cpp | 2 + decompiler/IR2/Form.cpp | 7 ++ decompiler/IR2/GenericElementMatcher.cpp | 2 + decompiler/ObjectFile/LinkedWord.h | 1 + decompiler/data/LinkedWordReader.h | 2 + decompiler/util/DecompilerTypeSystem.cpp | 1 + decompiler/util/TP_Type.cpp | 3 + decompiler/util/TP_Type.h | 3 + game/kernel/kscheme.cpp | 2 + game/sce/sif_ee.cpp | 1 + goalc/compiler/Val.cpp | 2 +- goalc/compiler/Val.h | 4 +- .../compiler/compilation/CompilerControl.cpp | 3 +- goalc/compiler/compilation/Static.cpp | 2 + goalc/emitter/IGen.h | 12 +++ goalc/emitter/Instruction.h | 2 + goalc/emitter/Register.cpp | 1 + goalc/listener/Listener.cpp | 13 +-- goalc/listener/MemoryMap.cpp | 2 + goalc/regalloc/IRegister.cpp | 1 + test/decompiler/reference/gcommon_REF.gc | 93 +++++++------------ test/decompiler/reference/gstring-h_REF.gc | 6 ++ test/offline/offline_test_main.cpp | 11 ++- 33 files changed, 158 insertions(+), 86 deletions(-) create mode 100644 test/decompiler/reference/gstring-h_REF.gc diff --git a/common/goos/PrettyPrinter.cpp b/common/goos/PrettyPrinter.cpp index 7655208dfc..bb5f0bda46 100644 --- a/common/goos/PrettyPrinter.cpp +++ b/common/goos/PrettyPrinter.cpp @@ -489,6 +489,15 @@ const std::unordered_set control_flow_start_forms = { }; } +PrettyPrinterNode* seek_to_next_non_whitespace(PrettyPrinterNode* in) { + in = in->next; + while (in && (in->is_line_separator || + (in->tok && in->tok->kind == FormToken::TokenKind::WHITESPACE))) { + in = in->next; + } + return in; +} + void insertSpecialBreaks(NodePool& pool, PrettyPrinterNode* node) { for (; node; node = node->next) { if (!node->is_line_separator && node->tok->kind == FormToken::TokenKind::STRING) { @@ -502,15 +511,39 @@ void insertSpecialBreaks(NodePool& pool, PrettyPrinterNode* node) { if (name == "defun" || name == "defmethod" || name == "defun-debug" || name == "let" || name == "let*") { - auto* parent_type_dec = getNextListOnLine(node); - if (parent_type_dec) { - insertNewlineAfter(pool, parent_type_dec->paren, 0); - breakList(pool, node->paren, parent_type_dec); + auto* first_list = getNextListOnLine(node); + if (first_list) { + insertNewlineAfter(pool, first_list->paren, 0); + breakList(pool, node->paren, first_list); } - if ((name == "let" || name == "let*") && parent_type_dec) { - if (parent_type_dec->tok->kind == FormToken::TokenKind::OPEN_PAREN) { - breakList(pool, parent_type_dec); + if ((name == "let" || name == "let*") && first_list) { + if (first_list->tok->kind == FormToken::TokenKind::OPEN_PAREN) { + // we only want to break the variable list if it has multiple. + bool single_var = false; + // auto var_close_paren = first_list->paren; + auto first_var_open = seek_to_next_non_whitespace(first_list); + if (first_var_open->tok && + first_var_open->tok->kind == FormToken::TokenKind::OPEN_PAREN) { + auto var_close_paren = first_var_open->paren; + if (var_close_paren && var_close_paren->next) { + auto iter = var_close_paren->next; + while (iter && + (iter->is_line_separator || + (iter->tok && iter->tok->kind == FormToken::TokenKind::WHITESPACE))) { + iter = iter->next; + } + if (iter) { + if (iter->tok && iter->tok->kind == FormToken::TokenKind::CLOSE_PAREN) { + single_var = true; + } + } + } + } + + if (!single_var) { + breakList(pool, first_list); + } } auto open_paren = node->prev; if (open_paren && open_paren->tok->kind == FormToken::TokenKind::OPEN_PAREN) { diff --git a/common/goos/TextDB.cpp b/common/goos/TextDB.cpp index 0990dbd6bf..6a97c69606 100644 --- a/common/goos/TextDB.cpp +++ b/common/goos/TextDB.cpp @@ -73,7 +73,7 @@ std::pair SourceText::get_containing_line(int offset) { return std::make_pair(offset_by_line[line], offset_by_line[line + 1]); } } - return std::make_pair(0, text.size()); + return std::make_pair(0, (int)text.size()); } /*! diff --git a/common/type_system/TypeFieldLookup.cpp b/common/type_system/TypeFieldLookup.cpp index 43c78348b9..6e1cf4a369 100644 --- a/common/type_system/TypeFieldLookup.cpp +++ b/common/type_system/TypeFieldLookup.cpp @@ -44,6 +44,7 @@ std::string FieldReverseLookupOutput::Token::print() const { return "__VAR__"; default: assert(false); + return {}; } } diff --git a/decompiler/Disasm/Instruction.cpp b/decompiler/Disasm/Instruction.cpp index 4c27bd593a..05ed7514af 100644 --- a/decompiler/Disasm/Instruction.cpp +++ b/decompiler/Disasm/Instruction.cpp @@ -153,6 +153,7 @@ bool InstructionAtom::operator==(const InstructionAtom& other) const { return true; default: assert(false); + return false; } } diff --git a/decompiler/Disasm/InstructionParser.cpp b/decompiler/Disasm/InstructionParser.cpp index 6ba19bfe90..c8b9720934 100644 --- a/decompiler/Disasm/InstructionParser.cpp +++ b/decompiler/Disasm/InstructionParser.cpp @@ -92,6 +92,7 @@ std::string get_before_paren(std::string& instr) { } } assert(false); + return {}; } std::string get_in_paren(std::string& instr) { @@ -110,6 +111,7 @@ std::string get_in_paren(std::string& instr) { } } assert(false); + return {}; } bool is_integer(const std::string& str) { diff --git a/decompiler/Function/Warnings.h b/decompiler/Function/Warnings.h index b4eccf57ab..4d85a2a74b 100644 --- a/decompiler/Function/Warnings.h +++ b/decompiler/Function/Warnings.h @@ -80,6 +80,7 @@ class DecompWarnings { return fmt::format("INFO: {}\n", message); default: assert(false); + return {}; } } diff --git a/decompiler/IR/BasicOpBuilder.cpp b/decompiler/IR/BasicOpBuilder.cpp index 36f04fdef6..60369114e0 100644 --- a/decompiler/IR/BasicOpBuilder.cpp +++ b/decompiler/IR/BasicOpBuilder.cpp @@ -110,6 +110,7 @@ std::shared_ptr instr_atom_to_ir(const InstructionAtom& ia, int idx) { return make_int(ia.get_imm()); default: assert(false); + return nullptr; } } diff --git a/decompiler/IR/IR.cpp b/decompiler/IR/IR.cpp index ae12a58ba9..6b6175b8b9 100644 --- a/decompiler/IR/IR.cpp +++ b/decompiler/IR/IR.cpp @@ -614,6 +614,7 @@ goos::Object BranchDelay::to_form(const LinkedObjectFile& file) const { return pretty_print::build_list("unknown-branch-delay"); default: assert(false); + return {}; } } @@ -669,6 +670,7 @@ int Condition::num_args() const { return 0; default: assert(false); + return -1; } } @@ -867,6 +869,7 @@ goos::Object Condition::to_form(const LinkedObjectFile& file) const { return pretty_print::to_symbol(condtion_operator); } else { assert(false); + return {}; } } @@ -992,6 +995,7 @@ goos::Object IR_AsmReg::to_form(const LinkedObjectFile& file) const { return pretty_print::to_symbol("ACC"); default: assert(false); + return {}; } } diff --git a/decompiler/IR2/AtomicOp.cpp b/decompiler/IR2/AtomicOp.cpp index 0483f838de..ffdb7cd05f 100644 --- a/decompiler/IR2/AtomicOp.cpp +++ b/decompiler/IR2/AtomicOp.cpp @@ -41,6 +41,7 @@ goos::Object RegisterAccess::to_form(const Env& env, Print mode) const { } default: assert(false); + return {}; } } @@ -268,6 +269,7 @@ std::string get_simple_expression_op_name(SimpleExpression::Kind kind) { return "max.ui"; default: assert(false); + return {}; } } } // namespace @@ -317,6 +319,7 @@ int get_simple_expression_arg_count(SimpleExpression::Kind kind) { return 2; default: assert(false); + return -1; } } @@ -718,6 +721,7 @@ std::string get_condition_kind_name(IR2_Condition::Kind kind) { return ">=0.ui"; default: assert(false); + return ""; } } @@ -760,6 +764,7 @@ int get_condition_num_args(IR2_Condition::Kind kind) { return 0; default: assert(false); + return -1; } } @@ -831,6 +836,7 @@ IR2_Condition::Kind get_condition_opposite(IR2_Condition::Kind kind) { return IR2_Condition::Kind::LESS_THAN_ZERO_UNSIGNED; default: assert(false); + return IR2_Condition::Kind::INVALID; } } @@ -1177,6 +1183,7 @@ goos::Object IR2_BranchDelay::to_form(const std::vector& labels return pretty_print::build_list("unknown-branch-delay!"); default: assert(false); + return {}; } } @@ -1375,6 +1382,7 @@ goos::Object SpecialOp::to_form(const std::vector& labels, cons return pretty_print::build_list("suspend"); default: assert(false); + return {}; } } diff --git a/decompiler/IR2/AtomicOpForm.cpp b/decompiler/IR2/AtomicOpForm.cpp index 75ee812fee..1ff9aceebf 100644 --- a/decompiler/IR2/AtomicOpForm.cpp +++ b/decompiler/IR2/AtomicOpForm.cpp @@ -15,6 +15,7 @@ RegClass get_reg_kind(const Register& r) { return RegClass::FLOAT; default: assert(false); + return RegClass::INVALID; } } } // namespace diff --git a/decompiler/IR2/AtomicOpTypeAnalysis.cpp b/decompiler/IR2/AtomicOpTypeAnalysis.cpp index 60f8bd154e..d73a3aeb31 100644 --- a/decompiler/IR2/AtomicOpTypeAnalysis.cpp +++ b/decompiler/IR2/AtomicOpTypeAnalysis.cpp @@ -27,6 +27,7 @@ RegClass get_reg_kind(const Register& r) { return RegClass::FLOAT; default: assert(false); + return RegClass::INVALID; } } @@ -758,6 +759,7 @@ TypeState SpecialOp::propagate_types_internal(const TypeState& input, return input; default: assert(false); + return input; } } diff --git a/decompiler/IR2/Form.cpp b/decompiler/IR2/Form.cpp index 97b1a04342..1fd9e0c54f 100644 --- a/decompiler/IR2/Form.cpp +++ b/decompiler/IR2/Form.cpp @@ -212,6 +212,7 @@ goos::Object LoadSourceElement::to_form_internal(const Env& env) const { return pretty_print::build_list("l.d", m_addr->to_form(env)); default: assert(false); + return {}; } break; case LoadVarOp::Kind::SIGNED: @@ -224,10 +225,12 @@ goos::Object LoadSourceElement::to_form_internal(const Env& env) const { return pretty_print::build_list("l.w", m_addr->to_form(env)); default: assert(false); + return {}; } break; default: assert(false); + return {}; } } @@ -1327,6 +1330,7 @@ goos::Object GenericOperator::to_form(const Env& env) const { return m_function->to_form(env); default: assert(false); + return {}; } } @@ -1369,6 +1373,7 @@ bool GenericOperator::operator==(const GenericOperator& other) const { return false; default: assert(false); + return false; } } @@ -1473,6 +1478,7 @@ std::string fixed_operator_to_string(FixedOperatorKind kind) { return "pair?"; default: assert(false); + return ""; } } @@ -1650,6 +1656,7 @@ goos::Object DerefToken::to_form(const Env& env) const { return pretty_print::to_symbol("PLACEHOLDER"); default: assert(false); + return {}; } } diff --git a/decompiler/IR2/GenericElementMatcher.cpp b/decompiler/IR2/GenericElementMatcher.cpp index 073cec67de..2f1d8ded46 100644 --- a/decompiler/IR2/GenericElementMatcher.cpp +++ b/decompiler/IR2/GenericElementMatcher.cpp @@ -500,6 +500,7 @@ bool DerefTokenMatcher::do_match(const DerefToken& input, MatchResult::Maps* map return false; default: assert(false); + return false; } } @@ -543,6 +544,7 @@ bool GenericOpMatcher::do_match(GenericOperator& input, MatchResult::Maps* maps_ return false; default: assert(false); + return false; } } diff --git a/decompiler/ObjectFile/LinkedWord.h b/decompiler/ObjectFile/LinkedWord.h index 744fa3dd2f..33b5a97480 100644 --- a/decompiler/ObjectFile/LinkedWord.h +++ b/decompiler/ObjectFile/LinkedWord.h @@ -45,6 +45,7 @@ class LinkedWord { return (data >> 24) & 0xff; default: assert(false); + return 0; } } }; diff --git a/decompiler/data/LinkedWordReader.h b/decompiler/data/LinkedWordReader.h index 6916617633..161757048e 100644 --- a/decompiler/data/LinkedWordReader.h +++ b/decompiler/data/LinkedWordReader.h @@ -3,6 +3,7 @@ #include #include #include +#include #include "common/common_types.h" #include "decompiler/ObjectFile/LinkedWord.h" @@ -17,6 +18,7 @@ class LinkedWordReader { return result; } else { assert(false); + throw std::runtime_error("LinkedWordReader::get_type_tag failed"); } } diff --git a/decompiler/util/DecompilerTypeSystem.cpp b/decompiler/util/DecompilerTypeSystem.cpp index 7be4bc9393..c9818af3f5 100644 --- a/decompiler/util/DecompilerTypeSystem.cpp +++ b/decompiler/util/DecompilerTypeSystem.cpp @@ -295,6 +295,7 @@ TP_Type DecompilerTypeSystem::tp_lca(const TP_Type& existing, case TP_Type::Kind::INVALID: default: assert(false); + return {}; } } else { // trying to combine two of different types. diff --git a/decompiler/util/TP_Type.cpp b/decompiler/util/TP_Type.cpp index 8f6b286277..0d579086e0 100644 --- a/decompiler/util/TP_Type.cpp +++ b/decompiler/util/TP_Type.cpp @@ -62,6 +62,7 @@ std::string TP_Type::print() const { case Kind::INVALID: default: assert(false); + return {}; } } @@ -107,6 +108,7 @@ bool TP_Type::operator==(const TP_Type& other) const { case Kind::INVALID: default: assert(false); + return false; } } @@ -155,6 +157,7 @@ TypeSpec TP_Type::typespec() const { case Kind::INVALID: default: assert(false); + return {}; } } } // namespace decompiler \ No newline at end of file diff --git a/decompiler/util/TP_Type.h b/decompiler/util/TP_Type.h index 6912774ee7..a1764aff71 100644 --- a/decompiler/util/TP_Type.h +++ b/decompiler/util/TP_Type.h @@ -1,6 +1,7 @@ #pragma once #include #include +#include #include "common/log/log.h" #include "common/type_system/TypeSpec.h" #include "common/common_types.h" @@ -239,6 +240,7 @@ struct TypeState { return fpr_types[r.get_fpr()]; default: assert(false); + throw std::runtime_error("TP_Type::get failed"); } } @@ -251,6 +253,7 @@ struct TypeState { default: lg::die("Cannot use register {} with TypeState.", r.to_charp()); assert(false); + throw std::runtime_error("TP_Type::get failed"); } } }; diff --git a/game/kernel/kscheme.cpp b/game/kernel/kscheme.cpp index 3e2d0106fd..513ecdfd07 100644 --- a/game/kernel/kscheme.cpp +++ b/game/kernel/kscheme.cpp @@ -165,6 +165,7 @@ u64 alloc_from_heap(u32 heapSymbol, u32 type, s32 size) { return kmalloc(*Ptr>(heapSymbol), size, KMALLOC_MEMSET, gstr->data()).offset; } else if (heapOffset == FIX_SYM_PROCESS_TYPE) { assert(false); // nyi + return 0; // allocate on current process heap // Ptr start = *ptr(getS6() + 0x4c + 8); // Ptr heapEnd = *ptr(getS6() + 0x4c + 4); @@ -181,6 +182,7 @@ u64 alloc_from_heap(u32 heapSymbol, u32 type, s32 size) { // } } else if (heapOffset == FIX_SYM_SCRATCH) { assert(false); // nyi, I think unused. + return 0; } else { memset(Ptr(heapSymbol).c(), 0, (size_t)alignedSize); // treat it as a stack address return heapSymbol; diff --git a/game/sce/sif_ee.cpp b/game/sce/sif_ee.cpp index b9e93571b5..b78b46ac30 100644 --- a/game/sce/sif_ee.cpp +++ b/game/sce/sif_ee.cpp @@ -173,6 +173,7 @@ s32 sceLseek(s32 fd, s32 offset, s32 where) { return ftell(kv->second); default: assert(false); + return -1; } } } diff --git a/goalc/compiler/Val.cpp b/goalc/compiler/Val.cpp index 4175b3a52c..96ed462af4 100644 --- a/goalc/compiler/Val.cpp +++ b/goalc/compiler/Val.cpp @@ -154,7 +154,7 @@ RegVal* MemoryDerefVal::to_reg(Env* fe) { if (base_as_co) { s64 offset; auto final_base = get_constant_offset_and_base(base_as_co, &offset); - fe->emit_ir(re, offset, final_base->to_gpr(fe), info); + fe->emit_ir(re, (int)offset, final_base->to_gpr(fe), info); } else { auto addr = base->to_gpr(fe); fe->emit(std::make_unique(re, 0, addr, info)); diff --git a/goalc/compiler/Val.h b/goalc/compiler/Val.h index a968befcfd..5e27b9cea3 100644 --- a/goalc/compiler/Val.h +++ b/goalc/compiler/Val.h @@ -181,14 +181,14 @@ class StackVarAddrVal : public Val { class MemoryOffsetConstantVal : public Val { public: - MemoryOffsetConstantVal(TypeSpec ts, Val* _base, int _offset) + MemoryOffsetConstantVal(TypeSpec ts, Val* _base, s64 _offset) : Val(std::move(ts)), base(_base), offset(_offset) {} std::string print() const override { return "(" + base->print() + " + " + std::to_string(offset) + ")"; } RegVal* to_reg(Env* fe) override; Val* base = nullptr; - int offset = 0; + s64 offset = 0; }; class MemoryOffsetVal : public Val { diff --git a/goalc/compiler/compilation/CompilerControl.cpp b/goalc/compiler/compilation/CompilerControl.cpp index ae70d78d09..dd0ff255b7 100644 --- a/goalc/compiler/compilation/CompilerControl.cpp +++ b/goalc/compiler/compilation/CompilerControl.cpp @@ -83,7 +83,7 @@ Val* Compiler::compile_asm_file(const goos::Object& form, const goos::Object& re bool no_code = false; bool disassemble = false; - std::vector> timing; + std::vector> timing; Timer total_timer; // parse arguments @@ -422,6 +422,7 @@ std::string Compiler::make_symbol_info_description(const SymbolInfo& info) { m_goos.reader.db.get_info_for(info.src_form())); default: assert(false); + return {}; } } diff --git a/goalc/compiler/compilation/Static.cpp b/goalc/compiler/compilation/Static.cpp index edf94236a2..a732ad8b43 100644 --- a/goalc/compiler/compilation/Static.cpp +++ b/goalc/compiler/compilation/Static.cpp @@ -33,6 +33,7 @@ bool integer_fits(s64 in, int size, bool is_signed) { return true; default: assert(false); + return false; } } @@ -415,6 +416,7 @@ StaticResult Compiler::compile_static_no_eval_for_pairs(const goos::Object& form return result; } else { assert(false); // not yet implemented + return {}; } } diff --git a/goalc/emitter/IGen.h b/goalc/emitter/IGen.h index 5bc4eef08b..9c4520d854 100644 --- a/goalc/emitter/IGen.h +++ b/goalc/emitter/IGen.h @@ -714,6 +714,7 @@ class IGen { return storevf_gpr64_plus_gpr64_plus_s32(value, addr, off, offset); } assert(false); + return {0}; } static Instruction store_goal_gpr(Register addr, @@ -764,6 +765,7 @@ class IGen { } default: assert(false); + return {0}; } } @@ -776,6 +778,7 @@ class IGen { return loadvf_gpr64_plus_gpr64_plus_s32(dst, addr, off, offset); } else { assert(false); + return {0}; } } @@ -871,6 +874,7 @@ class IGen { } default: assert(false); + return {0}; } } @@ -993,6 +997,7 @@ class IGen { return lea_reg_plus_off32(dest, base, offset); } else { assert(false); + return {0}; } } @@ -1076,6 +1081,7 @@ class IGen { return load32_xmm32_gpr64_plus_gpr64_plus_s32(xmm_dest, addr, off, offset); } else { assert(false); + return {0}; } } @@ -1088,6 +1094,7 @@ class IGen { return store32_xmm32_gpr64_plus_gpr64_plus_s32(addr, off, xmm_value, offset); } else { assert(false); + return {0}; } } @@ -1100,6 +1107,7 @@ class IGen { return store32_xmm32_gpr64_plus_s32(base, xmm_value, offset); } else { assert(false); + return {0}; } } @@ -1112,6 +1120,7 @@ class IGen { return load32_xmm32_gpr64_plus_s32(xmm_dest, base, offset); } else { assert(false); + return {0}; } } @@ -1211,6 +1220,7 @@ class IGen { return load128_xmm128_gpr64_s32(xmm_dest, base, offset); } else { assert(false); + return {0}; } } @@ -1223,6 +1233,7 @@ class IGen { return store128_gpr64_xmm128_s32(base, xmm_val, offset); } else { assert(false); + return {0}; } } @@ -2266,6 +2277,7 @@ class IGen { break; default: assert(false); + return {0}; } } diff --git a/goalc/emitter/Instruction.h b/goalc/emitter/Instruction.h index 3e4ec0b58e..9688d8ad4d 100644 --- a/goalc/emitter/Instruction.h +++ b/goalc/emitter/Instruction.h @@ -85,6 +85,7 @@ struct VEX3 { return result; } else { assert(false); + return -1; } } @@ -124,6 +125,7 @@ struct VEX2 { return result; } else { assert(false); + return -1; } } diff --git a/goalc/emitter/Register.cpp b/goalc/emitter/Register.cpp index a342f70da6..e6a6760d1e 100644 --- a/goalc/emitter/Register.cpp +++ b/goalc/emitter/Register.cpp @@ -91,6 +91,7 @@ HWRegKind reg_class_to_hw(RegClass reg_class) { return HWRegKind::GPR; default: assert(false); + return HWRegKind::INVALID; } } diff --git a/goalc/listener/Listener.cpp b/goalc/listener/Listener.cpp index 7aba60af0e..ce5761a502 100644 --- a/goalc/listener/Listener.cpp +++ b/goalc/listener/Listener.cpp @@ -1,8 +1,6 @@ /*! * @file Listener.cpp * The Listener can connect to a Deci2Server for debugging. - * - * TODO - msg ID? */ #ifdef __linux__ @@ -20,7 +18,6 @@ #undef max #endif -// TODO - i think im not including the dependency right..? #include "common/cross_sockets/xsocket.h" #include @@ -224,8 +221,8 @@ void Listener::receive_func() { if (hdr->msg_id == last_sent_id) { printf("[Listener] Received ACK for most recent message late.\n"); if (last_recvd_id != hdr->msg_id - 1) { - printf( - "[Listener] WARNING: message ID jumped from %ld to %ld. Some messages may have " + fmt::print( + "[Listener] WARNING: message ID jumped from {} to {}. Some messages may have " "been lost. You must wait for an ACK before sending the next message.\n", last_recvd_id, hdr->msg_id); } @@ -251,9 +248,9 @@ void Listener::receive_func() { got_ack = true; last_recvd_id = hdr->msg_id; if (last_recvd_id > last_sent_id) { - printf( - "[Listener] ERROR: Got an ack message with id of %ld, but the last message sent " - "had an ID of %ld.\n", + fmt::print( + "[Listener] ERROR: Got an ack message with id of {}, but the last message sent " + "had an ID of {}.\n", last_recvd_id, last_sent_id); } } else { diff --git a/goalc/listener/MemoryMap.cpp b/goalc/listener/MemoryMap.cpp index b620f0b263..4ca79bf789 100644 --- a/goalc/listener/MemoryMap.cpp +++ b/goalc/listener/MemoryMap.cpp @@ -1,5 +1,6 @@ #include #include +#include #include "MemoryMap.h" #include "third-party/fmt/core.h" #include "common/link_types.h" @@ -114,6 +115,7 @@ const MemoryMapEntry& MemoryMap::lookup(u32 addr) { } } assert(false); + throw std::runtime_error("MemoryMap::lookup failed"); } bool MemoryMap::lookup(const std::string& obj_name, u8 seg_id, MemoryMapEntry* out) { diff --git a/goalc/regalloc/IRegister.cpp b/goalc/regalloc/IRegister.cpp index b25efa39c2..a0990d996f 100644 --- a/goalc/regalloc/IRegister.cpp +++ b/goalc/regalloc/IRegister.cpp @@ -22,6 +22,7 @@ std::string IRegister::to_string() const { return fmt::format("ivf-{}", id); default: assert(false); + return {}; } } diff --git a/test/decompiler/reference/gcommon_REF.gc b/test/decompiler/reference/gcommon_REF.gc index 7e4bd43a73..8c46374670 100644 --- a/test/decompiler/reference/gcommon_REF.gc +++ b/test/decompiler/reference/gcommon_REF.gc @@ -188,13 +188,11 @@ (a1-0 "#") ) (.sllv a2-0 gp-0 r0-0) - (let ((a3-0 (sar gp-0 32)) - ) + (let ((a3-0 (sar gp-0 32))) (.pcpyud v1-0 gp-0 r0-0) (.sllv t0-0 v1-0 r0-0) (.pcpyud v1-1 gp-0 r0-0) - (let ((t1-0 (sar v1-1 32)) - ) + (let ((t1-0 (sar v1-1 32))) (.por t2-0 gp-0 r0-0) (t9-0 a0-1 a1-0 a2-0 a3-0 t0-0 t1-0 t2-0) ) @@ -248,8 +246,7 @@ ;; definition for function type-type? (defun type-type? ((child-type type) (parent-type type)) - (let ((end-type object) - ) + (let ((end-type object)) (until (begin (set! child-type (-> child-type parent)) @@ -266,8 +263,7 @@ ;; definition for function find-parent-method (defun find-parent-method ((child-type type) (method-id int)) (local-vars (current-method function)) - (let ((original-method (-> child-type method-table method-id)) - ) + (let ((original-method (-> child-type method-table method-id))) (until (!= current-method original-method) (if (= child-type object) (return nothing) @@ -300,8 +296,7 @@ (set! result 0) ) (else - (let ((iter (cdr obj)) - ) + (let ((iter (cdr obj))) (set! result 1) (while (and (not (null? iter)) (pair? iter)) (+! result 1) @@ -321,8 +316,7 @@ ;; definition for function last (defun last ((lst object)) - (let ((iter lst) - ) + (let ((iter lst)) (while (not (null? (cdr iter))) (nop!) (nop!) @@ -334,8 +328,7 @@ ;; definition for function member (defun member ((obj object) (lst object)) - (let ((iter lst) - ) + (let ((iter lst)) (while (not (or (null? iter) (= (car iter) obj))) (set! iter (cdr iter)) ) @@ -357,8 +350,7 @@ ;; definition for function assoc (defun assoc ((item object) (alist object)) - (let ((iter alist) - ) + (let ((iter alist)) (while (not (or (null? iter) (= (car (car iter)) item))) (set! iter (cdr iter)) ) @@ -370,8 +362,7 @@ ;; definition for function assoce (defun assoce ((item object) (alist object)) - (let ((iter alist) - ) + (let ((iter alist)) (while (not (or (null? iter) (= (car (car iter)) item) (= (car (car iter)) 'else))) (set! iter (cdr iter)) @@ -384,8 +375,7 @@ ;; definition for function nassoc (defun nassoc ((item-name string) (alist object)) - (while (not (or (null? alist) (let ((key (car (car alist))) - ) + (while (not (or (null? alist) (let ((key (car (car alist)))) (if (pair? key) (nmember item-name key) (name= (the-as basic key) item-name) @@ -402,8 +392,7 @@ ;; definition for function nassoce (defun nassoce ((item-name string) (alist object)) - (while (not (or (null? alist) (let ((key (car (car alist))) - ) + (while (not (or (null? alist) (let ((key (car (car alist)))) (if (pair? key) (nmember item-name key) (or @@ -428,8 +417,7 @@ back ) (else - (let ((iter front) - ) + (let ((iter front)) (while (not (null? (cdr iter))) (nop!) (nop!) @@ -494,20 +482,17 @@ ;; definition for function insert-cons! (defun insert-cons! ((kv object) (alist object)) - (let ((updated-list (delete-car! (car kv) alist)) - ) + (let ((updated-list (delete-car! (car kv) alist))) (cons kv updated-list) ) ) ;; definition for function sort (defun sort ((lst object) (compare-func (function object object object))) - (let ((unsorted-count -1) - ) + (let ((unsorted-count -1)) (while (nonzero? unsorted-count) (set! unsorted-count 0) - (let ((iter lst) - ) + (let ((iter lst)) (while (not (or (null? (cdr iter)) (not (pair? (cdr iter))))) (let* ((first-elt (car iter)) (seoncd-elt (car (cdr iter))) @@ -640,8 +625,7 @@ (local-vars (a2-8 int)) (format #t "#(") (if (type-type? (-> obj content-type) integer) - (let ((content-type-sym (-> obj content-type symbol)) - ) + (let ((content-type-sym (-> obj content-type symbol))) (cond ((= content-type-sym 'int32) (dotimes (s5-0 (-> obj length)) @@ -736,8 +720,7 @@ ) ) (let - ((v1-42 (+ (shl s5-8 4) (the-as int (the-as (array uint128) obj)))) - ) + ((v1-42 (+ (shl s5-8 4) (the-as int (the-as (array uint128) obj))))) (TODO.LQ a2-8 v1-42 :offset 12) ) (t9-10 a0-21 a1-11 a2-8) @@ -791,8 +774,7 @@ (format #t "~Tcontent-type: ~A~%" (-> obj content-type)) (format #t "~Tdata[~D]: @ #x~X~%" (-> obj allocated-length) (-> obj data)) (if (type-type? (-> obj content-type) integer) - (let ((content-type-sym (-> obj content-type symbol)) - ) + (let ((content-type-sym (-> obj content-type symbol))) (cond ((= content-type-sym 'int32) (dotimes (s5-0 (-> obj length)) @@ -843,8 +825,7 @@ (a1-15 "~T [~D] #x~X~%") (a2-13 s5-8) ) - (let ((v1-42 (+ (shl s5-8 4) (the-as int obj))) - ) + (let ((v1-42 (+ (shl s5-8 4) (the-as int obj)))) (TODO.LQ a3-10 v1-42 :offset 12) ) (t9-14 a0-25 a1-15 a2-13 a3-10) @@ -902,8 +883,7 @@ ;; definition for function mem-copy! (defun mem-copy! ((dst pointer) (src pointer) (size int)) - (let ((result dst) - ) + (let ((result dst)) (dotimes (i size) (set! (-> (the-as (pointer uint8) dst)) (-> (the-as (pointer uint8) src))) (&+! dst 1) @@ -918,10 +898,8 @@ ;; WARN: Inline assembly instruction marked with TODO - [TODO.SQ] (defun qmem-copy<-! ((dst pointer) (src pointer) (size int)) (local-vars (value int)) - (let ((result dst) - ) - (let ((qwc (sar (+ size 15) 4)) - ) + (let ((result dst)) + (let ((qwc (sar (+ size 15) 4))) (while (nonzero? qwc) (+! qwc -1) (TODO.LQ value src) @@ -939,10 +917,8 @@ ;; WARN: Inline assembly instruction marked with TODO - [TODO.SQ] (defun qmem-copy->! ((dst pointer) (src pointer) (size int)) (local-vars (src-ptr pointer) (dst-ptr pointer) (value int)) - (let ((result dst) - ) - (let ((qwc (sar (+ size 15) 4)) - ) + (let ((result dst)) + (let ((qwc (sar (+ size 15) 4))) (&+! dst (shl qwc 4)) (&+! src (shl qwc 4)) (while (nonzero? qwc) @@ -959,8 +935,7 @@ ;; definition for function mem-set32! (defun mem-set32! ((dst pointer) (size int) (value int)) - (let ((result dst) - ) + (let ((result dst)) (dotimes (i size) (set! (-> (the-as (pointer int32) dst)) value) (&+! dst 4) @@ -972,8 +947,7 @@ ;; definition for function mem-or! (defun mem-or! ((dst pointer) (src pointer) (size int)) - (let ((result dst) - ) + (let ((result dst)) (dotimes (i size) (set! (-> (the-as (pointer uint8) dst)) @@ -1010,8 +984,7 @@ ;; definition for function printl (defun printl ((arg0 object)) - (let ((a0-1 arg0) - ) + (let ((a0-1 arg0)) ((method-of-type (rtype-of a0-1) print) a0-1) ) (format #t "~%") @@ -1138,8 +1111,7 @@ ) #f ) - ((or (not in-goal-mem) (begin (let ((v1-10 #x8000) - ) + ((or (not in-goal-mem) (begin (let ((v1-10 #x8000)) (.daddu v1-11 v1-10 s7-0) ) (< (the-as uint obj) (the-as uint v1-11)) @@ -1289,8 +1261,7 @@ #f ) ((= expected-type symbol) - (let ((v1-43 #x8000) - ) + (let ((v1-43 #x8000)) (.daddu v1-44 v1-43 s7-0) ) (cond @@ -1312,8 +1283,7 @@ ) ) ) - ((begin (let ((v1-47 #x8000) - ) + ((begin (let ((v1-47 #x8000)) (.daddu v1-48 v1-47 s7-0) ) (< (the-as uint obj) (the-as uint v1-48)) @@ -1342,6 +1312,5 @@ ) ;; failed to figure out what this is: -(let ((v0-3 0) - ) +(let ((v0-3 0)) ) \ No newline at end of file diff --git a/test/decompiler/reference/gstring-h_REF.gc b/test/decompiler/reference/gstring-h_REF.gc new file mode 100644 index 0000000000..d92736d4cf --- /dev/null +++ b/test/decompiler/reference/gstring-h_REF.gc @@ -0,0 +1,6 @@ +;;-*-Lisp-*- +(in-package goal) + +;; failed to figure out what this is: +(let ((v0-0 0)) + ) diff --git a/test/offline/offline_test_main.cpp b/test/offline/offline_test_main.cpp index 2c6d1f2a0f..a63a325e01 100644 --- a/test/offline/offline_test_main.cpp +++ b/test/offline/offline_test_main.cpp @@ -9,12 +9,15 @@ namespace { // the object files to test -const std::unordered_set g_object_files_to_decompile = {"gcommon"}; +const std::unordered_set g_object_files_to_decompile = { + "gcommon", + "gstring-h", +}; // the object files to check against a reference in test/decompiler/reference -const std::unordered_set g_object_files_to_check_against_reference = { - "gcommon" // NOTE: this file needs work, but adding it for now just to test the framework. -}; +const std::vector g_object_files_to_check_against_reference = { + "gcommon", // NOTE: this file needs work, but adding it for now just to test the framework. + "gstring-h"}; // the functions we expect the decompiler to skip const std::unordered_set expected_skip_in_decompiler = {