[Avida-SVN] r1329 - in development: Avida.xcodeproj source/cpu source/tools

brysonda at myxo.css.msu.edu brysonda at myxo.css.msu.edu
Sat Feb 17 17:22:10 PST 2007


Author: brysonda
Date: 2007-02-17 20:22:10 -0500 (Sat, 17 Feb 2007)
New Revision: 1329

Added:
   development/source/cpu/cInstLib.h
   development/source/cpu/cInstLibEntry.h
Removed:
   development/source/cpu/cInstLibBase.h
Modified:
   development/Avida.xcodeproj/project.pbxproj
   development/source/cpu/SConscript
   development/source/cpu/cHardwareCPU.cc
   development/source/cpu/cHardwareCPU.h
   development/source/cpu/cHardwareExperimental.cc
   development/source/cpu/cHardwareExperimental.h
   development/source/cpu/cHardwareManager.cc
   development/source/cpu/cHardwareSMT.cc
   development/source/cpu/cHardwareSMT.h
   development/source/cpu/cHardwareTransSMT.cc
   development/source/cpu/cHardwareTransSMT.h
   development/source/cpu/cInstSet.h
   development/source/cpu/tInstLib.h
   development/source/cpu/tInstLibEntry.h
   development/source/tools/tDictionary.h
Log:
Modify InstLib classes to directly use the tInstLibEntry arrays built in the hardware classes.  Accessors in cInstLib now provide access to all of the extra information provided by the InstLib entries.   cInstLib now uses a dictionary internally for all name lookups.

Modified: development/Avida.xcodeproj/project.pbxproj
===================================================================
--- development/Avida.xcodeproj/project.pbxproj	2007-02-17 21:03:30 UTC (rev 1328)
+++ development/Avida.xcodeproj/project.pbxproj	2007-02-18 01:22:10 UTC (rev 1329)
@@ -62,6 +62,7 @@
 		704ADBC60A6EEFC300666970 /* DriverActions.cc in Sources */ = {isa = PBXBuildFile; fileRef = 704ADBC40A6EEFC300666970 /* DriverActions.cc */; };
 		704ADBC80A6EEFC300666970 /* DriverActions.cc in Sources */ = {isa = PBXBuildFile; fileRef = 704ADBC40A6EEFC300666970 /* DriverActions.cc */; };
 		704ADBF90A6EF3A300666970 /* DriverActions.cc in Sources */ = {isa = PBXBuildFile; fileRef = 704ADBC40A6EEFC300666970 /* DriverActions.cc */; };
+		705260BC0B87A7DB0007426F /* cInstLibEntry.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 705260BB0B87A7DB0007426F /* cInstLibEntry.h */; };
 		7053324C0929764C006BD186 /* cSpecies.cc in Sources */ = {isa = PBXBuildFile; fileRef = 705332480929764A006BD186 /* cSpecies.cc */; };
 		7053324D0929764E006BD186 /* cSpeciesQueue.cc in Sources */ = {isa = PBXBuildFile; fileRef = 7053324A0929764A006BD186 /* cSpeciesQueue.cc */; };
 		7053336D092A3DF9006BD186 /* cInjectGenotype.cc in Sources */ = {isa = PBXBuildFile; fileRef = 70533364092A3DF4006BD186 /* cInjectGenotype.cc */; };
@@ -425,6 +426,7 @@
 				7049F3730A66AD7E00640512 /* default-transsmt.org in CopyFiles */,
 				70B1A7430B7E3FFD00067486 /* instset-experimental.cfg in CopyFiles */,
 				70B1A75A0B7E431F00067486 /* experimental.org in CopyFiles */,
+				705260BC0B87A7DB0007426F /* cInstLibEntry.h in CopyFiles */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
@@ -451,7 +453,7 @@
 		700E12610A097A0800B604CD /* CMakeLists.txt */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = text; path = CMakeLists.txt; sourceTree = "<group>"; };
 		700E12630A097A1700B604CD /* CMakeLists.txt */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = text; path = CMakeLists.txt; sourceTree = "<group>"; };
 		700E28CF0859FFD700CF158A /* tObjectFactory.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = tObjectFactory.h; sourceTree = "<group>"; };
-		700E2B83085DE50C00CF158A /* avida-viewer */ = {isa = PBXFileReference; includeInIndex = 0; lastKnownFileType = "compiled.mach-o.executable"; path = "avida-viewer"; sourceTree = BUILT_PRODUCTS_DIR; };
+		700E2B83085DE50C00CF158A /* avida-viewer */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = "avida-viewer"; sourceTree = BUILT_PRODUCTS_DIR; };
 		7013845F09028B3E0087ED2E /* cAvidaConfig.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = cAvidaConfig.h; sourceTree = "<group>"; };
 		7013846009028B3E0087ED2E /* cAvidaConfig.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = cAvidaConfig.cc; sourceTree = "<group>"; };
 		701384A10902A16F0087ED2E /* defs.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = defs.h; sourceTree = "<group>"; };
@@ -516,6 +518,8 @@
 		704ADBC30A6EEFC300666970 /* DriverActions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DriverActions.h; sourceTree = "<group>"; };
 		704ADBC40A6EEFC300666970 /* DriverActions.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DriverActions.cc; sourceTree = "<group>"; };
 		704D57210AA53F8600207FC1 /* code_standards.html */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = text.html.documentation; path = code_standards.html; sourceTree = "<group>"; };
+		705260BB0B87A7DB0007426F /* cInstLibEntry.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = cInstLibEntry.h; sourceTree = "<group>"; };
+		705261050B87AF5C0007426F /* cInstLib.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = cInstLib.h; sourceTree = "<group>"; };
 		705332480929764A006BD186 /* cSpecies.cc */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = cSpecies.cc; sourceTree = "<group>"; };
 		705332490929764A006BD186 /* cSpecies.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = cSpecies.h; sourceTree = "<group>"; };
 		7053324A0929764A006BD186 /* cSpeciesQueue.cc */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = cSpeciesQueue.cc; sourceTree = "<group>"; };
@@ -550,7 +554,6 @@
 		705ACD4D0A13FED4002D5BA0 /* PrintActions.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PrintActions.cc; sourceTree = "<group>"; };
 		70658C59085DF67D00486BED /* libncurses.5.4.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libncurses.5.4.dylib; path = /usr/lib/libncurses.5.4.dylib; sourceTree = "<absolute>"; };
 		706C6F480B83E69D003174C1 /* cSaleItem.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = cSaleItem.h; sourceTree = "<group>"; };
-		706C6FD40B83EF96003174C1 /* cInstLibBase.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = cInstLibBase.h; sourceTree = "<group>"; };
 		706C6FFD0B83F254003174C1 /* cInstSet.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = cInstSet.h; sourceTree = "<group>"; };
 		706C6FFE0B83F265003174C1 /* cInstSet.cc */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = cInstSet.cc; sourceTree = "<group>"; };
 		706C703E0B83FB95003174C1 /* tInstLibEntry.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = tInstLibEntry.h; sourceTree = "<group>"; };
@@ -1380,10 +1383,10 @@
 		DCC30F7C0762539D008F7A48 /* cpu */ = {
 			isa = PBXGroup;
 			children = (
+				705261050B87AF5C0007426F /* cInstLib.h */,
 				706C703E0B83FB95003174C1 /* tInstLibEntry.h */,
 				706C6FFE0B83F265003174C1 /* cInstSet.cc */,
 				706C6FFD0B83F254003174C1 /* cInstSet.h */,
-				706C6FD40B83EF96003174C1 /* cInstLibBase.h */,
 				70B1A6530B7E238F00067486 /* cHardwareExperimental.h */,
 				70B1A64F0B7E237F00067486 /* cHardwareExperimental.cc */,
 				7049F2D70A66859300640512 /* cHardwareTransSMT.cc */,
@@ -1418,6 +1421,7 @@
 				DCC30FA90762539D008F7A48 /* CMakeLists.txt */,
 				7005A70109BA0FA90007E16E /* cTestCPUInterface.h */,
 				7005A70209BA0FA90007E16E /* cTestCPUInterface.cc */,
+				705260BB0B87A7DB0007426F /* cInstLibEntry.h */,
 			);
 			path = cpu;
 			sourceTree = "<group>";

Modified: development/source/cpu/SConscript
===================================================================
--- development/source/cpu/SConscript	2007-02-17 21:03:30 UTC (rev 1328)
+++ development/source/cpu/SConscript	2007-02-18 01:22:10 UTC (rev 1329)
@@ -17,7 +17,7 @@
   'cHardwareTracer.h',
   'cHardwareTrans.h',
   'cHeadCPU.h',
-  'cInstLibBase.h',
+  'cInstLib.h',
   'cInstSet.h',
   'cTestCPU.h',
   'cTestCPUInterface.h',

Modified: development/source/cpu/cHardwareCPU.cc
===================================================================
--- development/source/cpu/cHardwareCPU.cc	2007-02-17 21:03:30 UTC (rev 1328)
+++ development/source/cpu/cHardwareCPU.cc	2007-02-18 01:22:10 UTC (rev 1329)
@@ -73,9 +73,9 @@
      in the same order in tInstLibEntry<tMethod> s_f_array, and these entries must
      be the first elements of s_f_array.
      */
-    tInstLibEntry<tMethod>("nop-A", &cHardwareCPU::Inst_Nop, (nInstFlag::DEFAULT & nInstFlag::NOP), "No-operation instruction; modifies other instructions"),
-    tInstLibEntry<tMethod>("nop-B", &cHardwareCPU::Inst_Nop, (nInstFlag::DEFAULT & nInstFlag::NOP), "No-operation instruction; modifies other instructions"),
-    tInstLibEntry<tMethod>("nop-C", &cHardwareCPU::Inst_Nop, (nInstFlag::DEFAULT & nInstFlag::NOP), "No-operation instruction; modifies other instructions"),
+    tInstLibEntry<tMethod>("nop-A", &cHardwareCPU::Inst_Nop, (nInstFlag::DEFAULT | nInstFlag::NOP), "No-operation instruction; modifies other instructions"),
+    tInstLibEntry<tMethod>("nop-B", &cHardwareCPU::Inst_Nop, (nInstFlag::DEFAULT | nInstFlag::NOP), "No-operation instruction; modifies other instructions"),
+    tInstLibEntry<tMethod>("nop-C", &cHardwareCPU::Inst_Nop, (nInstFlag::DEFAULT | nInstFlag::NOP), "No-operation instruction; modifies other instructions"),
     
     tInstLibEntry<tMethod>("NULL", &cHardwareCPU::Inst_Nop, 0, "True no-operation instruction: does nothing"),
     tInstLibEntry<tMethod>("nop-X", &cHardwareCPU::Inst_Nop, 0, "True no-operation instruction: does nothing"),
@@ -337,17 +337,13 @@
   }
   
   const int f_size = sizeof(s_f_array)/sizeof(tInstLibEntry<tMethod>);
-  static cString f_names[f_size];
   static tMethod functions[f_size];
-  for (int i = 0; i < f_size; i++){
-    f_names[i] = s_f_array[i].name;
-    functions[i] = s_f_array[i].function;
-  }
+  for (int i = 0; i < f_size; i++) functions[i] = s_f_array[i].GetFunction();
 
 	const cInstruction error(255);
 	const cInstruction def(0);
   
-  return new tInstLib<tMethod>(n_size, f_size, n_names, f_names, nop_mods, functions, error, def);
+  return new tInstLib<tMethod>(f_size, s_f_array, n_names, nop_mods, functions, error, def);
 }
 
 cHardwareCPU::cHardwareCPU(cWorld* world, cOrganism* in_organism, cInstSet* in_m_inst_set)

Modified: development/source/cpu/cHardwareCPU.h
===================================================================
--- development/source/cpu/cHardwareCPU.h	2007-02-17 21:03:30 UTC (rev 1328)
+++ development/source/cpu/cHardwareCPU.h	2007-02-18 01:22:10 UTC (rev 1329)
@@ -72,7 +72,7 @@
  **/
 
 class cInjectGenotype;
-class cInstLibBase;
+class cInstLib;
 class cInstSet;
 class cMutation;
 class cOrganism;
@@ -124,7 +124,7 @@
 
 
   // --------  Member Variables  --------
-  tMethod* m_functions;
+  const tMethod* m_functions;
 
   cCPUMemory m_memory;          // Memory...
   cCPUStack m_global_stack;     // A stack that all threads share.

Modified: development/source/cpu/cHardwareExperimental.cc
===================================================================
--- development/source/cpu/cHardwareExperimental.cc	2007-02-17 21:03:30 UTC (rev 1328)
+++ development/source/cpu/cHardwareExperimental.cc	2007-02-18 01:22:10 UTC (rev 1329)
@@ -76,12 +76,12 @@
      in the same order in tInstLibEntry<tMethod> s_f_array, and these entries must
      be the first elements of s_f_array.
      */
-    tInstLibEntry<tMethod>("nop-A", &cHardwareExperimental::Inst_Nop, (nInstFlag::DEFAULT & nInstFlag::NOP), "No-operation instruction; modifies other instructions"),
-    tInstLibEntry<tMethod>("nop-B", &cHardwareExperimental::Inst_Nop, (nInstFlag::DEFAULT & nInstFlag::NOP), "No-operation instruction; modifies other instructions"),
-    tInstLibEntry<tMethod>("nop-C", &cHardwareExperimental::Inst_Nop, (nInstFlag::DEFAULT & nInstFlag::NOP), "No-operation instruction; modifies other instructions"),
-    tInstLibEntry<tMethod>("nop-D", &cHardwareExperimental::Inst_Nop, (nInstFlag::DEFAULT & nInstFlag::NOP), "No-operation instruction; modifies other instructions"),
-    tInstLibEntry<tMethod>("nop-E", &cHardwareExperimental::Inst_Nop, (nInstFlag::DEFAULT & nInstFlag::NOP), "No-operation instruction; modifies other instructions"),
-    tInstLibEntry<tMethod>("nop-F", &cHardwareExperimental::Inst_Nop, (nInstFlag::DEFAULT & nInstFlag::NOP), "No-operation instruction; modifies other instructions"),
+    tInstLibEntry<tMethod>("nop-A", &cHardwareExperimental::Inst_Nop, (nInstFlag::DEFAULT | nInstFlag::NOP), "No-operation instruction; modifies other instructions"),
+    tInstLibEntry<tMethod>("nop-B", &cHardwareExperimental::Inst_Nop, (nInstFlag::DEFAULT | nInstFlag::NOP), "No-operation instruction; modifies other instructions"),
+    tInstLibEntry<tMethod>("nop-C", &cHardwareExperimental::Inst_Nop, (nInstFlag::DEFAULT | nInstFlag::NOP), "No-operation instruction; modifies other instructions"),
+    tInstLibEntry<tMethod>("nop-D", &cHardwareExperimental::Inst_Nop, (nInstFlag::DEFAULT | nInstFlag::NOP), "No-operation instruction; modifies other instructions"),
+    tInstLibEntry<tMethod>("nop-E", &cHardwareExperimental::Inst_Nop, 0, "No-operation instruction; modifies other instructions"),
+    tInstLibEntry<tMethod>("nop-F", &cHardwareExperimental::Inst_Nop, 0, "No-operation instruction; modifies other instructions"),
     
     tInstLibEntry<tMethod>("NULL", &cHardwareExperimental::Inst_Nop, 0, "True no-operation instruction: does nothing"),
     tInstLibEntry<tMethod>("nop-X", &cHardwareExperimental::Inst_Nop, 0, "True no-operation instruction: does nothing"),
@@ -134,17 +134,13 @@
   }
   
   const int f_size = sizeof(s_f_array)/sizeof(tInstLibEntry<tMethod>);
-  static cString f_names[f_size];
   static tMethod functions[f_size];
-  for (int i = 0; i < f_size; i++){
-    f_names[i] = s_f_array[i].name;
-    functions[i] = s_f_array[i].function;
-  }
+  for (int i = 0; i < f_size; i++) functions[i] = s_f_array[i].GetFunction();
 
 	const cInstruction error(255);
 	const cInstruction def(0);
   
-  return new tInstLib<cHardwareExperimental::tMethod>(n_size, f_size, n_names, f_names, nop_mods, functions, error, def);
+  return new tInstLib<tMethod>(f_size, s_f_array, n_names, nop_mods, functions, error, def);
 }
 
 cHardwareExperimental::cHardwareExperimental(cWorld* world, cOrganism* in_organism, cInstSet* in_m_inst_set)

Modified: development/source/cpu/cHardwareExperimental.h
===================================================================
--- development/source/cpu/cHardwareExperimental.h	2007-02-17 21:03:30 UTC (rev 1328)
+++ development/source/cpu/cHardwareExperimental.h	2007-02-18 01:22:10 UTC (rev 1329)
@@ -71,7 +71,7 @@
  **/
 
 class cInjectGenotype;
-class cInstLibBase;
+class cInstLib;
 class cInstSet;
 class cMutation;
 class cOrganism;
@@ -122,7 +122,7 @@
 
 
   // --------  Member Variables  --------
-  tMethod* m_functions;
+  const tMethod* m_functions;
 
   cCPUMemory m_memory;          // Memory...
   cCPUStack m_global_stack;     // A stack that all threads share.

Modified: development/source/cpu/cHardwareManager.cc
===================================================================
--- development/source/cpu/cHardwareManager.cc	2007-02-17 21:03:30 UTC (rev 1328)
+++ development/source/cpu/cHardwareManager.cc	2007-02-18 01:22:10 UTC (rev 1329)
@@ -77,14 +77,7 @@
   file.Load();
   file.Compress();
   
-  tDictionary<int> nop_dict;
-  for(int i = 0; i < m_inst_set->GetInstLib()->GetNumNops(); i++)
-    nop_dict.Add(m_inst_set->GetInstLib()->GetNopName(i), i);
-  
-  tDictionary<int> inst_dict;
-  for(int i = 0; i < m_inst_set->GetInstLib()->GetSize(); i++)
-    inst_dict.Add(m_inst_set->GetInstLib()->GetName(i), i);
-  
+  const cInstLib& inst_lib = *m_inst_set->GetInstLib();
   for (int line_id = 0; line_id < file.GetNumLines(); line_id++) {
     cString cur_line = file.GetLine(line_id);
     cString inst_name = cur_line.PopWord();
@@ -105,22 +98,20 @@
     
     // Otherwise, this instruction will be in the set.
     // First, determine if it is a nop...
-    int nop_mod = -1;
-    if(nop_dict.Find(inst_name, nop_mod) == true) {
-      m_inst_set->AddNop(nop_mod, redundancy, ft_cost, cost, prob_fail, addl_time_cost);
-      continue;
-    }
+    int inst_idx = inst_lib.GetIndex(inst_name);
     
-    // Otherwise, it had better be in the main dictionary...
-    int fun_id = -1;
-    if(inst_dict.Find(inst_name, fun_id) == true){
-      m_inst_set->AddInst(fun_id, redundancy, ft_cost, cost, prob_fail, addl_time_cost);
-      continue;
+    if (inst_idx == -1) {
+      // Oh oh!  Didn't find an instruction!
+      cString errorstr("Could not find instruction '");
+      errorstr += inst_name + "'\n        (Best match = '" + inst_lib.GetNearMatch(inst_name) + "').";
+      m_world->GetDriver().RaiseFatalException(1, errorstr);
     }
     
-    // Oh oh!  Didn't find an instruction!
-    m_world->GetDriver().RaiseFatalException(1, cString("Could not find instruction '") + inst_name +
-                                             "'\n       (Best match = '" + inst_dict.NearMatch(inst_name) + "').");
+    if (inst_lib[inst_idx].IsNop()) {
+      m_inst_set->AddNop(inst_idx, redundancy, ft_cost, cost, prob_fail, addl_time_cost);
+    } else {
+      m_inst_set->AddInst(inst_idx, redundancy, ft_cost, cost, prob_fail, addl_time_cost);
+    }
   }
 }
 

Modified: development/source/cpu/cHardwareSMT.cc
===================================================================
--- development/source/cpu/cHardwareSMT.cc	2007-02-17 21:03:30 UTC (rev 1328)
+++ development/source/cpu/cHardwareSMT.cc	2007-02-18 01:22:10 UTC (rev 1329)
@@ -26,7 +26,7 @@
 
 #include "cAvidaContext.h"
 #include "cCPUTestInfo.h"
-#include "cInstLibBase.h"
+#include "cInstLib.h"
 #include "cInstSet.h"
 #include "cHardwareTracer.h"
 #include "cMutation.h"
@@ -62,10 +62,10 @@
   };
 	
   static const tInstLibEntry<tMethod> s_f_array[] = {
-    tInstLibEntry<tMethod>("Nop-A", &cHardwareSMT::Inst_Nop),
-    tInstLibEntry<tMethod>("Nop-B", &cHardwareSMT::Inst_Nop),
-    tInstLibEntry<tMethod>("Nop-C", &cHardwareSMT::Inst_Nop),
-    tInstLibEntry<tMethod>("Nop-D", &cHardwareSMT::Inst_Nop),
+    tInstLibEntry<tMethod>("Nop-A", &cHardwareSMT::Inst_Nop, nInstFlag::NOP),
+    tInstLibEntry<tMethod>("Nop-B", &cHardwareSMT::Inst_Nop, nInstFlag::NOP),
+    tInstLibEntry<tMethod>("Nop-C", &cHardwareSMT::Inst_Nop, nInstFlag::NOP),
+    tInstLibEntry<tMethod>("Nop-D", &cHardwareSMT::Inst_Nop, nInstFlag::NOP),
     tInstLibEntry<tMethod>("Alt", &cHardwareSMT::Inst_Alt),
     tInstLibEntry<tMethod>("Val-Shift", &cHardwareSMT::Inst_ValShift),
     tInstLibEntry<tMethod>("Val-Nand", &cHardwareSMT::Inst_ValNand),
@@ -124,20 +124,13 @@
   }
 	
   const int f_size = sizeof(s_f_array)/sizeof(tInstLibEntry<tMethod>);
-  static cString f_names[f_size];
   static tMethod functions[f_size];
-  for (int i = 0; i < f_size; i++){
-    f_names[i] = s_f_array[i].name;
-    functions[i] = s_f_array[i].function;
-  }
+  for (int i = 0; i < f_size; i++) functions[i] = s_f_array[i].GetFunction();
 	
 	const cInstruction error(255);
 	const cInstruction def(0);
 	
-  tInstLib<cHardwareSMT::tMethod>* inst_lib =
-    new tInstLib<cHardwareSMT::tMethod>(n_size, f_size, n_names, f_names, nop_mods, functions, error, def);
-	
-  return inst_lib;
+  return new tInstLib<tMethod>(f_size, s_f_array, n_names, nop_mods, functions, error, def);
 }
 
 cHardwareSMT::cHardwareSMT(cWorld* world, cOrganism* in_organism, cInstSet* in_m_inst_set)

Modified: development/source/cpu/cHardwareSMT.h
===================================================================
--- development/source/cpu/cHardwareSMT.h	2007-02-17 21:03:30 UTC (rev 1328)
+++ development/source/cpu/cHardwareSMT.h	2007-02-18 01:22:10 UTC (rev 1329)
@@ -108,7 +108,7 @@
     
 
   // --------  Member Variables  --------
-  tMethod* m_functions;
+  const tMethod* m_functions;
 
   // Stacks
   cCPUStack m_global_stacks[NUM_GLOBAL_STACKS];
@@ -207,7 +207,7 @@
 public:
   cHardwareSMT(cWorld* world, cOrganism* in_organism, cInstSet* in_inst_set);
   ~cHardwareSMT() { ; }
-  static cInstLibBase* GetInstLib() { return s_inst_slib; }
+  static cInstLib* GetInstLib() { return s_inst_slib; }
   static cString GetDefaultInstFilename() { return "instset-smt.cfg"; }
 	
   void Reset();

Modified: development/source/cpu/cHardwareTransSMT.cc
===================================================================
--- development/source/cpu/cHardwareTransSMT.cc	2007-02-17 21:03:30 UTC (rev 1328)
+++ development/source/cpu/cHardwareTransSMT.cc	2007-02-18 01:22:10 UTC (rev 1329)
@@ -26,7 +26,7 @@
 
 #include "cAvidaContext.h"
 #include "cCPUTestInfo.h"
-#include "cInstLibBase.h"
+#include "cInstLib.h"
 #include "cInstSet.h"
 #include "cHardwareTracer.h"
 #include "cMutation.h"
@@ -62,10 +62,10 @@
   };
 	
   static const tInstLibEntry<tMethod> s_f_array[] = {
-    tInstLibEntry<tMethod>("Nop-A", &cHardwareTransSMT::Inst_Nop), // 1
-    tInstLibEntry<tMethod>("Nop-B", &cHardwareTransSMT::Inst_Nop), // 2
-    tInstLibEntry<tMethod>("Nop-C", &cHardwareTransSMT::Inst_Nop), // 3
-    tInstLibEntry<tMethod>("Nop-D", &cHardwareTransSMT::Inst_Nop), // 4
+    tInstLibEntry<tMethod>("Nop-A", &cHardwareTransSMT::Inst_Nop, nInstFlag::NOP), // 1
+    tInstLibEntry<tMethod>("Nop-B", &cHardwareTransSMT::Inst_Nop, nInstFlag::NOP), // 2
+    tInstLibEntry<tMethod>("Nop-C", &cHardwareTransSMT::Inst_Nop, nInstFlag::NOP), // 3
+    tInstLibEntry<tMethod>("Nop-D", &cHardwareTransSMT::Inst_Nop, nInstFlag::NOP), // 4
     tInstLibEntry<tMethod>("Nop-X", &cHardwareTransSMT::Inst_Nop), // 5
     tInstLibEntry<tMethod>("Val-Shift-R", &cHardwareTransSMT::Inst_ShiftR), // 6
     tInstLibEntry<tMethod>("Val-Shift-L", &cHardwareTransSMT::Inst_ShiftL), // 7
@@ -123,20 +123,13 @@
   }
 	
   const int f_size = sizeof(s_f_array)/sizeof(tInstLibEntry<tMethod>);
-  static cString f_names[f_size];
   static tMethod functions[f_size];
-  for (int i = 0; i < f_size; i++){
-    f_names[i] = s_f_array[i].name;
-    functions[i] = s_f_array[i].function;
-  }
+  for (int i = 0; i < f_size; i++) functions[i] = s_f_array[i].GetFunction();
 	
 	const cInstruction error(255);
 	const cInstruction def(0);
 	
-  tInstLib<cHardwareTransSMT::tMethod>* inst_lib =
-    new tInstLib<cHardwareTransSMT::tMethod>(n_size, f_size, n_names, f_names, nop_mods, functions, error, def);
-	
-  return inst_lib;
+  return new tInstLib<tMethod>(f_size, s_f_array, n_names, nop_mods, functions, error, def);
 }
 
 cHardwareTransSMT::cHardwareTransSMT(cWorld* world, cOrganism* in_organism, cInstSet* in_m_inst_set)

Modified: development/source/cpu/cHardwareTransSMT.h
===================================================================
--- development/source/cpu/cHardwareTransSMT.h	2007-02-17 21:03:30 UTC (rev 1328)
+++ development/source/cpu/cHardwareTransSMT.h	2007-02-18 01:22:10 UTC (rev 1329)
@@ -108,7 +108,7 @@
     
 
   // --------  Member Variables  --------
-  tMethod* m_functions;
+  const tMethod* m_functions;
 
   // Stacks
   cCPUStack m_global_stacks[NUM_GLOBAL_STACKS];
@@ -206,7 +206,7 @@
 public:
   cHardwareTransSMT(cWorld* world, cOrganism* in_organism, cInstSet* in_inst_set);
   ~cHardwareTransSMT() { ; }
-  static cInstLibBase* GetInstLib() { return s_inst_slib; }
+  static cInstLib* GetInstLib() { return s_inst_slib; }
   static cString GetDefaultInstFilename() { return "instset-transsmt.cfg"; }
 	
   void Reset();

Copied: development/source/cpu/cInstLib.h (from rev 1326, development/source/cpu/cInstLibBase.h)
===================================================================
--- development/source/cpu/cInstLibBase.h	2007-02-15 16:38:07 UTC (rev 1326)
+++ development/source/cpu/cInstLib.h	2007-02-18 01:22:10 UTC (rev 1329)
@@ -0,0 +1,92 @@
+/*
+ *  cInstLib.h
+ *  Avida
+ *
+ *  Called "inst_lib_base.hh" prior to 12/5/05.
+ *  Copyright 1999-2007 Michigan State University. All rights reserved.
+ *  Copyright 1993-2003 California Institute of Technology.
+ *
+ *
+ *  This program is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU General Public License
+ *  as published by the Free Software Foundation; version 2
+ *  of the License.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ */
+
+#ifndef cInstLib_h
+#define cInstLib_h
+
+#ifndef cInstruction_h
+#include "cInstruction.h"
+#endif
+#ifndef tDictionary_h
+#include "tDictionary.h"
+#endif
+#ifndef cInstLibEntry_h
+#include "cInstLibEntry.h"
+#endif
+
+class cString;
+
+
+class cInstLib
+{
+protected:
+  const int m_size;
+  tDictionary<int> m_namemap;
+
+  const cInstruction m_inst_error;
+  const cInstruction m_inst_default;
+  
+  cInstLib(); // @not_implemented
+  
+public:
+  cInstLib(int size, const cInstruction inst_error, const cInstruction inst_default)
+    : m_size(size), m_inst_error(inst_error), m_inst_default(inst_default) { ; }
+
+  inline int GetSize() const { return m_size; }
+
+  virtual const cInstLibEntry& Get(int i) const = 0;
+  inline const cInstLibEntry& operator[](int i) const { return Get(i); }
+  inline int GetIndex(const cString& name) const;
+  inline cString GetNearMatch(const cString& name) const { return m_namemap.NearMatch(name); }
+
+  inline const cString& GetName(int entry) const { return Get(entry).GetName(); }
+  
+  virtual const cString& GetNopName(const unsigned int id) = 0;
+  virtual int GetNopMod(const unsigned int id) = 0;
+  virtual int GetNopMod(const cInstruction& inst) = 0;
+  
+  inline cInstruction GetInst(const cString& name);
+
+  const cInstruction GetInstDefault() const { return m_inst_default; }
+  const cInstruction GetInstError() const { return m_inst_error; }
+};
+
+
+inline int cInstLib::GetIndex(const cString& name) const
+{
+  int idx = -1;
+  if (m_namemap.Find(name, idx)) return idx;
+  return -1;
+}
+
+inline cInstruction cInstLib::GetInst(const cString& name)
+{
+  int idx;
+  if (m_namemap.Find(name, idx)) return cInstruction(idx);
+  return m_inst_error;
+}
+
+
+#endif

Deleted: development/source/cpu/cInstLibBase.h
===================================================================
--- development/source/cpu/cInstLibBase.h	2007-02-17 21:03:30 UTC (rev 1328)
+++ development/source/cpu/cInstLibBase.h	2007-02-18 01:22:10 UTC (rev 1329)
@@ -1,51 +0,0 @@
-/*
- *  cInstLibBase.h
- *  Avida
- *
- *  Called "inst_lib_base.hh" prior to 12/5/05.
- *  Copyright 1999-2007 Michigan State University. All rights reserved.
- *  Copyright 1993-2003 California Institute of Technology.
- *
- *
- *  This program is free software; you can redistribute it and/or
- *  modify it under the terms of the GNU General Public License
- *  as published by the Free Software Foundation; version 2
- *  of the License.
- *
- *  This program is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- *
- *  You should have received a copy of the GNU General Public License
- *  along with this program; if not, write to the Free Software
- *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- *
- */
-
-#ifndef cInstLibBase_h
-#define cInstLibBase_h
-
-#ifndef cInstruction_h
-#include "cInstruction.h"
-#endif
-
-class cString;
-
-class cInstLibBase
-{
-public:
-  cInstLibBase() { ; }
-  virtual ~cInstLibBase() { ; }
-  virtual const cString& GetName(const unsigned int id) = 0;
-  virtual const cString& GetNopName(const unsigned int id) = 0;
-  virtual int GetNopMod(const unsigned int id) = 0;
-  virtual int GetNopMod(const cInstruction& inst) = 0;
-  virtual int GetSize() = 0;
-  virtual int GetNumNops() = 0;
-  virtual cInstruction GetInst(const cString& in_name) = 0;
-  virtual const cInstruction GetInstDefault() = 0;
-  virtual const cInstruction GetInstError() = 0;
-};
-
-#endif

Added: development/source/cpu/cInstLibEntry.h
===================================================================
--- development/source/cpu/cInstLibEntry.h	2007-02-17 21:03:30 UTC (rev 1328)
+++ development/source/cpu/cInstLibEntry.h	2007-02-18 01:22:10 UTC (rev 1329)
@@ -0,0 +1,57 @@
+/*
+ *  cInstLibEntry.h
+ *  Avida
+ *
+ *  Created by David on 2/17/07.
+ *  Copyright 2007 Michigan State University. All rights reserved.
+ *
+ *
+ *  This program is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU General Public License
+ *  as published by the Free Software Foundation; version 2
+ *  of the License.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ */
+
+#ifndef cInstLibEntry_h
+#define cInstLibEntry_h
+
+
+namespace nInstFlag {
+  const unsigned int DEFAULT = 0x1;
+  const unsigned int NOP = 0x2;
+  const unsigned int LABEL = 0x4;
+}
+
+class cInstLibEntry
+{
+private:
+  const cString m_name;
+  const unsigned int m_flags;
+  const cString m_desc;
+  
+  cInstLibEntry(); // @not_implemented
+  
+public:
+  cInstLibEntry(const cString& name, unsigned int flags, const cString& desc) : m_name(name), m_flags(flags), m_desc(desc) { ; }
+
+  const cString& GetName() const { return m_name; }
+  const cString& GetDescription() const { return m_desc; }
+  
+  unsigned int GetFlags() const { return m_flags; }
+  bool IsDefault() const { return (m_flags & nInstFlag::DEFAULT); }
+  bool IsNop() const { return (m_flags & nInstFlag::NOP); }
+  bool IsLabel() const { return (m_flags & nInstFlag::LABEL); }
+  
+};
+
+#endif

Modified: development/source/cpu/cInstSet.h
===================================================================
--- development/source/cpu/cInstSet.h	2007-02-17 21:03:30 UTC (rev 1328)
+++ development/source/cpu/cInstSet.h	2007-02-18 01:22:10 UTC (rev 1329)
@@ -37,8 +37,8 @@
 #ifndef cInstruction_h
 #include "cInstruction.h"
 #endif
-#ifndef cInstLibBase_h
-#include "cInstLibBase.h"
+#ifndef cInstLib_h
+#include "cInstLib.h"
 #endif
 
 using namespace std;
@@ -58,7 +58,7 @@
 {
 public:
   cWorld* m_world;
-  cInstLibBase* m_inst_lib;
+  cInstLib* m_inst_lib;
   class cInstEntry {
   public:
     int lib_fun_id;
@@ -79,7 +79,7 @@
   cInstSet(); // @not_implemented
 
 public:
-  inline cInstSet(cWorld* world, cInstLibBase* inst_lib) : m_world(world), m_inst_lib(inst_lib),
+  inline cInstSet(cWorld* world, cInstLib* inst_lib) : m_world(world), m_inst_lib(inst_lib),
     m_inst_error(inst_lib->GetInstError()), m_inst_default(inst_lib->GetInstDefault()) { ; }
   inline cInstSet(const cInstSet& is);
   inline ~cInstSet() { ; }
@@ -118,7 +118,7 @@
   int AddNop(int lib_nopmod_id, int redundancy = 1, int ft_cost = 0, int cost = 0, double prob_fail = 0.0, int addl_time_cost = 0);
 
   // accessors for instruction library
-  cInstLibBase* GetInstLib() { return m_inst_lib; }
+  cInstLib* GetInstLib() { return m_inst_lib; }
 
   inline cInstruction GetInst(const cString& in_name) const;
   cString FindBestMatch(const cString& in_name) const;

Modified: development/source/cpu/tInstLib.h
===================================================================
--- development/source/cpu/tInstLib.h	2007-02-17 21:03:30 UTC (rev 1328)
+++ development/source/cpu/tInstLib.h	2007-02-18 01:22:10 UTC (rev 1329)
@@ -28,74 +28,44 @@
 #ifndef cString_h
 #include "cString.h"
 #endif
-#ifndef cInstLibBase_h
-#include "cInstLibBase.h"
+#ifndef cInstLib_h
+#include "cInstLib.h"
 #endif
+#ifndef tInstLibEntry_h
+#include "tInstLibEntry.h"
+#endif
 
 class cInstruction;
 
-template <class MethodType> class tInstLib : public cInstLibBase
+template <class MethodType> class tInstLib : public cInstLib
 {
 private:
-  const size_t m_nopmods_array_size;
-  const size_t m_function_array_size;
+  const tInstLibEntry<MethodType>* m_entries;
   cString* m_nopmod_names;
-  cString* m_function_names;
   const int* m_nopmods;
-  MethodType* m_functions;
-  const cInstruction inst_error;
-  const cInstruction inst_default;
+  const MethodType* m_functions;
 
-
 public:
-  tInstLib(size_t nopmod_array_size, size_t function_array_size, cString* nopmod_names,
-           cString* function_names, const int* nopmods, MethodType* functions,
-           const cInstruction& error, const cInstruction& def)
-  : m_nopmods_array_size(nopmod_array_size),
-    m_function_array_size(function_array_size),
+  tInstLib(int size, const tInstLibEntry<MethodType>* entries, cString* nopmod_names, const int* nopmods,
+           const MethodType* functions, const cInstruction error, const cInstruction def)
+  : cInstLib(size, error, def), m_entries(entries), 
     m_nopmod_names(nopmod_names),
-    m_function_names(function_names),
     m_nopmods(nopmods),
-    m_functions(functions),
-    inst_error(error),
-    inst_default(def)
+    m_functions(functions)
   {
+    // Fill out cInstLib::m_namemap dictionary with instruction name to entry index mappings
+    for(int i = 0; i < m_size; i++) m_namemap.Add(m_entries[i].GetName(), i);
   }
   
-  MethodType* GetFunctions(void){ return m_functions; } 
+  const MethodType* GetFunctions() const { return m_functions; } 
+
+  const cInstLibEntry& Get(int i) const { assert(i < m_size); return m_entries[i]; }
+
+
   
-  const cString& GetName(const unsigned int id)
-  {
-    assert(id < m_function_array_size);
-    return m_function_names[id];
-  }
-  const cString& GetNopName(const unsigned int id)
-  {
-    assert(id < m_nopmods_array_size);
-    return m_nopmod_names[id];
-  }  
-  int GetNopMod(const unsigned int id)
-  {
-    assert(id < m_nopmods_array_size);
-    return m_nopmods[id];
-  }
-  int GetNopMod(const cInstruction& inst)
-  {
-    return GetNopMod(inst.GetOp());
-  }
-  
-  int GetSize() { return m_function_array_size; }
-  int GetNumNops() { return m_nopmods_array_size; }
-  
-  cInstruction GetInst(const cString& in_name)
-  {
-    for (unsigned int i = 0; i < m_function_array_size; i++) {
-      if (m_function_names[i] == in_name) return cInstruction(i);
-    }
-    return tInstLib::GetInstError();
-  }
-  const cInstruction GetInstDefault() { return inst_default; }
-  const cInstruction GetInstError() { return inst_error; }
+  const cString& GetNopName(const unsigned int id) { return m_nopmod_names[id]; }  
+  int GetNopMod(const unsigned int id) { return m_nopmods[id]; }
+  int GetNopMod(const cInstruction& inst) { return GetNopMod(inst.GetOp()); }
 };
 
 #endif

Modified: development/source/cpu/tInstLibEntry.h
===================================================================
--- development/source/cpu/tInstLibEntry.h	2007-02-17 21:03:30 UTC (rev 1328)
+++ development/source/cpu/tInstLibEntry.h	2007-02-18 01:22:10 UTC (rev 1329)
@@ -22,29 +22,26 @@
  *
  */
 
+#ifndef tInstLibEntry_h
+#define tInstLibEntry_h
+
 #ifndef cInstLibEntry_h
-#define cInstLibEntry_h
+#include "cInstLibEntry.h"
+#endif
 
-namespace nInstFlag {
-  const unsigned int DEFAULT = 0x1;
-  const unsigned int NOP = 0x2;
-  const unsigned int LABEL = 0x4;
-}
 
-template <class FUN> class tInstLibEntry
+template <class FUN> class tInstLibEntry : public cInstLibEntry
 {
+private:
+  const FUN m_function;
+
+  tInstLibEntry(); // @not_implemented
+  
 public:
-  const cString name;
-  const FUN function;
-  const unsigned int flags;
-  const cString description;
+  tInstLibEntry(const cString& name, FUN function, unsigned int flags = 0, const cString& desc = "")
+    : cInstLibEntry(name, flags, desc), m_function(function) { ; }
   
-  bool IsDefault() const { return (flags & nInstFlag::DEFAULT); }
-  bool IsNop() const { return (flags & nInstFlag::NOP); }
-  bool IsLabel() const { return (flags & nInstFlag::LABEL); }
-  
-  tInstLibEntry(const cString& in_name, FUN in_fun, unsigned int in_flags = 0, const cString& in_desc = "")
-    : name(in_name), function(in_fun), flags(in_flags), description(in_desc) { ; }
+  const FUN GetFunction() const { return m_function; }
 };
 
 

Modified: development/source/tools/tDictionary.h
===================================================================
--- development/source/tools/tDictionary.h	2007-02-17 21:03:30 UTC (rev 1328)
+++ development/source/tools/tDictionary.h	2007-02-18 01:22:10 UTC (rev 1329)
@@ -91,7 +91,7 @@
   
   // This function has no direct implementation in tHashTable
   // Grabs key/value lists, and processes the keys.
-  cString NearMatch(const cString name) {
+  cString NearMatch(const cString name) const {
     tList<cString> keys;
     tList<T> values;
     m_hash.AsLists(keys, values);




More information about the Avida-cvs mailing list