* Copyright (c) 1984, 1986 Regents of the University of California.
* All rights reserved. The Berkeley software License Agreement
* specifies the terms and conditions for redistribution.
static char sccsid
[] = "@(#)machdep.c 7.1 (Berkeley) 6/5/86";
* The routines and tables in this file must be rewritten
* for each new machine that this program is ported to.
* Instruction stop table.
* All instructions that implicitly modify any of the temporary
* registers, change control flow, or implicitly loop must be
* listed in this table. It is used to find the end of a basic
* block when scanning backwards through the instruction stream
* trying to merge the inline expansion.
struct inststoptbl inststoptable
[] = {
{ "jbc" }, { "jlbc" }, { "jbs" }, { "jlbs" }, { "jbcc" },
{ "jbsc" }, { "jbcs" }, { "jbss" }, { "jbr" }, { "jcc" },
{ "jcs" }, { "jvc" }, { "jvs" }, { "jlss" }, { "jlssu" },
{ "jleq" }, { "jlequ" }, { "jeql" }, { "jeqlu" }, { "jneq" },
{ "jnequ" }, { "jgeq" }, { "jgequ" }, { "jgtr" }, { "jgtru" },
{ "chmk" }, { "chme" }, { "chms" }, { "chmu" }, { "rei" },
{ "ldpctx" }, { "svpctx" }, { "xfc" }, { "bpt" },
{ "bugw" }, { "bugl" }, { "halt" }, { "pushr" }, { "popr" },
{ "polyf" }, { "polyd" }, { "polyg" }, { "polyh" },
{ "bneq" }, { "bnequ" }, { "beql" }, { "beqlu" }, { "bgtr" },
{ "bleq" }, { "bgeq" }, { "blss" }, { "bgtru" }, { "blequ" },
{ "bvc" }, { "bvs" }, { "bgequ" }, { "bcc" }, { "blssu" },
{ "bcs" }, { "brb" }, { "brw" }, { "jmp" },
{ "bbs" }, { "bbc" }, { "bbss" }, { "bbcs" }, { "bbsc" },
{ "bbcc" }, { "bbssi" }, { "bbcci" }, { "blbs" }, { "blbc" },
{ "acbb" }, { "acbw" }, { "acbl" }, { "acbf" }, { "acbd" },
{ "acbg" }, { "acbh" }, { "aoblss" }, { "aobleq" },
{ "sobgeq" }, { "sobgtr" }, { "caseb" }, { "casew" }, { "casel" },
{ "bsbb" }, { "bsbw" }, { "jsb" }, { "rsb" },
{ "callg" }, { "calls" }, { "ret" },
{ "movc3" }, { "movc5" }, { "movtc" }, { "movtuc" },
{ "cmpc3" }, { "cmpc5" }, { "scanc" }, { "spanc" },
{ "locc" }, { "skpc" }, { "matchc" }, { "crc" },
{ "movp" }, { "cmpp3" }, { "cmpp4" }, { "addp4" }, { "addp6" },
{ "subp4" }, { "subp6" }, { "mulp" }, { "divp" }, { "cvtlp" },
{ "cvtpl" }, { "cvtpt" }, { "cvttp" }, { "cvtps" }, { "cvtsp" },
{ "ashp" }, { "editpc" },
{ "escd" }, { "esce" }, { "escf" },
* Check to see if a line is a candidate for replacement.
* Return pointer to name to be looked up in pattern table.
if (bcmp(cp
, "calls\t", 6) != 0)
if ((cp
= index(cp
+ 6, ',')) == 0)
* Find out how many arguments the function is being called with.
* A return value of -1 indicates that the count can't be determined.
if ((cp
= index(cp
, '$')) == 0)
* Find the next argument to the function being expanded.
register char *lastarg
= argv
[2];
bcmp(argv
[0], "mov", 3) == 0 &&
bcmp(argv
[1], "(sp)+", 6) == 0 &&
lastarg
[0] == 'r' && isdigit(lastarg
[1]) && lastarg
[2] == '\0')
return (lastarg
[1] - '0');
* Determine whether the current line pushes an argument.
if (argc
== 2 && bcmp(argv
[0], "push", 4) == 0)
if (bcmp(argv
[argc
- 1], "-(sp)", 6) == 0)
* Determine which (if any) registers are modified
* Return register number that is modified, -1 if none are modified.
* For the VAX all we care about are r0 to r5
register char *lastarg
= argv
[argc
- 1];
if (lastarg
[0] == 'r' && isdigit(lastarg
[1]) && lastarg
[2] == '\0')
return (lastarg
[1] - '0');
* Rewrite the instruction in (argc, argv) to store its
* contents into arg instead of onto the stack. The new
* instruction is placed in the buffer that is provided.
rewrite(instbuf
, argc
, argv
, target
)
fprintf(stderr
, "blank line to rewrite?\n");
sprintf(instbuf
, "\t%s\n", argv
[0]);
fprintf(stderr
, "rewrite?-> %s", instbuf
);
if (bcmp(argv
[0], "push", 4) == 0) {
sprintf(instbuf
, "\tmov%s\t%s,r%d\n",
&argv
[0][4], argv
[1], target
);
sprintf(instbuf
, "\t%s\tr%d\n", argv
[0], target
);
sprintf(instbuf
, "\t%s\t%s,r%d\n", argv
[0], argv
[1], target
);
sprintf(instbuf
, "\t%s\t%s,%s,r%d\n",
argv
[0], argv
[1], argv
[2], target
);
sprintf(instbuf
, "\t%s\t%s,%s,%s,r%d\n",
argv
[0], argv
[1], argv
[2], argv
[3], target
);
sprintf(instbuf
, "\t%s\t%s", argv
[0], argv
[1]);
(void) strcat(instbuf
, ",");
(void) strcat(instbuf
, *argv
++);
(void) strcat(instbuf
, "\n");
fprintf(stderr
, "rewrite?-> %s", instbuf
);
* Do any necessary post expansion cleanup.
* Instruction stop table.
* All instructions that implicitly modify any of the temporary
* registers, change control flow, or implicitly loop must be
* listed in this table. It is used to find the end of a basic
* block when scanning backwards through the instruction stream
* trying to merge the inline expansion.
struct inststoptbl inststoptable
[] = {
* Check to see if a line is a candidate for replacement.
* Return pointer to name to be looked up in pattern table.
if (bcmp(cp
, "jbsr\t", 5) == 0)
* Find out how many arguments the function is being called with.
* A return value of -1 indicates that the count can't be determined.
* Figure out what the count should be.
* Probably have to read the next instruction here
* instead of in cleanup() below.
* Find the next argument to the function being expanded.
register char *lastarg
= argv
[2];
bcmp(argv
[0], "movl", 5) == 0 &&
bcmp(argv
[1], "sp@+", 5) == 0 &&
(lastarg
[1] == '0' || lastarg
[1] == '1') &&
return (lastarg
[1] - '0');
return (lastarg
[1] - '0' + 8);
* Determine whether the current line pushes an argument.
if (argc
== 2 && bcmp(argv
[0], "pea", 4) == 0)
if (bcmp(argv
[argc
- 1], "sp@-", 5) == 0)
* Determine which (if any) registers are modified
* Return register number that is modified, -1 if none are modified.
* For the MC68000 all we care about are d0, d1, a0, and a1.
register char *lastarg
= argv
[argc
- 1];
if (lastarg
[0] == 'd' && isdigit(lastarg
[1]) && lastarg
[2] == '\0')
return (lastarg
[1] - '0');
if (lastarg
[0] == 'a' && isdigit(lastarg
[1]) && lastarg
[2] == '\0')
return (lastarg
[1] - '0' + 8);
* Rewrite the instruction in (argc, argv) to store its
* contents into arg instead of onto the stack. The new
* instruction is placed in the buffer that is provided.
rewrite(instbuf
, argc
, argv
, target
)
fprintf(stderr
, "blank line to rewrite?\n");
sprintf(instbuf
, "\t%s\n", argv
[0]);
fprintf(stderr
, "rewrite?-> %s", instbuf
);
if (bcmp(argv
[0], "pea", 4) == 0) {
sprintf(instbuf
, "\tlea\t%s,%c%d\n",
argv
[1], regtype
, regno
);
if (argv
[1][0] == '_' || isdigit(argv
[1][0])) {
sprintf(instbuf
, "\tmovl\t#%s,%c%d\n",
argv
[1], regtype
, regno
);
"\texg\ta0,d%d\n\tlea\t%s,a0\n\texg\ta0,d%d\n",
sprintf(instbuf
, "\t%s\t%c%d\n", argv
[0], regtype
, regno
);
sprintf(instbuf
, "\t%s\t%s,%c%d\n",
argv
[0], argv
[1], regtype
, regno
);
sprintf(instbuf
, "\t%s\t%s", argv
[0], argv
[1]);
(void) strcat(instbuf
, ",");
(void) strcat(instbuf
, *argv
++);
(void) strcat(instbuf
, "\n");
fprintf(stderr
, "rewrite?-> %s", instbuf
);
* Do any necessary post expansion cleanup.
* delete instruction to pop arguments.
* CHECK THAT INSTRUCTION IS A POP
fgets(line
[bufhead
], MAXLINELEN
, stdin
);