Add an implementation that uses JsonCpp (pretty slow!)

Signed-off-by: Adrian Conlon <adrian.conlon@gmail.com>
This commit is contained in:
Adrian Conlon 2021-10-11 19:13:05 +01:00
parent f3f6452119
commit 7a7b0046cd
12 changed files with 26907 additions and 14 deletions

View File

@ -23,7 +23,6 @@
<Keyword>Win32Proj</Keyword>
<ProjectGuid>{894eb6ef-4c8d-4401-bbaa-aba05a021abb}</ProjectGuid>
<RootNamespace>HarteTest_6502</RootNamespace>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
<ProjectName>HarteTest_6502</ProjectName>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
@ -73,20 +72,20 @@
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
<IncludePath>..\inc;..\..\inc;C:\Libraries\boost_1_77_0;$(IncludePath)</IncludePath>
<IncludePath>..\inc;..\..\inc;C:\Libraries\boost_1_77_0;$(ProjectDir)..\..\packages\JsonCpp.Windows.1.9.2\build\native\include;$(IncludePath)</IncludePath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
<IncludePath>..\inc;..\..\inc;C:\Libraries\boost_1_77_0;$(IncludePath)</IncludePath>
<IncludePath>..\inc;..\..\inc;C:\Libraries\boost_1_77_0;$(ProjectDir)..\..\packages\JsonCpp.Windows.1.9.2\build\native\include;$(IncludePath)</IncludePath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
<IncludePath>..\inc;..\..\inc;C:\Libraries\boost_1_77_0;$(IncludePath)</IncludePath>
<IncludePath>..\inc;..\..\inc;C:\Libraries\boost_1_77_0;$(ProjectDir)..\..\packages\JsonCpp.Windows.1.9.2\build\native\include;$(IncludePath)</IncludePath>
<LibraryPath>C:\Libraries\boost_1_77_0\lib64-msvc-14.2;$(LibraryPath)</LibraryPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
<IncludePath>..\inc;..\..\inc;C:\Libraries\boost_1_77_0;$(IncludePath)</IncludePath>
<IncludePath>..\inc;..\..\inc;C:\Libraries\boost_1_77_0;$(ProjectDir)..\..\packages\JsonCpp.Windows.1.9.2\build\native\include;$(IncludePath)</IncludePath>
<LibraryPath>C:\Libraries\boost_1_77_0\lib64-msvc-14.2;$(LibraryPath)</LibraryPath>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
@ -108,11 +107,15 @@
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<LanguageStandard>stdcpp17</LanguageStandard>
<PrecompiledHeader>Use</PrecompiledHeader>
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
<OmitFramePointers>true</OmitFramePointers>
<BufferSecurityCheck>false</BufferSecurityCheck>
<ControlFlowGuard>false</ControlFlowGuard>
<EnableParallelCodeGeneration>true</EnableParallelCodeGeneration>
<EnableEnhancedInstructionSet>AdvancedVectorExtensions</EnableEnhancedInstructionSet>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
@ -140,11 +143,15 @@
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<LanguageStandard>stdcpp17</LanguageStandard>
<PrecompiledHeader>Use</PrecompiledHeader>
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
<OmitFramePointers>true</OmitFramePointers>
<BufferSecurityCheck>false</BufferSecurityCheck>
<ControlFlowGuard>false</ControlFlowGuard>
<EnableParallelCodeGeneration>true</EnableParallelCodeGeneration>
<EnableEnhancedInstructionSet>AdvancedVectorExtensions</EnableEnhancedInstructionSet>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
@ -184,7 +191,17 @@
<Project>{d8726a1b-bbfe-47ef-9860-26b90140ba66}</Project>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
<Import Project="..\..\packages\JsonCpp.Windows.1.9.2\build\JsonCpp.Windows.targets" Condition="Exists('..\..\packages\JsonCpp.Windows.1.9.2\build\JsonCpp.Windows.targets')" />
</ImportGroup>
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\..\packages\JsonCpp.Windows.1.9.2\build\JsonCpp.Windows.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\JsonCpp.Windows.1.9.2\build\JsonCpp.Windows.targets'))" />
</Target>
</Project>

View File

@ -9,6 +9,9 @@
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>
</Filter>
<Filter Include="Header Files\nlohmann">
<UniqueIdentifier>{1b676a2e-dff7-46aa-b021-f4319b0419d7}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="tests.cpp">
@ -53,7 +56,10 @@
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="nlohmann\json.hpp">
<Filter>Header Files</Filter>
<Filter>Header Files\nlohmann</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
</Project>

File diff suppressed because it is too large Load Diff

View File

@ -2,9 +2,14 @@
#include "opcode_test_suite_t.h"
#include <cassert>
#include <exception>
#include <fstream>
#include <filesystem>
#ifdef USE_JSONCPP_JSON
std::unique_ptr<Json::CharReader> opcode_test_suite_t::m_reader;
#endif
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);
@ -37,4 +42,18 @@ void opcode_test_suite_t::load() {
m_raw = nlohmann::json::parse(contents);
}
#endif
#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

View File

@ -10,8 +10,17 @@
# include "nlohmann/json.hpp"
#endif
#ifdef USE_JSONCPP_JSON
# include <memory>
# include <json/json.h>
#endif
class opcode_test_suite_t final {
private:
#ifdef USE_JSONCPP_JSON
static std::unique_ptr<Json::CharReader> m_reader;
#endif
[[nodiscard]] static std::string read(std::string path);
std::string m_path;
@ -21,6 +30,12 @@ private:
#ifdef USE_NLOHMANN_JSON
nlohmann::json m_raw;
#endif
#ifdef USE_RAPIDJSON_JSON
rapidjson::Document m_raw;
#endif
#ifdef USE_JSONCPP_JSON
Json::Value m_raw;
#endif
public:
opcode_test_suite_t(std::string path);

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="JsonCpp.Windows" version="1.9.2" targetFramework="native" />
</packages>

View File

@ -76,3 +76,37 @@ void state_t::initialise(const nlohmann::json& serialised) {
}
#endif
#ifdef USE_JSONCPP_JSON
state_t::state_t(const Json::Value& serialised) {
assert(serialised.isObject());
initialise(serialised);
assert(initialised());
}
void state_t::initialise(const Json::Value& serialised) {
assert(!initialised());
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();
const auto& ram_entries = serialised["ram"];
assert(ram_entries.isArray());
for (const auto& ram_entry : ram_entries) {
assert(ram_entry.isArray());
assert(ram_entry.size() == 2);
const auto address = ram_entry[0].asUInt();
const auto value = ram_entry[1].asUInt();
m_ram[address] = value;
}
m_initialised = true;
}
#endif

View File

@ -11,6 +11,10 @@
# include "nlohmann/json.hpp"
#endif
#ifdef USE_JSONCPP_JSON
# include <json/json.h>
#endif
#include "json_t.h"
class state_t final : public json_t {
@ -35,6 +39,10 @@ private:
void initialise(const nlohmann::json& serialised);
#endif
#ifdef USE_JSONCPP_JSON
void initialise(const Json::Value& serialised);
#endif
public:
state_t();
@ -47,6 +55,10 @@ public:
state_t(const nlohmann::json& serialised);
#endif
#ifdef USE_JSONCPP_JSON
state_t(const Json::Value& serialised);
#endif
[[nodiscard]] constexpr auto pc() const noexcept { return m_pc; }
[[nodiscard]] constexpr auto s() const noexcept { return m_s; }
[[nodiscard]] constexpr auto a() const noexcept { return m_a; }

View File

@ -11,8 +11,9 @@
#include <unordered_map>
#include <vector>
//#define USE_BOOST_JSON
#define USE_NLOHMANN_JSON
#define USE_BOOST_JSON
//#define USE_NLOHMANN_JSON
//#define USE_JSONCPP_JSON
#ifdef USE_BOOST_JSON
# include <boost/json.hpp>
@ -20,4 +21,8 @@
#ifdef USE_NLOHMANN_JSON
# include "nlohmann/json.hpp"
#endif
#endif
#ifdef USE_JSONCPP_JSON
# include <json/json.h>
#endif

View File

@ -77,3 +77,30 @@ void test_t::initialise(const nlohmann::json& serialised) {
}
#endif
#ifdef USE_JSONCPP_JSON
test_t::test_t(const Json::Value& serialised) {
assert(serialised.isObject());
initialise(serialised);
}
void test_t::initialise(const Json::Value& serialised) {
m_name = serialised["name"].asString();
m_initial_state = state_t(serialised["initial"]);
m_final_state = state_t(serialised["final"]);
const auto& cycles_array = serialised["cycles"];
m_cycles.reserve(cycles_array.size());
for (const auto& cycles_entry : cycles_array) {
assert(cycles_entry.size() == 3);
const auto address = cycles_entry[0].asUInt();
const auto contents = cycles_entry[1].asUInt();
const auto action = to_action(cycles_entry[2].asString());
m_cycles.push_back({ address, contents, action });
}
}
#endif

View File

@ -13,6 +13,10 @@
# include "nlohmann/json.hpp"
#endif
#ifdef USE_JSONCPP_JSON
# include <json/json.h>
#endif
#include "state_t.h"
#include "json_t.h"
@ -40,6 +44,10 @@ private:
void initialise(const nlohmann::json& serialised);
#endif
#ifdef USE_JSONCPP_JSON
void initialise(const Json::Value& serialised);
#endif
public:
#ifdef USE_BOOST_JSON
@ -51,6 +59,10 @@ public:
test_t(const nlohmann::json& serialised);
#endif
#ifdef USE_JSONCPP_JSON
test_t(const Json::Value& serialised);
#endif
[[nodiscard]] constexpr const auto& name() const noexcept { return m_name; }
[[nodiscard]] constexpr const auto& initial_state() const noexcept { return m_initial_state; }
[[nodiscard]] constexpr const auto& final_state() const noexcept { return m_final_state; }

View File

@ -30,6 +30,9 @@ int main() {
#ifdef USE_NLOHMANN_JSON
const auto& opcode_test_array = opcode.raw();
#endif
#ifdef USE_JSONCPP_JSON
const auto& opcode_test_array = opcode.raw();
#endif
bool opcode_bad = false;
for (const auto& opcode_test_element : opcode_test_array) {