static void miscAnalysis( OPT_STORAGE *data ) { #if _CPU == 8086 if( data->bd || data->zu ) { if( TargetSwitches & SMART_WINDOWS ) { CErr1( ERR_ZWS_MUST_HAVE_SS_DS_SAME ); } } #endif if( GET_CPU( CpuSwitches ) < CPU_386 ) { /* issue warning message if /zf[f|p] or /zg[f|p] spec'd? */ TargetSwitches &= ~( FLOATING_FS | FLOATING_GS ); } if( ! CompFlags.save_restore_segregs ) { if( TargetSwitches & FLOATING_DS ) { HW_CTurnOff( WatcallInfo.save, HW_DS ); } if( TargetSwitches & FLOATING_ES ) { HW_CTurnOff( WatcallInfo.save, HW_ES ); } if( TargetSwitches & FLOATING_FS ) { HW_CTurnOff( WatcallInfo.save, HW_FS ); } if( TargetSwitches & FLOATING_GS ) { HW_CTurnOff( WatcallInfo.save, HW_GS ); } } if( GET_FPU( CpuSwitches ) > FPU_NONE ) { PreDefineStringMacro( "__FPI__" ); } #if _CPU == 386 if( ! CompFlags.register_conventions ) { SetAuxStackConventions(); } #endif if( data->zx ) { HW_CTurnOff( WatcallInfo.save, HW_FLTS ); } }
static void addDefaultImports( void ) { typedef enum { CM_DLLMAIN = 0x01, CM_WINMAIN = 0x02, CM_MAIN = 0x04, CM_NULL = 0x00 } check_mask; if( _HAS_ANY_MAIN ) { check_mask control; if( CompFlags.bd_switch_used ) { control = CM_DLLMAIN; } else if( CompFlags.bw_switch_used ) { control = CM_WINMAIN | CM_MAIN; } else if( CompFlags.bg_switch_used ) { control = CM_WINMAIN; } else if( CompFlags.bc_switch_used ) { control = CM_MAIN; } else { control = CM_DLLMAIN | CM_WINMAIN | CM_MAIN; } if( (control & CM_DLLMAIN) && _HAS_DLL_MAIN ) { if( CompFlags.has_wchar_entry ) { AddExtRefN( "__DLLstartw_" ); } else { AddExtRefN( "__DLLstart_" ); } control = CM_NULL; } #if _CPU == 8086 if( (control & CM_WINMAIN) && CompFlags.has_winmain || (TargetSwitches & WINDOWS) && CompFlags.has_main ) { #else if( (control & CM_WINMAIN) && CompFlags.has_winmain ) { #endif if( CompFlags.has_wchar_entry ) { AddExtRefN( "_wstartw_" ); } else { AddExtRefN( "_wstart_" ); } control = CM_NULL; } if( control & CM_MAIN ) { assert( CompFlags.has_main ); if( CompFlags.has_wchar_entry ) { AddExtRefN( "_cstartw_" ); } else { AddExtRefN( "_cstart_" ); } control = CM_NULL; } } #if ( _CPU == 8086 ) || ( _CPU == 386 ) if( CompFlags.emit_library_names ) { if( CompFlags.float_used ) { if( CompFlags.use_long_double ) { AddExtRefN( "_fltused_80bit_" ); } else { AddExtRefN( "_fltused_" ); } } #if _CPU == 8086 if( FirstStmt != 0 ) { if( TargetSwitches & BIG_CODE ) { AddExtRefN( "_big_code_" ); } else { AddExtRefN( "_small_code_" ); } } #endif if( CompFlags.pgm_used_8087 || CompFlags.float_used ) { if( GET_FPU( ProcRevision ) & FPU_EMU ) { #if _CPU == 8086 AddExtRefN( "__init_87_emulator" ); #else AddExtRefN( "__init_387_emulator" ); #endif } if( GET_FPU( ProcRevision ) > FPU_NONE ) { if( Stack87 == 4 ) { AddExtRefN( "__old_8087" ); } else { AddExtRefN( "__8087" ); } } } } #else if( CompFlags.emit_library_names ) { /* handle floating-point support */ if( CompFlags.float_used ) { AddExtRefN( "_fltused_" ); } } #endif #if ( _CPU == 8086 ) || ( _CPU == 386 ) if( CompFlags.main_has_parms ) { #if _CPU == 8086 if( CompFlags.has_wchar_entry ) { AddExtRefN( "__wargc" ); } else { AddExtRefN( "__argc" ); } #else if( CompFlags.register_conventions ) { if( CompFlags.has_wchar_entry ) { AddExtRefN( "__wargc" ); } else { AddExtRefN( "__argc" ); } } else { if( CompFlags.has_wchar_entry ) { AddExtRefN( "_wargc" ); } else { AddExtRefN( "_argc" ); } } #endif } #else if( CompFlags.main_has_parms ) { AddExtRefN( "_argc" ); } #endif /* handle default windowing app */ if( CompFlags.bw_switch_used ) { AddExtRefN( "__init_default_win" ); } #if ( _CPU == 8086 ) || ( _CPU == 386 ) /* handle NetWare */ if( TargSys == TS_NETWARE || TargSys == TS_NETWARE5 ) { /* is target NETWARE or NETWARE5? */ AddExtRefN( "__WATCOM_Prelude" ); } /* handle 'old' profiling */ if( TargetSwitches & P5_PROFILING ) { /* is profiling enabled (-et)? */ AddExtRefN( "__p5_profile" ); } /* handle 'new' profiling */ if( TargetSwitches & NEW_P5_PROFILING ) { /* is profiling enabled (-etp)? */ AddExtRefN( "__new_p5_profile" ); } #endif } /* // NextImport // Called (indirectly) from the code generator to inject automagically defined symbols. // Inputs: // index (n-1) // Usually called from a loop until we return 0/NULL to show no more symbols // are required. // request // NEXT_IMPORT // examines the current flags to see if any symbols should be // automagically inserted and returns the relevant index if so. // IMPORT_NAME // returns the requested name. if we have returned an index for // the current compiler settings we should be called with a valid // index but we still perform exactly the same checks as this is // good practise. // */ static CGPOINTER NextImport( int index, aux_class request ) /*******************************************************/ { char *name; int i; extref_info *e; if( !CompFlags.emit_targimp_symbols ) return( NULL ); name = NULL; if( index == 0 ) { addDefaultImports(); } if( request == NEXT_IMPORT ) ++index; if( index > 0 ) { for( i = 1, e = ExtrefInfo; e != NULL; e = e->next ) { if( e->symbol != NULL ) continue; if( i == index ) { name = e->name; break; } ++i; } } /* return the import name, or */ if( request == IMPORT_NAME || name == NULL ) return( (CGPOINTER)name ); /* return the index */ return( (CGPOINTER)(pointer_int)index ); }
/* // NextImport // Called (indirectly) from the code generator to inject automagically defined symbols. // Inputs: // index (n-1) // Usually called from a loop until we return 0/NULL to show no more symbols // are required. // request // NEXT_IMPORT // examines the current flags to see if any symbols should be // automagically inserted and returns the relevant index if so. // IMPORT_NAME // returns the requested name. if we have returned an index for // the current compiler settings we should be called with a valid // index but we still perform exactly the same checks as this is // good practise. // */ static VOIDPTR NextImport( int index, aux_class request ) { char *name; if(!CompFlags.emit_targimp_symbols) return (NULL); if( request == NEXT_IMPORT ) ++index; switch( index ) { /* handle entry points */ case 1: /* wide char or MBCS entry */ if( CompFlags.has_wchar_entry ) { name = "__DLLstartw_"; } else { name = "__DLLstart_"; } if( CompFlags.bd_switch_used ) /* build target == DLL ? */ break; if( CompFlags.has_libmain ) { /* object has defined symbol (w)LibMain/(w)DllMain */ /* build target == console or gui application ? */ if( !(CompFlags.bc_switch_used || CompFlags.bg_switch_used ) ) { break; } } /* wide char or MBCS entry */ if( CompFlags.has_wchar_entry ) { name = "_wstartw_"; } else { name = "_wstart_"; } /* symbol (w)WinMain defined */ if( CompFlags.has_winmain ) { /* gui application */ if( CompFlags.bg_switch_used ) break; /* target == DLL or target == console*/ if( !(CompFlags.bd_switch_used || CompFlags.bc_switch_used ) ) { break; } } #if _CPU == 8086 /* is target windows AND symbol (w)main is defined */ if(( TargetSwitches & WINDOWS ) && CompFlags.has_main ) break; #endif /* wide char or MBCS entry */ if( CompFlags.has_wchar_entry ) { name = "_cstartw_"; } else { name = "_cstart_"; } /* is symbol (w)main is defined ? */ if( CompFlags.has_main ) { /* build target == console ? */ if( CompFlags.bc_switch_used ) break; /* target == DLL or target = GUI app ? */ if( !(CompFlags.bd_switch_used || CompFlags.bg_switch_used ) ) { break; } } ++index; /* handle floating point support */ case 2: /* floating point used */ name = "_fltused_"; if( CompFlags.use_long_double ) { name = "_fltused_80bit_"; } if( CompFlags.emit_library_with_main /* emit default library info? */ || CompFlags.emit_library_any ) { /* -zlf emit all library info? */ /* 12-mar-90 */ if( CompFlags.float_used ) { /* has this object used any floating point code? */ break; } } ++index; /* handle code model library support */ case 3: #if _CPU == 8086 name = "_small_code_"; if( TargetSwitches & BIG_CODE ) { /* big code model ? */ name = "_big_code_"; } if( CompFlags.emit_library_with_main /* emit default library info? */ || CompFlags.emit_library_any ) { /* -zlf emit all library info? */ /* 12-mar-90 */ if( FirstStmt != 0 ) { break; } } #endif ++index; /* handle floating point emulator */ case 4: /* generating FPU instructions OR this object used floats ?*/ if( CompFlags.pgm_used_8087 || CompFlags.float_used ) { #if _CPU == 386 name = "__init_387_emulator"; #else name = "__init_87_emulator"; #endif if( GET_FPU( ProcRevision ) & FPU_EMU ) { /* using emulated FPU code? */ break; } } ++index; /*----------------------------------------------------------------------- // handle FPU requirement -----------------------------------------------------------------------*/ case 5: /* (emit default library info OR -zlf emit all library info) AND use backward compatible FPU code? */ if( (CompFlags.emit_library_with_main || CompFlags.emit_library_any ) && Stack87 == 4 ) { name = "__old_8087"; } else { name = "__8087"; } /* generating FPU instructions OR this object used floats? */ if( CompFlags.pgm_used_8087 || CompFlags.float_used ) { if( GET_FPU(ProcRevision) > FPU_NONE ) { break; } } ++index; /* handle entry point arg passing */ case 6: /* wide char or MBCS entry */ if( CompFlags.has_wchar_entry ) { name = "__wargc"; } else { name = "__argc"; } #if _CPU == 386 /* NOT using register convention arg passing? */ if( ! CompFlags.register_conventions ) { ++name; // change from __wargc , __argc to _wargc.. } #endif /* does (w)main have any arguments (NOT int main(void)) */ if( CompFlags.main_has_parms ) break; ++index; /* handle default windowing app */ case 7: /* is target default windowing application? */ name = "__init_default_win"; if( CompFlags.bw_switch_used ) break; ++index; /* handle NetWare */ case 8: /* is target NETWARE or NETWARE5? */ name = "__WATCOM_Prelude"; if( TargSys == TS_NETWARE ) break; if( TargSys == TS_NETWARE5 ) break; ++index; /* handle 'old' profiling */ case 9: /* is profiling enabled (-et)? */ name = "__p5_profile"; if( TargetSwitches & P5_PROFILING ) { break; } ++index; /* handle 'new' profiling */ case 10: /* is profiling enabled (-etp)? */ name = "__new_p5_profile"; if( TargetSwitches & NEW_P5_PROFILING ) { break; } /* unknown / fallthrough */ default: index = 0; // indicate no more name = NULL; break; } /* return the import name, or */ if( request == IMPORT_NAME ) return( name ); /* return the index */ return( (char *)index ); }
static const inline_funcs *IF_Lookup( const char *name ) { const inline_funcs *ifunc; size_t len; len = strlen( name ) + 1; if( GET_FPU( ProcRevision ) > FPU_NONE ) { for( ifunc = _8087_Functions; ifunc->name != NULL; ++ifunc ) { if( memcmp( ifunc->name, name, len ) == 0 ) { return( Flat( ifunc ) ); } } } if( OptSize == 100 ) { /* if /os specified */ ifunc = SInline_Functions; if( TargetSwitches & BIG_DATA ) { #if _CPU == 8086 if( TargetSwitches & FLOATING_DS ) { ifunc = ZF_Data_Functions; } else { ifunc = ZP_Data_Functions; } #else if( TargetSwitches & FLOATING_DS ) { ifunc = SBigData_Functions; } else { ifunc = SBigDataNoDs_Functions; } #endif } for( ; ifunc->name != NULL; ++ifunc ) { if( memcmp( ifunc->name, name, len ) == 0 ) { return( Flat( ifunc ) ); } } } #if _CPU == 386 if( TargetSwitches & FLAT_MODEL ) { for( ifunc = Flat_Functions; ifunc->name != NULL; ++ifunc ) { if( memcmp( ifunc->name, name, len ) == 0 ) { return( ifunc ); } } } #endif ifunc = Inline_Functions; if( TargetSwitches & BIG_DATA ) { #if _CPU == 8086 if( TargetSwitches & FLOATING_DS ) { ifunc = DF_Data_Functions; } else { ifunc = DP_Data_Functions; } #else if( TargetSwitches & FLOATING_DS ) { ifunc = BigData_Functions; } else { ifunc = BigDataNoDs_Functions; } #endif } for( ; ifunc->name != NULL; ++ifunc ) { if( memcmp( ifunc->name, name, len ) == 0 ) { return( Flat( ifunc ) ); } } for( ifunc = Common_Functions; ifunc->name != NULL; ++ifunc ) { if( memcmp( ifunc->name, name, len ) == 0 ) { return( Flat( ifunc ) ); } } return( NULL ); }
struct inline_funcs *IF_Lookup( char *name ) { struct inline_funcs *ifunc; if( GET_FPU( ProcRevision ) > FPU_NONE ) { ifunc = _8087_Functions; while( ifunc->name ) { if( strcmp( ifunc->name, name ) == 0 ) return( Flat( ifunc ) ); ++ifunc; } } if( OptSize == 100 ) { /* if /os specified */ ifunc = SInline_Functions; if( TargetSwitches & BIG_DATA ) { #if _CPU == 8086 if( TargetSwitches & FLOATING_DS ) { ifunc = ZF_Data_Functions; } else { ifunc = ZP_Data_Functions; } #else if( TargetSwitches & FLOATING_DS ) { ifunc = SBigData_Functions; } else { ifunc = SBigDataNoDs_Functions; } #endif } while( ifunc->name ) { if( strcmp( ifunc->name, name ) == 0 ) return( Flat( ifunc ) ); ++ifunc; } } #if _CPU == 386 if( TargetSwitches & FLAT_MODEL ) { ifunc = Flat_Functions; while( ifunc->name ) { if( strcmp( ifunc->name, name ) == 0 ) return( ifunc ); ++ifunc; } } #endif ifunc = Inline_Functions; if( TargetSwitches & BIG_DATA ) { #if _CPU == 8086 if( TargetSwitches & FLOATING_DS ) { ifunc = DF_Data_Functions; } else { ifunc = DP_Data_Functions; } #else if( TargetSwitches & FLOATING_DS ) { ifunc = BigData_Functions; } else { ifunc = BigDataNoDs_Functions; } #endif } while( ifunc->name ) { if( strcmp( ifunc->name, name ) == 0 ) return( Flat( ifunc ) ); ++ifunc; } ifunc = Common_Functions; while( ifunc->name ) { if( strcmp( ifunc->name, name ) == 0 ) return( Flat( ifunc ) ); ++ifunc; } return( NULL ); }