@@ -76,18 +76,19 @@ private async void StartSimulation(object sender, RoutedEventArgs e)
7676 try
7777 {
7878 var size = Int32 . Parse ( cacheSize . Text ) ;
79- var lineSize = Int32 . Parse ( cacheLineSize . Text ) ;
8079
81- var associativity = GetCacheAssociativity ( size , lineSize ) ;
80+ var associativity = GetCacheAssociativity ( size , GetCacheLineSize ( ) ) ;
8281 var numberOfCores = GetNumberOfCores ( ) ;
8382
8483 if ( numberOfCores > 128 )
8584 {
8685 numberOfCores = 128 ;
8786 }
8887
89- cpu = new CPU ( ( ramFileFullPath , size , associativity , lineSize ,
90- GetWritePolicy ( cacheWriteHitPolicyComboBox . Text ) , GetWritePolicy ( cacheWriteMissPolicyComboBox . Text ) , GetReplacementPolicy ( cacheReplacementPolicyComboBox . Text ) ) , numberOfCores ) ;
88+ // Build cache config information.
89+ var cacheConfigBuilder = GetCacheConfigBuilder ( ) ;
90+
91+ cpu = new CPU ( ( ramFileFullPath , size , associativity ) , cacheConfigBuilder . Build ( ) , numberOfCores ) ;
9192
9293 logLines . Append ( $ "Simulation { numberOfSimulation ++ } \n ") ;
9394
@@ -207,6 +208,18 @@ private async void StartSimulation(object sender, RoutedEventArgs e)
207208 EnableWindowComponents ( true ) ;
208209 }
209210
211+
212+ private CacheConfigurationBuilder GetCacheConfigBuilder ( )
213+ {
214+ var cacheConfigBuilder = new CacheConfigurationBuilder ( ) ;
215+ cacheConfigBuilder . Size ( GetCacheLineSize ( ) ) ;
216+ cacheConfigBuilder . WriteHitPolicy ( GetWritePolicy ( cacheWriteHitPolicyComboBox . Text ) ) ;
217+ cacheConfigBuilder . WriteMissPolicy ( GetWritePolicy ( cacheWriteMissPolicyComboBox . Text ) ) ;
218+ cacheConfigBuilder . ReplacementPolicy ( GetReplacementPolicy ( cacheReplacementPolicyComboBox . Text ) ) ;
219+
220+ return cacheConfigBuilder ;
221+ }
222+
210223 private void StopSimulation ( object sender , RoutedEventArgs e )
211224 {
212225 if ( ! isRunning || isCancelRequested )
@@ -218,6 +231,11 @@ private void StopSimulation(object sender, RoutedEventArgs e)
218231 source . Cancel ( ) ;
219232 }
220233
234+ private int GetCacheLineSize ( )
235+ {
236+ return Int32 . Parse ( cacheLineSize . Text ) ;
237+ }
238+
221239 private int GetCacheAssociativity ( int cacheSize , int lineSize )
222240 {
223241 return cacheAssociativityComboBox . Text switch
0 commit comments