BSD 4_3 release
[unix-history] / usr / src / ucb / pascal / src / p2put.c
CommitLineData
296a4829
KM
1/*
2 * Copyright (c) 1980 Regents of the University of California.
3 * All rights reserved. The Berkeley software License Agreement
4 * specifies the terms and conditions for redistribution.
5 */
6
7#ifndef lint
95f51977 8static char sccsid[] = "@(#)p2put.c 5.3 (Berkeley) 6/21/85";
296a4829
KM
9#endif not lint
10
b6a29e28
PK
11 /*
12 * functions to help pi put out
13 * polish postfix binary portable c compiler intermediate code
14 * thereby becoming the portable pascal compiler
15 */
16
17#include "whoami.h"
18#ifdef PC
19#include "0.h"
8a8fa8e8 20#include "objfmt.h"
c60bfb0d 21#include <pcc.h>
b6a29e28 22#include "pc.h"
8a8fa8e8 23#include "align.h"
f763caa4 24#include "tmps.h"
b6a29e28
PK
25\f
26 /*
27 * emits an ftext operator and a string to the pcstream
28 */
29puttext( string )
30 char *string;
31 {
32 int length = str4len( string );
33
f3434f0c 34 if ( !CGENNING )
b6a29e28 35 return;
c60bfb0d 36 p2word( PCCM_TRIPLE( PCCF_FTEXT , length , 0 ) );
b6a29e28
PK
37# ifdef DEBUG
38 if ( opt( 'k' ) ) {
c60bfb0d 39 fprintf( stdout , "PCCF_FTEXT | %3d | 0 " , length );
b6a29e28
PK
40 }
41# endif
42 p2string( string );
43 }
44
45int
46str4len( string )
47 char *string;
48 {
49
50 return ( ( strlen( string ) + 3 ) / 4 );
51 }
52
53 /*
54 * put formatted text into a buffer for printing to the pcstream.
55 * a call to putpflush actually puts out the text.
56 * none of arg1 .. arg5 need be present.
57 * and you can add more if you need them.
58 */
aafb1106 59/* VARARGS */
b6a29e28
PK
60putprintf( format , incomplete , arg1 , arg2 , arg3 , arg4 , arg5 )
61 char *format;
62 int incomplete;
63 {
64 static char ppbuffer[ BUFSIZ ];
65 static char *ppbufp = ppbuffer;
66
f3434f0c 67 if ( !CGENNING )
b6a29e28
PK
68 return;
69 sprintf( ppbufp , format , arg1 , arg2 , arg3 , arg4 , arg5 );
70 ppbufp = &( ppbuffer[ strlen( ppbuffer ) ] );
71 if ( ppbufp >= &( ppbuffer[ BUFSIZ ] ) )
72 panic( "putprintf" );
73 if ( ! incomplete ) {
74 puttext( ppbuffer );
75 ppbufp = ppbuffer;
76 }
77 }
78
79 /*
80 * emit a left bracket operator to pcstream
81 * with function number, the maximum temp register, and total local bytes
b6a29e28 82 */
f763caa4
PK
83putlbracket(ftnno, sizesp)
84 int ftnno;
85 struct om *sizesp;
86{
87 int maxtempreg;
88 int alignedframesize;
b6a29e28 89
f763caa4
PK
90# ifdef vax
91 maxtempreg = sizesp->curtmps.next_avail[REG_GENERAL];
92# endif vax
93# ifdef mc68000
94 /*
bd187e5b 95 * this is how /lib/f1 wants it.
f763caa4 96 */
bd187e5b
PK
97 maxtempreg = (sizesp->curtmps.next_avail[REG_ADDR] << 4)
98 | (sizesp->curtmps.next_avail[REG_DATA]);
f763caa4 99# endif mc68000
aafb1106
KM
100 alignedframesize = roundup((int)(BITSPERBYTE * -sizesp->curtmps.om_off),
101 (long)(BITSPERBYTE * A_STACK));
c60bfb0d 102 p2word( PCCM_TRIPLE( PCCF_FLBRAC , maxtempreg , ftnno ) );
f763caa4
PK
103 p2word(alignedframesize);
104# ifdef DEBUG
105 if ( opt( 'k' ) ) {
c60bfb0d 106 fprintf(stdout, "PCCF_FLBRAC | %3d | %d %d\n",
f763caa4
PK
107 maxtempreg, ftnno, alignedframesize);
108 }
109# endif
110}
b6a29e28
PK
111
112 /*
113 * emit a right bracket operator
bd187e5b 114 * which for the binary interface
b6a29e28
PK
115 * forces the stack allocate and register mask
116 */
117putrbracket( ftnno )
118 int ftnno;
119 {
120
c60bfb0d 121 p2word( PCCM_TRIPLE( PCCF_FRBRAC , 0 , ftnno ) );
b6a29e28
PK
122# ifdef DEBUG
123 if ( opt( 'k' ) ) {
c60bfb0d 124 fprintf( stdout , "PCCF_FRBRAC | 0 | %d\n" , ftnno );
b6a29e28
PK
125 }
126# endif
127 }
128
129 /*
130 * emit an eof operator
131 */
132puteof()
133 {
134
c60bfb0d 135 p2word( PCCF_FEOF );
b6a29e28
PK
136# ifdef DEBUG
137 if ( opt( 'k' ) ) {
c60bfb0d 138 fprintf( stdout , "PCCF_FEOF\n" );
b6a29e28
PK
139 }
140# endif
141 }
142
143 /*
144 * emit a dot operator,
145 * with a source file line number and name
146 * if line is negative, there was an error on that line, but who cares?
147 */
148putdot( filename , line )
149 char *filename;
150 int line;
151 {
152 int length = str4len( filename );
153
154 if ( line < 0 ) {
155 line = -line;
156 }
c60bfb0d 157 p2word( PCCM_TRIPLE( PCCF_FEXPR , length , line ) );
b6a29e28
PK
158# ifdef DEBUG
159 if ( opt( 'k' ) ) {
c60bfb0d 160 fprintf( stdout , "PCCF_FEXPR | %3d | %d " , length , line );
b6a29e28
PK
161 }
162# endif
163 p2string( filename );
164 }
165
166 /*
167 * put out a leaf node
168 */
169putleaf( op , lval , rval , type , name )
170 int op;
171 int lval;
172 int rval;
173 int type;
174 char *name;
175 {
f3434f0c 176 if ( !CGENNING )
b6a29e28
PK
177 return;
178 switch ( op ) {
179 default:
180 panic( "[putleaf]" );
c60bfb0d
RC
181 case PCC_ICON:
182 p2word( PCCM_TRIPLE( PCC_ICON , name != NIL , type ) );
b6a29e28
PK
183 p2word( lval );
184# ifdef DEBUG
185 if ( opt( 'k' ) ) {
c60bfb0d 186 fprintf( stdout , "PCC_ICON | %3d | 0x%x "
b6a29e28
PK
187 , name != NIL , type );
188 fprintf( stdout , "%d\n" , lval );
189 }
190# endif
191 if ( name )
192 p2name( name );
193 break;
c60bfb0d
RC
194 case PCC_NAME:
195 p2word( PCCM_TRIPLE( PCC_NAME , lval != 0 , type ) );
b6a29e28
PK
196 if ( lval )
197 p2word( lval );
198# ifdef DEBUG
199 if ( opt( 'k' ) ) {
c60bfb0d 200 fprintf( stdout , "PCC_NAME | %3d | 0x%x "
b6a29e28
PK
201 , lval != 0 , type );
202 if ( lval )
203 fprintf( stdout , "%d " , lval );
204 }
205# endif
206 p2name( name );
207 break;
c60bfb0d
RC
208 case PCC_REG:
209 p2word( PCCM_TRIPLE( PCC_REG , rval , type ) );
b6a29e28
PK
210# ifdef DEBUG
211 if ( opt( 'k' ) ) {
c60bfb0d 212 fprintf( stdout , "PCC_REG | %3d | 0x%x\n" ,
d7dc4314 213 rval , type );
b6a29e28
PK
214 }
215# endif
216 break;
217 }
218 }
219
220 /*
221 * rvalues are just lvalues with indirection, except
1f43951f
PK
222 * special cases for registers and for named globals,
223 * whose names are their rvalues.
b6a29e28 224 */
270467f1 225putRV( name , level , offset , other_flags , type )
b6a29e28
PK
226 char *name;
227 int level;
228 int offset;
270467f1 229 char other_flags;
b6a29e28
PK
230 int type;
231 {
232 char extname[ BUFSIZ ];
233 char *printname;
234
f3434f0c 235 if ( !CGENNING )
b6a29e28 236 return;
270467f1 237 if ( other_flags & NREGVAR ) {
1f43951f
PK
238 if ( ( offset < 0 ) || ( offset > P2FP ) ) {
239 panic( "putRV regvar" );
b401cf0d 240 }
c60bfb0d 241 putleaf( PCC_REG , 0 , offset , type , (char *) 0 );
4cadac06
KM
242 return;
243 }
aafb1106 244 if ( whereis( offset , other_flags ) == GLOBALVAR ) {
1f43951f
PK
245 if ( name != 0 ) {
246 if ( name[0] != '_' ) {
247 sprintf( extname , EXTFORMAT , name );
248 printname = extname;
249 } else {
250 printname = name;
251 }
c60bfb0d 252 putleaf( PCC_NAME , offset , 0 , type , printname );
1f43951f 253 return;
b6a29e28 254 } else {
1f43951f 255 panic( "putRV no name" );
b6a29e28 256 }
b6a29e28 257 }
270467f1 258 putLV( name , level , offset , other_flags , type );
c60bfb0d 259 putop( PCCOM_UNARY PCC_MUL , type );
b6a29e28
PK
260 }
261
262 /*
263 * put out an lvalue
264 * given a level and offset
265 * special case for
266 * named globals, whose lvalues are just their names as constants.
b6a29e28 267 */
270467f1 268putLV( name , level , offset , other_flags , type )
b6a29e28
PK
269 char *name;
270 int level;
271 int offset;
270467f1 272 char other_flags;
b6a29e28 273 int type;
4cadac06
KM
274{
275 char extname[ BUFSIZ ];
276 char *printname;
b6a29e28 277
f3434f0c 278 if ( !CGENNING )
4cadac06 279 return;
270467f1 280 if ( other_flags & NREGVAR ) {
1f43951f 281 panic( "putLV regvar" );
b6a29e28 282 }
aafb1106 283 switch ( whereis( offset , other_flags ) ) {
1f43951f
PK
284 case GLOBALVAR:
285 if ( ( name != 0 ) ) {
286 if ( name[0] != '_' ) {
287 sprintf( extname , EXTFORMAT , name );
288 printname = extname;
289 } else {
290 printname = name;
291 }
c60bfb0d 292 putleaf( PCC_ICON , offset , 0 , PCCM_ADDTYPE( type , PCCTM_PTR )
1f43951f
PK
293 , printname );
294 return;
295 } else {
296 panic( "putLV no name" );
297 }
4cadac06
KM
298 case PARAMVAR:
299 if ( level == cbn ) {
c60bfb0d 300 putleaf( PCC_REG, 0, P2AP, PCCM_ADDTYPE( type , PCCTM_PTR ), (char *) 0 );
4cadac06 301 } else {
c60bfb0d
RC
302 putleaf( PCC_NAME , (level * sizeof(struct dispsave)) + AP_OFFSET
303 , 0 , PCCTM_PTR | PCCT_CHAR , DISPLAYNAME );
199b9670 304 parts[ level ] |= NONLOCALVAR;
4cadac06 305 }
c60bfb0d
RC
306 putleaf( PCC_ICON , offset , 0 , PCCT_INT , (char *) 0 );
307 putop( PCC_PLUS , PCCTM_PTR | PCCT_CHAR );
4cadac06
KM
308 break;
309 case LOCALVAR:
310 if ( level == cbn ) {
c60bfb0d 311 putleaf( PCC_REG, 0, P2FP, PCCM_ADDTYPE( type , PCCTM_PTR ), (char *) 0 );
4cadac06 312 } else {
c60bfb0d
RC
313 putleaf( PCC_NAME , (level * sizeof(struct dispsave)) + FP_OFFSET
314 , 0 , PCCTM_PTR | PCCT_CHAR , DISPLAYNAME );
199b9670 315 parts[ level ] |= NONLOCALVAR;
4cadac06 316 }
c60bfb0d
RC
317 putleaf( PCC_ICON , -offset , 0 , PCCT_INT , (char *) 0 );
318 putop( PCC_MINUS , PCCTM_PTR | PCCT_CHAR );
4cadac06 319 break;
199b9670
KM
320 case NAMEDLOCALVAR:
321 if ( level == cbn ) {
c60bfb0d 322 putleaf( PCC_REG, 0, P2FP, PCCM_ADDTYPE( type , PCCTM_PTR ), (char *) 0 );
199b9670 323 } else {
c60bfb0d
RC
324 putleaf( PCC_NAME , (level * sizeof(struct dispsave)) + FP_OFFSET
325 , 0 , PCCTM_PTR | PCCT_CHAR , DISPLAYNAME );
199b9670
KM
326 parts[ level ] |= NONLOCALVAR;
327 }
c60bfb0d
RC
328 putleaf( PCC_ICON , 0 , 0 , PCCT_INT , name );
329 putop( PCC_MINUS , PCCTM_PTR | PCCT_CHAR );
199b9670 330 break;
4cadac06
KM
331 }
332 return;
333}
b6a29e28
PK
334
335 /*
336 * put out a floating point constant leaf node
337 * the constant is declared in aligned data space
c60bfb0d 338 * and a PCC_NAME leaf put out for it
b6a29e28 339 */
270467f1
KM
340putCON8( val )
341 double val;
b6a29e28 342 {
aafb1106 343 char *label;
b6a29e28
PK
344 char name[ BUFSIZ ];
345
f3434f0c 346 if ( !CGENNING )
b6a29e28 347 return;
b6a29e28 348 label = getlab();
8a8fa8e8
PK
349 putprintf( " .data" , 0 );
350 aligndot(A_DOUBLE);
aafb1106 351 (void) putlab( label );
8a8fa8e8
PK
352# ifdef vax
353 putprintf( " .double 0d%.20e" , 0 , val );
354# endif vax
355# ifdef mc68000
356 putprintf( " .long 0x%x,0x%x", 0, val);
357# endif mc68000
b6a29e28
PK
358 putprintf( " .text" , 0 );
359 sprintf( name , PREFIXFORMAT , LABELPREFIX , label );
c60bfb0d 360 putleaf( PCC_NAME , 0 , 0 , PCCT_DOUBLE , name );
b6a29e28
PK
361 }
362
363 /*
364 * put out either an lvalue or an rvalue for a constant string.
365 * an lvalue (for assignment rhs's) is the name as a constant,
366 * an rvalue (for parameters) is just the name.
367 */
368putCONG( string , length , required )
369 char *string;
370 int length;
371 int required;
372 {
373 char name[ BUFSIZ ];
aafb1106 374 char *label;
b6a29e28
PK
375 char *cp;
376 int pad;
377 int others;
378
f3434f0c 379 if ( !CGENNING )
b6a29e28
PK
380 return;
381 putprintf( " .data" , 0 );
8a8fa8e8 382 aligndot(A_STRUCT);
b6a29e28 383 label = getlab();
aafb1106 384 (void) putlab( label );
b6a29e28
PK
385 cp = string;
386 while ( *cp ) {
387 putprintf( " .byte 0%o" , 1 , *cp ++ );
388 for ( others = 2 ; ( others <= 8 ) && *cp ; others ++ ) {
389 putprintf( ",0%o" , 1 , *cp++ );
390 }
391 putprintf( "" , 0 );
392 }
393 pad = length - strlen( string );
394 while ( pad-- > 0 ) {
395 putprintf( " .byte 0%o" , 1 , ' ' );
396 for ( others = 2 ; ( others <= 8 ) && ( pad-- > 0 ) ; others++ ) {
397 putprintf( ",0%o" , 1 , ' ' );
398 }
399 putprintf( "" , 0 );
400 }
401 putprintf( " .byte 0" , 0 );
402 putprintf( " .text" , 0 );
403 sprintf( name , PREFIXFORMAT , LABELPREFIX , label );
404 if ( required == RREQ ) {
c60bfb0d 405 putleaf( PCC_NAME , 0 , 0 , PCCTM_ARY | PCCT_CHAR , name );
b6a29e28 406 } else {
c60bfb0d 407 putleaf( PCC_ICON , 0 , 0 , PCCTM_PTR | PCCT_CHAR , name );
b6a29e28
PK
408 }
409 }
410
411 /*
412 * map a pascal type to a c type
413 * this would be tail recursive, but i unfolded it into a for (;;).
414 * this is sort of like isa and lwidth
415 * a note on the types used by the portable c compiler:
416 * they are divided into a basic type (char, short, int, long, etc.)
417 * and qualifications on those basic types (pointer, function, array).
418 * the basic type is kept in the low 4 bits of the type descriptor,
419 * and the qualifications are arranged in two bit chunks, with the
420 * most significant on the right,
421 * and the least significant on the left
422 * e.g. int *foo();
423 * (a function returning a pointer to an integer)
424 * is stored as
425 * <ptr><ftn><int>
426 * so, we build types recursively
542a2aa0
PK
427 * also, we know that /lib/f1 can only deal with 6 qualifications
428 * so we stop the recursion there. this stops infinite type recursion
429 * through mutually recursive pointer types.
b6a29e28 430 */
542a2aa0 431#define MAXQUALS 6
b6a29e28
PK
432int
433p2type( np )
aafb1106 434 struct nl *np;
542a2aa0
PK
435{
436
437 return typerecur( np , 0 );
438}
439typerecur( np , quals )
440 struct nl *np;
441 int quals;
b6a29e28
PK
442 {
443
542a2aa0 444 if ( np == NIL || quals > MAXQUALS ) {
c60bfb0d 445 return PCCT_UNDEF;
542a2aa0 446 }
b6a29e28
PK
447 switch ( np -> class ) {
448 case SCAL :
449 case RANGE :
9965cdc3 450 case CRANGE :
b6a29e28 451 if ( np -> type == ( nl + TDOUBLE ) ) {
c60bfb0d 452 return PCCT_DOUBLE;
b6a29e28
PK
453 }
454 switch ( bytes( np -> range[0] , np -> range[1] ) ) {
455 case 1:
c60bfb0d 456 return PCCT_CHAR;
b6a29e28 457 case 2:
c60bfb0d 458 return PCCT_SHORT;
b6a29e28 459 case 4:
c60bfb0d 460 return PCCT_INT;
b6a29e28
PK
461 default:
462 panic( "p2type int" );
aafb1106 463 /* NOTREACHED */
b6a29e28
PK
464 }
465 case STR :
c60bfb0d 466 return ( PCCTM_ARY | PCCT_CHAR );
b6a29e28
PK
467 case RECORD :
468 case SET :
c60bfb0d 469 return PCCT_STRTY;
b6a29e28 470 case FILET :
c60bfb0d 471 return ( PCCTM_PTR | PCCT_STRTY );
b6a29e28
PK
472 case CONST :
473 case VAR :
474 case FIELD :
475 return p2type( np -> type );
476 case TYPE :
477 switch ( nloff( np ) ) {
478 case TNIL :
c60bfb0d 479 return ( PCCTM_PTR | PCCT_UNDEF );
b6a29e28 480 case TSTR :
c60bfb0d 481 return ( PCCTM_ARY | PCCT_CHAR );
b6a29e28 482 case TSET :
c60bfb0d 483 return PCCT_STRTY;
b6a29e28
PK
484 default :
485 return ( p2type( np -> type ) );
486 }
487 case REF:
488 case WITHPTR:
489 case PTR :
c60bfb0d 490 return PCCM_ADDTYPE( typerecur( np -> type , quals + 1 ) , PCCTM_PTR );
b6a29e28 491 case ARRAY :
c60bfb0d 492 return PCCM_ADDTYPE( typerecur( np -> type , quals + 1 ) , PCCTM_ARY );
b6a29e28
PK
493 case FUNC :
494 /*
495 * functions are really pointers to functions
496 * which return their underlying type.
497 */
c60bfb0d
RC
498 return PCCM_ADDTYPE( PCCM_ADDTYPE( typerecur( np -> type , quals + 2 ) ,
499 PCCTM_FTN ) , PCCTM_PTR );
b6a29e28
PK
500 case PROC :
501 /*
502 * procedures are pointers to functions
503 * which return integers (whether you look at them or not)
504 */
c60bfb0d 505 return PCCM_ADDTYPE( PCCM_ADDTYPE( PCCT_INT , PCCTM_FTN ) , PCCTM_PTR );
c4e911b6
PK
506 case FFUNC :
507 case FPROC :
508 /*
509 * formal procedures and functions are pointers
510 * to structures which describe their environment.
511 */
c60bfb0d 512 return ( PCCTM_PTR | PCCT_STRTY );
b6a29e28 513 default :
b6a29e28 514 panic( "p2type" );
aafb1106 515 /* NOTREACHED */
b6a29e28
PK
516 }
517 }
518
b6a29e28
PK
519 /*
520 * put a typed operator to the pcstream
521 */
522putop( op , type )
523 int op;
524 int type;
525 {
c60bfb0d 526 extern char *p2opname();
b6a29e28 527
f3434f0c 528 if ( !CGENNING )
b6a29e28 529 return;
c60bfb0d 530 p2word( PCCM_TRIPLE( op , 0 , type ) );
b6a29e28
PK
531# ifdef DEBUG
532 if ( opt( 'k' ) ) {
d7dc4314 533 fprintf( stdout , "%s (%d) | 0 | 0x%x\n"
c60bfb0d 534 , p2opname( op ) , op , type );
b6a29e28
PK
535 }
536# endif
537 }
538
539 /*
540 * put out a structure operator (STASG, STARG, STCALL, UNARY STCALL )
541 * which looks just like a regular operator, only the size and
542 * alignment go in the next consecutive words
543 */
544putstrop( op , type , size , alignment )
545 int op;
546 int type;
547 int size;
548 int alignment;
549 {
c60bfb0d 550 extern char *p2opname();
b6a29e28 551
f3434f0c 552 if ( !CGENNING )
b6a29e28 553 return;
c60bfb0d 554 p2word( PCCM_TRIPLE( op , 0 , type ) );
b6a29e28
PK
555 p2word( size );
556 p2word( alignment );
557# ifdef DEBUG
558 if ( opt( 'k' ) ) {
d7dc4314 559 fprintf( stdout , "%s (%d) | 0 | 0x%x %d %d\n"
c60bfb0d 560 , p2opname( op ) , op , type , size , alignment );
b6a29e28
PK
561 }
562# endif
563 }
564
565 /*
566 * the string names of p2ops
567 */
c60bfb0d
RC
568
569struct p2op {
570 int op;
571 char *name;
572};
573
574static struct p2op p2opnames[] = {
575 PCC_ERROR, "PCC_ERROR",
576 PCC_NAME, "PCC_NAME",
577 PCC_STRING, "PCC_STRING",
578 PCC_ICON, "PCC_ICON",
579 PCC_FCON, "PCC_FCON",
580 PCC_PLUS, "PCC_PLUS",
581 PCC_MINUS, "PCC_MINUS",
582 PCC_UMINUS, "PCC_UMINUS",
583 PCC_MUL, "PCC_MUL",
584 PCC_DEREF, "PCC_DEREF",
585 PCC_AND, "PCC_AND",
586 PCC_ADDROF, "PCC_ADDROF",
587 PCC_OR, "PCC_OR",
588 PCC_ER, "PCC_ER",
589 PCC_QUEST, "PCC_QUEST",
590 PCC_COLON, "PCC_COLON",
591 PCC_ANDAND, "PCC_ANDAND",
592 PCC_OROR, "PCC_OROR",
593 PCC_CM, "PCC_CM",
594 PCC_ASSIGN, "PCC_ASSIGN",
595 PCC_COMOP, "PCC_COMOP",
596 PCC_DIV, "PCC_DIV",
597 PCC_MOD, "PCC_MOD",
598 PCC_LS, "PCC_LS",
599 PCC_RS, "PCC_RS",
600 PCC_DOT, "PCC_DOT",
601 PCC_STREF, "PCC_STREF",
602 PCC_CALL, "PCC_CALL",
603 PCC_UCALL, "PCC_UCALL",
604 PCC_FORTCALL, "PCC_FORTCALL",
605 PCC_UFORTCALL, "PCC_UFORTCALL",
606 PCC_NOT, "PCC_NOT",
607 PCC_COMPL, "PCC_COMPL",
608 PCC_INCR, "PCC_INCR",
609 PCC_DECR, "PCC_DECR",
610 PCC_EQ, "PCC_EQ",
611 PCC_NE, "PCC_NE",
612 PCC_LE, "PCC_LE",
613 PCC_LT, "PCC_LT",
614 PCC_GE, "PCC_GE",
615 PCC_GT, "PCC_GT",
616 PCC_ULE, "PCC_ULE",
617 PCC_ULT, "PCC_ULT",
618 PCC_UGE, "PCC_UGE",
619 PCC_UGT, "PCC_UGT",
620 PCC_REG, "PCC_REG",
621 PCC_OREG, "PCC_OREG",
622 PCC_CCODES, "PCC_CCODES",
623 PCC_FREE, "PCC_FREE",
624 PCC_STASG, "PCC_STASG",
625 PCC_STARG, "PCC_STARG",
626 PCC_STCALL, "PCC_STCALL",
627 PCC_USTCALL, "PCC_USTCALL",
628 PCC_FLD, "PCC_FLD",
629 PCC_SCONV, "PCC_SCONV",
630 PCC_PCONV, "PCC_PCONV",
631 PCC_PMCONV, "PCC_PMCONV",
632 PCC_PVCONV, "PCC_PVCONV",
633 PCC_FORCE, "PCC_FORCE",
634 PCC_CBRANCH, "PCC_CBRANCH",
635 PCC_INIT, "PCC_INIT",
636 PCC_CAST, "PCC_CAST",
637 -1, ""
b6a29e28 638 };
c60bfb0d
RC
639
640char *
641p2opname( op )
642 register int op;
643 {
644 static char *p2map[PCC_MAXOP+1];
645 static bool mapready = FALSE;
646 register struct p2op *pp;
647
648 if ( mapready == FALSE ) {
649 for ( pp = p2opnames; pp->op >= 0; pp++ )
650 p2map[ pp->op ] = pp->name;
651 mapready = TRUE;
652 }
653 return ( p2map[ op ] ? p2map[ op ] : "unknown" );
654 }
b6a29e28
PK
655\f
656 /*
657 * low level routines
658 */
659
660 /*
661 * puts a long word on the pcstream
662 */
663p2word( word )
aafb1106 664 int word;
b6a29e28
PK
665 {
666
667 putw( word , pcstream );
668 }
669
670 /*
671 * put a length 0 mod 4 null padded string onto the pcstream
672 */
673p2string( string )
674 char *string;
675 {
676 int slen = strlen( string );
677 int wlen = ( slen + 3 ) / 4;
678 int plen = ( wlen * 4 ) - slen;
679 char *cp;
680 int p;
681
682 for ( cp = string ; *cp ; cp++ )
683 putc( *cp , pcstream );
684 for ( p = 1 ; p <= plen ; p++ )
685 putc( '\0' , pcstream );
686# ifdef DEBUG
687 if ( opt( 'k' ) ) {
688 fprintf( stdout , "\"%s" , string );
689 for ( p = 1 ; p <= plen ; p++ )
690 fprintf( stdout , "\\0" );
691 fprintf( stdout , "\"\n" );
692 }
693# endif
694 }
695
696 /*
697 * puts a name on the pcstream
698 */
699p2name( name )
700 char *name;
701 {
702 int pad;
703
704 fprintf( pcstream , NAMEFORMAT , name );
705 pad = strlen( name ) % sizeof (long);
706 for ( ; pad < sizeof (long) ; pad++ ) {
707 putc( '\0' , pcstream );
708 }
709# ifdef DEBUG
710 if ( opt( 'k' ) ) {
711 fprintf( stdout , NAMEFORMAT , name );
712 pad = strlen( name ) % sizeof (long);
713 for ( ; pad < sizeof (long) ; pad++ ) {
714 fprintf( stdout , "\\0" );
715 }
716 fprintf( stdout , "\n" );
717 }
718# endif
719 }
720
721 /*
722 * put out a jump to a label
723 */
724putjbr( label )
725 long label;
726 {
727
728 printjbr( LABELPREFIX , label );
729 }
730
731 /*
732 * put out a jump to any kind of label
733 */
734printjbr( prefix , label )
735 char *prefix;
736 long label;
737 {
738
8a8fa8e8
PK
739# ifdef vax
740 putprintf( " jbr " , 1 );
741 putprintf( PREFIXFORMAT , 0 , prefix , label );
742# endif vax
743# ifdef mc68000
744 putprintf( " jra " , 1 );
745 putprintf( PREFIXFORMAT , 0 , prefix , label );
746# endif mc68000
b6a29e28
PK
747 }
748
749 /*
750 * another version of put to catch calls to put
751 */
aafb1106
KM
752/* VARARGS */
753put()
b6a29e28
PK
754 {
755
8a8fa8e8 756 panic("put()");
b6a29e28
PK
757 }
758
759#endif PC