Split load/parse of opcode tests.

Signed-off-by: Adrian Conlon <adrian.conlon@gmail.com>
This commit is contained in:
Adrian Conlon 2021-10-12 17:07:45 +01:00
parent dcba8efc83
commit 4892ea95d3
3 changed files with 26 additions and 23 deletions

View File

@ -26,6 +26,10 @@ std::string opcode_test_suite_t::read(std::string path) {
opcode_test_suite_t::opcode_test_suite_t(std::string path)
: m_path(path) {}
void opcode_test_suite_t::load() {
m_contents = read(path());
}
#ifdef USE_BOOST_JSON
const boost::json::array& opcode_test_suite_t::get_array() const noexcept {
@ -33,46 +37,47 @@ const boost::json::array& opcode_test_suite_t::get_array() const noexcept {
return raw().get_array();
}
void opcode_test_suite_t::load() {
const auto contents = read(path());
m_raw = boost::json::parse(contents);
}
void opcode_test_suite_t::parse() {
m_raw = boost::json::parse(m_contents);
m_contents.clear();
m_contents.shrink_to_fit();}
#endif
#ifdef USE_NLOHMANN_JSON
void opcode_test_suite_t::load() {
const auto contents = read(path());
m_raw = nlohmann::json::parse(contents);
}
void opcode_test_suite_t::parse() {
m_raw = nlohmann::json::parse(m_contents);
m_contents.clear();
m_contents.shrink_to_fit();}
#endif
#ifdef USE_JSONCPP_JSON
void opcode_test_suite_t::load() {
void opcode_test_suite_t::parse() {
#ifdef JSON_PREFER_REUSE_OF_PARSER
if (m_parser == nullptr)
m_parser.reset(Json::CharReaderBuilder().newCharReader());
const auto contents = read(path());
if (!m_parser->parse(contents.data(), contents.data() + contents.size(), &m_raw, nullptr))
if (!m_parser->parse(m_contents.data(), m_contents.data() + m_contents.size(), &m_raw, nullptr))
throw std::runtime_error("Unable to parse tests");
#else
const auto contents = read(path());
std::unique_ptr<Json::CharReader> parser(Json::CharReaderBuilder().newCharReader());
if (!parser->parse(contents.data(), contents.data() + contents.size(), &m_raw, nullptr))
if (!parser->parse(m_contents.data(), m_contents.data() + m_contents.size(), &m_raw, nullptr))
throw std::runtime_error("Unable to parse tests");
#endif
m_contents.clear();
m_contents.shrink_to_fit();
}
#endif
#ifdef USE_SIMDJSON_JSON
void opcode_test_suite_t::load() {
const auto contents = read(path());
m_raw = m_parser.parse(contents);
void opcode_test_suite_t::parse() {
m_raw = m_parser.parse(m_contents);
m_contents.clear();
m_contents.shrink_to_fit();
}
#endif

View File

@ -36,6 +36,7 @@ private:
[[nodiscard]] static std::string read(std::string path);
std::string m_path;
std::string m_contents;
#ifdef USE_BOOST_JSON
boost::json::value m_raw;
#endif
@ -68,5 +69,6 @@ public:
[[nodiscard]] const boost::json::array& get_array() const noexcept;
#endif
void load();
void load(); // Reads into contents
void parse(); // Parse the contents
};

View File

@ -18,11 +18,10 @@ int main() {
const auto path = entry.path();
const auto filename = path.filename();
std::cout << "Processing: " << filename << "\n";
std::cout << "Processing: " << path.filename() << "\n";
opcode_test_suite_t opcode(path.string());
opcode.load();
opcode.parse();
#ifdef USE_BOOST_JSON
const auto& opcode_test_array = opcode.get_array();
@ -59,10 +58,7 @@ int main() {
}
const auto finish_time = std::chrono::steady_clock::now();
const auto elapsed_time = finish_time - start_time;
const auto seconds = std::chrono::duration_cast<std::chrono::duration<double>>(elapsed_time).count();
std::cout << "Elapsed time: " << seconds << " seconds" << std::endl;
}