/* Copyright (c) 1984 Regents of the University of California */
static char sccsid
[] = "@(#)main.c 1.1 (Berkeley) %G%";
register struct pats
*pp
, **hp
;
freopen(argv
[1], "r", stdin
);
freopen(argv
[2], "w", stdout
);
for (pp
= language_ptab
; pp
->name
[0] != '\0'; pp
++) {
hp
= hash(pp
->name
, &size
);
for (pp
= libc_ptab
; pp
->name
[0] != '\0'; pp
++) {
hp
= hash(pp
->name
, &size
);
for (pp
= machine_ptab
; pp
->name
[0] != '\0'; pp
++) {
hp
= hash(pp
->name
, &size
);
* check each line and replace as appropriate
while (fgets(bufp
, MAXLINELEN
, stdin
)) {
lp
= index(bufp
, LABELCHAR
);
for (cp
= bufp
; isspace(*cp
); cp
++)
if ((cp
= doreplaceon(cp
)) == 0) {
for (pp
= *hash(cp
, &size
); pp
; pp
= pp
->next
) {
if (pp
->size
== size
&& bcmp(pp
->name
, cp
, size
) == 0) {
* Integrate an expansion into the assembly stream
char *nextreplace
, *argv
[MAXARGS
];
int argc
, argreg
, queueempty
, mod
= 0;
for (curptr
= bufhead
; curptr
!= buftail
; ) {
queueempty
= (curptr
== buftail
);
nextreplace
= copyline(replace
, line
[bufhead
]);
argc
= parseline(line
[bufhead
], argv
, parsebuf
);
argreg
= nextarg(argc
, argv
);
argc
= parseline(line
[curptr
], argv
, parsebuf
);
if (ispusharg(argc
, argv
))
mod
|= 1 << modifies(argc
, argv
);
queueempty
= (curptr
== buftail
);
if (mod
& (1 << argreg
)) {
rewrite(line
[curptr
], argc
, argv
, argreg
);
* Parse a line of assembly language into opcode and arguments.
parseline(linep
, argv
, linebuf
)
register char *bufp
= linebuf
, *cp
= linep
;
if (argc
== MAXARGS
- 1) {
fprintf(stderr
, "instruction too long->%s", linep
);
while (!isspace(*cp
) && *cp
!= ',' && *cp
!= COMMENTCHAR
)
* Copy a newline terminated string.
* Return pointer to character following last character copied.
register char *from
, *to
;
* open space for next line in the queue
if (bufhead
== buftail
) {
fputs(line
[buftail
], stdout
);
* empty the queue by printing out all its lines.
while (buftail
!= bufhead
) {
fputs(line
[buftail
], stdout
);
* Compute the hash of a string.
* Return the hash and the size of the item hashed
while (*cp1
&& *cp1
!= '\n')