Simplify json datatype conversions.

Signed-off-by: Adrian Conlon <adrian.conlon@gmail.com>
This commit is contained in:
Adrian Conlon 2021-10-20 14:28:00 +01:00
parent 5d66d1aac3
commit 3a58bad0b0
8 changed files with 37 additions and 32 deletions

View File

@ -2,11 +2,6 @@
#include "byte_t.h"
#include <cassert>
#include <stdexcept>
byte_t::byte_t(uint16_t address, uint8_t value) noexcept
: m_address(address),
m_value(value) {}
#ifdef USE_SIMDJSON_JSON
@ -14,8 +9,8 @@ byte_t::byte_t(simdjson::dom::element input) noexcept
: byte_t(input.get_array()) {}
byte_t::byte_t(simdjson::dom::array input) noexcept
: m_address((uint16_t)(uint64_t)input.at(0)),
m_value((uint8_t)(uint64_t)input.at(1)) {
: m_address((uint16_t)(int64_t)input.at(0)),
m_value((uint8_t)(int64_t)input.at(1)) {
assert(input.size() == 2);
}
@ -57,8 +52,8 @@ byte_t::byte_t(const nlohmann::json& input) noexcept
#ifdef USE_JSONCPP_JSON
byte_t::byte_t(const Json::Value& input)
: m_address(input[0].asUInt()),
m_value(input[1].asUInt()) {
: m_address((uint16_t)input[0].asInt64()),
m_value((uint8_t)input[1].asInt64()) {
assert(input.size() == 2);
}

View File

@ -28,7 +28,6 @@ private:
uint8_t m_value = 0xff;
public:
byte_t(uint16_t address, uint8_t value) noexcept;
#ifdef USE_SIMDJSON_JSON
byte_t(simdjson::dom::element input) noexcept;

View File

@ -2,7 +2,6 @@
#include "cycle_t.h"
#include <cassert>
#include <stdexcept>
cycle_t::action_t cycle_t::to_action(std::string value) noexcept {
if (value == "read")
@ -31,8 +30,8 @@ cycle_t::cycle_t(simdjson::dom::element input) noexcept
: cycle_t(input.get_array()) {}
cycle_t::cycle_t(simdjson::dom::array input) noexcept
: m_address((uint16_t)(uint64_t)input.at(0)),
m_value((uint8_t)(uint64_t)input.at(1)),
: m_address((uint16_t)(int64_t)input.at(0)),
m_value((uint8_t)(int64_t)input.at(1)),
m_action(to_action((std::string)input.at(2))) {
assert(input.size() == 3);
}
@ -78,8 +77,8 @@ cycle_t::cycle_t(const nlohmann::json& input) noexcept
#ifdef USE_JSONCPP_JSON
cycle_t::cycle_t(const Json::Value& input)
: m_address(input[0].asUInt()),
m_value(input[1].asUInt()),
: m_address((uint16_t)input[0].asInt64()),
m_value((uint8_t)input[1].asInt64()),
m_action(to_action(input[2].asString())) {
assert(input.size() == 3);
}

View File

@ -80,9 +80,13 @@ void opcode_test_suite_t::parse() {
#ifdef USE_RAPIDJSON_JSON
void opcode_test_suite_t::parse() {
#ifdef JSON_INSITU_PARSE
m_raw.ParseInsitu((char*)m_contents.c_str());
#else
m_raw.Parse(m_contents);
m_contents.clear();
m_contents.shrink_to_fit();
#endif
}
#endif

View File

@ -1,7 +1,6 @@
#pragma once
#include <cstdint>
#include <utility>
#include <vector>
#ifdef USE_SIMDJSON_JSON

View File

@ -5,12 +5,12 @@
#ifdef USE_SIMDJSON_JSON
state_t::state_t(const simdjson::dom::element serialised)
: m_pc((uint16_t)(uint64_t)serialised["pc"]),
m_s((uint8_t)(uint64_t)serialised["s"]),
m_a((uint8_t)(uint64_t)serialised["a"]),
m_x((uint8_t)(uint64_t)serialised["x"]),
m_y((uint8_t)(uint64_t)serialised["y"]),
m_p((uint8_t)(uint64_t)serialised["p"]),
: m_pc((uint16_t)(int64_t)serialised["pc"]),
m_s((uint8_t)(int64_t)serialised["s"]),
m_a((uint8_t)(int64_t)serialised["a"]),
m_x((uint8_t)(int64_t)serialised["x"]),
m_y((uint8_t)(int64_t)serialised["y"]),
m_p((uint8_t)(int64_t)serialised["p"]),
m_ram(serialised["ram"].get_array()) {}
#endif
@ -60,12 +60,12 @@ state_t::state_t(const nlohmann::json& serialised)
#ifdef USE_JSONCPP_JSON
state_t::state_t(const Json::Value& serialised)
: m_pc(serialised["pc"].asUInt()),
m_s(serialised["s"].asUInt()),
m_a(serialised["a"].asUInt()),
m_x(serialised["x"].asUInt()),
m_y(serialised["y"].asUInt()),
m_p(serialised["p"].asUInt()),
: m_pc(serialised["pc"].asInt64()),
m_s(serialised["s"].asInt64()),
m_a(serialised["a"].asInt64()),
m_x(serialised["x"].asInt64()),
m_y(serialised["y"].asInt64()),
m_p(serialised["p"].asInt64()),
m_ram(serialised["ram"]) {}
#endif

View File

@ -1,16 +1,26 @@
#pragma once
#include <cassert>
#include <chrono>
#include <cstdint>
#include <exception>
#include <filesystem>
#include <fstream>
#include <iostream>
#include <map>
#include <memory>
#include <sstream>
#include <stdexcept>
#include <string>
#include <utility>
#include <map>
#include <vector>
#include <Bus.h>
#include <Ram.h>
#include <mos6502.h>
#include <Disassembly.h>
#include <Symbols.h>
//#define TEST_JSON_PERFORMANCE
#define USE_SIMDJSON_JSON // 13 seconds (19)
@ -28,6 +38,7 @@
#ifdef USE_RAPIDJSON_JSON
# define RAPIDJSON_HAS_STDSTRING 1
# define RAPIDJSON_SSE42
# define JSON_INSITU_PARSE
# include "rapidjson/document.h"
#endif
@ -36,6 +47,7 @@
#endif
#ifdef USE_NLOHMANN_JSON
# define JSON_USE_IMPLICIT_CONVERSIONS 0
# include "nlohmann/json.hpp"
#endif

View File

@ -1,9 +1,6 @@
#pragma once
#include <cstdint>
#include <string>
#include <vector>
#include <tuple>
#ifdef USE_SIMDJSON_JSON
# include "simdjson/simdjson.h"