Use smart pointers in main.
This commit is contained in:
@@ -45,7 +45,7 @@ using namespace tlm;
|
||||
|
||||
TraceSetup::TraceSetup(const std::string &uri,
|
||||
const std::string &pathToResources,
|
||||
std::vector<TrafficInitiator *> &players)
|
||||
std::vector<std::unique_ptr<TrafficInitiator>> &players)
|
||||
{
|
||||
// Load Simulation:
|
||||
nlohmann::json simulationdoc = parseJSON(uri);
|
||||
@@ -126,9 +126,8 @@ TraceSetup::TraceSetup(const std::string &uri,
|
||||
else
|
||||
throw std::runtime_error("Unsupported file extension in " + name);
|
||||
|
||||
players.push_back(player);
|
||||
|
||||
totalTransactions += player->getNumberOfLines();
|
||||
players.push_back(std::unique_ptr<TrafficInitiator>(player));
|
||||
}
|
||||
else if (type == "generator")
|
||||
{
|
||||
@@ -187,8 +186,6 @@ TraceSetup::TraceSetup(const std::string &uri,
|
||||
if (maxAddress < minAddress)
|
||||
SC_REPORT_FATAL("TraceSetup", "maxAddress is smaller than minAddress.");
|
||||
|
||||
TrafficInitiator* generator;
|
||||
|
||||
if (addressDistribution == "sequential")
|
||||
{
|
||||
uint64_t addressIncrement = 0x0;
|
||||
@@ -197,21 +194,17 @@ TraceSetup::TraceSetup(const std::string &uri,
|
||||
else
|
||||
addressIncrement = value["addressIncrement"];
|
||||
|
||||
generator = new TrafficGeneratorSequential(name.c_str(), playerClk, numRequests,
|
||||
maxPendingReadRequests, maxPendingWriteRequests,
|
||||
needsLengthConverter, minAddress, maxAddress, rwRatio,
|
||||
addressIncrement, seed, this);
|
||||
players.push_back(std::unique_ptr<TrafficInitiator>(new TrafficGeneratorSequential(name.c_str(),
|
||||
playerClk, numRequests, maxPendingReadRequests, maxPendingWriteRequests,
|
||||
needsLengthConverter, minAddress, maxAddress, rwRatio, addressIncrement, seed, this)));
|
||||
}
|
||||
else
|
||||
{
|
||||
generator = new TrafficGeneratorRandom(name.c_str(), playerClk, numRequests,
|
||||
maxPendingReadRequests, maxPendingWriteRequests,
|
||||
needsLengthConverter, minAddress, maxAddress, rwRatio,
|
||||
seed, this);
|
||||
players.push_back(std::unique_ptr<TrafficInitiator>(new TrafficGeneratorRandom(name.c_str(),
|
||||
playerClk, numRequests, maxPendingReadRequests, maxPendingWriteRequests,
|
||||
needsLengthConverter, minAddress, maxAddress, rwRatio, seed, this)));
|
||||
}
|
||||
|
||||
players.push_back(generator);
|
||||
|
||||
totalTransactions += numRequests;
|
||||
}
|
||||
else if (type == "hammer")
|
||||
@@ -224,9 +217,8 @@ TraceSetup::TraceSetup(const std::string &uri,
|
||||
SC_REPORT_FATAL("TraceSetup", "Row increment is not a number.");
|
||||
uint64_t rowIncrement = value["rowIncrement"];
|
||||
|
||||
TrafficInitiator* generator = new TrafficGeneratorHammer(name.c_str(), playerClk, numRequests,
|
||||
rowIncrement, this);
|
||||
players.push_back(generator);
|
||||
players.push_back(std::unique_ptr<TrafficInitiator>(new TrafficGeneratorHammer(name.c_str(), playerClk,
|
||||
numRequests, rowIncrement, this)));
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
@@ -39,6 +39,7 @@
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <memory>
|
||||
|
||||
#include <tlm>
|
||||
#include "MemoryManager.h"
|
||||
@@ -50,7 +51,7 @@ class TraceSetup
|
||||
public:
|
||||
TraceSetup(const std::string &uri,
|
||||
const std::string &pathToResources,
|
||||
std::vector<TrafficInitiator *> &devices);
|
||||
std::vector<std::unique_ptr<TrafficInitiator>> &devices);
|
||||
|
||||
void trafficInitiatorTerminates();
|
||||
void transactionFinished();
|
||||
|
||||
@@ -42,6 +42,7 @@
|
||||
#include <vector>
|
||||
#include <list>
|
||||
#include <chrono>
|
||||
#include <memory>
|
||||
|
||||
#include <systemc>
|
||||
#include "simulation/DRAMSys.h"
|
||||
@@ -97,24 +98,24 @@ int sc_main(int argc, char **argv)
|
||||
resources = argv[2];
|
||||
}
|
||||
|
||||
std::vector<TrafficInitiator *> players;
|
||||
std::vector<std::unique_ptr<TrafficInitiator>> players;
|
||||
std::list<LengthConverter> lengthConverters;
|
||||
|
||||
// Instantiate DRAMSys:
|
||||
DRAMSys *dramSys;
|
||||
std::unique_ptr<DRAMSys> dramSys;
|
||||
#ifdef RECORDING
|
||||
json simulationdoc = parseJSON(simulationJson);
|
||||
json simulatordoc = parseJSON(resources + "configs/simulator/"
|
||||
+ std::string(simulationdoc["simulation"]["simconfig"]));
|
||||
|
||||
if (simulatordoc["simconfig"]["DatabaseRecording"])
|
||||
dramSys = new DRAMSysRecordable("DRAMSys", simulationJson, resources);
|
||||
dramSys = std::unique_ptr<DRAMSys>(new DRAMSysRecordable("DRAMSys", simulationJson, resources));
|
||||
else
|
||||
#endif
|
||||
dramSys = new DRAMSys("DRAMSys", simulationJson, resources);
|
||||
dramSys = std::unique_ptr<DRAMSys>(new DRAMSys("DRAMSys", simulationJson, resources));
|
||||
|
||||
// Instantiate STL Players:
|
||||
TraceSetup *setup = new TraceSetup(simulationJson, resources, players);
|
||||
TraceSetup setup(simulationJson, resources, players);
|
||||
|
||||
// Bind STL Players with DRAMSys:
|
||||
for (size_t i = 0; i < players.size(); i++)
|
||||
@@ -122,8 +123,8 @@ int sc_main(int argc, char **argv)
|
||||
if (Configuration::getInstance().checkTLM2Protocol)
|
||||
{
|
||||
std::string str = "TLMCheckerPlayer" + std::to_string(i);
|
||||
tlm_utils::tlm2_base_protocol_checker<> *playerTlmChecker =
|
||||
new tlm_utils::tlm2_base_protocol_checker<>(("TLMCheckerPlayer" + std::to_string(i)).c_str());
|
||||
auto* playerTlmChecker =
|
||||
new tlm_utils::tlm2_base_protocol_checker<>(("TLMCheckerPlayer" + std::to_string(i)).c_str());
|
||||
dramSys->playersTlmCheckers.push_back(playerTlmChecker);
|
||||
if (players[i]->needsLengthConverter())
|
||||
{
|
||||
@@ -168,11 +169,5 @@ int sc_main(int argc, char **argv)
|
||||
auto finish = std::chrono::high_resolution_clock::now();
|
||||
std::chrono::duration<double> elapsed = finish - start;
|
||||
std::cout << "Simulation took " + std::to_string(elapsed.count()) + " seconds." << std::endl;
|
||||
|
||||
delete dramSys;
|
||||
for (auto player : players)
|
||||
delete player;
|
||||
delete setup;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user