cg.c

来自「开放源码的编译器open watcom 1.6.0版的源代码」· C语言 代码 · 共 953 行 · 第 1/2 页

C
953
字号
/**********************************************************************/

    Action( "CGSelRange" );
    Action( "( %d, %l, %l, %s )%n", s->i, lo, hi, Label( lb ) );
    CRefLabel( lb );
    SelRange(s,lo,hi,lb);
}
extern  void    SelRange( sh *s, signed_32 lo, signed_32 hi, l *lb ) {
/********************************************************************/

    rh  **or;
    rh  *n;

    VerLabel(lb);
    CRefLabel(lb);
    if(lo>hi) { CGError( "lo bound > hi bound" ); }
    or = &s->r;
    for(;;) {
        if( *or==NULL) break;
        if(hi< (*or)->l) break;
        if(lo<= (*or)->h) { CGError( "case range overlap" ); }
        or = &(*or)->n;
    }
    n=CGAlloc(sizeof( rh ));
    n->l=lo;
    n->h=hi;
    n->lb=lb;
    n->n= *or;
    *or=n;
}
extern  void    CGSelOther( sh *s, l *lb ) {
/******************************************/

    Action( "CGSelOther" );
    Action( "( %d, %s )%n", s->i, Label( lb ) );
    CRefLabel(lb);
    if(s->o!=NULL) { CGError( "Otherwise already defined" ); }
    s->o=lb;
}
extern  void    CGSelect( sh *s, n *e ) {
/***************************************/

    rh  *r;

    Action( "CGSelect" );
    VerNode(e);
    Action( "( %d, %t )%n", s->i, e );
    Code( "select: " );
    DumpTree(e);
    NoDanglers();
    while( s->r != NULL ) {
        r = s->r;
        Code( "range: %s,", LToS(r->l) );
        Code( "%s", LToS( r->h ) );
        Code( " %s%n", Label(r->lb) );
        s->r=r->n;
        CGFree(r);
    }
    if(s->o!=NULL) { Code( "default: %s%n", Label(s->o) ); }
    Code("}%n");
    CGFree(s);
}
extern  n       *CGInteger( signed_32 i, cg_type t ) {
/****************************************************/

    n   *in;

    Action( "CGInteger" );
    Action( "( %l, %s )", i, Tipe( t ) );
    in = NewNode( LEAF, t );
    in->l = (n *)ACopyOf( LToS(i) );
    VerTipe(t,CGIntTypes);
    Action( " -> %t%n", in );
    return( in );
}
extern  n       *CGCallback( pointer func, pointer parm ) {
/*********************************************************/
    n   *nd;
    call_back* cb;

    Action( "CGCallback" );
    nd = NewNode( CALLBACK, T_DEFAULT );
    cb = CGAlloc( sizeof( call_back ) );
    nd->l = (n*)cb;
    cb->function = func;
    cb->data = parm;
    Action( "( %p, %p ) -> %t%n", func, parm, nd );
    return( nd );
}
extern  n       *CGPatchNode( pointer p, cg_type t ) {
/****************************************************/
    n   *l;

    Action( "CGPatchNode" );
    VerTipe( t, CGIntTypes );
    l = NewNode( LEAF, t );
    l->l = (n *)ACopyOf( LToS( -1 ) );
    Action( "( %p, %s ) -> %t%n", p, Tipe( t ), l );
    return( l );
}
extern  n       *CGFloat(char *s,cg_type t) {
/*******************************************/

    n   *l;

    Action( "CGFloat" );
    VerTipe( t,FloatTypes );
    l = NewNode( LEAF, t );
    l->l = (n*)ACopyOf( s );
    Action( "( %s, %s ) -> %t%n", s, Tipe(t), l );
    return( l );
}
static  cg_type PtrTipe( pointer s ) {
/************************************/

    fe_attr     a;

    if( s != NULL ) {
        a = FEAttr( s );
    } else {
        a = 0;
    }
    if( a & FE_PROC ) {
        return( T_CODE_PTR );
    } else {
        return( T_POINTER );
    }
}
extern  n       *CGFEName( pointer sym, cg_type t ) {
/*************************************************/

    n   *nd;
    a   *au;
    s   *st;
    b   *bk;

    Action( "CGFEName" );
    nd = NewNode( LEAF,PtrTipe( sym ) );
    nd->l = (n*)ACopyOf( FEName( sym ) );
    nd->src = sym;
//  Action( "( %s, %s ) -> %t", nd->l, Tipe(t), nd );
    Action( "( %s, %s ) -> %t", Name( sym ), Tipe(t), nd );
    Attrs( sym );
    if( FEAttr( sym ) & FE_STATIC ) {
        bk = FEBack( sym );
        VerBack( bk );
        if( !( FEAttr( sym ) & FE_IMPORT ) ) DRefLabel( bk->lp );
        for( st = StaticList; st; st = st->n ) {
            if( st->s == sym ) break;
        }
        if( st == NULL ) {
            st = CGAlloc( sizeof( s ) );
            st->n = StaticList;
            st->s = sym;
            st->a = FEAttr( sym );
            StaticList = st;
        }
    } else if( FELexLevel( sym ) != 0 ) {
        CGError( "Lex level for %s(%p) must be 0", FEName( sym ), sym );
    } else {
        au = LkAddBack( sym, NULL );
        if( au != NULL ) {
            VerAuto( au );
            if( au->s != sym ) {
                CGError( "Wrong auto back handle for %s(%p)",
                         FEName( sym ), sym );
            }
            if( au->o ) {
                CGError( "Outdated auto back handle for %s(%p)",
                FEName( sym ), sym );
            }
        } else {
            Action( "WARNING: Allocating back handle for lookup of %s(%p)%n",
                 FEName( sym ), sym );
            au = CGAlloc( sizeof( a ) );
            au->n = AutoList;
            au->s = sym;
            au->o = 0;
            AutoList = au;
            LkAddBack( sym, au );
        }
    }
    return( nd );
}
extern  n       *CGBackName( b *s, cg_type t ) {
/***************************************************/

    n   *nd;

    Action( "CGBackName" );
    nd = NewNode(LEAF,PtrTipe( NULL ));
    VerBack( s );
    DRefLabel( s->lp );
    CopyStr( Label( s->lp ), UBuff );
    nd->l = (n*)ACopyOf( UBuff );
    VerTipe(t,NULL);
    Action( "( %s, %s ) -> %t%n", nd->l, Tipe(t), nd );
    return( nd );
}
extern  t       *CGTemp( cg_type ty ) {
/*************************************/

    t   *tm;
    ty=ty;
    Action( "CGTemp" );
    tm = CGAlloc( sizeof( t ) );
    tm->n = TempList;
    tm->i = ++TempId;
    Action( "( %s ) ->%d%n", Tipe( ty ), tm->i );
    TempList = tm;
    return(tm);
}
extern  n       *CGTempName( t *tm, cg_type ty ) {
/************************************************/

    n   *nd;
    char *c;

    Action( "CGTempName" );
    Find( "back end temp", (pointer *)TempList, tm );
    nd = NewNode(LEAF,ty);
    c = LToS( tm->i );
    *--c = 'T';
    nd->l = (n*)ACopyOf( c );
    Action( "( %d, %s ) ->%t%n", tm->i, Tipe( ty ), nd );
    return(nd);
}
extern  n       *CGBitMask( n *r, byte st, byte ln, cg_type t ) {
/***************************************************************/

    n   *nd;

    Action( "CGBitMask" );
    Action( "( %t, %d, %d, %s )", r, st, ln, Tipe( t ) );
    NotDefault( t );
    Action( "%s", Tipe(t) );
    nd = Unary( OP_BIT_FIELD, r, t );
    nd->st = st;
    nd->ln = ln;
    Action( " -> %t%n", nd );
    return( nd );
}
extern  n       *DoCGAssign( n *l, n *r, cg_type t, int i ) {
/**************************************************/

    n   *new;

    NotDefault( t );
    VerNode( l ); VerNode( r );
    Action( "( %t, %t, %s )", l, r, Tipe(t) );
    new = Binary( i,l,r,t );
    Action( " -> %t%n", new );
    return( new );
}
extern  n       *CGAssign( n *l, n *r, cg_type t ) {
/****************************************************/

    Action( "CGAssign" );
    return( DoCGAssign( l, r, t, O_GETS ) );
}
extern  n       *CGLVAssign( n *l, n *r, cg_type t ) {
/****************************************************/

    Action( "CGLVAssign" );
    return( DoCGAssign( l, r, t, O_LV_GETS ) );
}
extern  n       *DoCGPreGets( cg_op o, n *l, n *r, cg_type t, int i ) {
/************************************************************/

    n   *new;

    NotDefault( t );
    VerNode( l ); VerNode( r ); VerOp( o, BinaryOps );
    Action( "( %s, %t, %t, %s )", Op(o), l, r, Tipe(t) );
    new = Unary( i, Binary(o,l,r,t),t );
    Action( " -> %t%n", new );
    return( new );
}
extern  n       *CGPreGets( cg_op o, n *l, n *r, cg_type t ) {
/***************************************************************/

    Action( "CGPreGets" );
    return( DoCGPreGets( o, l, r, t, O_PRE_GETS ) );
}
extern  n       *CGLVPreGets( cg_op o, n *l, n *r, cg_type t ) {
/**************************************************************/

    Action( "CGLVPreGets" );
    return( DoCGPreGets( o, l, r, t, O_LV_PRE_GETS ) );
}
extern  n       *CGPostGets( cg_op o, n *l, n *r, cg_type t ) {
/*************************************************************/

    n   *new;

    Action( "CGPostGets" );
    NotDefault( t );
    VerNode( l ); VerNode( r ); VerOp( o, BinaryOps );
    Action( "( %s, %t, %t, %s )", Op(o), l, r, Tipe(t) );
    new = Unary( O_POST_GETS,Binary(o,l,r,t),t );
    Action( " -> %t%n", new );
    return( new );
}
extern  n       *CGUnary( cg_op o, n *r, cg_type t ) {
/****************************************************/

    n   *new;

    Action( "CGUnary" );
    VerNode( r ); VerOp( o, UnaryOps );
    Action( "( %s, %t, %s )", Op(o), r, Tipe(t) );
    if( o == O_POINTS ) { NotDefault( t ); }
    new = Unary( o, r, t );
    Action( " -> %t%n", new );
    return( new );
}
extern  n       *CGBinary( cg_op o, n *l, n *r, cg_type t ) {
/***********************************************************/

    n   *new;

    Action( "CGBinary" );
    VerNode( r ); VerNode( l ); VerOp( o, BinaryOps );
    Action( "( %s, %t, %t, %s )", Op(o), l, r, Tipe(t) );
    new = Binary( o,l,r,t );
    Action( " -> %t%n", new );
    return( new );
}
extern  n       *CGIndex( n *l, n *r, cg_type t, cg_type s ) {
/*************************************************/

    n   *new;

    s=s;
    Action( "CGIndex" );
    VerNode( l ); VerNode( r );
    Action( "( %t, %t, %s )", l, r, Tipe(t) );
    new = Binary( O_PLUS,l,r,t );
    Action( " -> %t%n", new );
    return( new );
}
extern  n       *CGInitCall( n *l, cg_type t, sym_handle h ) {
/************************************************************/

    n   *new;

    Action( "CGInitCall" );
    VerNode(l);
//  Action( "( %t, %s )", l, Tipe(t) );
    Action( "( %t, %s, %s )", l, Tipe(t), FEName(h) );
    new = Binary(O_CALL,l,NULL,t);
    new->h = h;
    Action( " -> %t%n", new );
    return( new );
}
extern  void    CGAddParm( n *l, n *p, cg_type t ) {
/**************************************************/

    Action( "CGAddParm" );
    VerNode( l );
    VerNode( p );
    Action( "( %t, %t, %s )%n", l, p, Tipe(t) );
    l->r=Binary(O_PARM,p,l->r,t);
}
extern  n       *CGCall( n *r ) {
/*******************************/

    call_class  *pc;

    Action( "CGCall( %t )", r );
    pc = (call_class *)FEAuxInfo( r->h, CALL_CLASS );
    if( *pc & MAKE_CALL_INLINE ) {
        Action( " inline handle=%p%n", r );
    } else {
        DumpCClass( *pc );
        Action( "%n" );
    }
    VerNode( r );
    if( r->r != NULL ) r->r->i++;
    return( r );
}
extern  void    CGReturn( n *r, cg_type t ) {
/*******************************************/

    s   *st;
    ic  *icall;
    ip  *iparm;
    ip  *junk;

    Action("CGReturn");
    Action( "( %t, %s )%n%n", r, Tipe( t ) );
    VerTipe( t,NULL );
    if( r != NULL ) {
        VerNode( r );
        DumpTree( Unary( O_RETURN,r,t ) );
    }
    NoDanglers();
    if( Inlines ) {
#if 0
        if( Inlines->t != t ) {
#else
        if( ! inlineTypeEquivalent( Inlines->t, t ) ) {
#endif
            CGError( "Return type of inline '%s' does not match",
                      Name(Inlines->h) );
        }
        iparm = Inlines->p;
        while( iparm ) {
            junk = iparm;
            iparm = iparm->n;
            CGFree(junk);
        }
        icall = Inlines;
        Inlines = Inlines->n;
        CGFree(icall);
    } else {
        InProc = NULL;
        dumpAutoLocn();
        for( st = StaticList; st; st = st->n ) {
            if( st->a != FEAttr( st->s ) ) {
                CGError( "Symbol %p freed too soon", st->s );
            }
        }
    }
}
extern  n       *CGChoose( n *s, n *l, n *r, cg_type t ) {
/********************************************************/

    n   *new;

    Action( "CGChoose" );
    VerNode( s ); VerNode( r ); VerNode( l );
    Action( "( %t, %t, %t, %s )", s, l, r, Tipe(t) );
    new = Binary( OP_CHOOSE,s,Binary( OP_JOIN,l,r,t ),t );
    Action( " -> %t%n", new );
    return( new );
}
extern  n       *CGWarp( n *b4, l *lb, n *af ) {
/**********************************************/

    n   *r;

    Action( "CGWarp" );
    if( b4 != NULL ) {
        VerNode( b4 );
    }
    VerNode( af );
    Action( "( %t, %s, %t )", b4, Label(lb), af );
    CRefLabel(lb);
    r = Binary( OP_WARP,Binary( OP_JOIN,NULL,b4,T_DEFAULT ),af,af->t );
    r->l->l = (n*)lb;
    Action( " -> %t%n", r );
    return( r );
}
extern  cg_type CGType( n *nd ) {
/*******************************/

    Action( "CGType( %t )", nd );
    VerNode( nd );
    VerTipe( nd->t,NULL );
    Action( " -> %d%n", TypeAddress( nd->t )->refno );
    return( TypeAddress( nd->t )->refno );
}
extern  void    CGBigGoto( l *lb, int ll ) {
/*******************************************/

    Action( "CGBigGoto( %d )", ll );
    VerCGCtrl( FALSE, O_BIG_GOTO, NULL, lb );
}
extern  void    CGBigLabel( b *bk ) {
/************************************/

    Action( "CGBigLabel" );
    VerCGCtrl( FALSE, O_BIG_LABEL, NULL, bk->lp );
}

⌨️ 快捷键说明

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