[Avida-SVN] r1948 - in development/source: analyze cpu

brysonda at myxo.css.msu.edu brysonda at myxo.css.msu.edu
Thu Aug 16 10:43:10 PDT 2007


Author: brysonda
Date: 2007-08-16 13:43:10 -0400 (Thu, 16 Aug 2007)
New Revision: 1948

Modified:
   development/source/analyze/cAnalyze.cc
   development/source/analyze/cAnalyzeGenotype.cc
   development/source/cpu/cHardwareCPU.cc
   development/source/cpu/cHardwareExperimental.cc
   development/source/cpu/cHardwareGX.cc
   development/source/cpu/cHardwareManager.cc
   development/source/cpu/cHardwareSMT.cc
   development/source/cpu/cHardwareTransSMT.cc
   development/source/cpu/cHeadCPU.h
   development/source/cpu/cInstLib.h
   development/source/cpu/cInstSet.cc
   development/source/cpu/cInstSet.h
   development/source/cpu/tInstLib.h
Log:
Centralize handling of NULL instruction insertion for Knockout tests.  Also add protection to prevent adding the NULL instruction in any other way so that it will remain meaningful in tests that require it.

Modified: development/source/analyze/cAnalyze.cc
===================================================================
--- development/source/analyze/cAnalyze.cc	2007-08-16 17:24:17 UTC (rev 1947)
+++ development/source/analyze/cAnalyze.cc	2007-08-16 17:43:10 UTC (rev 1948)
@@ -4186,18 +4186,7 @@
   
   // Setup a NULL instruction in a special inst set.
   cInstSet ko_inst_set(inst_set);
-  // Locate the instruction corresponding to "NULL" in the instruction library.
-  {
-    cInstruction lib_null_inst = ko_inst_set.GetInstLib()->GetInst("NULL");
-    if (lib_null_inst == ko_inst_set.GetInstLib()->GetInstError()) {
-      cout << "<cAnalyze::AnalyzeKnockouts> got error:" << endl
-      << "  instruction 'NULL' not in current hardware type" << endl;
-      if (exit_on_error) exit(1);
-    }
-    // Add mapping to located instruction. 
-    ko_inst_set.AddInst(lib_null_inst.GetOp());
-  }
-  const cInstruction null_inst = ko_inst_set.GetInst("NULL");
+  const cInstruction null_inst = ko_inst_set.ActivateNullInst();
   
   // Loop through all of the genotypes in this batch...
   tListIterator<cAnalyzeGenotype> batch_it(batch[cur_batch].List());
@@ -4588,19 +4577,7 @@
     }
     
     cInstSet map_inst_set(inst_set);
-    // Locate instruction corresponding to "NULL" in the instruction library.
-    {
-      const cInstruction inst_lib_null_inst = map_inst_set.GetInstLib()->GetInst("NULL");
-      if(inst_lib_null_inst == map_inst_set.GetInstLib()->GetInstError()){
-        cout << "<cAnalyze::CommandMapTasks> got error:" << endl;
-        cout << " --- instruction \"NULL\" isn't in the instruction library for the" << endl;
-        cout << " --- current hardware type." << endl;
-        if (exit_on_error) exit(1);
-      }
-      // Add mapping to located instruction. 
-      map_inst_set.AddInst(inst_lib_null_inst.GetOp());
-    }
-    const cInstruction null_inst = map_inst_set.GetInst("NULL");
+    const cInstruction null_inst = map_inst_set.ActivateNullInst();
     
     // Loop through all the lines of code, testing the removal of each.
     for (int line_num = 0; line_num < max_line; line_num++) {
@@ -4850,24 +4827,8 @@
       double sum_task_overlap = 0;// task overlap for for this geneome
         
         cInstSet map_inst_set(inst_set);
+        const cInstruction null_inst = map_inst_set.ActivateNullInst();
         
-        // Locate instruction corresponding to "NULL" in the instruction library.
-        {
-          const cInstruction inst_lib_null_inst = map_inst_set.GetInstLib()->GetInst("NULL");
-          if(inst_lib_null_inst == map_inst_set.GetInstLib()->GetInstError()){
-            cout << "<cAnalyze::CommandMapTasks> got error:" << endl;
-            cout << " --- instruction \"NULL\" isn't in the instruction library;" << endl;
-            cout << " --- get somebody to map a function to \"NULL\" in the library." << endl;
-            cout << " --- (probably to class method \"cHardware-of-some-type::initInstLib\"" << endl;
-            cout << " --- in file named \"cpu/hardware-of-some-type.cc\".)" << endl;
-            cout << " --- bailing-out." << endl;
-            if (exit_on_error) exit(1);
-          }
-          // Add mapping to located instruction. 
-          map_inst_set.AddInst(inst_lib_null_inst.GetOp());
-        }
-        const cInstruction null_inst = map_inst_set.GetInst("NULL");
-        
         // Loop through all the lines of code, testing the removal of each.
         for (int line_num = 0; line_num < max_line; line_num++) {
           int cur_inst = base_genome[line_num].GetOp();
@@ -5074,19 +5035,9 @@
   
   // Setup the map_inst_set with the NULL instruction
   cInstSet map_inst_set(inst_set);
+  const cInstruction null_inst = map_inst_set.ActivateNullInst();
   
-  // Locate the NULL instruction in the library
-  const cInstruction lib_null = map_inst_set.GetInstLib()->GetInst("NULL");
-  if (lib_null == map_inst_set.GetInstLib()->GetInstError()) {
-    cerr << "Internal ERROR: Instruction 'NULL' not found." << endl;
-    if (exit_on_error) exit(1);
-  }
   
-  // Add mapping to located instruction.
-  map_inst_set.AddInst(lib_null.GetOp());
-  const cInstruction null_inst = map_inst_set.GetInst("NULL");
-  
-  
   // Loop through all genotypes in this batch.
   tListIterator<cAnalyzeGenotype> batch_it(batch[cur_batch].List());
   cAnalyzeGenotype * genotype = NULL;
@@ -5324,22 +5275,7 @@
     
     // Build an empty instruction into the an instruction library.
     cInstSet map_inst_set(inst_set);
-    // Locate instruction corresponding to "NULL" in the instruction library.
-    {
-      const cInstruction inst_lib_null_inst = map_inst_set.GetInstLib()->GetInst("NULL");
-      if (inst_lib_null_inst == map_inst_set.GetInstLib()->GetInstError()){
-        cout << "<cAnalyze::CommandMapMutations> got error:" << endl;
-        cout << " --- instruction \"NULL\" isn't in the instruction library;" << endl;
-        cout << " --- get somebody to map a function to \"NULL\" in the library." << endl;
-        cout << " --- (probably to class method \"cHardware-of-some-type::initInstLib\"" << endl;
-        cout << " --- in file named \"cpu/hardware-of-some-type.cc\".)" << endl;
-        cout << " --- bailing-out." << endl;
-        if (exit_on_error) exit(1);
-      }
-      // Add mapping to located instruction. 
-      map_inst_set.AddInst(inst_lib_null_inst.GetOp());
-    }
-    const cInstruction null_inst = map_inst_set.GetInst("NULL");
+    const cInstruction null_inst = map_inst_set.ActivateNullInst();
     
     cString color_string;  // For coloring cells...
     

Modified: development/source/analyze/cAnalyzeGenotype.cc
===================================================================
--- development/source/analyze/cAnalyzeGenotype.cc	2007-08-16 17:24:17 UTC (rev 1947)
+++ development/source/analyze/cAnalyzeGenotype.cc	2007-08-16 17:43:10 UTC (rev 1948)
@@ -228,16 +228,7 @@
   
   // Setup a NULL instruction in a special inst set.
   cInstSet ko_inst_set(inst_set);
-  // Locate the instruction corresponding to "NULL" in the instruction library.
-  {
-    cInstruction lib_null_inst = ko_inst_set.GetInstLib()->GetInst("NULL");
-    if (lib_null_inst == ko_inst_set.GetInstLib()->GetInstError()) {
-      m_world->GetDriver().RaiseFatalException(1, "instruction 'NULL' not in current hardware type");
-    }
-    // Add mapping to located instruction. 
-    ko_inst_set.AddInst(lib_null_inst.GetOp());
-  }
-  const cInstruction null_inst = ko_inst_set.GetInst("NULL");
+  const cInstruction null_inst = ko_inst_set.ActivateNullInst();
   
   // If we are keeping track of the specific effects on tasks from the
   // knockouts, setup the matrix.

Modified: development/source/cpu/cHardwareCPU.cc
===================================================================
--- development/source/cpu/cHardwareCPU.cc	2007-08-16 17:24:17 UTC (rev 1947)
+++ development/source/cpu/cHardwareCPU.cc	2007-08-16 17:43:10 UTC (rev 1948)
@@ -79,7 +79,6 @@
     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"),
     tInstLibEntry<tMethod>("if-equ-0", &cHardwareCPU::Inst_If0, 0, "Execute next instruction if ?BX?==0, else skip it"),
     tInstLibEntry<tMethod>("if-not-0", &cHardwareCPU::Inst_IfNot0, 0, "Execute next instruction if ?BX?!=0, else skip it"),
@@ -362,6 +361,8 @@
     // Placebo instructions
     tInstLibEntry<tMethod>("skip", &cHardwareCPU::Inst_Skip),
 
+    // Must always be the last instruction in the array
+    tInstLibEntry<tMethod>("NULL", &cHardwareCPU::Inst_Nop, 0, "True no-operation instruction: does nothing"),
   };
   
   const int n_size = sizeof(s_n_array)/sizeof(cNOPEntryCPU);
@@ -379,8 +380,9 @@
 
 	const cInstruction error(255);
 	const cInstruction def(0);
+  const cInstruction null_inst(f_size - 1);
   
-  return new tInstLib<tMethod>(f_size, s_f_array, n_names, nop_mods, functions, error, def);
+  return new tInstLib<tMethod>(f_size, s_f_array, n_names, nop_mods, functions, error, def, null_inst);
 }
 
 cHardwareCPU::cHardwareCPU(cWorld* world, cOrganism* in_organism, cInstSet* in_m_inst_set)

Modified: development/source/cpu/cHardwareExperimental.cc
===================================================================
--- development/source/cpu/cHardwareExperimental.cc	2007-08-16 17:24:17 UTC (rev 1947)
+++ development/source/cpu/cHardwareExperimental.cc	2007-08-16 17:43:10 UTC (rev 1948)
@@ -138,8 +138,9 @@
 
 	const cInstruction error(255);
 	const cInstruction def(0);
+  const cInstruction null_inst(4);
   
-  return new tInstLib<tMethod>(f_size, s_f_array, n_names, nop_mods, functions, error, def);
+  return new tInstLib<tMethod>(f_size, s_f_array, n_names, nop_mods, functions, error, def, null_inst);
 }
 
 cHardwareExperimental::cHardwareExperimental(cWorld* world, cOrganism* in_organism, cInstSet* in_m_inst_set)

Modified: development/source/cpu/cHardwareGX.cc
===================================================================
--- development/source/cpu/cHardwareGX.cc	2007-08-16 17:24:17 UTC (rev 1947)
+++ development/source/cpu/cHardwareGX.cc	2007-08-16 17:43:10 UTC (rev 1948)
@@ -80,7 +80,6 @@
     tInstLibEntry<tMethod>("nop-B", &cHardwareGX::Inst_Nop, (nInstFlag::DEFAULT | nInstFlag::NOP), "No-operation instruction; modifies other instructions"),
     tInstLibEntry<tMethod>("nop-C", &cHardwareGX::Inst_Nop, (nInstFlag::DEFAULT | nInstFlag::NOP), "No-operation instruction; modifies other instructions"),
     
-    tInstLibEntry<tMethod>("NULL", &cHardwareGX::Inst_Nop, 0, "True no-operation instruction: does nothing"),
     tInstLibEntry<tMethod>("nop-X", &cHardwareGX::Inst_Nop, 0, "True no-operation instruction: does nothing"),
     tInstLibEntry<tMethod>("if-equ-0", &cHardwareGX::Inst_If0, 0, "Execute next instruction if ?BX?==0, else skip it"),
     tInstLibEntry<tMethod>("if-not-0", &cHardwareGX::Inst_IfNot0, 0, "Execute next instruction if ?BX?!=0, else skip it"),
@@ -284,6 +283,9 @@
     tInstLibEntry<tMethod>("READABLE", &cHardwareGX::Inst_Nop),
     tInstLibEntry<tMethod>("BINDABLE", &cHardwareGX::Inst_Nop),
     tInstLibEntry<tMethod>("EXECUTABLE", &cHardwareGX::Inst_Nop),
+    
+    // Must always be the last instruction
+    tInstLibEntry<tMethod>("NULL", &cHardwareGX::Inst_Nop, 0, "True no-operation instruction: does nothing"),
   };
   
   const int n_size = sizeof(s_n_array)/sizeof(cNOPEntryCPU);
@@ -301,8 +303,9 @@
 
 	const cInstruction error(255);
 	const cInstruction def(0);
+  const cInstruction null_inst(f_size - 1);
   
-  return new tInstLib<tMethod>(f_size, s_f_array, n_names, nop_mods, functions, error, def);
+  return new tInstLib<tMethod>(f_size, s_f_array, n_names, nop_mods, functions, error, def, null_inst);
 }
 
 

Modified: development/source/cpu/cHardwareManager.cc
===================================================================
--- development/source/cpu/cHardwareManager.cc	2007-08-16 17:24:17 UTC (rev 1947)
+++ development/source/cpu/cHardwareManager.cc	2007-08-16 17:43:10 UTC (rev 1948)
@@ -76,52 +76,10 @@
   
   if (m_world->GetConfig().INST_SET_FORMAT.Get()) {
     m_inst_set->LoadFromFile(filename);
-    return;
+  } else {
+    m_inst_set->LoadFromLegacyFile(filename);
   }
   
-  cInitFile file(filename);
-  
-  if (file.WasOpened() == false) {
-    m_world->GetDriver().RaiseFatalException(1, cString("Could not open instruction set '") + filename + "'.");
-  }
-  
-  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();
-    int redundancy = cur_line.PopWord().AsInt();
-    int cost = cur_line.PopWord().AsInt();
-    int ft_cost = cur_line.PopWord().AsInt();
-    int energy_cost = cur_line.PopWord().AsInt();
-    double prob_fail = cur_line.PopWord().AsDouble();
-    int addl_time_cost = cur_line.PopWord().AsInt();
-
-    // If this instruction has 0 redundancy, we don't want it!
-    if (redundancy < 0) continue;
-    if (redundancy > 256) {
-      cString msg("Max redundancy is 256.  Resetting redundancy of \"");
-      msg += inst_name; msg += "\" from "; msg += redundancy; msg += " to 256.";
-      m_world->GetDriver().NotifyWarning(msg);
-      redundancy = 256;
-    }
-    
-    // Otherwise, this instruction will be in the set.
-    // First, determine if it is a nop...
-    int inst_idx = inst_lib.GetIndex(inst_name);
-    
-    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);
-    }
-    
-    if (inst_lib[inst_idx].IsNop()) {
-      m_inst_set->AddNop(inst_idx, redundancy, ft_cost, cost, energy_cost, prob_fail, addl_time_cost);
-    } else {
-      m_inst_set->AddInst(inst_idx, redundancy, ft_cost, cost, energy_cost, prob_fail, addl_time_cost);
-    }
-  }
 }
 
 cHardwareBase* cHardwareManager::Create(cOrganism* in_org)

Modified: development/source/cpu/cHardwareSMT.cc
===================================================================
--- development/source/cpu/cHardwareSMT.cc	2007-08-16 17:24:17 UTC (rev 1947)
+++ development/source/cpu/cHardwareSMT.cc	2007-08-16 17:43:10 UTC (rev 1948)
@@ -129,8 +129,9 @@
 	
 	const cInstruction error(255);
 	const cInstruction def(0);
-	
-  return new tInstLib<tMethod>(f_size, s_f_array, n_names, nop_mods, functions, error, def);
+	const cInstruction null_inst(f_size - 1);
+  
+  return new tInstLib<tMethod>(f_size, s_f_array, n_names, nop_mods, functions, error, def, null_inst);
 }
 
 cHardwareSMT::cHardwareSMT(cWorld* world, cOrganism* in_organism, cInstSet* in_m_inst_set)

Modified: development/source/cpu/cHardwareTransSMT.cc
===================================================================
--- development/source/cpu/cHardwareTransSMT.cc	2007-08-16 17:24:17 UTC (rev 1947)
+++ development/source/cpu/cHardwareTransSMT.cc	2007-08-16 17:43:10 UTC (rev 1948)
@@ -128,8 +128,9 @@
 	
 	const cInstruction error(255);
 	const cInstruction def(0);
+  const cInstruction null_inst(f_size - 1);
 	
-  return new tInstLib<tMethod>(f_size, s_f_array, n_names, nop_mods, functions, error, def);
+  return new tInstLib<tMethod>(f_size, s_f_array, n_names, nop_mods, functions, error, def, null_inst);
 }
 
 cHardwareTransSMT::cHardwareTransSMT(cWorld* world, cOrganism* in_organism, cInstSet* in_m_inst_set)

Modified: development/source/cpu/cHeadCPU.h
===================================================================
--- development/source/cpu/cHeadCPU.h	2007-08-16 17:24:17 UTC (rev 1947)
+++ development/source/cpu/cHeadCPU.h	2007-08-16 17:43:10 UTC (rev 1948)
@@ -88,7 +88,7 @@
 
   inline const cInstruction& GetInst() const { return GetMemory()[m_position]; }
   inline const cInstruction& GetInst(int offset) const { return GetMemory()[m_position + offset]; }
-  inline const cInstruction& GetNextInst() const;
+  inline cInstruction GetNextInst() const;
 
   inline void SetInst(const cInstruction& value) { GetMemory()[m_position] = value; }
   inline void InsertInst(const cInstruction& inst) { GetMemory().Insert(m_position, inst); }
@@ -159,7 +159,7 @@
   (m_mem_space == in_cpu_head.m_mem_space);
 }
 
-inline const cInstruction& cHeadCPU::GetNextInst() const
+inline cInstruction cHeadCPU::GetNextInst() const
 {
   return (AtEnd()) ? m_hardware->GetInstSet().GetInstError() : GetMemory()[m_position + 1];
 }

Modified: development/source/cpu/cInstLib.h
===================================================================
--- development/source/cpu/cInstLib.h	2007-08-16 17:24:17 UTC (rev 1947)
+++ development/source/cpu/cInstLib.h	2007-08-16 17:43:10 UTC (rev 1948)
@@ -47,12 +47,13 @@
 
   const cInstruction m_inst_error;
   const cInstruction m_inst_default;
+  const cInstruction m_inst_null;
   
   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) { ; }
+  cInstLib(int size, const cInstruction inst_error, const cInstruction inst_default, const cInstruction inst_null)
+    : m_size(size), m_inst_error(inst_error), m_inst_default(inst_default), m_inst_null(inst_null) { ; }
   virtual ~cInstLib() { ; }
 
   inline int GetSize() const { return m_size; }
@@ -70,8 +71,9 @@
   
   inline cInstruction GetInst(const cString& name);
 
+  const cInstruction GetInstError() const { return m_inst_error; }
   const cInstruction GetInstDefault() const { return m_inst_default; }
-  const cInstruction GetInstError() const { return m_inst_error; }
+  const cInstruction GetInstNull() const { return m_inst_null; }
 };
 
 

Modified: development/source/cpu/cInstSet.cc
===================================================================
--- development/source/cpu/cInstSet.cc	2007-08-16 17:24:17 UTC (rev 1947)
+++ development/source/cpu/cInstSet.cc	2007-08-16 17:43:10 UTC (rev 1948)
@@ -62,8 +62,12 @@
   return cInstruction(inst_op);
 }
 
+
 int cInstSet::AddInst(int lib_fun_id, int redundancy, int ft_cost, int cost, int energy_cost, double prob_fail, int addl_time_cost)
 {
+  if (lib_fun_id == m_inst_lib->GetInstNull().GetOp())
+    m_world->GetDriver().RaiseFatalException(1,"Invalid use of NULL instruction");
+  
   const int inst_id = m_lib_name_map.GetSize();
 
   assert(inst_id < 255);
@@ -90,6 +94,7 @@
   return inst_id;
 }
 
+
 int cInstSet::AddNop(int lib_nopmod_id, int redundancy, int ft_cost, int cost, int energy_cost, double prob_fail, int addl_time_cost)
 {
   // Assert nops are at the _beginning_ of an inst_set.
@@ -103,6 +108,33 @@
   return inst_id;
 }
 
+cInstruction cInstSet::ActivateNullInst()
+{  
+  const int inst_id = m_lib_name_map.GetSize();
+  const int null_fun_id = m_inst_lib->GetInstNull().GetOp();
+  
+  assert(inst_id < 255);
+  
+  // Make sure not to activate again if NULL is already active
+  for (int i = 0; i < inst_id; i++) if (m_lib_name_map[i].lib_fun_id == null_fun_id) return cInstruction(i);
+  
+  
+  // Increase the size of the array...
+  m_lib_name_map.Resize(inst_id + 1);
+  
+  // Setup the new function...
+  m_lib_name_map[inst_id].lib_fun_id = null_fun_id;
+  m_lib_name_map[inst_id].redundancy = 0;
+  m_lib_name_map[inst_id].cost = 0;
+  m_lib_name_map[inst_id].ft_cost = 0;
+  m_lib_name_map[inst_id].energy_cost = 0;
+  m_lib_name_map[inst_id].prob_fail = 0.0;
+  m_lib_name_map[inst_id].addl_time_cost = 0;
+  
+  return cInstruction(inst_id);
+}
+
+
 cString cInstSet::FindBestMatch(const cString& in_name) const
 {
   int best_dist = 1024;
@@ -199,3 +231,51 @@
     m_world->GetDriver().RaiseFatalException(1,"Failed to load instruction set due to previous errors.");
   }
 }
+
+
+void cInstSet::LoadFromLegacyFile(const cString& filename)
+{
+  cInitFile file(filename);
+  
+  if (file.WasOpened() == false) {
+    m_world->GetDriver().RaiseFatalException(1, cString("Could not open instruction set '") + filename + "'.");
+  }
+  
+  for (int line_id = 0; line_id < file.GetNumLines(); line_id++) {
+    cString cur_line = file.GetLine(line_id);
+    cString inst_name = cur_line.PopWord();
+    int redundancy = cur_line.PopWord().AsInt();
+    int cost = cur_line.PopWord().AsInt();
+    int ft_cost = cur_line.PopWord().AsInt();
+    int energy_cost = cur_line.PopWord().AsInt();
+    double prob_fail = cur_line.PopWord().AsDouble();
+    int addl_time_cost = cur_line.PopWord().AsInt();
+    
+    // If this instruction has 0 redundancy, we don't want it!
+    if (redundancy < 0) continue;
+    if (redundancy > 256) {
+      cString msg("Max redundancy is 256.  Resetting redundancy of \"");
+      msg += inst_name; msg += "\" from "; msg += redundancy; msg += " to 256.";
+      m_world->GetDriver().NotifyWarning(msg);
+      redundancy = 256;
+    }
+    
+    // Otherwise, this instruction will be in the set.
+    // First, determine if it is a nop...
+    int inst_idx = m_inst_lib->GetIndex(inst_name);
+    
+    if (inst_idx == -1) {
+      // Oh oh!  Didn't find an instruction!
+      cString errorstr("Could not find instruction '");
+      errorstr += inst_name + "'\n        (Best match = '" + m_inst_lib->GetNearMatch(inst_name) + "').";
+      m_world->GetDriver().RaiseFatalException(1, errorstr);
+    }
+    
+    if ((*m_inst_lib)[inst_idx].IsNop()) {
+      AddNop(inst_idx, redundancy, ft_cost, cost, energy_cost, prob_fail, addl_time_cost);
+    } else {
+      AddInst(inst_idx, redundancy, ft_cost, cost, energy_cost, prob_fail, addl_time_cost);
+    }
+  }
+  
+}

Modified: development/source/cpu/cInstSet.h
===================================================================
--- development/source/cpu/cInstSet.h	2007-08-16 17:24:17 UTC (rev 1947)
+++ development/source/cpu/cInstSet.h	2007-08-16 17:43:10 UTC (rev 1948)
@@ -122,6 +122,8 @@
   // Insertion of new instructions...
   int AddInst(int lib_fun_id, int redundancy = 1, int ft_cost = 0, int cost = 0, int energy_cost = 0, double prob_fail = 0.0, int addl_time_cost = 0);
   int AddNop(int lib_nopmod_id, int redundancy = 1, int ft_cost = 0, int cost = 0, int energy_cost = 0, double prob_fail = 0.0, int addl_time_cost = 0);
+  
+  cInstruction ActivateNullInst();
 
   // accessors for instruction library
   cInstLib* GetInstLib() { return m_inst_lib; }
@@ -130,10 +132,11 @@
   cString FindBestMatch(const cString& in_name) const;
   bool InstInSet(const cString& in_name) const;
 
-  const cInstruction& GetInstDefault() const { return m_inst_default; }
-  const cInstruction& GetInstError() const { return m_inst_error; }
+  cInstruction GetInstDefault() const { return m_inst_default; }
+  cInstruction GetInstError() const { return m_inst_error; }
   
   void LoadFromFile(const cString& filename);
+  void LoadFromLegacyFile(const cString& filename);
 };
 
 

Modified: development/source/cpu/tInstLib.h
===================================================================
--- development/source/cpu/tInstLib.h	2007-08-16 17:24:17 UTC (rev 1947)
+++ development/source/cpu/tInstLib.h	2007-08-16 17:43:10 UTC (rev 1948)
@@ -47,8 +47,8 @@
 
 public:
   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), 
+           const MethodType* functions, const cInstruction error, const cInstruction def, const cInstruction null_inst)
+  : cInstLib(size, error, def, null_inst), m_entries(entries), 
     m_nopmod_names(nopmod_names),
     m_nopmods(nopmods),
     m_functions(functions)




More information about the Avida-cvs mailing list