Add ORC_CODE=randomize to randomize registers
authorDavid Schleef <ds@schleef.org>
Fri, 6 May 2011 19:02:37 +0000 (12:02 -0700)
committerDavid Schleef <ds@schleef.org>
Sat, 14 May 2011 00:49:29 +0000 (17:49 -0700)
orc/orccompiler.c
orc/orcprogram.h
testsuite/compile_opcodes_sys.c

index 182fec4..e5cf4f1 100644 (file)
@@ -45,6 +45,7 @@ static char **_orc_compiler_flag_list;
 int _orc_compiler_flag_backup;
 int _orc_compiler_flag_emulate;
 int _orc_compiler_flag_debug;
+int _orc_compiler_flag_randomize;
 
 void
 _orc_compiler_init (void)
@@ -59,6 +60,7 @@ _orc_compiler_init (void)
   _orc_compiler_flag_backup = orc_compiler_flag_check ("backup");
   _orc_compiler_flag_emulate = orc_compiler_flag_check ("emulate");
   _orc_compiler_flag_debug = orc_compiler_flag_check ("debug");
+  _orc_compiler_flag_randomize = orc_compiler_flag_check ("randomize");
 }
 
 int
@@ -89,10 +91,10 @@ orc_compiler_allocate_register (OrcCompiler *compiler, int data_reg)
   }
 
   roff = 0;
-#if 0
-  /* for testing */
-  roff = rand()&0xf;
-#endif
+  if (_orc_compiler_flag_randomize) {
+    /* for testing */
+    roff = rand()&0x1f;
+  }
 
   for(i=0;i<32;i++){
     reg = offset + ((roff + i)&0x1f);
index df31114..812c7eb 100644 (file)
@@ -783,6 +783,7 @@ extern const char *_orc_cpu_name;
 extern int _orc_compiler_flag_backup;
 extern int _orc_compiler_flag_emulate;
 extern int _orc_compiler_flag_debug;
+extern int _orc_compiler_flag_randomize;
 
 void orc_code_chunk_free (OrcCodeChunk *chunk);
 
index e688a49..8390938 100644 (file)
@@ -7,6 +7,8 @@
 #include <orc/orc.h>
 #include <orc-test/orctest.h>
 
+#include <time.h>
+
 
 int error = FALSE;
 
@@ -20,6 +22,7 @@ main (int argc, char *argv[])
   int i;
   OrcOpcodeSet *opcode_set;
 
+  srand(time(NULL));
   orc_init();
   orc_test_init();