Deserialize std::variant without throwing exception
This commit is contained in:
@@ -37,6 +37,7 @@
|
||||
#define DRAMSYSCONFIGURATION_ADDRESSMAPPING_H
|
||||
|
||||
#include <DRAMUtils/util/json_utils.h>
|
||||
#include <DRAMUtils/util/collapsingvector.h>
|
||||
|
||||
#include <optional>
|
||||
|
||||
@@ -47,7 +48,7 @@ struct AddressMapping
|
||||
{
|
||||
static constexpr std::string_view KEY = "addressmapping";
|
||||
|
||||
using BitEntry = std::variant<unsigned int, std::vector<unsigned int>>;
|
||||
using BitEntry = DRAMUtils::util::CollapsingVector<unsigned int>;
|
||||
|
||||
std::optional<std::vector<BitEntry>> BYTE_BIT;
|
||||
std::optional<std::vector<BitEntry>> COLUMN_BIT;
|
||||
|
||||
@@ -37,7 +37,10 @@
|
||||
#define DRAMSYSCONFIGURATION_TRACESETUP_H
|
||||
|
||||
#include <DRAMUtils/util/json_utils.h>
|
||||
#include <DRAMUtils/util/id_variant.h>
|
||||
#include <DRAMUtils/util/types.h>
|
||||
|
||||
#include <string_view>
|
||||
#include <optional>
|
||||
#include <variant>
|
||||
|
||||
@@ -72,6 +75,8 @@ NLOHMANN_JSON_SERIALIZE_ENUM(AddressDistribution,
|
||||
|
||||
struct TracePlayer
|
||||
{
|
||||
static constexpr inline const std::string_view id = "player";
|
||||
|
||||
uint64_t clkMhz{};
|
||||
std::string name;
|
||||
std::optional<unsigned int> maxPendingReadRequests;
|
||||
@@ -122,6 +127,8 @@ NLOHMANN_JSONIFY_ALL_THINGS(TrafficGeneratorStateTransition, from, to, probabili
|
||||
|
||||
struct TrafficGenerator
|
||||
{
|
||||
static constexpr inline const std::string_view id = "generator";
|
||||
|
||||
uint64_t clkMhz{};
|
||||
std::string name;
|
||||
std::optional<unsigned int> maxPendingReadRequests;
|
||||
@@ -158,6 +165,8 @@ NLOHMANN_JSONIFY_ALL_THINGS(TrafficGenerator,
|
||||
|
||||
struct TrafficGeneratorStateMachine
|
||||
{
|
||||
static constexpr inline const std::string_view id = "statemachine";
|
||||
|
||||
uint64_t clkMhz{};
|
||||
std::string name;
|
||||
std::optional<unsigned int> maxPendingReadRequests;
|
||||
@@ -185,6 +194,8 @@ NLOHMANN_JSONIFY_ALL_THINGS(TrafficGeneratorStateMachine,
|
||||
|
||||
struct RowHammer
|
||||
{
|
||||
static constexpr inline const std::string_view id = "rowhammer";
|
||||
|
||||
uint64_t clkMhz{};
|
||||
std::string name;
|
||||
std::optional<unsigned int> maxPendingReadRequests;
|
||||
@@ -207,8 +218,14 @@ struct TraceSetupConstants
|
||||
static constexpr std::string_view KEY = "tracesetup";
|
||||
};
|
||||
|
||||
using Initiator =
|
||||
std::variant<TracePlayer, TrafficGenerator, TrafficGeneratorStateMachine, RowHammer>;
|
||||
using InitiatorTypes = DRAMUtils::util::type_sequence<
|
||||
TracePlayer,
|
||||
TrafficGenerator,
|
||||
TrafficGeneratorStateMachine,
|
||||
RowHammer
|
||||
>;
|
||||
|
||||
DRAMUTILS_DECLARE_IDVARIANT(Initiator, "type", InitiatorTypes)
|
||||
|
||||
} // namespace DRAMSys::Config
|
||||
|
||||
|
||||
@@ -37,6 +37,7 @@
|
||||
*/
|
||||
|
||||
#include "AddressDecoder.h"
|
||||
#include "DRAMSys/config/AddressMapping.h"
|
||||
|
||||
#include <bitset>
|
||||
#include <cmath>
|
||||
@@ -50,23 +51,14 @@ static void addMapping(std::vector<Config::AddressMapping::BitEntry> const& mapp
|
||||
std::vector<unsigned>& bitVector,
|
||||
std::vector<std::vector<unsigned>>& xorVector)
|
||||
{
|
||||
for (const auto& bitEntry : mappingVector)
|
||||
for (const Config::AddressMapping::BitEntry& bitEntry : mappingVector)
|
||||
{
|
||||
std::visit(
|
||||
[&bitVector, &xorVector](auto&& arg)
|
||||
{
|
||||
using T = std::decay_t<decltype(arg)>;
|
||||
if constexpr (std::is_same_v<T, unsigned>)
|
||||
{
|
||||
bitVector.push_back(arg);
|
||||
}
|
||||
else if constexpr (std::is_same_v<T, std::vector<unsigned>>)
|
||||
{
|
||||
bitVector.push_back(arg.at(0));
|
||||
xorVector.push_back(arg);
|
||||
}
|
||||
},
|
||||
bitEntry);
|
||||
if (bitEntry.get_type() == Config::AddressMapping::BitEntry::Type::SINGLE) {
|
||||
bitVector.push_back(bitEntry.at(0));
|
||||
} else {
|
||||
bitVector.push_back(bitEntry.at(0));
|
||||
xorVector.push_back(bitEntry);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -148,7 +148,7 @@ Simulator::instantiateInitiator(const DRAMSys::Config::Initiator& initiator)
|
||||
std::move(hammer));
|
||||
}
|
||||
},
|
||||
initiator);
|
||||
initiator.getVariant());
|
||||
}
|
||||
|
||||
void Simulator::run()
|
||||
|
||||
Reference in New Issue
Block a user