fix count on bzero
[unix-history] / usr / src / sys / vax / inline / machdep.c
CommitLineData
58248d62
KM
1/* Copyright (c) 1984 Regents of the University of California */
2
3#ifndef lint
4static char sccsid[] = "@(#)machdep.c 1.1 (Berkeley) %G%";
5#endif not lint
6
7#include <stdio.h>
8#include <ctype.h>
9
10/*
11 * The routines in this file must be rewritten for each
12 * new machine that this program is ported to.
13 */
14
15/*
16 * Check to see if a line is a candidate for replacement.
17 * Return pointer to name to be looked up in pattern table.
18 */
19char *
20doreplaceon(cp)
21 char *cp;
22{
23
24 if (bcmp(cp, "calls\t$", 7) == 0)
25 return (cp + 7);
26 return (0);
27}
28
29/*
30 * Find the next argument to the function being expanded.
31 * MACHINE DEPENDENT
32 */
33nextarg(argc, argv)
34 int argc;
35 char *argv[];
36{
37 register char *lastarg = argv[2];
38
39 if (argc == 3 &&
40 bcmp(argv[0], "mov", 3) == 0 &&
41 bcmp(argv[1], "(sp)+", 6) == 0 &&
42 lastarg[0] == 'r' && isdigit(lastarg[1]) && lastarg[2] == '\0')
43 return (lastarg[1] - '0');
44 return (-1);
45}
46
47/*
48 * Determine whether the current line pushes an argument.
49 * MACHINE DEPENDENT
50 */
51 ispusharg(argc, argv)
52 int argc;
53 char *argv[];
54{
55
56 if (argc < 2)
57 return (0);
58 if (argc == 2 && bcmp(argv[0], "push", 4) == 0)
59 return (1);
60 if (bcmp(argv[argc - 1], "-(sp)", 6) == 0)
61 return (1);
62 return (0);
63}
64
65/*
66 * Determine which (if any) registers are modified
67 * Return register number that is modified, -1 if none are modified.
68 * MACHINE DEPENDENT
69 */
70modifies(argc, argv)
71 int argc;
72 char *argv[];
73{
74 /*
75 * For the VAX all we care about are r0 to r5
76 */
77 register char *lastarg = argv[argc - 1];
78
79 if (lastarg[0] == 'r' && isdigit(lastarg[1]) && lastarg[2] == '\0')
80 return (lastarg[1] - '0');
81 return (-1);
82}
83
84/*
85 * Rewrite the instruction in (argc, argv) to store its
86 * contents into arg instead of onto the stack. The new
87 * instruction is placed in the buffer that is provided.
88 * MACHINE DEPENDENT
89 */
90rewrite(instbuf, argc, argv, target)
91 char *instbuf;
92 int argc;
93 char *argv[];
94 int target;
95{
96
97 switch (argc) {
98 case 0:
99 instbuf[0] = '\0';
100 fprintf("blank line to rewrite?\n");
101 return;
102 case 1:
103 sprintf(instbuf, "\t%s\n", argv[0]);
104 fprintf(stderr, "rewrite?-> %s", instbuf);
105 return;
106 case 2:
107 if (bcmp(argv[0], "push", 4) == 0) {
108 sprintf(instbuf, "\tmov%s\t%s,r%d\n",
109 &argv[0][4], argv[1], target);
110 return;
111 }
112 sprintf(instbuf, "\t%s\tr%d\n", argv[0], target);
113 return;
114 case 3:
115 sprintf(instbuf, "\t%s\t%s,r%d\n", argv[0], argv[1], target);
116 return;
117 case 4:
118 sprintf(instbuf, "\t%s\t%s,%s,r%d\n",
119 argv[0], argv[1], argv[2], target);
120 return;
121 default:
122 sprintf(instbuf, "\t%s\t%s", argv[0], argv[1]);
123 argc -= 2, argv += 2;
124 while (argc-- > 0) {
125 strcat(instbuf, ",");
126 strcat(instbuf, *argv++);
127 }
128 strcat(instbuf, "\n");
129 fprintf(stderr, "rewrite?-> %s", instbuf);
130 return;
131 }
132}