diff --git a/include/optimizer.hpp b/include/optimizer.hpp index 6fce98b..c027b9e 100644 --- a/include/optimizer.hpp +++ b/include/optimizer.hpp @@ -64,6 +64,10 @@ bool optimize(std::vector &instructions, const Personality &personality // someone just loaded lda with a different value, so we need to abort! break; } + // abort at pla + if (instructions[next_op].opcode == mos6502::OpCode::pla) { break; } + // abort at jsr + if (instructions[next_op].opcode == mos6502::OpCode::jsr) { break; } // abort at label if (instructions[next_op].type == ASMLine::Type::Label) { break; } @@ -141,7 +145,8 @@ bool optimize(std::vector &instructions, const Personality &personality if (instructions[op].opcode == mos6502::OpCode::ldy && instructions[op].op.type == Operand::Type::literal) { auto op2 = op + 1; - while (op2 < instructions.size() && (instructions[op2].type != ASMLine::Type::Label)) { + while (op2 < instructions.size() && (instructions[op2].type != ASMLine::Type::Label) + && (instructions[op2].opcode == mos6502::OpCode::jsr)) { // while inside this label if (instructions[op2].opcode == mos6502::OpCode::ldy) { @@ -163,7 +168,7 @@ bool optimize(std::vector &instructions, const Personality &personality for (size_t op = 0; op < instructions.size() - 1; ++op) { if (instructions[op].opcode == mos6502::OpCode::lda && instructions[op].op.type == Operand::Type::literal) { const auto operand = instructions[op].op; - auto op2 = op + 1; + auto op2 = op + 1; // look for multiple stores of the same value while ( op2 < instructions.size() diff --git a/test/tests.cpp b/test/tests.cpp index 946b719..2bf852a 100644 --- a/test/tests.cpp +++ b/test/tests.cpp @@ -41,10 +41,19 @@ std::vector execute_c64_program(const std::string_view &name, return "unknown"; }(); - const auto source_filename{ fmt::format("{}{}.cpp", name, optimization_level) }; - const auto vice_script_filename{ fmt::format("{}{}-vice_script", name, optimization_level) }; - const auto prg_filename{ fmt::format("{}{}.prg", name, optimization_level) }; - const auto ram_dump_filename{ fmt::format("{}{}-ram_dump", name, optimization_level) }; + const auto optimize_6502_name = [&]() -> std::string_view { + switch (o6502) { + case Optimize6502::Enabled: return "-optimize"; + case Optimize6502::Disabled: return "-no-optimize"; + } + + return "unknown"; + }(); + + const auto source_filename{ fmt::format("{}{}{}.cpp", name, optimization_level, optimize_6502_name) }; + const auto vice_script_filename{ fmt::format("{}{}{}-vice_script", name, optimization_level, optimize_6502_name) }; + const auto prg_filename{ fmt::format("{}{}{}.prg", name, optimization_level, optimize_6502_name) }; + const auto ram_dump_filename{ fmt::format("{}{}{}-ram_dump", name, optimization_level, optimize_6502_name) }; {