/* Copyright (c) 1984 Regents of the University of California */
static char sccsid
[] = "@(#)machdep.c 1.4 (Berkeley) 9/20/84";
* 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$", 7) == 0)
* Find the next argument to the function being expanded.
* If register ends with a '#' then source may be used directly.
* If register ends with a '@' then source may be used if an indirect
nextarg(argc
, argv
, flag
)
register char *lastarg
= argv
[2];
bcmp(argv
[0], "mov", 3) == 0 &&
bcmp(argv
[1], "(sp)+", 6) == 0 &&
lastarg
[0] == 'r' && isdigit(lastarg
[1])) {
if (lastarg
[2] == '\0') {
return (lastarg
[1] - '0');
} else if (lastarg
[2] == '$') {
return (lastarg
[1] - '0');
} else if (lastarg
[2] == '*') {
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');
checkvar(argc
, argv
, flag
, source
, mod
)
register char *cp1
, *cp2
;
if (flag
== 0) return(0);
if (bcmp(argv
[0], "push", 4) != 0 && bcmp(argv
[0], "mov", 3) != 0)
while (*cp1
) if (*cp1
++ == 'r' && isdigit(*cp1
) &&
(mod
& (1 << (*cp1
++ - '0'))) &&
(*cp1
== '\0' || *cp1
== ')' || *cp1
== ']'))
if ((argv
[0][0] == 'p' && argv
[0][4] == 'a') ||
(argv
[0][0] == 'm' && argv
[0][3] == 'a'))
while (*cp2
++ = *cp1
++) ;
if (cp1
== NULL
) return(0);
while (*cp2
++ = *cp1
++) ;
* 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("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]);
strcat(instbuf
, *argv
++);
fprintf(stderr
, "rewrite?-> %s", instbuf
);
/* Return indirect version of variable:
* a(rn)[rm] -> *a(rn)[rm]
* _foo(rn)[rm] -> *_foo(rn)[rm]
if (*cp
== '*' || (*cp
== '-' && *(cp
+1) == '(')) return(NULL
);
if (*++c
== '+') return(NULL
);
if (*cp
== '$' && *(cp
+1) == 'L') {
output_replace(replace
, oparg
, argno
, f
)
replace
= copyline(replace
, newline
);
argc
= parseline(newline
, argv
, parsebuf
);
for (i
= 0; i
< argno
; i
++)
replace_arg(argc
, argv
, oparg
[i
].reg
, oparg
[i
].source
);
buildline(argc
, argv
, newline
);
} while (*replace
!= '\0');
replace_arg(argc
, argv
, reg
, source
)
for (i
= 1; i
< argc
; i
++) {
if (*c
++ == 'r' && (*c
++ - '0') == reg
&& !isdigit(*c
)) {
buildline(argc
, argv
, newline
)
sprintf(newline
, "%s\n", argv
[0]);
sprintf(newline
, "\t%s\t%s", argv
[0], argv
[1]);
if (*cp1
== '$' || *cp1
== '*') *cp1
= '\0';
strcat(newline
, *argv
++);
* 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 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("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]);
strcat(instbuf
, *argv
++);
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
);