summaryrefslogtreecommitdiff
path: root/copt
diff options
context:
space:
mode:
authorRobert de Bath <rdebath@poboxes.com>1998-02-12 22:41:49 +0100
committerLubomir Rintel <lkundrak@v3.sk>2013-10-23 23:40:21 +0200
commit2f828530e36a02c5b4c534e42ab812370c2bf7d9 (patch)
treec26ea035d122f5374ed4c9ef39c6748742541ef5 /copt
parent48f0b3eb836162d41622cedc1eb5f5168168fb8e (diff)
downloaddev86-2f828530e36a02c5b4c534e42ab812370c2bf7d9.tar.gz
Import Dev86src-0.14.0.tar.gzv0.14.0
Diffstat (limited to 'copt')
-rw-r--r--copt/copt.c95
-rw-r--r--copt/rules.18630
-rw-r--r--copt/rules.3868
-rw-r--r--copt/rules.i278
-rw-r--r--copt/rules.inl8
5 files changed, 396 insertions, 23 deletions
diff --git a/copt/copt.c b/copt/copt.c
index 6cef964..12a5ac2 100644
--- a/copt/copt.c
+++ b/copt/copt.c
@@ -40,6 +40,8 @@
#include <string.h>
#include <ctype.h>
+#define KEEPCOMMENTS
+
#define MAXLINE 1024
#define HASHSIZE 107
#define NOCHAR '\177'
@@ -52,6 +54,9 @@ struct line_s {
char *text;
struct line_s *prev;
struct line_s *next;
+#ifdef KEEPCOMMENTS
+ int comment_flg;
+#endif
};
@@ -191,13 +196,19 @@ static struct line_s *readlist(FILE *fp, char quit, char comment)
if (quit != NOCHAR && quit == *cp)
break;
if (comment != NOCHAR && comment == *cp)
- continue;
+#ifdef KEEPCOMMENTS
+ if (quit != NOCHAR)
+#endif
+ continue;
if (*cp == '\0')
continue;
lp = mymalloc(sizeof(struct line_s));
lp->text = install(cp, -1);
lp->prev = last_line;
lp->next = NULL;
+#ifdef KEEPCOMMENTS
+ lp->comment_flg = (comment != NOCHAR && *cp == comment);
+#endif
if (first_line == NULL)
first_line = lp;
if (last_line != NULL)
@@ -436,12 +447,20 @@ static int match(char *ins, char *pat)
int len;
while (*ins && *pat)
- if (pat[0] == '%' && pat[1] == '%') {
+ {
+ if (pat[0] != '%')
+ {
+ if (*pat++ != *ins++)
+ return(0);
+ else
+ continue;
+ }
+ if (pat[1] == '%') {
/* '%%' actually means '%' */
if (*ins != '%')
return(0);
pat += 2;
- } else if (pat[0] == '%' && (pat[1] == '*' || isdigit(pat[1]))) {
+ } else if ((pat[1] == '*' || isdigit(pat[1]))) {
/* Copy variable text into vars array */
pat += 2;
for (cp = ins; *ins && !match(ins, pat); ins++) ;
@@ -454,7 +473,7 @@ static int match(char *ins, char *pat)
else if (strlen(vars[varnum]) != len ||
strncmp(vars[varnum], cp, len))
return(0);
- } else if (pat[0] == '%' && pat[1] == '[') {
+ } else if (pat[1] == '[') {
/* Copy only specific variable text into vars array */
if ((cp = strchr(pat + 2, ']')) == NULL ||
(*(cp + 1) != '*' && !isdigit(*(cp + 1)))) {
@@ -487,7 +506,7 @@ static int match(char *ins, char *pat)
else if (strlen(vars[varnum]) != len ||
strncmp(vars[varnum], oldpat, len))
return(0);
- } else if (pat[0] == '%' && pat[1] == '!') {
+ } else if (pat[1] == '!') {
/* Match only if the pattern string is not found */
if (pat[2] != '[' || (cp = strchr(pat + 3, ']')) == NULL) {
if (*ins != '!')
@@ -505,7 +524,7 @@ static int match(char *ins, char *pat)
return(0);
oldpat += len;
}
- } else if (pat[0] == '%' && pat[1] == '(') {
+ } else if (pat[1] == '(') {
/* Match ins with expression */
if ((cp = strchr(pat + 2, ')')) == NULL) {
if (*ins != '(')
@@ -521,8 +540,10 @@ static int match(char *ins, char *pat)
len = ins - cp;
if (val != eval(cp, len))
return(0);
- } else if (*pat++ != *ins++)
+ }
+ else /* Bad % format cannot match */
return(0);
+ }
return(*ins == *pat);
}
@@ -656,10 +677,23 @@ static struct line_s *optline(struct line_s *cur)
/* Scan through pattern texts and match them against the input file */
ins = cur;
pat = rp->old;
+#ifndef KEEPCOMMENTS
while (ins != NULL && pat != NULL && match(ins->text, pat->text)) {
ins = ins->next;
pat = pat->next;
}
+#else
+ while (ins != NULL
+ && pat != NULL
+ && ( ins->comment_flg ||
+ ( /* (pat->text[0]=='%' || ins->text[0]==pat->text[0]) && */
+ match(ins->text, pat->text)))) {
+
+ if (!ins->comment_flg)
+ pat = pat->next;
+ ins = ins->next;
+ }
+#endif
/* Current pattern matched input line, so replace input with new */
if (pat == NULL) {
@@ -667,9 +701,25 @@ static struct line_s *optline(struct line_s *cur)
lp1 = cur;
cur = cur->prev;
while (lp1 != ins) {
- lp2 = lp1;
- lp1 = lp1->next;
- free(lp2);
+#ifdef KEEPCOMMENTS
+#if 0 /* I'd like to keep the comment lines but this doesn't work XXX */
+ if( lp1->comment_flg )
+ {
+ lp2 = lp1;
+ lp1 = lp1->next;
+ lp2->next = cur->next;
+ cur->next = lp2;
+ lp2->prev = cur;
+ cur=cur->next;
+ }
+ else
+#endif
+#endif
+ {
+ lp2 = lp1;
+ lp1 = lp1->next;
+ free(lp2);
+ }
}
/* Insert new lines into list */
pat = rp->new;
@@ -680,6 +730,9 @@ static struct line_s *optline(struct line_s *cur)
lp2->text = subst(pat->text);
lp2->next = NULL;
lp2->prev = lp1;
+#ifdef KEEPCOMMENTS
+ lp2->comment_flg = 0;
+#endif
if (lp1 != NULL)
lp1->next = lp2;
else
@@ -710,16 +763,28 @@ static void optimize(int backup)
{
struct line_s *cur, *lp;
int i;
+#ifdef KEEPCOMMENTS
+ int in_asm = 0;
+#endif
/* Scan through all lines in the input file */
cur = infile;
while (cur != NULL) {
- if ((lp = optline(cur)) != NULL && lp != cur->next) {
- for (i = 0; i < backup && lp != NULL; i++)
- lp = lp->prev;
- if (lp == NULL)
- lp = infile;
+#ifdef KEEPCOMMENTS
+ if (cur->comment_flg || in_asm)
+ {
+ lp=cur->next;
+ if (memcmp(cur->text, "!BCC_", 5) == 0)
+ in_asm = (memcmp(cur->text+5, "ASM", 3) == 0);
}
+ else
+#endif
+ if ((lp = optline(cur)) != NULL && lp != cur->next) {
+ for (i = 0; i < backup && lp != NULL; i++)
+ lp = lp->prev;
+ if (lp == NULL)
+ lp = infile;
+ }
cur = lp;
}
}
diff --git a/copt/rules.186 b/copt/rules.186
new file mode 100644
index 0000000..4d4522c
--- /dev/null
+++ b/copt/rules.186
@@ -0,0 +1,30 @@
+# Enter and leave ...
+
+mov sp,bp
+pop bp
+=
+leave
+
+push bp
+mov bp,sp
+add sp,#-%1
+=
+enter %1,0
+
+push bp
+mov bp,sp
+dec sp
+dec sp
+=
+enter 2,0
+
+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 c2d07d7..6875e40 100644
--- a/copt/rules.386
+++ b/copt/rules.386
@@ -319,6 +319,11 @@ call l%3%[ul|l]*
=
%3 eax,[%2]
+mov di,*%2
+call lsll
+=
+lsl eax,*%2
+
lea di,%2
call l%3%[ul|l]*
=
@@ -425,3 +430,6 @@ com %1
=
not %1
+xor bx,bx
+=
+and eax,#$0000FFFF
diff --git a/copt/rules.i b/copt/rules.i
new file mode 100644
index 0000000..9506bd9
--- /dev/null
+++ b/copt/rules.i
@@ -0,0 +1,278 @@
+# Rules for optimizing BCC assembler output
+
+# Rules for inlining C library functions
+
+push word %[#|*]0%1
+call __htons
+inc sp
+inc sp
+=
+mov ax,#((%1 & $00FF) << 8) + ((%1 & $FF00) >> 8)
+
+mov ax,%[#|*]0%1
+push ax
+call __htons
+inc sp
+inc sp
+=
+mov ax,#((%1 & $00FF) << 8) + ((%1 & $FF00) >> 8)
+
+push %0[%1]
+call __htons
+inc sp
+inc sp
+=
+mov ax,%0[%1]
+xchg al,ah
+
+push ax
+call __htons
+inc sp
+inc sp
+=
+xchg al,ah
+
+push %[bx|cx|dx]1
+call __htons
+inc sp
+inc sp
+=
+mov ax,%1
+xchg al,ah
+
+call ___get_ds
+=
+mov ax,ds
+
+call ___get_es
+=
+mov ax,es
+
+call ___get_cs
+=
+mov ax,cs
+
+push word %[#|*]0%1
+call ___set_es
+inc sp
+inc sp
+=
+mov ax,#%1
+mov es,ax
+
+mov ax,%[#|*]0%1
+push ax
+call ___set_es
+inc sp
+inc sp
+=
+mov ax,#%1
+mov es,ax
+
+push %0[%1]
+call ___set_es
+inc sp
+inc sp
+=
+mov ax,%0[%1]
+mov es,ax
+
+push %[ax|bx|cx|dx]1
+call ___set_es
+inc sp
+inc sp
+=
+mov es,%1
+
+push word %[#|*]0%1
+call ___deek_es
+inc sp
+inc sp
+=
+seg es
+mov ax,[%1]
+
+mov ax,%[#|*]0%1
+push ax
+call ___deek_es
+inc sp
+inc sp
+=
+seg es
+mov ax,[%1]
+
+push %0[%1]
+call ___deek_es
+inc sp
+inc sp
+=
+mov bx,%0[%1]
+seg es
+mov ax,[bx]
+
+push bx
+call ___deek_es
+inc sp
+inc sp
+=
+seg es
+mov ax,[bx]
+
+push %[ax|cx|dx]1
+call ___deek_es
+inc sp
+inc sp
+=
+mov bx,%1
+seg es
+mov ax,[bx]
+
+push word %[#|*]0%1
+call ___peek_es
+inc sp
+inc sp
+=
+seg es
+mov al,[%1]
+xor ah,ah
+
+mov ax,%[#|*]0%1
+push ax
+call ___peek_es
+inc sp
+inc sp
+=
+seg es
+mov al,[%1]
+xor ah,ah
+
+push %0[%1]
+call ___peek_es
+inc sp
+inc sp
+=
+mov bx,%0[%1]
+seg es
+mov al,[bx]
+xor ah,ah
+
+push bx
+call ___peek_es
+inc sp
+inc sp
+=
+seg es
+mov al,[bx]
+xor ah,ah
+
+push %[ax|cx|dx]1
+call ___peek_es
+inc sp
+inc sp
+=
+mov bx,%1
+seg es
+mov al,[bx]
+xor ah,ah
+
+push word %[#|*]0%1
+call ___poke_es
+add sp,*4
+=
+pop ax
+seg es
+mov [%1],al
+
+mov ax,%[#|*]0%1
+push ax
+call ___poke_es
+add sp,*4
+=
+pop ax
+seg es
+mov [%1],al
+
+push %0[%1]
+call ___poke_es
+add sp,*4
+=
+mov bx,%0[%1]
+pop ax
+seg es
+mov [bx],al
+
+push bx
+call ___poke_es
+add sp,*4
+=
+pop ax
+seg es
+mov [bx],al
+
+push %[ax|cx|dx]1
+call ___poke_es
+add sp,*4
+=
+mov bx,%1
+pop ax
+seg es
+mov [bx],al
+
+push word %[#|*]0%1
+call ___doke_es
+add sp,*4
+=
+pop ax
+seg es
+mov [%1],ax
+
+mov ax,%[#|*]0%1
+push ax
+call ___doke_es
+add sp,*4
+=
+pop ax
+seg es
+mov [%1],ax
+
+push %0[%1]
+call ___doke_es
+add sp,*4
+=
+mov bx,%0[%1]
+pop ax
+seg es
+mov [bx],ax
+
+push bx
+call ___doke_es
+add sp,*4
+=
+pop ax
+seg es
+mov [bx],ax
+
+push %[ax|cx|dx]1
+call ___doke_es
+add sp,*4
+=
+mov bx,%1
+pop ax
+seg es
+mov [bx],ax
+
+push ax
+mov bx,%1
+pop ax
+=
+mov bx,%1
+
+push %1
+pop ax
+=
+mov ax,%1
+
+mov ax,ax
+=
+!
+
diff --git a/copt/rules.inl b/copt/rules.inl
deleted file mode 100644
index 8a3e218..0000000
--- a/copt/rules.inl
+++ /dev/null
@@ -1,8 +0,0 @@
-
-mov ax,%1
-mov bx,%2
-call isr
-=
-mov ax,%1
-mov cx,%2
-sar ax,cl