| 1 |
#include "catch.hpp" |
| 2 |
|
| 3 |
#include "Dasm.hh" |
| 4 |
|
| 5 |
#include <iostream> |
| 6 |
#include <set> |
| 7 |
|
| 8 |
using namespace openmsx; |
| 9 |
|
| 10 |
TEST_CASE("instructionLength, dasm") |
| 11 |
{ |
| 12 |
std::set<std::string, std::less<>> allInstructions; |
| 13 |
std::array<uint8_t, 4> opcode = {0, 0, 0, 0}; |
| 14 |
std::string dasmString; |
| 15 |
|
| 16 |
unsigned count = 0; |
| 17 |
bool end = false; |
| 18 |
while (!end) { |
| 19 |
++count; |
| 20 |
|
| 21 |
auto instrLen = instructionLength(opcode); |
| 22 |
REQUIRE(instrLen); |
| 23 |
REQUIRE(1 <= *instrLen); |
| 24 |
REQUIRE(*instrLen <= 4); |
| 25 |
|
| 26 |
dasmString.clear(); |
| 27 |
auto dasmLen = dasm(std::span(opcode.data(), *instrLen), 0x1234, dasmString); |
| 28 |
CHECK(dasmLen == *instrLen); |
| 29 |
|
| 30 |
|
| 31 |
auto [it, inserted] = allInstructions.insert(dasmString); |
| 32 |
CHECK(inserted); |
| 33 |
|
| 34 |
if (dasmLen != *instrLen || !inserted) { |
| 35 |
std::string info; |
| 36 |
for (auto i : xrange(*instrLen)) { |
| 37 |
strAppend(info, ' ', hex_string<2>(opcode[i])); |
| 38 |
} |
| 39 |
std::cout << "opcode:" << info << " (" << dasmString << ")\n"; |
| 40 |
} |
| 41 |
|
| 42 |
|
| 43 |
unsigned idx = *instrLen - 1; |
| 44 |
while (true) { |
| 45 |
if (opcode[idx] == 255) { |
| 46 |
opcode[idx] = 0; |
| 47 |
if (idx == 0) { |
| 48 |
end = true; |
| 49 |
break; |
| 50 |
} |
| 51 |
--idx; |
| 52 |
} else { |
| 53 |
++opcode[idx]; |
| 54 |
break; |
| 55 |
} |
| 56 |
} |
| 57 |
} |
| 58 |
REQUIRE(count == 2'904'196); |
| 59 |
} |