From 500e65b895ca102375c799a3dcabf8f67e586df3 Mon Sep 17 00:00:00 2001 From: Adrian Conlon Date: Wed, 13 Oct 2021 23:33:08 +0100 Subject: [PATCH] Tidy up the code a little (including removing some no longer needed code). Signed-off-by: Adrian Conlon --- M6502/HarteTest_6502/HarteTest_6502.vcxproj | 2 - .../HarteTest_6502.vcxproj.filters | 6 -- M6502/HarteTest_6502/TestRunner.h | 1 - M6502/HarteTest_6502/json_t.cpp | 58 ------------------- M6502/HarteTest_6502/json_t.h | 28 --------- M6502/HarteTest_6502/opcode_test_suite_t.cpp | 5 -- M6502/HarteTest_6502/opcode_test_suite_t.h | 4 -- M6502/HarteTest_6502/state_t.cpp | 22 ++++--- M6502/HarteTest_6502/state_t.h | 8 +-- M6502/HarteTest_6502/stdafx.h | 10 ++-- M6502/HarteTest_6502/test_t.cpp | 19 +++--- M6502/HarteTest_6502/test_t.h | 3 +- M6502/HarteTest_6502/tests.cpp | 5 +- 13 files changed, 32 insertions(+), 139 deletions(-) delete mode 100644 M6502/HarteTest_6502/json_t.cpp delete mode 100644 M6502/HarteTest_6502/json_t.h diff --git a/M6502/HarteTest_6502/HarteTest_6502.vcxproj b/M6502/HarteTest_6502/HarteTest_6502.vcxproj index d321c2c..55b59e5 100644 --- a/M6502/HarteTest_6502/HarteTest_6502.vcxproj +++ b/M6502/HarteTest_6502/HarteTest_6502.vcxproj @@ -161,7 +161,6 @@ - NotUsing @@ -181,7 +180,6 @@ - diff --git a/M6502/HarteTest_6502/HarteTest_6502.vcxproj.filters b/M6502/HarteTest_6502/HarteTest_6502.vcxproj.filters index 5d63c68..492f0f6 100644 --- a/M6502/HarteTest_6502/HarteTest_6502.vcxproj.filters +++ b/M6502/HarteTest_6502/HarteTest_6502.vcxproj.filters @@ -23,9 +23,6 @@ Source Files - - Source Files - Source Files @@ -46,9 +43,6 @@ Header Files - - Header Files - Header Files diff --git a/M6502/HarteTest_6502/TestRunner.h b/M6502/HarteTest_6502/TestRunner.h index 25f3803..531dc11 100644 --- a/M6502/HarteTest_6502/TestRunner.h +++ b/M6502/HarteTest_6502/TestRunner.h @@ -40,7 +40,6 @@ private: bool check(std::string what, uint16_t address, uint8_t expected, uint8_t actual); - void addActualEvent(test_t::action action, uint16_t address, uint8_t value); void dumpEvents(std::string which, const test_t::events_t& events); diff --git a/M6502/HarteTest_6502/json_t.cpp b/M6502/HarteTest_6502/json_t.cpp deleted file mode 100644 index eb87aba..0000000 --- a/M6502/HarteTest_6502/json_t.cpp +++ /dev/null @@ -1,58 +0,0 @@ -#include "stdafx.h" -#include "json_t.h" - -#ifdef USE_BOOST_JSON - -#include - -const boost::json::value& json_t::get_value(const boost::json::object& object, std::string key) { - auto* value = object.if_contains(key); - assert(value != nullptr); - return *value; -} - -int64_t json_t::get_int64(const boost::json::value& value) { - assert(value.is_number()); - assert(value.is_int64()); - return value.get_int64(); -} - -uint16_t json_t::get_uint16(const boost::json::value& value) { - return static_cast(get_int64(value)); -} - -uint8_t json_t::get_uint8(const boost::json::value& value) { - return static_cast(get_int64(value)); -} - -int64_t json_t::get_int64(const boost::json::object& object, std::string key) { - return get_int64(get_value(object, key)); -} - -uint16_t json_t::get_uint16(const boost::json::object& object, std::string key) { - return static_cast(get_int64(object, key)); -} - -uint8_t json_t::get_uint8(const boost::json::object& object, std::string key) { - return static_cast(get_int64(object, key)); -} - -const boost::json::array& json_t::get_array(const boost::json::value& value) { - assert(value.is_array()); - return value.get_array(); -} - -const boost::json::array& json_t::get_array(const boost::json::object& object, std::string key) { - return get_array(get_value(object, key)); -} - -const boost::json::string& json_t::get_string(const boost::json::value& value) { - assert(value.is_string()); - return value.get_string(); -} - -const boost::json::string& json_t::get_string(const boost::json::object& object, std::string key) { - return get_string(get_value(object, key)); -} - -#endif \ No newline at end of file diff --git a/M6502/HarteTest_6502/json_t.h b/M6502/HarteTest_6502/json_t.h deleted file mode 100644 index 1f03a85..0000000 --- a/M6502/HarteTest_6502/json_t.h +++ /dev/null @@ -1,28 +0,0 @@ -#pragma once - -#ifdef USE_BOOST_JSON -# include -# include -# include -#endif - -class json_t { -#ifdef USE_BOOST_JSON -protected: - [[nodiscard]] static const boost::json::value& get_value(const boost::json::object& object, std::string key); - - [[nodiscard]] static int64_t get_int64(const boost::json::value& value); - [[nodiscard]] static uint16_t get_uint16(const boost::json::value& value); - [[nodiscard]] static uint8_t get_uint8(const boost::json::value& value); - - [[nodiscard]] static int64_t get_int64(const boost::json::object& object, std::string key); - [[nodiscard]] static uint16_t get_uint16(const boost::json::object& object, std::string key); - [[nodiscard]] static uint8_t get_uint8(const boost::json::object& object, std::string key); - - [[nodiscard]] static const boost::json::array& get_array(const boost::json::value& value); - [[nodiscard]] static const boost::json::array& get_array(const boost::json::object& object, std::string key); - - [[nodiscard]] static const boost::json::string& get_string(const boost::json::value& value); - [[nodiscard]] static const boost::json::string& get_string(const boost::json::object& object, std::string key); -#endif -}; diff --git a/M6502/HarteTest_6502/opcode_test_suite_t.cpp b/M6502/HarteTest_6502/opcode_test_suite_t.cpp index 8ed0ebb..1009ec5 100644 --- a/M6502/HarteTest_6502/opcode_test_suite_t.cpp +++ b/M6502/HarteTest_6502/opcode_test_suite_t.cpp @@ -32,11 +32,6 @@ void opcode_test_suite_t::load() { #ifdef USE_BOOST_JSON -const boost::json::array& opcode_test_suite_t::get_array() const noexcept { - assert(raw().is_array()); - return raw().get_array(); -} - void opcode_test_suite_t::parse() { m_raw = boost::json::parse(m_contents); m_contents.clear(); diff --git a/M6502/HarteTest_6502/opcode_test_suite_t.h b/M6502/HarteTest_6502/opcode_test_suite_t.h index 34f034e..535586f 100644 --- a/M6502/HarteTest_6502/opcode_test_suite_t.h +++ b/M6502/HarteTest_6502/opcode_test_suite_t.h @@ -65,10 +65,6 @@ public: [[nodiscard]] constexpr const auto& raw() const noexcept { return m_raw; } #endif -#ifdef USE_BOOST_JSON - [[nodiscard]] const boost::json::array& get_array() const noexcept; -#endif - void load(); // Reads into contents void parse(); // Parse the contents }; diff --git a/M6502/HarteTest_6502/state_t.cpp b/M6502/HarteTest_6502/state_t.cpp index 25fda33..21f0a55 100644 --- a/M6502/HarteTest_6502/state_t.cpp +++ b/M6502/HarteTest_6502/state_t.cpp @@ -12,8 +12,7 @@ state_t::state_t(const boost::json::object& serialised) { } state_t::state_t(const boost::json::value& serialised) { - assert(serialised.is_object()); - initialise(serialised.get_object()); + initialise(serialised.as_object()); assert(initialised()); } @@ -21,20 +20,19 @@ void state_t::initialise(const boost::json::object& serialised) { assert(!initialised()); - m_pc = get_uint16(serialised, "pc"); - m_s = get_uint8(serialised, "s"); - m_a = get_uint8(serialised, "a"); - m_x = get_uint8(serialised, "x"); - m_y = get_uint8(serialised, "y"); - m_p = get_uint8(serialised, "p"); + m_pc = (uint16_t)serialised.at("pc").as_int64(); + m_s = (uint8_t)serialised.at("s").as_int64(); + m_a = (uint8_t)serialised.at("a").as_int64(); + m_x = (uint8_t)serialised.at("x").as_int64(); + m_y = (uint8_t)serialised.at("y").as_int64(); + m_p = (uint8_t)serialised.at("p").as_int64(); - const auto& ram_entries = get_array(serialised, "ram"); + const auto& ram_entries = serialised.at("ram").as_array(); for (const auto& ram_entry : ram_entries) { - assert(ram_entry.is_array()); const auto& ram_entry_array = ram_entry.as_array(); assert(ram_entry_array.size() == 2); - const auto address = get_uint16(ram_entry_array[0]); - const auto value = get_uint8(ram_entry_array[1]); + const auto address = (uint16_t)ram_entry_array[0].as_int64(); + const auto value = (uint8_t)ram_entry_array[1].as_int64(); m_ram[address] = value; } diff --git a/M6502/HarteTest_6502/state_t.h b/M6502/HarteTest_6502/state_t.h index 04d86ed..316b6d9 100644 --- a/M6502/HarteTest_6502/state_t.h +++ b/M6502/HarteTest_6502/state_t.h @@ -1,7 +1,7 @@ #pragma once #include -#include +#include #ifdef USE_BOOST_JSON # include @@ -19,9 +19,7 @@ # include "simdjson/simdjson.h" #endif -#include "json_t.h" - -class state_t final : public json_t { +class state_t final { private: bool m_initialised = false; @@ -31,7 +29,7 @@ private: uint8_t m_x = 0xff; uint8_t m_y = 0xff; uint8_t m_p = 0xff; - std::unordered_map m_ram; + std::map m_ram; [[nodiscard]] constexpr auto initialised() const noexcept { return m_initialised; } diff --git a/M6502/HarteTest_6502/stdafx.h b/M6502/HarteTest_6502/stdafx.h index 8415d3b..4e5ceb3 100644 --- a/M6502/HarteTest_6502/stdafx.h +++ b/M6502/HarteTest_6502/stdafx.h @@ -8,15 +8,15 @@ #include #include #include -#include +#include #include //#define TEST_JSON_PERFORMANCE -#define USE_SIMDJSON_JSON // 15 seconds -//#define USE_BOOST_JSON // 32 seconds -//#define USE_NLOHMANN_JSON // 58 seconds -//#define USE_JSONCPP_JSON // 88 seconds +#define USE_SIMDJSON_JSON // 16 seconds +//#define USE_BOOST_JSON // 31 seconds +//#define USE_NLOHMANN_JSON // 73 seconds +//#define USE_JSONCPP_JSON // 105 seconds #ifdef USE_BOOST_JSON # include diff --git a/M6502/HarteTest_6502/test_t.cpp b/M6502/HarteTest_6502/test_t.cpp index aa04e1f..5c712af 100644 --- a/M6502/HarteTest_6502/test_t.cpp +++ b/M6502/HarteTest_6502/test_t.cpp @@ -26,25 +26,24 @@ test_t::test_t(const boost::json::object& serialised) { } test_t::test_t(const boost::json::value& serialised) { - assert(serialised.is_object()); - initialise(serialised.get_object()); + initialise(serialised.as_object()); } void test_t::initialise(const boost::json::object& serialised) { - m_name = get_string(serialised, "name"); - m_initial_state = state_t(get_value(serialised, "initial")); - m_final_state = state_t(get_value(serialised, "final")); + m_name = serialised.at("name").as_string(); + m_initial_state = state_t(serialised.at("initial")); + m_final_state = state_t(serialised.at("final")); - const auto& cycles_array = get_array(serialised, "cycles"); + const auto& cycles_array = serialised.at("cycles").as_array(); m_cycles.reserve(cycles_array.size()); for (const auto& cycles_entry : cycles_array) { - const auto& cycle_array = get_array(cycles_entry); + const auto& cycle_array = cycles_entry.as_array(); assert(cycle_array.size() == 3); - const auto address = get_uint16(cycle_array[0]); - const auto contents = get_uint8(cycle_array[1]); - const auto action = to_action((std::string)get_string(cycle_array[2])); + const auto address = (uint16_t)cycle_array[0].as_int64(); + const auto contents = (uint8_t)cycle_array[1].as_int64(); + const auto action = to_action((std::string)cycle_array[2].as_string()); m_cycles.push_back({ address, contents, action }); } } diff --git a/M6502/HarteTest_6502/test_t.h b/M6502/HarteTest_6502/test_t.h index 5b5ff8d..8fae1c8 100644 --- a/M6502/HarteTest_6502/test_t.h +++ b/M6502/HarteTest_6502/test_t.h @@ -22,9 +22,8 @@ #endif #include "state_t.h" -#include "json_t.h" -class test_t final : public json_t { +class test_t final { public: enum class action { read, write }; diff --git a/M6502/HarteTest_6502/tests.cpp b/M6502/HarteTest_6502/tests.cpp index f650b3c..09d1408 100644 --- a/M6502/HarteTest_6502/tests.cpp +++ b/M6502/HarteTest_6502/tests.cpp @@ -24,12 +24,15 @@ int main() { opcode.parse(); #ifdef USE_BOOST_JSON - const auto& opcode_test_array = opcode.get_array(); + assert(opcode.raw().is_array()); + const auto& opcode_test_array = opcode.raw().as_array(); #endif #ifdef USE_NLOHMANN_JSON + assert(opcode.raw().is_array()); const auto& opcode_test_array = opcode.raw(); #endif #ifdef USE_JSONCPP_JSON + assert(opcode.raw().is_array()); const auto& opcode_test_array = opcode.raw(); #endif #ifdef USE_SIMDJSON_JSON