From 5a005e06314beac879bac3a2ed6974fd162e205c Mon Sep 17 00:00:00 2001 From: ManDude <7569514+ManDude@users.noreply.github.com> Date: Sat, 9 Jan 2021 05:58:52 +0000 Subject: [PATCH] debugger: use enum class for InstructionInfo::Kind --- goalc/compiler/CodeGenerator.cpp | 31 ++++++++++++++++--------------- goalc/debugger/disassemble.cpp | 2 +- goalc/debugger/disassemble.h | 2 +- 3 files changed, 18 insertions(+), 17 deletions(-) diff --git a/goalc/compiler/CodeGenerator.cpp b/goalc/compiler/CodeGenerator.cpp index c25b5a0b42..d39b775066 100644 --- a/goalc/compiler/CodeGenerator.cpp +++ b/goalc/compiler/CodeGenerator.cpp @@ -89,14 +89,14 @@ void CodeGenerator::do_goal_function(FunctionEnv* env, int f_idx) { // offset the stack stack_offset += xmm_backup_stack_offset; m_gen.add_instr_no_ir(f_rec, IGen::sub_gpr64_imm(RSP, xmm_backup_stack_offset), - InstructionInfo::PROLOGUE); + InstructionInfo::Kind::PROLOGUE); // back up xmms int i = 0; for (auto& saved_reg : allocs.used_saved_regs) { if (saved_reg.is_xmm()) { int offset = i * XMM_SIZE; m_gen.add_instr_no_ir(f_rec, IGen::store128_xmm128_reg_offset(RSP, saved_reg, offset), - InstructionInfo::PROLOGUE); + InstructionInfo::Kind::PROLOGUE); i++; } } @@ -106,9 +106,9 @@ void CodeGenerator::do_goal_function(FunctionEnv* env, int f_idx) { for (auto& saved_reg : allocs.used_saved_regs) { if (saved_reg.is_xmm()) { m_gen.add_instr_no_ir(f_rec, IGen::sub_gpr64_imm8s(RSP, XMM_SIZE), - InstructionInfo::PROLOGUE); + InstructionInfo::Kind::PROLOGUE); m_gen.add_instr_no_ir(f_rec, IGen::store128_gpr64_xmm128(RSP, saved_reg), - InstructionInfo::PROLOGUE); + InstructionInfo::Kind::PROLOGUE); stack_offset += XMM_SIZE; } } @@ -117,7 +117,7 @@ void CodeGenerator::do_goal_function(FunctionEnv* env, int f_idx) { // back up gprs for (auto& saved_reg : allocs.used_saved_regs) { if (saved_reg.is_gpr()) { - m_gen.add_instr_no_ir(f_rec, IGen::push_gpr64(saved_reg), InstructionInfo::PROLOGUE); + m_gen.add_instr_no_ir(f_rec, IGen::push_gpr64(saved_reg), InstructionInfo::Kind::PROLOGUE); stack_offset += GPR_SIZE; } } @@ -141,7 +141,7 @@ void CodeGenerator::do_goal_function(FunctionEnv* env, int f_idx) { // otherwise to an extra push, and remember so we can do an extra pop later on. bonus_push = true; m_gen.add_instr_no_ir(f_rec, IGen::push_gpr64(ri.get_saved_gpr(0)), - InstructionInfo::PROLOGUE); + InstructionInfo::Kind::PROLOGUE); } stack_offset += 8; } @@ -151,7 +151,7 @@ void CodeGenerator::do_goal_function(FunctionEnv* env, int f_idx) { // do manual stack offset. if (manually_added_stack_offset) { m_gen.add_instr_no_ir(f_rec, IGen::sub_gpr64_imm(RSP, manually_added_stack_offset), - InstructionInfo::PROLOGUE); + InstructionInfo::Kind::PROLOGUE); } } @@ -209,19 +209,20 @@ void CodeGenerator::do_goal_function(FunctionEnv* env, int f_idx) { env->needs_aligned_stack()) { if (manually_added_stack_offset) { m_gen.add_instr_no_ir(f_rec, IGen::add_gpr64_imm(RSP, manually_added_stack_offset), - InstructionInfo::EPILOGUE); + InstructionInfo::Kind::EPILOGUE); } if (bonus_push) { assert(!manually_added_stack_offset); - m_gen.add_instr_no_ir(f_rec, IGen::pop_gpr64(ri.get_saved_gpr(0)), InstructionInfo::EPILOGUE); + m_gen.add_instr_no_ir(f_rec, IGen::pop_gpr64(ri.get_saved_gpr(0)), + InstructionInfo::Kind::EPILOGUE); } } for (int i = int(allocs.used_saved_regs.size()); i-- > 0;) { auto& saved_reg = allocs.used_saved_regs.at(i); if (saved_reg.is_gpr()) { - m_gen.add_instr_no_ir(f_rec, IGen::pop_gpr64(saved_reg), InstructionInfo::EPILOGUE); + m_gen.add_instr_no_ir(f_rec, IGen::pop_gpr64(saved_reg), InstructionInfo::Kind::EPILOGUE); } } @@ -234,26 +235,26 @@ void CodeGenerator::do_goal_function(FunctionEnv* env, int f_idx) { j--; int offset = j * XMM_SIZE; m_gen.add_instr_no_ir(f_rec, IGen::load128_xmm128_reg_offset(saved_reg, RSP, offset), - InstructionInfo::EPILOGUE); + InstructionInfo::Kind::EPILOGUE); } } assert(j == 0); m_gen.add_instr_no_ir(f_rec, IGen::add_gpr64_imm(RSP, xmm_backup_stack_offset), - InstructionInfo::EPILOGUE); + InstructionInfo::Kind::EPILOGUE); } } else { for (int i = int(allocs.used_saved_regs.size()); i-- > 0;) { auto& saved_reg = allocs.used_saved_regs.at(i); if (saved_reg.is_xmm()) { m_gen.add_instr_no_ir(f_rec, IGen::load128_xmm128_gpr64(saved_reg, RSP), - InstructionInfo::EPILOGUE); + InstructionInfo::Kind::EPILOGUE); m_gen.add_instr_no_ir(f_rec, IGen::add_gpr64_imm8s(RSP, XMM_SIZE), - InstructionInfo::EPILOGUE); + InstructionInfo::Kind::EPILOGUE); } } } - m_gen.add_instr_no_ir(f_rec, IGen::ret(), InstructionInfo::EPILOGUE); + m_gen.add_instr_no_ir(f_rec, IGen::ret(), InstructionInfo::Kind::EPILOGUE); } void CodeGenerator::do_asm_function(FunctionEnv* env, int f_idx, bool allow_saved_regs) { diff --git a/goalc/debugger/disassemble.cpp b/goalc/debugger/disassemble.cpp index 6e1b63c27f..777f53ee29 100644 --- a/goalc/debugger/disassemble.cpp +++ b/goalc/debugger/disassemble.cpp @@ -113,7 +113,7 @@ std::string disassemble_x86_function(u8* data, if (current_instruction_idx >= 0 && current_instruction_idx < int(x86_instructions.size())) { const auto& debug_instr = x86_instructions.at(current_instruction_idx); - if (debug_instr.kind == InstructionInfo::IR && debug_instr.ir_idx != current_ir_idx) { + if (debug_instr.kind == InstructionInfo::Kind::IR && debug_instr.ir_idx != current_ir_idx) { current_ir_idx = debug_instr.ir_idx; print_ir = true; } diff --git a/goalc/debugger/disassemble.h b/goalc/debugger/disassemble.h index 86da2dc301..d03c5a81b8 100644 --- a/goalc/debugger/disassemble.h +++ b/goalc/debugger/disassemble.h @@ -7,7 +7,7 @@ struct InstructionInfo { emitter::Instruction instruction; //! the actual x86 instruction - enum Kind { PROLOGUE, IR, EPILOGUE } kind; + enum class Kind { PROLOGUE, IR, EPILOGUE } kind; int ir_idx = -1; int offset = -1;