@@ -19,22 +19,18 @@ namespace SST::RevCPU {
19
19
20
20
using MemSegment = RevMem::MemSegment;
21
21
22
- const char splash_msg[] = " \
23
- \n \
24
- ******* \n \
25
- /**////** \n \
26
- /** /** ***** ** **\n \
27
- /******* **///**/** /**\n \
28
- /**///** /*******//** /** \n \
29
- /** //** /**//// //**** \n \
30
- /** //**//****** //** \n \
31
- // // ////// // \n \
32
- \n \
33
- " ;
34
-
35
- RevCPU::RevCPU ( SST::ComponentId_t id, const SST::Params& params )
36
- : SST::Component( id ), PrivTag( 0 ), address( -1 ), EnableMemH( false ), DisableCoprocClock( false ), Nic( nullptr ),
37
- Ctrl ( nullptr ), ClockHandler( nullptr ) {
22
+ const char splash_msg[] = R"(
23
+ *******
24
+ /**////**
25
+ /** /** ***** ** **
26
+ /******* **///**/** /**
27
+ /**///** /*******//** /**
28
+ /** //** /**//// //****
29
+ /** //**//****** //**
30
+ // // ////// //
31
+ )" ;
32
+
33
+ RevCPU::RevCPU ( SST::ComponentId_t id, const SST::Params& params ) : SST::Component( id ) {
38
34
39
35
const int Verbosity = params.find <int >( " verbose" , 0 );
40
36
@@ -52,12 +48,12 @@ RevCPU::RevCPU( SST::ComponentId_t id, const SST::Params& params )
52
48
53
49
// Derive the simulation parameters
54
50
// We must always derive the number of cores before initializing the options
55
- numCores = params.find <unsigned >( " numCores" , " 1" );
56
- numHarts = params.find <uint16_t >( " numHarts" , " 1" );
51
+ numCores = params.find <uint32_t >( " numCores" , " 1" );
52
+ numHarts = params.find <uint32_t >( " numHarts" , " 1" );
57
53
58
- // Make sure someone isn't trying to have more than 65536 harts per core
54
+ // Make sure someone isn't trying to have more than _MAX_HARTS_ harts per core
59
55
if ( numHarts > _MAX_HARTS_ ) {
60
- output.fatal ( CALL_INFO, -1 , " Error: number of harts must be <= %" PRIu32 " \n " , _MAX_HARTS_ );
56
+ output.fatal ( CALL_INFO, -1 , " Error: number of harts must be <= %" PRIu32 " \n " , uint32_t { _MAX_HARTS_ } );
61
57
}
62
58
output.verbose (
63
59
CALL_INFO, 1 , 0 , " Building Rev with %" PRIu32 " cores and %" PRIu32 " hart(s) on each core \n " , numCores, numHarts
@@ -67,9 +63,7 @@ RevCPU::RevCPU( SST::ComponentId_t id, const SST::Params& params )
67
63
auto Exe = params.find <std::string>( " program" , " a.out" );
68
64
69
65
// Create the options object
70
- Opts = new ( std::nothrow ) RevOpts ( numCores, numHarts, Verbosity );
71
- if ( !Opts )
72
- output.fatal ( CALL_INFO, -1 , " Error: failed to initialize the RevOpts object\n " );
66
+ Opts = std::make_unique<RevOpts>( numCores, numHarts, Verbosity );
73
67
74
68
// Program arguments
75
69
Opts->SetArgs ( params );
@@ -85,7 +79,7 @@ RevCPU::RevCPU( SST::ComponentId_t id, const SST::Params& params )
85
79
} ) {
86
80
std::vector<std::string> optList;
87
81
params.find_array ( ParamName, optList );
88
- if ( !( Opts->*InitFunc )( optList ) )
82
+ if ( !( Opts. get () ->*InitFunc )( optList ) )
89
83
output.fatal ( CALL_INFO, -1 , " Error: failed to initialize %s\n " , ParamName );
90
84
}
91
85
@@ -125,28 +119,15 @@ RevCPU::RevCPU( SST::ComponentId_t id, const SST::Params& params )
125
119
const uint64_t memSize = params.find <unsigned long >( " memSize" , 1073741824 );
126
120
EnableMemH = params.find <bool >( " enable_memH" , 0 );
127
121
if ( !EnableMemH ) {
128
- // TODO: Use std::nothrow to return null instead of throwing std::bad_alloc
129
- Mem = new RevMem ( memSize, Opts, &output );
130
- if ( !Mem )
131
- output.fatal ( CALL_INFO, -1 , " Error: failed to initialize the memory object\n " );
122
+ Mem = std::make_unique<RevMem>( memSize, Opts.get (), &output );
132
123
} else {
133
- Ctrl = loadUserSubComponent<RevMemCtrl>( " memory" );
124
+ Ctrl = std::unique_ptr<RevMemCtrl>( loadUserSubComponent<RevMemCtrl>( " memory" ) );
134
125
if ( !Ctrl )
135
126
output.fatal ( CALL_INFO, -1 , " Error : failed to inintialize the memory controller subcomponent\n " );
136
-
137
- // TODO: Use std::nothrow to return null instead of throwing std::bad_alloc
138
- Mem = new RevMem ( memSize, Opts, Ctrl, &output );
139
- if ( !Mem )
140
- output.fatal ( CALL_INFO, -1 , " Error : failed to initialize the memory object\n " );
127
+ Mem = std::make_unique<RevMem>( memSize, Opts.get (), Ctrl.get (), &output );
141
128
142
129
if ( EnableFaults )
143
- output.verbose (
144
- CALL_INFO,
145
- 1 ,
146
- 0 ,
147
- " Warning: memory faults cannot be enabled with "
148
- " memHierarchy support\n "
149
- );
130
+ output.verbose ( CALL_INFO, 1 , 0 , " Warning: memory faults cannot be enabled with memHierarchy support\n " );
150
131
}
151
132
152
133
// Set TLB Size
@@ -158,27 +139,24 @@ RevCPU::RevCPU( SST::ComponentId_t id, const SST::Params& params )
158
139
Mem->SetMaxHeapSize ( maxHeapSize );
159
140
160
141
// Load the binary into memory
161
- Loader = new ( std::nothrow ) RevLoader ( Exe, Opts->GetArgv (), Mem, &output );
162
- if ( !Loader ) {
163
- output.fatal ( CALL_INFO, -1 , " Error: failed to initialize the RISC-V loader\n " );
164
- }
142
+ Loader = std::make_unique<RevLoader>( Exe, Opts->GetArgv (), Mem.get (), &output );
165
143
166
144
// Create the processor objects
167
145
Procs.reserve ( Procs.size () + numCores );
168
146
for ( unsigned i = 0 ; i < numCores; i++ ) {
169
- Procs.push_back ( new RevCore ( i, Opts, numHarts, Mem, Loader, this ->GetNewTID (), &output ) );
147
+ Procs.push_back ( std::make_unique< RevCore> ( i, Opts. get () , numHarts, Mem. get () , Loader. get () , this ->GetNewTID (), &output ) );
170
148
}
171
149
172
150
EnableCoProc = params.find <bool >( " enableCoProc" , 0 );
173
151
if ( EnableCoProc ) {
174
152
// Create the co-processor objects
175
153
for ( unsigned i = 0 ; i < numCores; i++ ) {
176
- RevCoProc* CoProc = loadUserSubComponent<RevCoProc>( " co_proc" , SST::ComponentInfo::SHARE_NONE, Procs[i] );
154
+ RevCoProc* CoProc = loadUserSubComponent<RevCoProc>( " co_proc" , SST::ComponentInfo::SHARE_NONE, Procs[i]. get () );
177
155
if ( !CoProc ) {
178
156
output.fatal ( CALL_INFO, -1 , " Error : failed to inintialize the co-processor subcomponent\n " );
179
157
}
180
- CoProcs.push_back ( CoProc );
181
158
Procs[i]->SetCoProc ( CoProc );
159
+ CoProcs.push_back ( std::unique_ptr<RevCoProc>( CoProc ) );
182
160
}
183
161
}
184
162
@@ -335,7 +313,7 @@ RevCPU::RevCPU( SST::ComponentId_t id, const SST::Params& params )
335
313
DisableCoprocClock = params.find <bool >( " independentCoprocClock" , 0 );
336
314
337
315
// Create the completion array
338
- Enabled = new bool [ numCores]{ false } ;
316
+ Enabled = std::vector< bool >( numCores ) ;
339
317
340
318
const unsigned Splash = params.find <bool >( " splash" , 0 );
341
319
@@ -352,32 +330,6 @@ RevCPU::RevCPU( SST::ComponentId_t id, const SST::Params& params )
352
330
}
353
331
}
354
332
355
- RevCPU::~RevCPU () {
356
- // delete the competion array
357
- delete[] Enabled;
358
-
359
- // delete the processors objects
360
- for ( size_t i = 0 ; i < Procs.size (); i++ ) {
361
- delete Procs[i];
362
- }
363
-
364
- for ( size_t i = 0 ; i < CoProcs.size (); i++ ) {
365
- delete CoProcs[i];
366
- }
367
-
368
- // delete the memory controller if present
369
- delete Ctrl;
370
-
371
- // delete the memory object
372
- delete Mem;
373
-
374
- // delete the loader object
375
- delete Loader;
376
-
377
- // delete the options object
378
- delete Opts;
379
- }
380
-
381
333
void RevCPU::DecodeFaultWidth ( const std::string& width ) {
382
334
fault_width = 1 ; // default to single bit failures
383
335
@@ -850,7 +802,7 @@ void RevCPU::HandleThreadStateChangesForProc( uint32_t ProcID ) {
850
802
}
851
803
852
804
void RevCPU::InitMainThread ( uint32_t MainThreadID, const uint64_t StartAddr ) {
853
- auto MainThreadRegState = std::make_unique<RevRegFile>( Procs[0 ] );
805
+ auto MainThreadRegState = std::make_unique<RevRegFile>( Procs[0 ]. get () );
854
806
855
807
// The Program Counter gets set to the start address
856
808
MainThreadRegState->SetPC ( StartAddr );
0 commit comments