Refactor the JSON core parsing code a little

Signed-off-by: Adrian Conlon <adrian.conlon@gmail.com>
This commit is contained in:
Adrian Conlon 2021-10-24 13:39:08 +01:00
parent 76c03bb4d4
commit 3158b2238a
6 changed files with 55 additions and 28 deletions

View File

@ -106,7 +106,6 @@
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<LanguageStandard>stdcpp17</LanguageStandard>
<PrecompiledHeader>Use</PrecompiledHeader>
@ -115,7 +114,8 @@
<BufferSecurityCheck>false</BufferSecurityCheck>
<ControlFlowGuard>false</ControlFlowGuard>
<EnableParallelCodeGeneration>true</EnableParallelCodeGeneration>
<EnableEnhancedInstructionSet>AdvancedVectorExtensions</EnableEnhancedInstructionSet>
<EnableEnhancedInstructionSet>AdvancedVectorExtensions2</EnableEnhancedInstructionSet>
<InlineFunctionExpansion>AnySuitable</InlineFunctionExpansion>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
@ -142,7 +142,6 @@
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<LanguageStandard>stdcpp17</LanguageStandard>
<PrecompiledHeader>Use</PrecompiledHeader>
@ -151,7 +150,8 @@
<BufferSecurityCheck>false</BufferSecurityCheck>
<ControlFlowGuard>false</ControlFlowGuard>
<EnableParallelCodeGeneration>true</EnableParallelCodeGeneration>
<EnableEnhancedInstructionSet>AdvancedVectorExtensions</EnableEnhancedInstructionSet>
<EnableEnhancedInstructionSet>AdvancedVectorExtensions2</EnableEnhancedInstructionSet>
<InlineFunctionExpansion>AnySuitable</InlineFunctionExpansion>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
@ -167,6 +167,7 @@
<ClCompile Include="cycle_t.cpp" />
<ClCompile Include="element_t.cpp" />
<ClCompile Include="opcode_test_suite_t.cpp" />
<ClCompile Include="parser_t.cpp" />
<ClCompile Include="ram_t.cpp" />
<ClCompile Include="simdjson\simdjson.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">NotUsing</PrecompiledHeader>
@ -192,6 +193,7 @@
<ClInclude Include="cycle_t.h" />
<ClInclude Include="element_t.h" />
<ClInclude Include="opcode_test_suite_t.h" />
<ClInclude Include="parser_t.h" />
<ClInclude Include="ram_t.h" />
<ClInclude Include="simdjson\simdjson.h" />
<ClInclude Include="state_t.h" />

View File

@ -53,6 +53,9 @@
<ClCompile Include="element_t.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="parser_t.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="stdafx.h">
@ -91,5 +94,8 @@
<ClInclude Include="element_t.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="parser_t.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>

View File

@ -1,11 +1,5 @@
#include "stdafx.h"
#include "opcode_test_suite_t.h"
simdjson::dom::parser opcode_test_suite_t::m_parser;
opcode_test_suite_t::opcode_test_suite_t(const std::string path)
: m_path(path) {}
void opcode_test_suite_t::load() {
m_raw = m_parser.load(path());
}
opcode_test_suite_t::opcode_test_suite_t(const std::string path) noexcept
: parser_t(path) {}

View File

@ -2,25 +2,15 @@
#include <string>
#include "simdjson/simdjson.h"
#include "parser_t.h"
class opcode_test_suite_t final {
class opcode_test_suite_t final : public parser_t {
private:
// N.B.
// The parser must be kept for the lifetime of any parsed data.
// Therefore, it can only be used for one document at a time.
static simdjson::dom::parser m_parser;
std::string m_path;
simdjson::dom::array m_raw;;
[[nodiscard]] auto array() const noexcept { return raw().get_array(); }
public:
opcode_test_suite_t(std::string path);
opcode_test_suite_t(std::string path) noexcept;
[[nodiscard]] constexpr const auto& path() const noexcept { return m_path; }
void load();
[[nodiscard]] auto begin() const noexcept { return m_raw.begin(); }
[[nodiscard]] auto end() const noexcept { return m_raw.end(); }
[[nodiscard]] auto begin() const noexcept { return array().begin(); }
[[nodiscard]] auto end() const noexcept { return array().end(); }
};

View File

@ -0,0 +1,11 @@
#include "stdafx.h"
#include "parser_t.h"
simdjson::dom::parser parser_t::m_parser;
parser_t::parser_t(const std::string path) noexcept
: m_path(path) {}
void parser_t::load() {
m_raw = m_parser.load(path());
}

View File

@ -0,0 +1,24 @@
#pragma once
#include <string>
#include "simdjson/simdjson.h"
class parser_t {
private:
// N.B.
// The parser must be kept for the lifetime of any parsed data.
// Therefore, it can only be used for one document at a time.
static simdjson::dom::parser m_parser;
std::string m_path;
simdjson::dom::element m_raw;
public:
parser_t(std::string path) noexcept;
[[nodiscard]] constexpr const auto& path() const noexcept { return m_path; }
[[nodiscard]] const auto raw() const noexcept { return m_raw; }
virtual void load();
};