⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 p2put.c

📁 早期freebsd实现
💻 C
📖 第 1 页 / 共 2 页
字号:
/*- * Copyright (c) 1980, 1993 *	The Regents of the University of California.  All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright *    notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright *    notice, this list of conditions and the following disclaimer in the *    documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software *    must display the following acknowledgement: *	This product includes software developed by the University of *	California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors *    may be used to endorse or promote products derived from this software *    without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */#ifndef lintstatic char sccsid[] = "@(#)p2put.c	8.1 (Berkeley) 6/6/93";#endif /* not lint */    /*     *	functions to help pi put out     *	polish postfix binary portable c compiler intermediate code     *	thereby becoming the portable pascal compiler     */#include	"whoami.h"#ifdef PC#include	"0.h"#include	"objfmt.h"#include	<pcc.h>#include	"pc.h"#include	"align.h"#include	"tmps.h"    /*     *	emits an ftext operator and a string to the pcstream     */puttext( string )    char	*string;    {	int	length = str4len( string );	if ( !CGENNING )	    return;	p2word( PCCM_TRIPLE( PCCF_FTEXT , length , 0 ) );#	ifdef DEBUG	    if ( opt( 'k' ) ) {		fprintf( stdout , "PCCF_FTEXT | %3d | 0	" , length );	    }#	endif	p2string( string );    }intstr4len( string )    char	*string;    {		return ( ( strlen( string ) + 3 ) / 4 );    }    /*     *	put formatted text into a buffer for printing to the pcstream.     *	a call to putpflush actually puts out the text.     *	none of arg1 .. arg5 need be present.     *	and you can add more if you need them.     *//* VARARGS */putprintf( format , incomplete , arg1 , arg2 , arg3 , arg4 , arg5 )    char	*format;    int		incomplete;    {	static char	ppbuffer[ BUFSIZ ];	static char	*ppbufp = ppbuffer;	if ( !CGENNING )	    return;	sprintf( ppbufp , format , arg1 , arg2 , arg3 , arg4 , arg5 );	ppbufp = &( ppbuffer[ strlen( ppbuffer ) ] );	if ( ppbufp >= &( ppbuffer[ BUFSIZ ] ) )	    panic( "putprintf" );	if ( ! incomplete ) {	    puttext( ppbuffer );	    ppbufp = ppbuffer;	}    }    /*     *	emit a left bracket operator to pcstream     *	with function number, the maximum temp register, and total local bytes     */putlbracket(ftnno, sizesp)    int		ftnno;    struct om	*sizesp;{    int	maxtempreg;	    int	alignedframesize;#   if defined(vax) || defined(tahoe)	maxtempreg = sizesp->curtmps.next_avail[REG_GENERAL];#   endif vax || tahoe#   ifdef mc68000	    /*	     *	this is how /lib/f1 wants it.	     */	maxtempreg =	(sizesp->curtmps.next_avail[REG_ADDR] << 4)		      | (sizesp->curtmps.next_avail[REG_DATA]);#   endif mc68000    alignedframesize = roundup((int)(BITSPERBYTE * -sizesp->curtmps.om_off),	(long)(BITSPERBYTE * A_STACK));    p2word( PCCM_TRIPLE( PCCF_FLBRAC , maxtempreg , ftnno ) );    p2word(alignedframesize);#   ifdef DEBUG	if ( opt( 'k' ) ) {	    fprintf(stdout, "PCCF_FLBRAC | %3d | %d	%d\n",		maxtempreg, ftnno, alignedframesize);	}#   endif}    /*     *	emit a right bracket operator     *	which for the binary interface     *	forces the stack allocate and register mask     */putrbracket( ftnno )    int	ftnno;    {	p2word( PCCM_TRIPLE( PCCF_FRBRAC , 0 , ftnno ) );#	ifdef DEBUG	    if ( opt( 'k' ) ) {		fprintf( stdout , "PCCF_FRBRAC |   0 | %d\n" , ftnno );	    }#	endif    }    /*     *	emit an eof operator     */puteof()    {		p2word( PCCF_FEOF );#	ifdef DEBUG	    if ( opt( 'k' ) ) {		fprintf( stdout , "PCCF_FEOF\n" );	    }#	endif    }    /*     *	emit a dot operator,     *	with a source file line number and name     *	if line is negative, there was an error on that line, but who cares?     */putdot( filename , line )    char	*filename;    int		line;    {	int	length = str4len( filename );	if ( line < 0 ) {	    line = -line;	}	p2word( PCCM_TRIPLE( PCCF_FEXPR , length , line ) );#	ifdef DEBUG	    if ( opt( 'k' ) ) {		fprintf( stdout , "PCCF_FEXPR | %3d | %d	" , length , line );	    }#	endif	p2string( filename );    }    /*     *	put out a leaf node     */putleaf( op , lval , rval , type , name )    int		op;    int		lval;    int		rval;    int		type;    char	*name;    {	if ( !CGENNING )	    return;	switch ( op ) {	    default:		panic( "[putleaf]" );	    case PCC_ICON:		p2word( PCCM_TRIPLE( PCC_ICON , name != NIL , type ) );		p2word( lval );#		ifdef DEBUG		    if ( opt( 'k' ) ) {			fprintf( stdout , "PCC_ICON | %3d | 0x%x	" 			       , name != NIL , type );			fprintf( stdout , "%d\n" , lval );		    }#		endif		if ( name )		    p2name( name );		break;	    case PCC_NAME:		p2word( PCCM_TRIPLE( PCC_NAME , lval != 0 , type ) );		if ( lval ) 		    p2word( lval );#		ifdef DEBUG		    if ( opt( 'k' ) ) {			fprintf( stdout , "PCC_NAME | %3d | 0x%x	" 			       , lval != 0 , type );			if ( lval )			    fprintf( stdout , "%d	" , lval );		    }#		endif		p2name( name );		break;	    case PCC_REG:		p2word( PCCM_TRIPLE( PCC_REG , rval , type ) );#		ifdef DEBUG		    if ( opt( 'k' ) ) {			fprintf( stdout , "PCC_REG | %3d | 0x%x\n" ,				rval , type );		    }#		endif		break;	}    }    /*     *	rvalues are just lvalues with indirection, except     *	special cases for registers and for named globals,     *	whose names are their rvalues.     */putRV( name , level , offset , other_flags , type )    char	*name;    int		level;    int		offset;    char	other_flags;    int		type;    {	char	extname[ BUFSIZ ];	char	*printname;	if ( !CGENNING )	    return;	if ( other_flags & NREGVAR ) {	    if ( ( offset < 0 ) || ( offset > P2FP ) ) {		panic( "putRV regvar" );	    }	    putleaf( PCC_REG , 0 , offset , type , (char *) 0 );	    return;	}	if ( whereis( offset , other_flags ) == GLOBALVAR ) {	    if ( name != 0 ) {		if ( name[0] != '_' ) {			sprintf( extname , EXTFORMAT , name );			printname = extname;		} else {			printname = name;		}		putleaf( PCC_NAME , offset , 0 , type , printname );		return;	    } else {		panic( "putRV no name" );	    }	}	putLV( name , level , offset , other_flags , type );	putop( PCCOM_UNARY PCC_MUL , type );    }    /*     *	put out an lvalue      *	given a level and offset     *	special case for     *	    named globals, whose lvalues are just their names as constants.     */putLV( name , level , offset , other_flags , type )    char	*name;    int		level;    int		offset;    char	other_flags;    int		type;{    char		extname[ BUFSIZ ];    char		*printname;    if ( !CGENNING )	return;    if ( other_flags & NREGVAR ) {	panic( "putLV regvar" );    }    switch ( whereis( offset , other_flags ) ) {	case GLOBALVAR:	    if ( ( name != 0 ) ) {		if ( name[0] != '_' ) {			sprintf( extname , EXTFORMAT , name );			printname = extname;		} else {			printname = name;		}		putleaf( PCC_ICON , offset , 0 , PCCM_ADDTYPE( type , PCCTM_PTR )			, printname );		return;	    } else {		panic( "putLV no name" );	    }	case PARAMVAR:	    if ( level == cbn ) {		putleaf( PCC_REG, 0, P2AP, PCCM_ADDTYPE( type , PCCTM_PTR ), (char *) 0 );	    } else {		putleaf( PCC_NAME , (level * sizeof(struct dispsave)) + AP_OFFSET		    , 0 , PCCTM_PTR | PCCT_CHAR , DISPLAYNAME );		parts[ level ] |= NONLOCALVAR;	    }	    putleaf( PCC_ICON , offset , 0 , PCCT_INT , (char *) 0 );	    putop( PCC_PLUS , PCCTM_PTR | PCCT_CHAR );	    break;	case LOCALVAR:	    if ( level == cbn ) {		putleaf( PCC_REG, 0, P2FP, PCCM_ADDTYPE( type , PCCTM_PTR ), (char *) 0 );	    } else {		putleaf( PCC_NAME , (level * sizeof(struct dispsave)) + FP_OFFSET		    , 0 , PCCTM_PTR | PCCT_CHAR , DISPLAYNAME );		parts[ level ] |= NONLOCALVAR;	    }	    putleaf( PCC_ICON , -offset , 0 , PCCT_INT , (char *) 0 );	    putop( PCC_MINUS , PCCTM_PTR | PCCT_CHAR );	    break;	case NAMEDLOCALVAR:	    if ( level == cbn ) {		putleaf( PCC_REG, 0, P2FP, PCCM_ADDTYPE( type , PCCTM_PTR ), (char *) 0 );	    } else {		putleaf( PCC_NAME , (level * sizeof(struct dispsave)) + FP_OFFSET		    , 0 , PCCTM_PTR | PCCT_CHAR , DISPLAYNAME );		parts[ level ] |= NONLOCALVAR;	    }	    putleaf( PCC_ICON , 0 , 0 , PCCT_INT , name );	    putop( PCC_MINUS , PCCTM_PTR | PCCT_CHAR );	    break;    }    return;}    /*     *	put out a floating point constant leaf node     *	the constant is declared in aligned data space     *	and a PCC_NAME leaf put out for it     */putCON8( val )    double	val;    {	char	*label;	char	name[ BUFSIZ ];	if ( !CGENNING )	    return;	label = getlab();	putprintf( "	.data" , 0 );	aligndot(A_DOUBLE);	(void) putlab( label );#	if defined(vax) || defined(tahoe)	    putprintf( "	.double 0d%.20e" , 0 , val );#	endif vax || tahoe#	ifdef mc68000	    putprintf( "	.long 	0x%x,0x%x", 0, val);#	endif mc68000	putprintf( "	.text" , 0 );	sprintf( name , PREFIXFORMAT , LABELPREFIX , label );	putleaf( PCC_NAME , 0 , 0 , PCCT_DOUBLE , name );    }	/*	 * put out either an lvalue or an rvalue for a constant string.	 * an lvalue (for assignment rhs's) is the name as a constant, 	 * an rvalue (for parameters) is just the name.	 */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -