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-11 18:13:05 +00:00
|
|
|
#ifdef USE_JSONCPP_JSON
|
|
|
|
std::unique_ptr<Json::CharReader> opcode_test_suite_t::m_reader;
|
|
|
|
#endif
|
|
|
|
|
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-11 13:59:23 +00:00
|
|
|
#ifdef USE_BOOST_JSON
|
|
|
|
|
2021-10-10 20:26:30 +00:00
|
|
|
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::load() {
|
|
|
|
const auto contents = read(path());
|
|
|
|
m_raw = boost::json::parse(contents);
|
|
|
|
}
|
2021-10-11 13:59:23 +00:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef USE_NLOHMANN_JSON
|
|
|
|
|
|
|
|
void opcode_test_suite_t::load() {
|
|
|
|
const auto contents = read(path());
|
|
|
|
m_raw = nlohmann::json::parse(contents);
|
|
|
|
}
|
|
|
|
|
2021-10-11 18:13:05 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef USE_JSONCPP_JSON
|
|
|
|
|
|
|
|
void opcode_test_suite_t::load() {
|
|
|
|
if (m_reader == nullptr) {
|
|
|
|
Json::CharReaderBuilder builder;
|
|
|
|
m_reader.reset(builder.newCharReader());
|
|
|
|
}
|
|
|
|
const auto contents = read(path());
|
|
|
|
if (!m_reader->parse(contents.data(), contents.data() + contents.size(), &m_raw, nullptr))
|
|
|
|
throw std::runtime_error("Unable to parse tests");
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|