inline.c

来自「开放源码的编译器open watcom 1.6.0版的源代码」· C语言 代码 · 共 493 行 · 第 1/2 页

C
493
字号
// ax    - number of spaces to append
// si bx - source pointer
// cx    - number of characters to move
static  char    __RTIStrBlastNeWin[] =  { "aux __RTIStrBlastNe          \
                                        parm    reverse                 \
                                                [es di] [dx] [si bx] [ax]\
                                        modify  exact [di dx si ax cx] =\
                                        \"push  ds\"                    \
                                        \"mov   ds,si\"                 \
                                        \"mov   si,bx\"                 \
                                        \"mov   cx,ax\"                 \
                                        \"shr   cx,1\"                  \
                                        \"rep   movsw\"                 \
                                        \"adc   cx,0\"                  \
                                        \"rep   movsb\"                 \
                                        \"mov   cx,dx\"                 \
                                        \"mov   ax,0x2020\"             \
                                        \"shr   cx,1\"                  \
                                        \"rep   stosw\"                 \
                                        \"adc   cx,0\"                  \
                                        \"rep   stosb\"                 \
                                        \"pop   ds\"                    \
                                " };

// Small memory pragmas.

// Space Optimizations pragmas

// di   - destination pointer
// si   - source pointer
// cx   - number of characters to move
static  char    __RTIStrBlastEqSOS[] =  { "aux __RTIStrBlastEq          \
                                        parm    reverse                 \
                                                [di] [si] [cx]          \
                                        modify  [es] =                  \
                                        \"push  ds\"                    \
                                        \"pop   es\"                    \
                                        \"rep   movsb\"                 \
                                " };

// di   - destination pointer
// ax   - number of spaces to append
// si   - source pointer
// cx   - number of characters to move
static  char    __RTIStrBlastNeSOS[] =  { "aux __RTIStrBlastNe          \
                                        parm    reverse                 \
                                                [di] [ax] [si] [cx]     \
                                        modify  [es] =                  \
                                        \"push  ds\"                    \
                                        \"pop   es\"                    \
                                        \"rep   movsb\"                 \
                                        \"mov   cx, ax\"                \
                                        \"mov   ax, 0x2020\"            \
                                        \"rep   stosb\"                 \
                                " };

// Time Optimization pragmas

// di   - destination pointer
// si   - source pointer
// cx   - number of 2 character tuples to move (strlen >> 21
// ax   - number of characters left over after initial 2-tuple move (strlen & 1)
static  char    __RTIStrBlastEqS[] =  { "aux __RTIStrBlastEq            \
                                        parm    reverse                 \
                                                [di] [si] [cx] [ax]     \
                                        modify  [es] =                  \
                                        \"push  ds\"                    \
                                        \"pop   es\"                    \
                                        \"rep   movsw\"                 \
                                        \"mov   cx, ax\"                \
                                        \"rep   movsb\"                 \
                                " };

// di   - destination pointer
// ax   - number of spaces to append
// si   - source pointer
// cx   - number of characters to move
static  char    __RTIStrBlastNeS[] =  { "aux __RTIStrBlastNe            \
                                        parm    reverse                 \
                                                [di] [dx] [si] [ax]     \
                                        modify  [cx es] =               \
                                        \"push  ds\"                    \
                                        \"pop   es\"                    \
                                        \"mov   cx, ax\"                \
                                        \"shr   cx, 1\"                 \
                                        \"rep   movsw\"                 \
                                        \"adc   cx, 0\"                 \
                                        \"rep   movsb\"                 \
                                        \"mov   cx, dx\"                \
                                        \"mov   ax, 0x2020\"            \
                                        \"shr   cx, 1\"                 \
                                        \"rep   stosw\"                 \
                                        \"adc   cx, 0\"                 \
                                        \"rep   stosb\"                 \
                                " };
#endif

typedef struct inline_rtn {
    char        __FAR *name;
    char        __FAR *pragma;
    cg_type     typ;
    sym_id      sym_ptr;
    aux_info    *aux;
} inline_rtn;

static inline_rtn  __FAR NormalInlineTab[] = {
        "__RTIStrBlastEq", __RTIStrBlastEq, T_INTEGER, NULL, NULL,
        "__RTIStrBlastNe", __RTIStrBlastNe, T_INTEGER, NULL, NULL
};

static inline_rtn  __FAR OptSpaceInlineTab[] = {
        "__RTIStrBlastEq", __RTIStrBlastEqOS, T_INTEGER, NULL, NULL,
        "__RTIStrBlastNe", __RTIStrBlastNeOS, T_INTEGER, NULL, NULL
};

#if _CPU == 8086
static inline_rtn  __FAR WinNormalInlineTab[] = {
        "__RTIStrBlastEq", __RTIStrBlastEqWin, T_INTEGER, NULL, NULL,
        "__RTIStrBlastNe", __RTIStrBlastNeWin, T_INTEGER, NULL, NULL
};

static inline_rtn  __FAR WinOptSpaceInlineTab[] = {
        "__RTIStrBlastEq", __RTIStrBlastEqWinOS, T_INTEGER, NULL, NULL,
        "__RTIStrBlastNe", __RTIStrBlastNeWinOS, T_INTEGER, NULL, NULL
};

static inline_rtn  __FAR SmallModelInlineTab[] = {
        "__RTIStrBlastEq", __RTIStrBlastEqS, T_INTEGER, NULL, NULL,
        "__RTIStrBlastNe", __RTIStrBlastNeS, T_INTEGER, NULL, NULL
};

static inline_rtn  __FAR OptSpaceSmallModelInlineTab[] = {
        "__RTIStrBlastEq", __RTIStrBlastEqSOS, T_INTEGER, NULL, NULL,
        "__RTIStrBlastNe", __RTIStrBlastNeSOS, T_INTEGER, NULL, NULL
};
#endif

static inline_rtn  __FAR *InlineTab = NormalInlineTab;

#define MAX_IN_INDEX    (sizeof( NormalInlineTab ) / sizeof( inline_rtn ))

static bool     CreatedPragmas = FALSE;

#endif

call_handle     InitInlineCall( int rtn_id ) {
//============================================

// Initialize a call to a runtime routine.

#if _CPU == 386 || _CPU == 8086
    sym_id              sym;
    inline_rtn __FAR    *in_entry;
    int                 name_len;

    if( !CreatedPragmas ) {
        InitInlinePragmas();
    }
    in_entry = &InlineTab[ rtn_id ];
    sym = in_entry->sym_ptr;
    if( sym == NULL ) {
        name_len = strlen( in_entry->name );
        strcpy( SymBuff, in_entry->name );
        sym = STAdd( SymBuff, name_len );
        sym->ns.flags = SY_USAGE | SY_TYPE | SY_SUBPROGRAM | SY_FUNCTION;
        sym->ns.typ = TY_INTEGER_TARG;
        sym->ns.xt.size = TypeSize( sym->ns.typ );
        sym->ns.address = NULL;
        in_entry->sym_ptr = sym;
        in_entry->aux = AuxLookupName( in_entry->name, name_len );
    }
    return( CGInitCall( CGFEName( sym, in_entry->typ ), in_entry->typ,
                        in_entry->aux ) );
#else
    rtn_id = rtn_id;
    return( 0 );
#endif
}


void    InitInlinePragmas( void ) {
//===========================

#if _CPU == 386 || _CPU == 8086
    int index;

    if( !CreatedPragmas ) {
        if( OZOpts & OZOPT_O_SPACE ) {
            InlineTab = OptSpaceInlineTab;
#if _CPU == 8086
            if( CGOpts & CGOPT_M_MEDIUM ) {
                InlineTab = OptSpaceSmallModelInlineTab;
            } else {
                // using large/huge memory model
                if( CGOpts & CGOPT_WINDOWS ) {
                    InlineTab = WinOptSpaceInlineTab;
                }
            }
        } else {
            if( CGOpts & CGOPT_M_MEDIUM ) {
                InlineTab = SmallModelInlineTab;
            } else {
                // using large/huge memory model
                if( CGOpts & CGOPT_WINDOWS ) {
                    InlineTab = WinNormalInlineTab;
                }
            }
#endif
        }
        for( index = 0; index < MAX_IN_INDEX; index++ ) {
            DoPragma( InlineTab[ index ].pragma );
        }
        CreatedPragmas = TRUE;
    }
    for( index = 0; index < MAX_IN_INDEX; index++ ) {
        InlineTab[ index ].sym_ptr = NULL;
    }
#endif
}


void    FreeInlinePragmas( void ) {
//===========================

// Free symbol table entries for run-time routines.

#if _CPU == 386 || _CPU == 8086
    int         index;
    sym_id      sym;

    if( !CreatedPragmas ) return;
    for( index = 0; index < MAX_IN_INDEX; index++ ) {
        sym = InlineTab[ index ].sym_ptr;
        if( sym != NULL ) {
            if( ( CGFlags & CG_FATAL ) == 0 ) {
                if( sym->ns.address != NULL ) {
                    BEFreeBack( sym->ns.address );
                }
            }
            STFree( sym );
            InlineTab[ index ].sym_ptr = NULL;
        }
    }
#endif
}

⌨️ 快捷键说明

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