// SPDX-License-Identifier: GPL-3.0-or-later // Exercise the actual built compiler rule; expose its private entry only in // this test translation unit. Vendor sources and normal objects stay unchanged. #include "util.h" #include #include #define private public #include "ASMText.h" #undef private #include #include void check(const char* first, const char* middleOp, const char* middle, const char* last, bool expectRemoval) { ASMText text(true); text.ins("LDB", first); text.ins(middleOp, middle); text.ins("LDB", last); const bool removed = text.removeUselessLdaOrLdb(0); if (removed != expectRemoval) throw std::runtime_error(std::string(first) + "; " + middleOp + " " + middle + "; LDB " + last); } int main() { try { check("5,U", "LDX", "#array", "D,X", false); check("5,U", "LDX", "#array", "B,X", false); check("5,U", "LDX", "#array", "[D,X]", false); check("5,U", "LDX", "#array", "[B,X]", false); check("5,U", "LDX", "D,Y", ",X", false); check("5,U", "LDX", "B,Y", ",X", false); check("5,U", "LDX", "[D,Y]", ",X", false); check("5,U", "LEAX", "D,Y", ",X", false); check("5,U", "LEAX", "B,Y", ",X", false); check(",S+", "LDX", "#array", ",X", false); check(",--X", "LDX", "#array", ",X", false); check("[,Y++]", "LDX", "#array", ",X", false); check("[,--U]", "LDX", "#array", ",X", false); check("5,U", "LDX", "#array", ",X", true); check("5,U", "LEAX", "4,Y", "4,X", true); std::cout << "PASS indexed-load rule: 13 dependency/side-effect guards, 2 safe removals\n"; return 0; } catch (const std::exception& error) { std::cerr << error.what() << '\n'; return 1; } }