diff options
author | Robert de Bath <rdebath@poboxes.com> | 2002-08-11 08:50:48 +0200 |
---|---|---|
committer | Lubomir Rintel <lkundrak@v3.sk> | 2013-10-23 23:48:48 +0200 |
commit | 26ade8d624457b7164502ed9c190ca3f146bda0c (patch) | |
tree | 75a70b6a562bc595c971e170994a8e302a8c7b3b /copt | |
parent | 660429af0232d4afcb3e03fb0437053dd6e16286 (diff) | |
download | dev86-26ade8d624457b7164502ed9c190ca3f146bda0c.tar.gz |
Import Dev86src-0.16.8.tar.gzv0.16.8
Diffstat (limited to 'copt')
-rw-r--r-- | copt/copt.c | 28 | ||||
-rw-r--r-- | copt/rules.186 | 10 | ||||
-rw-r--r-- | copt/rules.386 | 4 | ||||
-rw-r--r-- | copt/rules.86 | 182 | ||||
-rw-r--r-- | copt/rules.end | 5 | ||||
-rw-r--r-- | copt/rules.i | 6 | ||||
-rw-r--r-- | copt/rules.start | 4 |
7 files changed, 182 insertions, 57 deletions
diff --git a/copt/copt.c b/copt/copt.c index 35588d3..350c163 100644 --- a/copt/copt.c +++ b/copt/copt.c @@ -43,7 +43,11 @@ #define KEEPCOMMENTS #define MAXLINE 1024 +#ifdef __BCC__ #define HASHSIZE 107 +#else +#define HASHSIZE 1999 +#endif #define NOCHAR '\177' #define VARNUM 10 @@ -112,7 +116,7 @@ static char *install(char *str, int slen) struct hash_s *hp; char *chkstr; char *cp; - int hashval; + unsigned int hashval; /* Clear the hashing table if not already done */ if (!hash_init) { @@ -131,7 +135,7 @@ static char *install(char *str, int slen) /* Determine hashing value of string */ hashval = 0; for (cp = chkstr; *cp; cp++) - hashval += *cp; + hashval = hashval*75 + *cp; hashval %= HASHSIZE; /* Check if the string is already in the hashing table */ @@ -238,14 +242,25 @@ static void readpattern(char *rulesdir, char *filename) rp = (struct rule_s *)mymalloc(sizeof(struct rule_s)); rp->old = readlist(fp, '=', '#'); rp->new = readlist(fp, '\0', '#'); - rp->next = first; if (rp->old == NULL || rp->new == NULL) { free(rp); break; } + +/* This put the rules into the table in reverse order; this is confusing * + rp->next = first; first = rp; if (last == NULL) last = rp; +*/ + rp->next = NULL; + if (last) { + last->next = rp; + last = rp; + } else { + first = last = rp; + } + } /* Close pattern file */ @@ -679,6 +694,11 @@ static struct line_s *optline(struct line_s *cur) if (!ins->comment_flg) pat = pat->next; + else if (ins->text[0]==pat->text[0]) /* Matching a comment! */ + { + if (match(ins->text, pat->text)) + pat = pat->next; + } ins = ins->next; } @@ -688,7 +708,7 @@ static struct line_s *optline(struct line_s *cur) lp1 = cur; cur = cur->prev; while (lp1 != ins) { -#if 0 /* I'd like to keep the comment lines but this doesn't work XXX */ +#if 0 if( lp1->comment_flg ) { lp2 = lp1; diff --git a/copt/rules.186 b/copt/rules.186 index 4d4522c..90db16e 100644 --- a/copt/rules.186 +++ b/copt/rules.186 @@ -28,3 +28,13 @@ push bx = push #%1 +mov ax,*%1 +push ax += +push *%1 + +mov bx,*%1 +push bx += +push *%1 + diff --git a/copt/rules.386 b/copt/rules.386 index 6875e40..955d4b6 100644 --- a/copt/rules.386 +++ b/copt/rules.386 @@ -1,5 +1,7 @@ # Rules to optimize BCC assembler output for 386 +# Many of these rules are very broken, ho hum. + # Rules for loading a long constant xor ax,ax @@ -351,7 +353,7 @@ push word ptr %0[%1] mov %[ax|bx|cx|dx|si|di]2,%[#|*]0%1 push %[ax|bx|cx|dx|si|di]2 = -push word %0%1 +push %0%1 # Shifting rules diff --git a/copt/rules.86 b/copt/rules.86 index f0654f4..15b0749 100644 --- a/copt/rules.86 +++ b/copt/rules.86 @@ -2,76 +2,90 @@ # Rules for loading short variables -mov %0$0[%2],%3 -= -mov %0[%2],%3 - mov %2,%[ax|bx|cx|dx]1 mov %[ax|bx|cx|dx]1,%2 = mov %2,%1 -# Breaks: a = b = 125; -# mov %[ax|bx|cx|dx]3,%[#|*]0%1 -# mov %2[%4],%[ax|bx|cx|dx]3 -# = -# mov word ptr %2[%4],%0%1 - -# This gets a few back. +# Assign a constant mov %[ax|bx|cx|dx]3,%[#|*]0%1 mov %2[%4],%[ax|bx|cx|dx]3 -mov %[ax|bx|cx|dx]3,%5 +!BCC_EOS = mov word ptr %2[%4],%0%1 -mov %3,%5 +!BCC_EOS -mov %[ax|bx|cx|dx]3,%[#|*]0%1 -mov %[ax|bx|cx|dx]2,%[ax|bx|cx|dx]3 +# Assign a constant char +mov al,%[#|*]0%1 +mov %2,al +!BCC_EOS = -mov %2,%0%1 - -# Breaks: a = b = 'a'; -# mov al,%[#|*]0%1 -# mov %2,al -# = -# mov byte ptr %2,%0%1 +mov byte ptr %2,%0%1 +!BCC_EOS +# Assign a constant long from a small int xor ax,ax mov bx,%[#|*]0%1 mov [%2],ax mov [%2+2],bx +!BCC_EOS = mov word ptr [%2],#0 mov word ptr [%2+2],%0%1 +!BCC_EOS +# Assign a constant long from a 2^16 mod int. mov ax,%[#|*]0%1 xor bx,bx mov [%2],ax mov [%2+2],bx +!BCC_EOS = mov word ptr [%2],%0%1 mov word ptr [%2+2],#0 +!BCC_EOS +# Assign a constant long from a big int mov ax,%[#|*]4%1 mov bx,%[#|*]5%3 mov [%2],ax mov [%2+2],bx +!BCC_EOS = mov word ptr [%2],%4%1 mov word ptr [%2+2],%5%3 +!BCC_EOS +# rule for (char*) *x++ +mov bx,%1 +%[inc|dec]2 bx +mov %1,bx +mov al,-1[bx] +xor ah,ah += +mov bx,%1 +%2 word ptr %1 +mov al,[bx] +xor ah,ah # Rules for incrementing short variables +mov %[ax|bx|si|di]2,%1 +%[inc|dec]3 %[ax|bx|si|di]2 +mov %1,%[ax|bx|si|di]2 +!BCC_EOS += +%3 word ptr %1 +!BCC_EOS -mov %[ax|bx]2,%1 -%[inc|dec]3 %[ax|bx]2 -mov %1,%[ax|bx]2 +mov %[ax|bx|si|di]2,%1 +%[inc|dec]3 %[ax|bx|si|di]2 +mov %1,%[ax|bx|si|di]2 = %3 word ptr %1 mov %2,%1 -# Rules for manipulating characters +# Rules for manipulating characters with register char*s inc %[si|di]* inc %[si|di]* @@ -140,37 +154,44 @@ cld # Rules for manipulating short values -# This is the broken rule - Chad - -#mov %[ax|bx]2,%1 -#%[add|and|xor|sub|or]4 %[ax|bx]2,%3 -#mov %1,%[ax|bx]2 -#= -#mov %2,%3 -#%4 %1,%2 +# These rules only apply at end of statment. +mov %[ax|bx]2,%1 +%[add|and|xor|sub|or]4 %[ax|bx]2,%3 +mov %1,%[ax|bx]2 +!BCC_EOS += +mov %2,%3 +%4 %1,%2 +!BCC_EOS mov %[ax|bx]2,%1 %[add|and|xor|or]4 %[ax|bx]2,%3 mov %3,%[ax|bx]2 +!BCC_EOS = mov %2,%1 %4 %3,%2 - -mov %[ax|bx]4,%1 -%[add|and|xor|sub|or]2 %[si|di]3,%[ax|bx]4 -= -%2 %3,%1 +!BCC_EOS mov al,%1 xor ah,ah %[add|and|xor|sub|or]2 ax,%[#|*]0%3 mov %1,al +!BCC_EOS = %2 byte ptr %1,%0%3 +!BCC_EOS +# This is safe with an embedded assign. +mov %[ax|bx]4,%1 +%[add|and|xor|sub|or]2 %[si|di]3,%[ax|bx]4 += +%2 %3,%1 # Rules for comparing short values +# Compare doesn't need to leave any register in a specific state. + mov %[ax|bx]3,%1[%4] cmp %[ax|bx]3,%[#|*]0%2 = @@ -348,9 +369,11 @@ jmp .%1 jmp .%1 .%2: +!BCC_EOS .%1: = .%2: +!BCC_EOS .%1: jmp .%1 @@ -445,4 +468,83 @@ pop bx pop cx pop dx = -! push/pop +! push/pop float + +# Long right shift by 16 unsigned +mov ax,%1 +mov bx,%2 +xchg bx,ax +xor bx,bx += +mov ax,%2 +xor bx,bx + +# Long right shift by 16 signed +mov ax,%1 +mov bx,%2 +xchg bx,ax +cwd += +mov ax,%2 +cwd + +# Load long and exchange +mov ax,%1 +mov bx,%2 +xchg bx,ax += +mov bx,%1 +mov ax,%2 + +# Repeated clear. +xor bx,bx +xchg bx,ax +xor ax,ax += +xchg bx,ax +xor ax,ax + +# Long expression assigned to an int +cwd +mov bx,dx +mov %1,ax +!BCC_EOS += +mov %1,ax +!BCC_EOS + +# Load unsigned into high word of long +mov ax,%1 +xchg bx,ax +xor ax,ax += +mov bx,%1 +xor ax,ax + +# Souped up strcpy; "while(*d++ = *s++);" in a function with no reg vars. +.%3: +!BCC_EOS +.%4: +mov bx,%1 +inc bx +mov %1,bx +mov si,%2 +inc si +mov %2,si +mov al,-1[bx] +mov -1[si],al +test al,al +jne .%3 += +.%4: +mov si,%1 +mov di,%2 +.%3: +lodsb +stosb +test al,al +jne .%3 +mov %1,si +mov %2,di +!BCC_EOS + diff --git a/copt/rules.end b/copt/rules.end index cf2c6df..5f6eaba 100644 --- a/copt/rules.end +++ b/copt/rules.end @@ -15,8 +15,3 @@ pop si pop di pop bp ret - -pmov %1,%2 -= -push %1 -mov %1,%2 diff --git a/copt/rules.i b/copt/rules.i index 3cb8aca..917a995 100644 --- a/copt/rules.i +++ b/copt/rules.i @@ -57,7 +57,7 @@ call ___set_es inc sp inc sp = -mov ax,#%1 +mov ax,%0%1 mov es,ax mov ax,%[#|*]0%1 @@ -66,7 +66,7 @@ call ___set_es inc sp inc sp = -mov ax,#%1 +mov ax,%0%1 mov es,ax push %0[%1] @@ -290,5 +290,5 @@ mov ax,%1 mov ax,ax = -! +!mov ax,ax diff --git a/copt/rules.start b/copt/rules.start index 5a38888..f494305 100644 --- a/copt/rules.start +++ b/copt/rules.start @@ -17,7 +17,3 @@ ret = proc_end -push %1 -mov %1,%2 -= -pmov %1,%2 |