2021-10-10 20:26:30 +00:00
|
|
|
#include "stdafx.h"
|
|
|
|
#include "opcode_test_suite_t.h"
|
|
|
|
|
|
|
|
#include <cassert>
|
2021-10-11 18:13:05 +00:00
|
|
|
#include <exception>
|
2021-10-10 20:26:30 +00:00
|
|
|
#include <fstream>
|
|
|
|
#include <filesystem>
|
|
|
|
|
2021-10-12 09:10:45 +00:00
|
|
|
#ifdef JSON_PREFER_REUSE_OF_PARSER
|
2021-10-11 18:13:05 +00:00
|
|
|
#ifdef USE_JSONCPP_JSON
|
2021-10-11 22:23:59 +00:00
|
|
|
std::unique_ptr<Json::CharReader> opcode_test_suite_t::m_parser;
|
2021-10-11 18:13:05 +00:00
|
|
|
#endif
|
2021-10-11 21:09:03 +00:00
|
|
|
#ifdef USE_SIMDJSON_JSON
|
2021-10-12 09:10:45 +00:00
|
|
|
simdjson::dom::parser opcode_test_suite_t::m_parser;
|
|
|
|
#endif
|
2021-10-11 21:09:03 +00:00
|
|
|
#endif
|
2021-10-11 18:13:05 +00:00
|
|
|
|
2021-10-10 20:26:30 +00:00
|
|
|
std::string opcode_test_suite_t::read(std::string path) {
|
|
|
|
std::ifstream file(path, std::ios::in | std::ios::binary);
|
|
|
|
const auto size = std::filesystem::file_size(path);
|
|
|
|
std::string result(size, '\0');
|
|
|
|
file.read(result.data(), size);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
opcode_test_suite_t::opcode_test_suite_t(std::string path)
|
|
|
|
: m_path(path) {}
|
|
|
|
|
2021-10-12 16:07:45 +00:00
|
|
|
void opcode_test_suite_t::load() {
|
|
|
|
m_contents = read(path());
|
|
|
|
}
|
|
|
|
|
2021-10-11 13:59:23 +00:00
|
|
|
#ifdef USE_BOOST_JSON
|
|
|
|
|
2021-10-12 16:07:45 +00:00
|
|
|
void opcode_test_suite_t::parse() {
|
|
|
|
m_raw = boost::json::parse(m_contents);
|
|
|
|
m_contents.clear();
|
|
|
|
m_contents.shrink_to_fit();}
|
2021-10-11 13:59:23 +00:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef USE_NLOHMANN_JSON
|
|
|
|
|
2021-10-12 16:07:45 +00:00
|
|
|
void opcode_test_suite_t::parse() {
|
|
|
|
m_raw = nlohmann::json::parse(m_contents);
|
|
|
|
m_contents.clear();
|
|
|
|
m_contents.shrink_to_fit();}
|
2021-10-11 13:59:23 +00:00
|
|
|
|
2021-10-11 18:13:05 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef USE_JSONCPP_JSON
|
|
|
|
|
2021-10-12 16:07:45 +00:00
|
|
|
void opcode_test_suite_t::parse() {
|
2021-10-12 09:10:45 +00:00
|
|
|
#ifdef JSON_PREFER_REUSE_OF_PARSER
|
2021-10-11 22:23:59 +00:00
|
|
|
if (m_parser == nullptr)
|
|
|
|
m_parser.reset(Json::CharReaderBuilder().newCharReader());
|
2021-10-12 16:07:45 +00:00
|
|
|
if (!m_parser->parse(m_contents.data(), m_contents.data() + m_contents.size(), &m_raw, nullptr))
|
2021-10-11 18:13:05 +00:00
|
|
|
throw std::runtime_error("Unable to parse tests");
|
2021-10-12 09:10:45 +00:00
|
|
|
#else
|
|
|
|
std::unique_ptr<Json::CharReader> parser(Json::CharReaderBuilder().newCharReader());
|
2021-10-12 16:07:45 +00:00
|
|
|
if (!parser->parse(m_contents.data(), m_contents.data() + m_contents.size(), &m_raw, nullptr))
|
2021-10-12 09:10:45 +00:00
|
|
|
throw std::runtime_error("Unable to parse tests");
|
|
|
|
#endif
|
2021-10-12 16:07:45 +00:00
|
|
|
m_contents.clear();
|
|
|
|
m_contents.shrink_to_fit();
|
2021-10-11 18:13:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
2021-10-11 21:09:03 +00:00
|
|
|
|
|
|
|
#ifdef USE_SIMDJSON_JSON
|
|
|
|
|
2021-10-12 16:07:45 +00:00
|
|
|
void opcode_test_suite_t::parse() {
|
|
|
|
m_raw = m_parser.parse(m_contents);
|
|
|
|
m_contents.clear();
|
|
|
|
m_contents.shrink_to_fit();
|
2021-10-11 21:09:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|