disbuild.c

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

C
874
字号
/****************************************************************************
*
*                            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:  Build tables that drive the disassembler.
*
****************************************************************************/


#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "distypes.h"
#include "dis.h"

#define NUM_ELTS( a ) (sizeof( a ) / sizeof( a[0] ))

#define LENGTH_BIT      0x80

typedef struct {
    char                *string;
    unsigned            string_idx;
} string_data;

typedef struct {
    unsigned_32         opcode;
    unsigned_32         mask;
    unsigned            idx;
    char                *idx_name;
    char                *handler;
} ins_decode_data;

#if DISCPU & DISCPU_axp

ins_decode_data AXPDecodeTable1[] = {
    #undef inspick
    #define inspick( idx, name, opcode, mask, handler ) { opcode, mask, DI_AXP_##idx, #idx, #handler },
    #include "insaxp.h"
};

string_data AXPInsTable1[] = {
    #undef inspick
    #define inspick( idx, name, opcode, mask, handler ) { name, 0 },
    #include "insaxp.h"
};

string_data AXPRegTable[] = {
    #undef regpick
    #define regpick( idx, name ) { name, 0 },
    #include "regaxp.h"
};

string_data AXPRefTable[] = {
    #undef refpick
    #define refpick( idx, name ) { name, 0 },
    #include "refaxp.h"
};

unsigned AXPInsNum[] = {
    NUM_ELTS( AXPDecodeTable1 ),
    0
};

ins_decode_data *AXPDecodeTable[] = {
    AXPDecodeTable1,
    NULL
};

string_data *AXPInsTable[] = {
    AXPInsTable1,
    NULL
};

#endif

#if DISCPU & DISCPU_ppc

ins_decode_data PPCDecodeTable1[] = {
    #undef inspick
    #define inspick( idx, name, opcode, mask, handler ) { opcode, mask, DI_PPC_##idx, #idx, #handler },
    #include "insppc.h"
};

string_data PPCInsTable1[] = {
    #undef inspick
    #define inspick( idx, name, opcode, mask, handler ) { name, 0 },
    #include "insppc.h"
};

string_data PPCRegTable[] = {
    #undef regpick
    #define regpick( idx, name ) { name, 0 },
    #include "regppc.h"
};

string_data PPCRefTable[] = {
    #undef refpick
    #define refpick( idx, name ) { name, 0 },
    #include "refppc.h"
};

unsigned PPCInsNum[] = {
    NUM_ELTS( PPCDecodeTable1 ),
    0
};

ins_decode_data *PPCDecodeTable[] = {
    PPCDecodeTable1,
    NULL
};

string_data *PPCInsTable[] = {
    PPCInsTable1,
    NULL
};

#endif

#if DISCPU & DISCPU_x86

ins_decode_data X86DecodeTable1[] = {
    #undef inspick
    #define inspick( idx, name, opcode, mask, handler ) { opcode, mask, DI_X86_##idx, #idx, #handler },
    #include "insx86.h"
};

string_data X86InsTable1[] = {
    #undef inspick
    #define inspick( idx, name, opcode, mask, handler ) { name, 0 },
    #include "insx86.h"
};

ins_decode_data X86DecodeTable2[] = {
    #undef inspick
    #define inspick( idx, name, opcode, mask, handler ) { opcode, mask, DI_X86_##idx, #idx, #handler },
    #include "insx86e1.h"
};

string_data X86InsTable2[] = {
    #undef inspick
    #define inspick( idx, name, opcode, mask, handler ) { name, 0 },
    #include "insx86e1.h"
};

ins_decode_data X86DecodeTable3[] = {
    #undef inspick
    #define inspick( idx, name, opcode, mask, handler ) { opcode, mask, DI_X86_##idx, #idx, #handler },
    #include "insx86e2.h"
};

string_data X86InsTable3[] = {
    #undef inspick
    #define inspick( idx, name, opcode, mask, handler ) { name, 0 },
    #include "insx86e2.h"
};

ins_decode_data X86DecodeTable4[] = {
    #undef inspick
    #define inspick( idx, name, opcode, mask, handler ) { opcode, mask, DI_X86_##idx, #idx, #handler },
    #include "insx86e3.h"
};

string_data X86InsTable4[] = {
    #undef inspick
    #define inspick( idx, name, opcode, mask, handler ) { name, 0 },
    #include "insx86e3.h"
};

ins_decode_data X86DecodeTable5[] = {
    #undef inspick
    #define inspick( idx, name, opcode, mask, handler ) { opcode, mask, DI_X86_##idx, #idx, #handler },
    #include "insx86e4.h"
};

string_data X86InsTable5[] = {
    #undef inspick
    #define inspick( idx, name, opcode, mask, handler ) { name, 0 },
    #include "insx86e4.h"
};

string_data X86RegTable[] = {
    #undef regpick
    #define regpick( idx, name ) { name, 0 },
    #include "regx86.h"
};

string_data X86RefTable[] = {
    #undef refpick
    #define refpick( idx, name ) { name, 0 },
    #include "refx86.h"
};

unsigned X86InsNum[] = {
    NUM_ELTS( X86DecodeTable1 ),
    NUM_ELTS( X86DecodeTable2 ),
    NUM_ELTS( X86DecodeTable3 ),
    NUM_ELTS( X86DecodeTable4 ),
    NUM_ELTS( X86DecodeTable5 ),
    0
};

ins_decode_data *X86DecodeTable[] = {
    X86DecodeTable1,
    X86DecodeTable2,
    X86DecodeTable3,
    X86DecodeTable4,
    X86DecodeTable5,
    NULL
};

string_data *X86InsTable[] = {
    X86InsTable1,
    X86InsTable2,
    X86InsTable3,
    X86InsTable4,
    X86InsTable5,
    NULL
};

#endif

#if DISCPU & DISCPU_x64

ins_decode_data X64DecodeTable1[] = {
    #undef inspick
    #define inspick( idx, name, opcode, mask, handler ) { opcode, mask, DI_X64_##idx, #idx, #handler },
    #include "insx64.h"
};

string_data X64InsTable1[] = {
    #undef inspick
    #define inspick( idx, name, opcode, mask, handler ) { name, 0 },
    #include "insx64.h"
};

string_data X64RegTable[] = {
    #undef regpick
    #define regpick( idx, name ) { name, 0 },
    #include "regx64.h"
};

string_data X64RefTable[] = {
    #undef refpick
    #define refpick( idx, name ) { name, 0 },
    #include "refx64.h"
};

unsigned X64InsNum[] = {
    NUM_ELTS( X64DecodeTable1 ),
    0
};

ins_decode_data *X64DecodeTable[] = {
    X64DecodeTable1,
    NULL
};

string_data *X64InsTable[] = {
    X64InsTable1,
    NULL
};

#endif

#if DISCPU & DISCPU_jvm

ins_decode_data JVMDecodeTable1[] = {
    #undef inspick
    #define inspick( idx, name, opcode, mask, handler ) { opcode, mask, DI_JVM_##idx, #idx, #handler },
    #include "insjvm.h"
};

string_data JVMInsTable1[] = {
    #undef inspick
    #define inspick( idx, name, opcode, mask, handler ) { name, 0 },
    #include "insjvm.h"
};

string_data JVMRegTable[] = {
    #undef regpick
    #define regpick( idx, name ) { name, 0 },
    #include "regjvm.h"
};

string_data JVMRefTable[] = {
    #undef refpick
    #define refpick( idx, name ) { name, 0 },
    #include "refjvm.h"
};

unsigned JVMInsNum[] = {
    NUM_ELTS( JVMDecodeTable1 ),
    0
};

ins_decode_data *JVMDecodeTable[] = {
    JVMDecodeTable1,
    NULL
};

string_data *JVMInsTable[] = {
    JVMInsTable1,
    NULL
};

#endif

#if DISCPU & DISCPU_sparc

ins_decode_data SPARCDecodeTable1[] = {
    #undef inspick
    #define inspick( idx, name, opcode, mask, handler ) { opcode, mask, DI_SPARC_##idx, #idx, #handler },
    #include "inssparc.h"
};

string_data SPARCInsTable1[] = {
    #undef inspick
    #define inspick( idx, name, opcode, mask, handler ) { name, 0 },
    #include "inssparc.h"
};

string_data SPARCRegTable[] = {
    #undef regpick
    #define regpick( idx, name ) { name, 0 },
    #include "regsparc.h"
};

string_data SPARCRefTable[] = {
    #undef refpick
    #define refpick( idx, name ) { name, 0 },
    #include "refsparc.h"
};

unsigned SPARCInsNum[] = {
    NUM_ELTS( SPARCDecodeTable1 ),
    0
};

ins_decode_data *SPARCDecodeTable[] = {
    SPARCDecodeTable1,
    NULL
};

string_data *SPARCInsTable[] = {
    SPARCInsTable1,
    NULL
};

#endif

#if DISCPU & DISCPU_mips

ins_decode_data MIPSDecodeTable1[] = {
    #undef inspick
    #define inspick( idx, name, opcode, mask, handler ) { opcode, mask, DI_MIPS_##idx, #idx, #handler },
    #include "insmips.h"
};

string_data MIPSInsTable1[] = {
    #undef inspick
    #define inspick( idx, name, opcode, mask, handler ) { name, 0 },
    #include "insmips.h"
};

string_data MIPSRegTable[] = {
    #undef regpick
    #define regpick( idx, name ) { name, 0 },
    #include "regmips.h"
};

string_data MIPSRefTable[] = {
    #undef refpick
    #define refpick( idx, name ) { name, 0 },
    #include "refmips.h"
};

unsigned MIPSInsNum[] = {
    NUM_ELTS( MIPSDecodeTable1 ),
    0
};

ins_decode_data *MIPSDecodeTable[] = {
    MIPSDecodeTable1,
    NULL
};

string_data *MIPSInsTable[] = {
    MIPSInsTable1,
    NULL
};

#endif

typedef struct {
    string_data         *reg_names;
    unsigned            num_reg_names;
    string_data         *ref_names;
    unsigned            num_ref_names;
    unsigned            *num_ins;
    string_data         **ins_names;
    ins_decode_data     **decode;
    char                *prefix;
} machine_data;

#define TABLE( who )                    \
        {                               \
        who##RegTable,                  \
        NUM_ELTS( who##RegTable ),      \
        who##RefTable,                  \
        NUM_ELTS( who##RefTable ),      \
        who##InsNum,                    \
        who##InsTable,                  \
        who##DecodeTable,               \
        #who                            \
        }

⌨️ 快捷键说明

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