/* Copyright (c) 1979 Regents of the University of California */
* pi - Pascal interpreter code translator
* Charles Haley, Bill Joy UCB
* Version 1.2 November 1978
* 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) {
printf ( ")#%5d\tCON8\t%10.3f\n" ,
* ( ( double * ) &p
[1] ) );
for ( i
= 1 ; i
<= 4 ; i
++ )
if (op
>= O_REL2
&& op
<= O_REL84
) {
if ((i
= (subop
>> 1) * 5 ) >= 30)
string
= &"IFEQ\0IFNE\0IFLT\0IFGT\0IFLE\0IFGE"[i
];
/* relative addressing */
p
[1] -= ( unsigned ) lc
+ 2;
string
= &"22\024\042\044"[subop
*3];
cp
= * ( ( char ** ) &p
[2] ) ;
printf(")#%5d\tCONG:%d\t%s\n",
w
|= (*cp
? *cp
++ : ' ') << 8;
(string
= "'x'")[1] = p
[1];
printf(")#%5d\tCASE1\t%d\n"
, ( int ) *( ( long * ) &p
[1] ) );
* this to build a byte size case table
* saving bytes across calls in casewrd
* so they can be put out by word()
casewrd
= *( ( long * ) &p
[1] );
| ( ( int ) *( ( long * ) &p
[1] ) << 8 ) );
printf(")#%5d\tCASE2\t%d\n"
, ( int ) *( ( long * ) &p
[1] ) );
word( ( short ) *( ( long * ) &p
[1] ) );
/* absolute long addressing */
case O_RANG4
+ 1: /* O_RANG24 */
case O_RSNG4
+ 1: /* O_RSNG24 */
printf( ")#%5d\t%s" , lc
- HEAD_BYTES
, cp
);
; i
+= sizeof ( long )/sizeof ( short ) )
printf( "\t%D " , *lp
++ );
for ( i
= 1 ; i
< n
; i
++ )
printf(")#%5d\t%s", lc
- HEAD_BYTES
, cp
);
printf("%d ", ( short ) p
[i
]);
* Putspace puts out a table
* of nothing to leave space
* for the case branch table e.g.
printf(")#%5d\t.=.+%d\n", lc
- HEAD_BYTES
, n
);
for (i
= even(n
); i
> 0; i
-= 2)
* Patch repairs the branch
* at location loc to come
* to the current location.
patchfil(loc
, lc
-loc
-2, 1);
patchfil(loc
, lc
- HEAD_BYTES
, 2);
* Patchfil makes loc+2 have value
patchfil(loc
, value
, words
)
printf(")#\tpatch %u %d\n", loc
- HEAD_BYTES
, value
);
i
= ((unsigned) loc
+ 2 - ((unsigned) lc
& ~01777))/2;
lseek(ofil
, (long) loc
+2, 0);
lseek(ofil
, (long) 0, 2);
* Put the word o into the code
i
= (obufp
- ( ( short * ) obuf
) ) * 2;
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.