static void init( // MODULE INITIALIZATION INITFINI* defn ) // - definition { defn = defn; defined_type = TY_FIRST_FREE; cg_member_ptr = NULL_CGREFNO; #if _CPU == _AXP defaultDataPtrClass = PTR_NEAR; defaultCodePtrClass = PTR_NEAR; #elif _INTEL_CPU defaultDataPtrClass = PTR_NEAR; defaultCodePtrClass = PTR_NEAR; if( !IsFlat() ) { if( IsHugeData() ) { defaultDataPtrClass = PTR_HUGE; } else if( IsBigData() ) { defaultDataPtrClass = PTR_LONG; } if( IsBigCode() ) { defaultCodePtrClass = PTR_LONG; } } #else #error bad target #endif }
static enum sym_type PtrType( type_flag flags ) { enum sym_type retn; if( flags & ( TF1_FAR | TF1_HUGE ) ) { retn = SYM_DFAR; } else if( flags & TF1_NEAR ) { retn = SYM_DNEAR; } else if( IsBigData() ) { retn = SYM_DFAR; } else { retn = SYM_DNEAR; } return retn; }
static fe_seg_id cgSegIdVariable( SYMBOL sym, type_flag flags, SEGID_CONTROL control ) { fe_seg_id id; target_size_t size; size = CgMemorySize( sym->sym_type ); #ifdef _CHECK_SIZE // only defined if needed if( !(flags & TF1_HUGE) ) { if( _CHECK_SIZE( size ) ) { CErr2p( ERR_DATA_TOO_BIG, sym ); return( SEG_NULL ); } } #endif if( flags & TF1_NEAR ) { id = cgSegIdNearVariable( sym, flags, size, control ); } else if( flags & TF1_HUGE ) { id = cgSegIdHugeVariable( sym, flags, size, control ); } else if( flags & TF1_FAR ) { id = cgSegIdFarVariable( sym, flags, size, control ); } else { boolean assume_near = TRUE; if( IsBigData() ) { if( flags & TF1_DEFAULT_FAR ) { assume_near = FALSE; } else if( size == 0 || size > DataThreshold ) { assume_near = FALSE; } else if( CompFlags.zc_switch_used ) { if( cgSegIdConst( sym, flags, control ) ) { // symbol may have been placed in code segment assume_near = FALSE; } } } if( assume_near ) { id = cgSegIdNearVariable( sym, flags, size, control ); } else { id = cgSegIdFarVariable( sym, flags, size, control ); } } return( id ); }
bool TypeTruncByMemModel( // TEST TYPE TRUNCATION FOR DEF. MEMORY MODEL TYPE type ) // - the type { bool ok; // - true ==> type matches default mem. model type_flag flags; // - flags for the type type_flag mflags; // - memory-model flags for the type type = TypeGetActualFlags( type, &flags ); mflags = flags & TF1_MEM_MODEL; if( 0 == mflags ) { ok = false; } else { if( type->id == TYP_FUNCTION ) { ok = ( !IsBigCode() && (TF1_NEAR & mflags) == 0 ); } else { ok = ( !IsBigData() && (TF1_NEAR & mflags) == 0 ); } } return( ok ); }
back_handle DgStringConst( // STORE STRING CONSTANT WITH NULL STRING_CONSTANT str, // - string to store uint_16 *psegid, // - addr(string segid) unsigned control ) // - control mask (DSC_*) { back_handle handle; // - back handle for literal target_offset_t str_align; // - string's alignment target_size_t str_len; // - string's length (in bytes) segment_id str_seg; // - string's segment segment_id old_seg; // - old segment str_seg = str->segid; handle = str->cg_handle; if( control & DSC_CONST ) { if( handle == 0 ) { handle = BENewBack( 0 ); str->cg_handle = handle; str_len = str->len + TARGET_CHAR; if( str->wide_string ) { str_align = TARGET_WIDE_CHAR; } else { str_align = TARGET_CHAR; } #if _CPU == _AXP str_seg = SEG_CONST; #else if( CompFlags.strings_in_code_segment && ( control & DSC_CODE_OK ) != 0 ) { if( IsBigData() ) { str_seg = SegmentAddStringCodeFar( str_len, str_align ); } else { if( IsFlat() ) { str_seg = SegmentAddStringCodeFar( str_len, str_align ); } else { str_seg = SEG_CONST; } } } else { if( IsBigData() ) { str_seg = SegmentAddStringConstFar( str_len, str_align ); } else { str_seg = SEG_CONST; } } #endif str->segid = str_seg; old_seg = BESetSeg( str_seg ); #if _CPU == _AXP DGAlign( TARGET_INT ); #else DGAlign( str_align ); // NT requires word aligned wide strings #endif DGLabel( handle ); DGString( str->string, str->len ); DgByte( 0 ); #if _CPU == _AXP DGAlign( TARGET_INT ); #endif BESetSeg( old_seg ); } } else { // char a[] = "asdf"; initialization (use current segment) str_seg = DgCurrSeg(); str->segid = str_seg; DGString( str->string, str->len ); DgByte( 0 ); } if( psegid != NULL ) { *psegid = str_seg; } return( handle ); }