⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 coptions.c

📁 Open Watcom 的 C 编译器源代码
💻 C
📖 第 1 页 / 共 5 页
字号:
/****************************************************************************
*
*                            Open Watcom Project
*
*    Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
*  ========================================================================
*
*    This file contains Original Code and/or Modifications of Original
*    Code as defined in and that are subject to the Sybase Open Watcom
*    Public License version 1.0 (the 'License'). You may not use this file
*    except in compliance with the License. BY USING THIS FILE YOU AGREE TO
*    ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
*    provided with the Original Code and Modifications, and is also
*    available at www.sybase.com/developer/opensource.
*
*    The Original Code and all software distributed under the License are
*    distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
*    EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
*    ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
*    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
*    NON-INFRINGEMENT. Please see the License for the specific language
*    governing rights and limitations under the License.
*
*  ========================================================================
*
* Description:  C compiler command line option processing.
*
****************************************************************************/


/*****************************************************************************
*                                                                            *
*       If you add an option, don't forget to change ../usage.sp             *
*       Also, don't forget to add a case in MacroDefs                        *
*       to predefine a __SW_xx macro                                         *
*                                                                            *
*****************************************************************************/
#include "cvars.h"
#include <ctype.h>
#include "pragdefn.h"
#include "pdefn2.h"
#include "cgswitch.h"
#include "iopath.h"
#include <unistd.h>
#include <fcntl.h>
#ifdef __OSI__
 #include "ostype.h"
#endif
#ifndef O_BINARY
#define O_BINARY 0
#endif

enum encoding {
    ENC_ZK = 1,
    ENC_ZK0,
    ENC_ZK1,
    ENC_ZK2,
    ENC_ZK3,
    ENC_ZKL,
    ENC_ZKU,
    ENC_ZK0U
};

struct  option {
    char        *option;
    unsigned    value;
    void        (*function)(void);
};

static unsigned OptValue;
static char    *OptScanPtr;
static char    *OptParm;

#define __isdigit(c)    ((c) >= '0' && (c) <= '9')

#define PEGGED( r )     unsigned peg_##r##s_used        : 1;    \
                        unsigned peg_##r##s_on          : 1

static struct
{
    char        *sys_name;

    enum    /* TARGET CPU SUPPORT - Intel defined (AXP/PPC uses CPU0 as default CPU) */
    {
        SW_CPU_DEF,     /*  No target CPU specified     */
        SW_CPU0,        /*  Target 8086/8               */
        SW_CPU1,        /*  Target 80186/8              */
        SW_CPU2,        /*  Target 80286                */
        SW_CPU3,        /*  Target 80386                */
        SW_CPU4,        /*  Target 80486                */
        SW_CPU5,        /*  Target Pentium              */
        SW_CPU6         /*  Target Pentium-Pro          */
    }cpu;

    enum    /* TARGET FPU SUPPORT */
    {
        SW_FPU_DEF,     /*  No target FPU specified     */
        SW_FPU0,        /*  Target 8087 co-pro          */
        SW_FPU3,        /*  Target 80387 co-pro         */
        SW_FPU5,        /*  Target Pentium int fpu      */
        SW_FPU6         /*  Target Pentium-Pro int fpu  */
    }fpu;

    enum    /* FPU CALL TYPES */
    {
        SW_FPT_DEF,     /*  No FPU call type specified  */
        SW_FPT_CALLS,   /*  FPU calls via library       */
        SW_FPT_EMU,     /*  FPU calls inline & emulated */
        SW_FPT_INLINE   /*  FPU calls inline            */
    }fpt;

    enum    /* MEMORY MODELS */
    {
        SW_M_DEF,       /*  No memory model specified   */
        SW_MF,          /*  Flat memory model           */
        SW_MS,          /*  Small memory model          */
        SW_MM,          /*  Medium memory model         */
        SW_MC,          /*  Compact memory model        */
        SW_ML,          /*  Large memory model          */
        SW_MH           /*  Huge memory model           */
    }mem;

    enum    /*  DEBUGGING INFORMATION TYPE */
    {
        SW_DF_DEF,      /*  No debug type specified     */
        SW_DF_WATCOM,   /*  Use Watcom                  */
        SW_DF_CV,       /*  Use CodeView                */
        SW_DF_DWARF,    /*  Use DWARF                   */
        SW_DF_DWARF_A,  /*  Use DWARF + A?              */
        SW_DF_DWARF_G   /*  Use DWARF + G?              */
    }dbg_fmt;

    PEGGED( d );
    PEGGED( e );
    PEGGED( f );
    PEGGED( g );
    unsigned    nd_used         : 1;
} SwData;

// local functions.
local void SetStackConventions( void );

// local variables
static int character_encoding = 0;
static long unicode_CP = 0;

int EqualChar( int c )
{
    return( c == '#' || c == '=' );
}

static void SetCharacterEncoding( void )
{
    CompFlags.jis_to_unicode = 0;

    switch( character_encoding ) {
    case ENC_ZKU:
        LoadUnicodeTable( unicode_CP );
        break;
    case ENC_ZK0U:
        CompFlags.use_unicode = 0;
        SetDBChar( 0 );                     /* set double-byte char type */
        CompFlags.jis_to_unicode = 1;
        break;
    case ENC_ZK:
    case ENC_ZK0:
        CompFlags.use_unicode = 0;
        SetDBChar( 0 );                     /* set double-byte char type */
        break;
    case ENC_ZK1:
        CompFlags.use_unicode = 0;
        SetDBChar( 1 );                     /* set double-byte char type */
        break;
    case ENC_ZK2:
        CompFlags.use_unicode = 0;
        SetDBChar( 2 );                     /* set double-byte char type */
        break;
    case ENC_ZK3:
        CompFlags.use_unicode = 0;
        SetDBChar( 3 );                     /* set double-byte char type */
        break;
    case ENC_ZKL:
        CompFlags.use_unicode = 0;
        SetDBChar( -1 );                    /* set double-byte char type to defualt */
        break;
    }
}

local void SetTargName( char *name, unsigned len )
{
    char        *p;

    if( SwData.sys_name != NULL ) {
        CMemFree( SwData.sys_name );
        SwData.sys_name = NULL;
    }
    if( name == NULL || len == 0 ) return;
    SwData.sys_name = CMemAlloc( len + 1 ); /* for NULLCHAR */
    p = SwData.sys_name;
    while( len != 0 )
    {
        *p++ = toupper( *name++ );
        --len;
    }
    *p++ = '\0';
}

#define _SetConstTarg( name ) SetTargName( name, sizeof( name ) - 1 )

local void SetTargSystem()                               /* 07-aug-90 */
{
    char        buff[128];

#if _MACHINE == _ALPHA
    PreDefine_Macro( "M_ALPHA" );
    PreDefine_Macro( "_M_ALPHA" );
    PreDefine_Macro( "__ALPHA__" );
    PreDefine_Macro( "_ALPHA_" );
    PreDefine_Macro( "__AXP__" );
    PreDefine_Macro( "_STDCALL_SUPPORTED" );
#elif _MACHINE == _SPARC
    PreDefine_Macro( "M_SPARC" );
    PreDefine_Macro( "_M_SPARC" );
    PreDefine_Macro( "__SPARC__" );
    PreDefine_Macro( "_SPARC_" );
#elif _MACHINE == _PPC
    PreDefine_Macro( "M_PPC" );
    PreDefine_Macro( "_M_PPC" );
    PreDefine_Macro( "__POWERPC__" );
    PreDefine_Macro( "__PPC__" );
    PreDefine_Macro( "_PPC_" );
#elif _CPU == 386
    PreDefine_Macro( "M_I386" );                    /* 03-jul-91 */
    PreDefine_Macro( "__386__" );
    PreDefine_Macro( "__X86__" );
    PreDefine_Macro( "_X86_" );
    PreDefine_Macro( "_STDCALL_SUPPORTED" );
#elif _CPU == 8086
    PreDefine_Macro( "M_I86" );
    PreDefine_Macro( "__I86__" );
    PreDefine_Macro( "__X86__" );
    PreDefine_Macro( "_X86_" );
#else
    #error SetTargSystem not configured
#endif


    PreDefine_Macro( "__WATCOM_INT64__" );
    PreDefine_Macro( "_INTEGRAL_MAX_BITS=64" );
    if( SwData.sys_name == NULL )
    {
        #if _CPU == 386 || _CPU == 8086
            #if defined( __OSI__ )
                switch( __OS )
                {                        // 11-mar-94
                case OS_DOS:
                case OS_WIN:
                    _SetConstTarg( "dos" );
                    break;
                case OS_OS2:
                    _SetConstTarg( "os2" );
                    break;
                case OS_NT:
                    _SetConstTarg( "nt" );
                    break;
                }
            #elif defined( __NOVELL__ )
                _SetConstTarg( "netware" );
            #elif _OS == _QNX
                _SetConstTarg( "qnx" );
            #elif _OS == _LINUX
                _SetConstTarg( "linux" );
            #elif _OS == _OS2
                _SetConstTarg( "os2" );
            #elif _OS == _NT
                _SetConstTarg( "nt" );
            #elif _OS == _DOS
                _SetConstTarg( "dos" );
            #else
                #error "Target OS not defined"
            #endif
        #elif _MACHINE == _ALPHA || _MACHINE == _PPC || _MACHINE == _SPARC
            /* we only have NT libraries for Alpha right now */
            _SetConstTarg( "nt" );
        #else
            #error Target Machine OS not configured
        #endif
    }

    if( strcmp( SwData.sys_name, "DOS" ) == 0 )
    {
        TargSys = TS_DOS;
    }
    else if( strcmp( SwData.sys_name, "NETWARE" ) == 0 )
    {
        TargSys = TS_NETWARE;
    }
    else if( strcmp( SwData.sys_name, "NETWARE5" ) == 0 )
    {
        TargSys = TS_NETWARE5;
    }
    else if( strcmp( SwData.sys_name, "WINDOWS" ) == 0 )
    {
        TargSys = TS_WINDOWS;
    }
    else if( strcmp( SwData.sys_name, "CHEAP_WINDOWS" ) == 0 )
    {
        TargSys = TS_CHEAP_WINDOWS;
    }
    else if( strcmp( SwData.sys_name, "NT" ) == 0 )
    {
        TargSys = TS_NT;
    }
    else if( strcmp( SwData.sys_name, "LINUX" ) == 0 )
    {
        TargSys = TS_LINUX;
    }
    else if( strcmp( SwData.sys_name, "QNX" ) == 0 )
    {
        TargSys = TS_QNX;
    }
    else if( strcmp( SwData.sys_name, "OS2" ) == 0 )
    {
        TargSys = TS_OS2;
    }
    else
    {
        TargSys = TS_OTHER;
    }

    switch( TargSys )
    {
    case TS_DOS:
        PreDefine_Macro( "MSDOS" );
        PreDefine_Macro( "_DOS" );
    break;

#if _CPU == 386
    case TS_NETWARE:
        Stack87 = 4;
        /* fall through */
    case TS_NETWARE5:
        /* no "fpr" for Netware 5.0 */
        if( SwData.mem == SW_M_DEF )
        {
            SwData.mem = SW_MS;
        }
        if( TargSys == TS_NETWARE5 )
            PreDefine_Macro( "__NETWARE__" );
        PreDefine_Macro( "__NETWARE_386__" );
        /*
        //  NETWARE uses stack based calling conventions
        //  by default - silly people.
        */
        if( !CompFlags.register_conv_set )
        {
            CompFlags.register_conventions = 0;
        }
    break;

    case TS_NT:
        PreDefine_Macro( "_WIN32" );
    break;
#endif
    case TS_QNX:
        /* fall through */
    case TS_LINUX:
        PreDefine_Macro( "__UNIX__" );
    break;

    case TS_CHEAP_WINDOWS:
        #if _CPU == 8086
            PreDefine_Macro( "__WINDOWS__" );
            PreDefine_Macro( "_WINDOWS" );
        #else
            TargSys = TS_WINDOWS;
        #endif
        /* fall through */

    case TS_WINDOWS:
        #if _CPU == 386
            PreDefine_Macro( "__WINDOWS_386__" );
            if( !SwData.peg_fs_used )
            {
                SwData.peg_fs_on = 0;
                SwData.peg_fs_used = 1;
            }
            switch( SwData.fpt )
            {
            case SW_FPT_DEF:
            case SW_FPT_EMU:
                SwData.fpt = SW_FPT_INLINE;
                break;
            default:
                break;
            }
            TargetSwitches |= WINDOWS | CHEAP_WINDOWS;
        #elif _CPU == 8086
            if( !SwData.peg_ds_used )
            {
                SwData.peg_ds_on = 1;
                SwData.peg_ds_used = 1;
            }
            TargetSwitches |= WINDOWS | CHEAP_WINDOWS;
        #endif
        break;
    }
    strcpy( buff, "__" );
    strcat( buff, SwData.sys_name );
    strcat( buff, "__" );
    PreDefine_Macro( buff );
}

#define SET_PEG( r ) if( !SwData.peg_##r##s_used ) SwData.peg_##r##s_on = 1;

static void SetGenSwitches()
{
#if _CPU == 8086 || _CPU == 386
    #if _CPU == 386

⌨️ 快捷键说明

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