From 5d9c8a32acc589f78b0fa7353ef1e758eea2357e Mon Sep 17 00:00:00 2001 From: David Schleef Date: Fri, 6 May 2011 12:02:37 -0700 Subject: [PATCH] Add ORC_CODE=randomize to randomize registers --- orc/orccompiler.c | 10 ++++++---- orc/orcprogram.h | 1 + testsuite/compile_opcodes_sys.c | 3 +++ 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/orc/orccompiler.c b/orc/orccompiler.c index 182fec4..e5cf4f1 100644 --- a/orc/orccompiler.c +++ b/orc/orccompiler.c @@ -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); diff --git a/orc/orcprogram.h b/orc/orcprogram.h index df31114..812c7eb 100644 --- a/orc/orcprogram.h +++ b/orc/orcprogram.h @@ -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); diff --git a/testsuite/compile_opcodes_sys.c b/testsuite/compile_opcodes_sys.c index e688a49..8390938 100644 --- a/testsuite/compile_opcodes_sys.c +++ b/testsuite/compile_opcodes_sys.c @@ -7,6 +7,8 @@ #include #include +#include + 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(); -- 2.7.4