Exemplo n.º 1
0
static void parseExtRef ( void )
/******************************/
{
    SYM_HANDLE   extref_sym;

    if( CurToken == T_STRING ) {
        AddExtRefN( Buffer );
    } else {
        extref_sym = SymLook( HashValue, Buffer );
        if( extref_sym != NULL ) {
            AddExtRefS( extref_sym );
        } else {
            CErr2p( ERR_UNDECLARED_SYM, Buffer );
        }
    }
}
Exemplo n.º 2
0
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 );
}