cg_name CgSaveAsTemp( // SAVE INTO A TEMPORARY temp_handle* a_hand, // - addr[ temp handle ] cg_name expr, // - expression to be saved cg_type type ) // - and its type { temp_handle handle; // - allocated temporary handle handle = CGTemp( type ); *a_hand = handle; return CGLVAssign( CGTempName( handle, type ), expr, type ); }
label_handle CgSwitchBeg // GENERATE CODE FOR START OF SWITCH STMT ( FN_CTL* fctl ) // - function control { SW_CTL *ctl; // - control for switch cg_name sw_expr; // - switch expression cg_type sw_type; // - switch type sw_expr = CgExprPopType( &sw_type ); CgExprDtored( sw_expr, sw_type, DGRP_TEMPS, fctl ); sw_expr = CgExprPopType( &sw_type ); ctl = VstkPush( &stack_switches ); ctl->id = CGSelInit(); ctl->cases = 0; ctl->temp = CGTemp( sw_type ); ctl->type = sw_type; ctl->label = BENewLabel(); CgAssign( CGTempName( ctl->temp, sw_type ), sw_expr, sw_type ); return ctl->label; }
void CmplxAssign( sym_id sym, cg_type dst_typ, cg_type src_typ ) { //=========================================================================== // Do complex assignment. cg_type typ; cg_name dest; cg_name dest_1; cg_name dest_2; cg_cmplx z; uint_16 flags; temp_handle tr; temp_handle ti; flags = sym->u.ns.flags; dest = NULL; if( (flags & SY_CLASS) == SY_SUBPROGRAM ) { // assigning to statement function if( (OZOpts & OZOPT_O_INLINE) == 0 ) { dest = SymAddr( sym ); } } else { // check for structure type before checking for array // Consider: A(1).X = A(2).X // where A is an array of structures containing complex field X if( sym->u.ns.u1.s.typ == FT_STRUCTURE ) { dest = XPop(); GetU16(); // ignore structure information } else if( flags & SY_SUBSCRIPTED ) { dest = XPop(); } else { dest = SymAddr( sym ); } } typ = CmplxBaseType( dst_typ ); if( ( src_typ != TY_COMPLEX ) && ( src_typ != TY_DCOMPLEX ) && ( src_typ != TY_XCOMPLEX ) ) { z.realpart = XPopValue( src_typ ); z.imagpart = CGInteger( 0, typ ); } else { XPopCmplx( &z, src_typ ); z.imagpart = CGEval( z.imagpart ); } z.realpart = CGEval( z.realpart ); // Before assigning the real and imaginary parts, force evaluation of each. // Consider: Z = Z * Z // The above expression will be evaluated as follows. // z.r = z.r*z.r - z.i*z.i // z.i = z.r*z.i + z.r*z.i // In the expression that evaluates the imaginary part, the value of "z.r" // must be the original value and not the new value. if( ((flags & SY_CLASS) == SY_SUBPROGRAM) && (OZOpts & OZOPT_O_INLINE) ) { XPush( z.imagpart ); XPush( z.realpart ); return; } // Code to avoid the criss cross problem // i.e. z = complx(imag(z), real(z)) // or similar problems due to overwriting of one part with the other // before accessing it. // This should not affect efficiency (for optimized code) very much // because the temps will not be used when they are not required tr = CGTemp( typ ); ti = CGTemp( typ ); CGDone( CGAssign( CGTempName( tr, typ ), z.realpart, typ ) ); CGDone( CGAssign( CGTempName( ti, typ ), z.imagpart, typ ) ); CloneCGName( dest, &dest_1, &dest_2 ); XPush( CGAssign( ImagPtr( dest_2, typ ), CGUnary( O_POINTS, CGTempName( ti, typ ), typ ), typ ) ); XPush( CGAssign( dest_1, CGUnary( O_POINTS, CGTempName( tr, typ ), typ ), typ ) ); }
cg_name CgFetchTemp( // FETCH A TEMPORARY temp_handle handle, // - handle for temporary cg_type type ) // - type of temp { return CgFetchType( CGTempName( handle, type ), type ); }