[Avida-SVN] r1940 - in development: Avida.xcodeproj source/cpu source/main

brysonda at myxo.css.msu.edu brysonda at myxo.css.msu.edu
Wed Aug 15 10:57:46 PDT 2007


Author: brysonda
Date: 2007-08-15 13:57:46 -0400 (Wed, 15 Aug 2007)
New Revision: 1940

Modified:
   development/Avida.xcodeproj/project.pbxproj
   development/source/cpu/cHardwareManager.cc
   development/source/cpu/cInstSet.cc
   development/source/cpu/cInstSet.h
   development/source/main/cAvidaConfig.h
Log:
First pass at implementing a new more flexible instruction set file format.  This format is not currently the default.  It must be manually selected by setting INST_SET_FORMAT to 1 in avida.cfg.

Modified: development/Avida.xcodeproj/project.pbxproj
===================================================================
--- development/Avida.xcodeproj/project.pbxproj	2007-08-15 17:26:16 UTC (rev 1939)
+++ development/Avida.xcodeproj/project.pbxproj	2007-08-15 17:57:46 UTC (rev 1940)
@@ -191,7 +191,6 @@
 		70B1A75A0B7E431F00067486 /* experimental.org in CopyFiles */ = {isa = PBXBuildFile; fileRef = 70B1A7590B7E431F00067486 /* experimental.org */; };
 		70B6514F0BEA6FCC002472ED /* main.cc in Sources */ = {isa = PBXBuildFile; fileRef = 701EF27E0BEA5D2300DAE168 /* main.cc */; };
 		70B651B70BEA9AEC002472ED /* unit-tests in CopyFiles */ = {isa = PBXBuildFile; fileRef = 70B6514C0BEA6FAD002472ED /* unit-tests */; };
-		70D046610C32EA90000614E7 /* cBirthChamber.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 702D4F3908DA61E2007BA469 /* cBirthChamber.h */; };
 		70DCAC9C097AF7C0002F8733 /* primitive.cc in Sources */ = {isa = PBXBuildFile; fileRef = 70DCAC9B097AF7C0002F8733 /* primitive.cc */; };
 		70F9FC100C469DD70083B788 /* cASTDumpVisitor.cc in Sources */ = {isa = PBXBuildFile; fileRef = 70F9FC0F0C469DC10083B788 /* cASTDumpVisitor.cc */; };
 		B4FA258A0C5EB65E0086D4B5 /* cPlasticPhenotype.cc in Sources */ = {isa = PBXBuildFile; fileRef = B4FA25810C5EB6510086D4B5 /* cPlasticPhenotype.cc */; };
@@ -323,7 +322,6 @@
 				7049F3730A66AD7E00640512 /* default-transsmt.org in CopyFiles */,
 				70B1A7430B7E3FFD00067486 /* instset-experimental.cfg in CopyFiles */,
 				70B1A75A0B7E431F00067486 /* experimental.org in CopyFiles */,
-				70D046610C32EA90000614E7 /* cBirthChamber.h in CopyFiles */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};

Modified: development/source/cpu/cHardwareManager.cc
===================================================================
--- development/source/cpu/cHardwareManager.cc	2007-08-15 17:26:16 UTC (rev 1939)
+++ development/source/cpu/cHardwareManager.cc	2007-08-15 17:57:46 UTC (rev 1940)
@@ -73,6 +73,12 @@
     m_world->GetDriver().NotifyComment(cString("Using default instruction set: ") + filename);
   }
   
+  
+  if (m_world->GetConfig().INST_SET_FORMAT.Get()) {
+    m_inst_set->LoadFromFile(filename);
+    return;
+  }
+  
   cInitFile file(filename);
   
   if (file.IsOpen() == false) {

Modified: development/source/cpu/cInstSet.cc
===================================================================
--- development/source/cpu/cInstSet.cc	2007-08-15 17:26:16 UTC (rev 1939)
+++ development/source/cpu/cInstSet.cc	2007-08-15 17:57:46 UTC (rev 1940)
@@ -25,9 +25,13 @@
 
 #include "cInstSet.h"
 
+#include "cArgContainer.h"
+#include "cArgSchema.h"
 #include "cAvidaContext.h"
+#include "cInitFile.h"
 #include "cStringUtil.h"
 #include "cWorld.h"
+#include "cWorldDriver.h"
 
 using namespace std;
 
@@ -128,3 +132,74 @@
   return false;
 }
 
+void cInstSet::LoadFromFile(const cString& filename)
+{
+  cArgSchema schema;
+  
+  // Integer
+  schema.AddEntry("redundancy", 0, 1);
+  schema.AddEntry("cost", 1, 0);
+  schema.AddEntry("initial_cost", 2, 0);
+  schema.AddEntry("energy_cost", 3, 0);
+  schema.AddEntry("addl_time_cost", 4, 0);
+  
+  // Double
+  schema.AddEntry("prob_fail", 0, 0.0);
+  
+  
+  cInitFile file(filename);
+  if (!file.Good()) {
+    m_world->GetDriver().RaiseFatalException(1, cString("Unable to load instruction set '") + filename + "'.");
+  }
+  
+  file.Load();
+  file.Close();
+  file.Compress();
+  
+  tList<cString> errors;
+  bool success = true;
+  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 inst_idx = m_inst_lib->GetIndex(inst_name);
+    if (inst_idx == -1) {
+      // Oh oh!  Didn't find an instruction!
+      cString* errorstr = new cString("Unknown instruction '");
+      *errorstr += inst_name + "' (Best match = '" + m_inst_lib->GetNearMatch(inst_name) + "').";
+      errors.PushRear(errorstr);
+      success = false;
+      continue;
+    }
+    
+    cArgContainer* args = cArgContainer::Load(cur_line, schema, &errors);
+    if (!args) {
+      success = false;
+      continue;
+    }
+    
+    int redundancy = args->GetInt(0);
+    int cost = args->GetInt(1);
+    int ft_cost = args->GetInt(2);
+    int energy_cost = args->GetInt(3);
+    double prob_fail = args->GetDouble(0);
+    int addl_time_cost = args->GetInt(4);
+    
+    delete args;
+    
+    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);
+    }
+  }
+  
+  if (!success) {
+    cString* errstr = NULL;
+    while ((errstr = errors.Pop())) {
+      m_world->GetDriver().RaiseException(*errstr);
+      delete errstr;
+    }
+    m_world->GetDriver().RaiseFatalException(1,"Failed to load instruction set due to previous errors.");
+  }
+}

Modified: development/source/cpu/cInstSet.h
===================================================================
--- development/source/cpu/cInstSet.h	2007-08-15 17:26:16 UTC (rev 1939)
+++ development/source/cpu/cInstSet.h	2007-08-15 17:57:46 UTC (rev 1940)
@@ -132,6 +132,8 @@
 
   const cInstruction& GetInstDefault() const { return m_inst_default; }
   const cInstruction& GetInstError() const { return m_inst_error; }
+  
+  void LoadFromFile(const cString& filename);
 };
 
 

Modified: development/source/main/cAvidaConfig.h
===================================================================
--- development/source/main/cAvidaConfig.h	2007-08-15 17:26:16 UTC (rev 1939)
+++ development/source/main/cAvidaConfig.h	2007-08-15 17:57:46 UTC (rev 1940)
@@ -201,6 +201,7 @@
   CONFIG_ADD_GROUP(CONFIG_FILE_GROUP, "Configuration Files");
   CONFIG_ADD_VAR(DATA_DIR, cString, "data", "Directory in which config files are found");
   CONFIG_ADD_VAR(INST_SET, cString, "-", "File containing instruction set");
+  CONFIG_ADD_VAR(INST_SET_FORMAT, int, 0, "Instruction set file format.\n0 = Default\n1 = New Style");
   CONFIG_ADD_VAR(EVENT_FILE, cString, "events.cfg", "File containing list of events during run");
   CONFIG_ADD_VAR(ANALYZE_FILE, cString, "analyze.cfg", "File used for analysis mode");
   CONFIG_ADD_VAR(ENVIRONMENT_FILE, cString, "environment.cfg", "File that describes the environment");




More information about the Avida-cvs mailing list