Refactor deserilization of RefreshPolicyType and remove McConfig.cpp
This commit is contained in:
@@ -1,73 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2021, Technische Universität Kaiserslautern
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER
|
||||
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* Authors:
|
||||
* Derek Christ
|
||||
*/
|
||||
|
||||
#include "McConfig.h"
|
||||
|
||||
namespace DRAMSys::Config
|
||||
{
|
||||
|
||||
void to_json(json_t &j, const RefreshPolicyType &r)
|
||||
{
|
||||
if (r == RefreshPolicyType::NoRefresh)
|
||||
j = "NoRefresh";
|
||||
else if (r == RefreshPolicyType::AllBank)
|
||||
j = "AllBank";
|
||||
else if (r == RefreshPolicyType::PerBank)
|
||||
j = "PerBank";
|
||||
else if (r == RefreshPolicyType::Per2Bank)
|
||||
j = "Per2Bank";
|
||||
else if (r == RefreshPolicyType::SameBank)
|
||||
j = "SameBank";
|
||||
else
|
||||
j = nullptr;
|
||||
}
|
||||
|
||||
void from_json(const json_t &j, RefreshPolicyType &r)
|
||||
{
|
||||
if (j == "NoRefresh")
|
||||
r = RefreshPolicyType::NoRefresh;
|
||||
else if (j == "AllBank" || j == "Rankwise")
|
||||
r = RefreshPolicyType::AllBank;
|
||||
else if (j == "PerBank" || j == "Bankwise")
|
||||
r = RefreshPolicyType::PerBank;
|
||||
else if (j == "SameBank" || j == "Groupwise")
|
||||
r = RefreshPolicyType::SameBank;
|
||||
else if (j == "Per2Bank")
|
||||
r = RefreshPolicyType::Per2Bank;
|
||||
else
|
||||
r = RefreshPolicyType::Invalid;
|
||||
}
|
||||
|
||||
} // namespace DRAMSys::Config
|
||||
@@ -123,6 +123,19 @@ enum class RefreshPolicyType
|
||||
Invalid = -1
|
||||
};
|
||||
|
||||
NLOHMANN_JSON_SERIALIZE_ENUM(RefreshPolicyType, {{RefreshPolicyType::Invalid, nullptr},
|
||||
{RefreshPolicyType::NoRefresh, "NoRefresh"},
|
||||
{RefreshPolicyType::AllBank, "AllBank"},
|
||||
{RefreshPolicyType::PerBank, "PerBank"},
|
||||
{RefreshPolicyType::Per2Bank, "Per2Bank"},
|
||||
{RefreshPolicyType::SameBank, "SameBank"},
|
||||
|
||||
// Alternative conversions to provide backwards-compatibility
|
||||
// when deserializing. Will not be used for serializing.
|
||||
{RefreshPolicyType::AllBank, "Rankwise"},
|
||||
{RefreshPolicyType::PerBank, "Bankwise"},
|
||||
{RefreshPolicyType::SameBank, "Groupwise"}})
|
||||
|
||||
enum class PowerDownPolicyType
|
||||
{
|
||||
NoPowerDown,
|
||||
@@ -202,12 +215,6 @@ NLOHMANN_JSONIFY_ALL_THINGS(McConfig,
|
||||
BlockingReadDelay,
|
||||
BlockingWriteDelay)
|
||||
|
||||
void to_json(json_t &j, const RefreshPolicyType &r);
|
||||
void from_json(const json_t &j, RefreshPolicyType &r);
|
||||
|
||||
// void from_dump(const std::string &dump, McConfig &c);
|
||||
// std::string dump(const McConfig &c, unsigned int indentation = -1);
|
||||
|
||||
} // namespace Configuration
|
||||
|
||||
#endif // DRAMSYSCONFIGURATION_MCCONFIG_H
|
||||
|
||||
@@ -286,6 +286,19 @@ TEST(Configuration, FromPath)
|
||||
Configuration config = from_path("reference.json");
|
||||
}
|
||||
|
||||
TEST(RefreshPolicyType, BackwardsCompatibility)
|
||||
{
|
||||
// Deserializing
|
||||
EXPECT_EQ(json_t("Rankwise").get<RefreshPolicyType>(), RefreshPolicyType::AllBank);
|
||||
EXPECT_EQ(json_t("Bankwise").get<RefreshPolicyType>(), RefreshPolicyType::PerBank);
|
||||
EXPECT_EQ(json_t("Groupwise").get<RefreshPolicyType>(), RefreshPolicyType::SameBank);
|
||||
|
||||
// Serializing
|
||||
EXPECT_EQ(json_t(RefreshPolicyType::AllBank).get<std::string>(), "AllBank");
|
||||
EXPECT_EQ(json_t(RefreshPolicyType::PerBank).get<std::string>(), "PerBank");
|
||||
EXPECT_EQ(json_t(RefreshPolicyType::SameBank).get<std::string>(), "SameBank");
|
||||
}
|
||||
|
||||
TEST_F(ConfigurationTest, SimConfig)
|
||||
{
|
||||
std::string_view simconfig_string = R"(
|
||||
|
||||
Reference in New Issue
Block a user