changeset 1a46c5d58ede in /z/repo/m5
details: http://repo.m5sim.org/m5?cmd=changeset;node=1a46c5d58ede
description:
        ruby: Removed if else statement in create_system

        Based on Steve's suggestion, the ugly if-elif statement and multiple 
protocol
        module import calls are removed and replaced with exec statements using 
the
        protocol string.

diffstat:

1 file changed, 10 insertions(+), 40 deletions(-)
configs/ruby/Ruby.py |   50 ++++++++++----------------------------------------

diffs (64 lines):

diff -r 1620cffaa3b6 -r 1a46c5d58ede configs/ruby/Ruby.py
--- a/configs/ruby/Ruby.py      Fri Jan 29 20:29:33 2010 -0800
+++ b/configs/ruby/Ruby.py      Fri Jan 29 20:29:33 2010 -0800
@@ -32,50 +32,20 @@
 from m5.defines import buildEnv
 from m5.util import addToPath
 
-import MOESI_hammer
-import MESI_CMP_directory
-import MOESI_CMP_directory
-import MI_example
-import MOESI_CMP_token
+protocol = buildEnv['PROTOCOL']
+
+exec "import %s" % protocol
 
 def create_system(options, physmem, piobus = None, dma_devices = []):
 
-    protocol = buildEnv['PROTOCOL']
-
-    if protocol == "MOESI_hammer":
+    try:
         (cpu_sequencers, dir_cntrls, all_cntrls) = \
-            MOESI_hammer.create_system(options, \
-                                       physmem, \
-                                       piobus, \
-                                       dma_devices)
-    elif protocol == "MESI_CMP_directory":
-        (cpu_sequencers, dir_cntrls, all_cntrls) = \
-            MESI_CMP_directory.create_system(options, \
-                                             physmem, \
-                                             piobus, \
-                                             dma_devices)
-    elif protocol == "MOESI_CMP_directory":
-        (cpu_sequencers, dir_cntrls, all_cntrls) = \
-            MOESI_CMP_directory.create_system(options, \
-                                          physmem, \
-                                          piobus, \
-                                          dma_devices)
-    elif protocol == "MI_example":
-        (cpu_sequencers, dir_cntrls, all_cntrls) = \
-            MI_example.create_system(options, \
-                                     physmem, \
-                                     piobus, \
-                                     dma_devices)
-    elif protocol == "MOESI_CMP_token":
-        (cpu_sequencers, dir_cntrls, all_cntrls) = \
-            MOESI_CMP_token.create_system(options, \
-                                          physmem, \
-                                          piobus, \
-                                          dma_devices)
-    else:
-         print "Error: unsupported ruby protocol"
-         sys.exit(1)
-
+          eval("%s.create_system(options, physmem, piobus, dma_devices)" \
+               % protocol)
+    except:
+        print "Error: could not create sytem for ruby protocol %s" % protocol
+        sys.exit(1)
+        
     #
     # Important: the topology constructor must be called before the network
     # constructor.
_______________________________________________
m5-dev mailing list
[email protected]
http://m5sim.org/mailman/listinfo/m5-dev

Reply via email to