diff options
author | Stuart Bennett <sb476@cam.ac.uk> | 2007-12-10 17:09:32 +0000 |
---|---|---|
committer | Stuart Bennett <sb476@cam.ac.uk> | 2007-12-10 17:09:32 +0000 |
commit | 5a70622ad5676789c710ce183f8578f8b07f1a5b (patch) | |
tree | ee25609a7e78c0bfd29d44e44dd4fc1b8b9dac6a | |
parent | c71f9893cd74f5ddb210a7931362168671e30443 (diff) |
Handle loops to as-yet unvisited places
-rw-r--r-- | deloopify.c | 30 |
1 files changed, 22 insertions, 8 deletions
diff --git a/deloopify.c b/deloopify.c index 0a39784..5006604 100644 --- a/deloopify.c +++ b/deloopify.c @@ -16,7 +16,9 @@ #include <string.h> /* length of sliding history of line beginnings */ -#define MAX_LOOP_LEN 30000 +#define MAX_LOOP_LEN 32768 + +#define SIG_LEN 128 bool loop_concluded(FILE *tracef, uint16_t loopendip) { @@ -48,7 +50,8 @@ int main(int argc, char *argv[]) { FILE *tracef, *outf; long inlineno = 0, outlineno = -1; - char sig[MAX_LOOP_LEN][100]; + typedef char asig[SIG_LEN]; + asig *sig; char loopsig[] = "Loop"; bool borken = false; @@ -64,7 +67,11 @@ int main(int argc, char *argv[]) exit(EXIT_FAILURE); } - memset(sig, 0, sizeof(sig)); + if (!(sig = calloc(MAX_LOOP_LEN, SIG_LEN))) { + printf("Signature table calloc failed\n"); + exit(EXIT_FAILURE); + } + while (!feof(tracef)) { char line[180]; @@ -132,8 +139,8 @@ int main(int argc, char *argv[]) int looplen = 1; int bonus = 0; - for ( ; looplen < MAX_LOOP_LEN; looplen++) { - /* on our way back through the sliding sig list, retrive the + for ( ; looplen < MAX_LOOP_LEN && looplen < outlineno; looplen++) { + /* on our way back through the sliding sig list, retrieve the * uncontracted length of any previously compacted loops */ if (!strncmp(loopsig, sig[(outlineno - looplen) % MAX_LOOP_LEN], 4)) { @@ -147,9 +154,14 @@ int main(int argc, char *argv[]) break; } - if (looplen == MAX_LOOP_LEN) { /* fail */ - printf("Didn't find start of loop -- try increasing MAX_LOOP_LEN?\n"); - exit(EXIT_FAILURE); + /* we don't bail out on these two cases, as loops to places we haven't yet visited do occur, + * so just ignore this loop instr + */ + if (looplen == outlineno) /* didn't find start of loop and searched through complete history */ + continue; + if (looplen == MAX_LOOP_LEN) { /* fail */ + printf("Didn't find start of loop at line %ld in history -- try increasing MAX_LOOP_LEN?\n", inlineno); + continue; } //fprintf(outf, "loop sig %s, startsig %s, found %s, looplen %d, bonus %d\n", sig[outlineno % MAX_LOOP_LEN], startsig, sig[(outlineno - looplen - 4) % MAX_LOOP_LEN], looplen, bonus); @@ -200,5 +212,7 @@ next: } } + free(sig); + return 0; } |