/* Copyright (c) 1979 Regents of the University of California */
* pi - Pascal interpreter code translator
* Charles Haley, Bill Joy UCB
* Version 1.2 January 1979
* If DEBUG is defined, include the table
* of the printing opcode names.
* Put is responsible for the interpreter equivalent of code
* generation. Since the interpreter is specifically designed
* for Pascal, little work is required here.
int n
, subop
, suboppr
, op
, oldlc
, w
;
* It would be nice to do some more
* optimizations here. The work
* done to collapse offsets in lval
* should be done here, the IFEQ etc
* relational operators could be used
* code disabled - do nothing
suboppr
= subop
= (*p
>>8) & 0377;
if ((cp
= otext
[op
]) == NIL
) {
if (p
[1] < 128 && p
[1] >= -128) {
if (op
>= O_REL2
&& op
<= O_REL84
) {
if ((i
= (subop
>> 1) * 5 ) >= 30)
string
= &"IFEQ\0IFNE\0IFLT\0IFGT\0IFLE\0IFGE"[i
];
string
= &"22\024\042\044"[subop
*3];
printf("%5d\tCONG:%d\t%s\n", lc
, i
, cp
);
w
=| (*cp
? *cp
++ : ' ') << 8;
(string
= "'x'")[1] = p
[1];
printf("%5d\tCASE1\t%d\n", lc
, p
[2]);
word(casewrd
| p
[2] << 8);
printf("%5d\tCASE2\t%d\n", lc
, p
[2]);
printf("%5d\tCASE4\t%d %d\n", lc
, p
[1], p
[2]);
printf("%5d\t%s", lc
, cp
);
* Putspace puts out a table
* of nothing to leave space
* for the case branch table e.g.
printf("%5d\t.=.+%d\n", lc
, i
);
for (i
= even(n
); i
> 0; i
=- 2)
* Patch repairs the branch
* at location loc to come
* to the current location.
* Patchfil makes loc+2 have value
printf("\tpatch %u %d\n", loc
, value
);
i
= (loc
+ 2 - (lc
& ~0777))/2;
* Put the word o into the code
if (i
!= 0 && write(ofil
, obuf
, i
) != i
)
perror(obj
), pexit(DIED
);
* Getlab - returns the location counter.
* included here for the eventual code generator.
* Putlab - lay down a label.