#include "decl.h" /* This file contains two arrays with information concerning the C_INSTR tokens: * t_C_info C_info[]; - Describes the arguments of EM-instructions * struct ? EM_instr[]; - Contains per entry: * 1) The name of the C_INSTR * 2) The type of its argument, an index in * C_info[]. * 3) The segment for which code/data must * be generated. * The array is sorted on the C_INSTR-name. * * Furthermore there are two routines present in this file : * set_C_instr_info( instr) - It looks 'instr' up in EM_instr[] and * char *instr; - sets the global variables * - 'C_instr_info' and 'segment'. * * arg_type( arg) - 'arg' must be a string starting with a '$' * char *arg; - and a number. arg_type() will return the * - type of the 'number'th argment of the current * - C_INSTR. * - For example, if the EM_table contains: * C_loc ==> "pushl $1". * then arg_type( "$1") will return ARITH. */ t_C_info C_info[] = { /* NO_ARGS */ { "()\n{\n", { 0, 0, 0, 0}, { 0, 0, 0, 0}, { 0, 0, 0, 0}}, /* C_ARG */ { "( c)\narith c;\n{\n", { ARITH, 0, 0, 0}, { "c", 0, 0, 0}, { "c", 0, 0, 0}}, /* D_ARG */ { "( d)\narith d;\n{\n", { ARITH, 0, 0, 0}, { "d", 0, 0, 0}, { "d", 0, 0, 0}}, /* F_ARG */ { "( f)\narith f;\n{\n", { ARITH, 0, 0, 0}, { "f", 0, 0, 0}, { "f", 0, 0, 0}}, /* L_ARG */ { "( l)\narith l;\n{\n", { ARITH, 0, 0, 0}, { "l", 0, 0, 0}, { "(l >= 0 ? l + EM_BSIZE : l)", 0, 0, 0}}, /* N_ARG */ { "( n)\narith n;\n{\n", { ARITH, 0, 0, 0}, { "n", 0, 0, 0}, { "n", 0, 0, 0}}, /* O_ARG */ { "( o)\narith o;\n{\n", { ARITH, 0, 0, 0}, { "o", 0, 0, 0}, { "o", 0, 0, 0}}, /* R_ARG */ { "( r)\narith r;\n{\n", { ARITH, 0, 0, 0}, { "r", 0, 0, 0}, { "r", 0, 0, 0}}, /* S_ARG */ { "( s)\narith s;\n{\n", { ARITH, 0, 0, 0}, { "s", 0, 0, 0}, { "s", 0, 0, 0}}, /* Z_ARG */ { "( z)\narith z;\n{\n", { ARITH, 0, 0, 0}, { "z", 0, 0, 0}, { "z", 0, 0, 0}}, /* W_ARG */ { "( w)\narith w;\n{\n", { ARITH, 0, 0, 0}, { "w", 0, 0, 0}, { "w", 0, 0, 0}}, /* EXTERNAL */ { "( g)\narith g;\n{\n", { STRING, ARITH, 0, 0}, { "FAKE-ARGUMENT", "g", 0, 0}, { "extnd_hol( holno)", "g", 0, 0}}, /* EXTERNAL_DNAM*/ { "( g, o)\nchar *g;\narith o;\n{\n", { STRING, ARITH, 0, 0}, { "g", "o", 0, 0}, { "extnd_dnam( g)", "o", 0, 0}}, /* EXTERNAL_DLB */ { "( g, o)\nchar *g;\narith o;\n{\n", { STRING, ARITH, 0, 0}, { "g", "o", 0, 0}, { "extnd_dlb( g)", "o", 0, 0}}, /* P_ARG */ { "( p)\nchar *p;\n{\n", { STRING, 0, 0, 0}, { "p", 0, 0, 0}, { "extnd_name( p)", 0, 0, 0}}, /* B_ARG */ { "( b)\nlabel b;\n{\n", { STRING, 0, 0, 0}, { "b", 0, 0, 0}, { "extnd_ilb( b, procno)", 0, 0, 0}}, /* STRING+ARITH */ { "( val, sz)\nchar *val;\narith sz;\n{\n", { STRING, ARITH, 0, 0}, { "val", "sz", 0, 0}, { "val", "sz", 0, 0}}, /* BSS_EXT_DNAM */ { "( n, g, o, i)\nchar *g;\narith n, o;\nint i;\n{\n", { ARITH, STRING, ARITH, INT}, { "n", "g", "o", "i"}, { "n", "extnd_dnam( g)", "o", "i"}}, /* BSS_EXT_DLB */ { "( n, g, o, i)\nchar *g;\narith n, o;\nint i;\n{\n", { ARITH, STRING, ARITH, INT}, { "n", "g", "o", "i"}, { "n", "extnd_dlb( g)", "o", "i"}}, /* BSS_STR+AR */ { "( n, val, sz, i)\nchar *val;\narith n, sz;\nint i;\n{\n", { ARITH, STRING, ARITH, INT}, { "n", "val", "sz", "i"}, { "n", "val", "sz", "i"}}, /* BSS_W_ARG */ { "( n, w, i)\narith n, w;\nint i;\n{\n", { ARITH, ARITH, INT, 0}, { "n", "w", "i", 0}, { "n", "w", "i", 0}}, /* BSS_PNAM */ { "( n, p, i)\narith n;\nchar *p;int i;\n\n{\n", { ARITH, STRING, INT, 0}, { "n", "p", "i", 0}, { "n", "extnd_name( p)", "i", 0}}, /* BSS_ILB */ { "( n, b, i)\narith n;\nlabel b;int i;\n\n{\n", { ARITH, STRING, INT, 0}, { "n", "b", "i", 0}, { "n", "extnd_ilb( b, procno)", "i", 0}}, /* ID+N_ARG */ { "( p, n)\nchar *p;\narith n;\n{\n", { STRING, ARITH, 0, 0}, { "p", "n", 0, 0}, { "extnd_name( p)", "n", 0, 0}}, /* ARITH+ARITH */ { "( n, w)\narith n, w;\n{\n", { ARITH, ARITH, 0, 0}, { "n", "w", 0, 0}, { "n", "w", 0, 0}}, /* EXT_DNAM */ { "( g)\nchar *g;\n{\n", { STRING, 0, 0, 0}, { "g", 0, 0, 0}, { "extnd_dnam( g)", 0, 0, 0}}, /* EXT_DLB */ { "( g)\nchar *g;\n{\n", { STRING, 0, 0, 0}, { "g", 0, 0, 0}, { "extnd_dlb( g)", 0, 0, 0}}, /* ONE_INT */ { "( i)\nint i;\n{\n", { INT, 0, 0, 0}, { "i", 0, 0, 0}, { "i", 0, 0, 0}}, /* _STRING */ { "( str)\nchar *str;\n{\n", { STRING, 0, 0, 0}, { "str", 0, 0, 0}, { "str", 0, 0, 0}} }, *C_instr_info; #define N_INSTR 269 struct { char *name; int class, segment;} EM_instr[ N_INSTR ] = { { "C_aar", W_ARG, SEGTXT}, { "C_aar_narg", NO_ARGS, SEGTXT}, { "C_adf", W_ARG, SEGTXT}, { "C_adf_narg", NO_ARGS, SEGTXT}, { "C_adi", W_ARG, SEGTXT}, { "C_adi_narg", NO_ARGS, SEGTXT}, { "C_adp", F_ARG, SEGTXT}, { "C_ads", W_ARG, SEGTXT}, { "C_ads_narg", NO_ARGS, SEGTXT}, { "C_adu", W_ARG, SEGTXT}, { "C_adu_narg", NO_ARGS, SEGTXT}, { "C_and", W_ARG, SEGTXT}, { "C_and_narg", NO_ARGS, SEGTXT}, { "C_asp", F_ARG, SEGTXT}, { "C_ass", W_ARG, SEGTXT}, { "C_ass_narg", NO_ARGS, SEGTXT}, { "C_beq", B_ARG, SEGTXT}, { "C_bge", B_ARG, SEGTXT}, { "C_bgt", B_ARG, SEGTXT}, { "C_ble", B_ARG, SEGTXT}, { "C_blm", Z_ARG, SEGTXT}, { "C_bls", W_ARG, SEGTXT}, { "C_bls_narg", NO_ARGS, SEGTXT}, { "C_blt", B_ARG, SEGTXT}, { "C_bne", B_ARG, SEGTXT}, { "C_bra", B_ARG, SEGTXT}, { "C_bss_cst", BSS_W_ARG, SEGBSS}, { "C_bss_dlb", BSS_EXT_DLB, SEGBSS}, { "C_bss_dnam", BSS_EXT_DNAM, SEGBSS}, { "C_bss_fcon", BSS_STR_AR, SEGBSS}, { "C_bss_icon", BSS_STR_AR, SEGBSS}, { "C_bss_ilb", BSS_ILB, SEGBSS}, { "C_bss_pnam", BSS_PNAM, SEGBSS}, { "C_bss_ucon", BSS_STR_AR, SEGBSS}, { "C_cai", NO_ARGS, SEGTXT}, { "C_cal", P_ARG, SEGTXT}, { "C_cff", NO_ARGS, SEGTXT}, { "C_cfi", NO_ARGS, SEGTXT}, { "C_cfu", NO_ARGS, SEGTXT}, { "C_cif", NO_ARGS, SEGTXT}, { "C_cii", NO_ARGS, SEGTXT}, { "C_ciu", NO_ARGS, SEGTXT}, { "C_close", NO_ARGS, NOSEG}, { "C_cmf", W_ARG, SEGTXT}, { "C_cmf_narg", NO_ARGS, SEGTXT}, { "C_cmi", W_ARG, SEGTXT}, { "C_cmi_narg", NO_ARGS, SEGTXT}, { "C_cmp", NO_ARGS, SEGTXT}, { "C_cms", W_ARG, SEGTXT}, { "C_cms_narg", NO_ARGS, SEGTXT}, { "C_cmu", W_ARG, SEGTXT}, { "C_cmu_narg", NO_ARGS, SEGTXT}, { "C_com", W_ARG, SEGTXT}, { "C_com_narg", NO_ARGS, SEGTXT}, { "C_con_cst", C_ARG, SEGCON}, { "C_con_dlb", EXTERNAL_DLB, SEGCON}, { "C_con_dnam", EXTERNAL_DNAM, SEGCON}, { "C_con_fcon", STRING_ARITH, SEGCON}, { "C_con_icon", STRING_ARITH, SEGCON}, { "C_con_ilb", B_ARG, SEGCON}, { "C_con_pnam", P_ARG, SEGCON}, { "C_con_scon", STRING_ARITH, SEGCON}, { "C_con_ucon", STRING_ARITH, SEGCON}, { "C_csa", W_ARG, SEGTXT}, { "C_csa_narg", NO_ARGS, SEGTXT}, { "C_csb", W_ARG, SEGTXT}, { "C_csb_narg", NO_ARGS, SEGTXT}, { "C_cst", C_ARG, NOSEG}, { "C_cuf", NO_ARGS, SEGTXT}, { "C_cui", NO_ARGS, SEGTXT}, { "C_cuu", NO_ARGS, SEGTXT}, { "C_dch", NO_ARGS, SEGTXT}, { "C_dec", NO_ARGS, SEGTXT}, { "C_dee", EXTERNAL, SEGTXT}, { "C_dee_dlb", EXTERNAL_DLB, SEGTXT}, { "C_dee_dnam", EXTERNAL_DNAM, SEGTXT}, { "C_del", L_ARG, SEGTXT}, { "C_df_dlb", EXT_DLB, NOSEG}, { "C_df_dnam", EXT_DNAM, NOSEG}, { "C_df_ilb", B_ARG, SEGTXT}, { "C_dlb", STRING_ARITH, SEGTXT}, { "C_dnam", STRING_ARITH, SEGTXT}, { "C_dup", S_ARG, SEGTXT}, { "C_dus", W_ARG, SEGTXT}, { "C_dus_narg", NO_ARGS, SEGTXT}, { "C_dvf", W_ARG, SEGTXT}, { "C_dvf_narg", NO_ARGS, SEGTXT}, { "C_dvi", W_ARG, SEGTXT}, { "C_dvi_narg", NO_ARGS, SEGTXT}, { "C_dvu", W_ARG, SEGTXT}, { "C_dvu_narg", NO_ARGS, SEGTXT}, { "C_end", Z_ARG, SEGTXT}, { "C_end_narg", NO_ARGS, SEGTXT}, { "C_exa_dlb", EXT_DLB, NOSEG}, { "C_exa_dnam", EXT_DNAM, NOSEG}, { "C_exc", ARITH_ARITH, NOSEG}, { "C_exg", W_ARG, SEGTXT}, { "C_exg_narg", NO_ARGS, SEGTXT}, { "C_exp", P_ARG, SEGTXT}, { "C_fcon", STRING_ARITH, SEGTXT}, { "C_fef", W_ARG, SEGTXT}, { "C_fef_narg", NO_ARGS, SEGTXT}, { "C_fif", W_ARG, SEGTXT}, { "C_fif_narg", NO_ARGS, SEGTXT}, { "C_fil", EXTERNAL, SEGTXT}, { "C_fil_dlb", EXTERNAL_DLB, SEGTXT}, { "C_fil_dnam", EXTERNAL_DNAM, SEGTXT}, { "C_gto", EXTERNAL, SEGTXT}, { "C_gto_dlb", EXTERNAL_DLB, SEGTXT}, { "C_gto_dnam", EXTERNAL_DNAM, SEGTXT}, { "C_hol_cst", BSS_W_ARG, SEGHOL}, { "C_hol_dlb", BSS_EXT_DLB, SEGHOL}, { "C_hol_dnam", BSS_EXT_DNAM, SEGHOL}, { "C_hol_fcon", BSS_STR_AR, SEGHOL}, { "C_hol_icon", BSS_STR_AR, SEGHOL}, { "C_hol_ilb", BSS_ILB, SEGHOL}, { "C_hol_pnam", BSS_PNAM, SEGHOL}, { "C_hol_ucon", BSS_STR_AR, SEGHOL}, { "C_icon", STRING_ARITH, SEGTXT}, { "C_ilb", B_ARG, SEGTXT}, { "C_ina_dlb", EXT_DLB, SEGTXT}, { "C_ina_dnam", EXT_DNAM, SEGTXT}, { "C_inc", NO_ARGS, SEGTXT}, { "C_ine", EXTERNAL, SEGTXT}, { "C_ine_dlb", EXTERNAL_DLB, SEGTXT}, { "C_ine_dnam", EXTERNAL_DNAM, SEGTXT}, { "C_init", ARITH_ARITH, SEGTXT}, { "C_inl", L_ARG, SEGTXT}, { "C_inn", W_ARG, SEGTXT}, { "C_inn_narg", NO_ARGS, SEGTXT}, { "C_inp", P_ARG, NOSEG}, { "C_ior", W_ARG, SEGTXT}, { "C_ior_narg", NO_ARGS, SEGTXT}, { "C_lae", EXTERNAL, SEGTXT}, { "C_lae_dlb", EXTERNAL_DLB, SEGTXT}, { "C_lae_dnam", EXTERNAL_DNAM, SEGTXT}, { "C_lal", L_ARG, SEGTXT}, { "C_lar", W_ARG, SEGTXT}, { "C_lar_narg", NO_ARGS, SEGTXT}, { "C_ldc", D_ARG, SEGTXT}, { "C_lde", EXTERNAL, SEGTXT}, { "C_lde_dlb", EXTERNAL_DLB, SEGTXT}, { "C_lde_dnam", EXTERNAL_DNAM, SEGTXT}, { "C_ldf", F_ARG, SEGTXT}, { "C_ldl", L_ARG, SEGTXT}, { "C_lfr", S_ARG, SEGTXT}, { "C_lil", L_ARG, SEGTXT}, { "C_lim", NO_ARGS, SEGTXT}, { "C_lin", N_ARG, SEGTXT}, { "C_lni", NO_ARGS, SEGTXT}, { "C_loc", C_ARG, SEGTXT}, { "C_loe", EXTERNAL, SEGTXT}, { "C_loe_dlb", EXTERNAL_DLB, SEGTXT}, { "C_loe_dnam", EXTERNAL_DNAM, SEGTXT}, { "C_lof", F_ARG, SEGTXT}, { "C_loi", O_ARG, SEGTXT}, { "C_lol", L_ARG, SEGTXT}, { "C_lor", R_ARG, SEGTXT}, { "C_los", W_ARG, SEGTXT}, { "C_los_narg", NO_ARGS, SEGTXT}, { "C_lpb", NO_ARGS, SEGTXT}, { "C_lpi", P_ARG, SEGTXT}, { "C_lxa", N_ARG, SEGTXT}, { "C_lxl", N_ARG, SEGTXT}, { "C_magic", NO_ARGS, NOSEG}, { "C_mes_begin", ONE_INT, NOSEG}, { "C_mes_end", NO_ARGS, NOSEG}, { "C_mlf", W_ARG, SEGTXT}, { "C_mlf_narg", NO_ARGS, SEGTXT}, { "C_mli", W_ARG, SEGTXT}, { "C_mli_narg", NO_ARGS, SEGTXT}, { "C_mlu", W_ARG, SEGTXT}, { "C_mlu_narg", NO_ARGS, SEGTXT}, { "C_mon", NO_ARGS, SEGTXT}, { "C_ngf", W_ARG, SEGTXT}, { "C_ngf_narg", NO_ARGS, SEGTXT}, { "C_ngi", W_ARG, SEGTXT}, { "C_ngi_narg", NO_ARGS, SEGTXT}, { "C_nop", NO_ARGS, SEGTXT}, { "C_open", _STRING, NOSEG}, { "C_pnam", P_ARG, NOSEG}, { "C_pro", P_ARG, SEGTXT}, { "C_pro_narg", NO_ARGS, SEGTXT}, { "C_rck", W_ARG, SEGTXT}, { "C_rck_narg", NO_ARGS, SEGTXT}, { "C_ret", Z_ARG, SEGTXT}, { "C_rmi", W_ARG, SEGTXT}, { "C_rmi_narg", NO_ARGS, SEGTXT}, { "C_rmu", W_ARG, SEGTXT}, { "C_rmu_narg", NO_ARGS, SEGTXT}, { "C_rol", W_ARG, SEGTXT}, { "C_rol_narg", NO_ARGS, SEGTXT}, { "C_rom_cst", C_ARG, SEGROM}, { "C_rom_dlb", EXTERNAL_DLB, SEGROM}, { "C_rom_dnam", EXTERNAL_DNAM, SEGROM}, { "C_rom_fcon", STRING_ARITH, SEGROM}, { "C_rom_icon", STRING_ARITH, SEGROM}, { "C_rom_ilb", B_ARG, SEGROM}, { "C_rom_pnam", P_ARG, SEGROM}, { "C_rom_scon", STRING_ARITH, SEGROM}, { "C_rom_ucon", STRING_ARITH, SEGROM}, { "C_ror", W_ARG, SEGTXT}, { "C_ror_narg", NO_ARGS, SEGTXT}, { "C_rtt", NO_ARGS, SEGTXT}, { "C_sar", W_ARG, SEGTXT}, { "C_sar_narg", NO_ARGS, SEGTXT}, { "C_sbf", W_ARG, SEGTXT}, { "C_sbf_narg", NO_ARGS, SEGTXT}, { "C_sbi", W_ARG, SEGTXT}, { "C_sbi_narg", NO_ARGS, SEGTXT}, { "C_sbs", W_ARG, SEGTXT}, { "C_sbs_narg", NO_ARGS, SEGTXT}, { "C_sbu", W_ARG, SEGTXT}, { "C_sbu_narg", NO_ARGS, SEGTXT}, { "C_scon", STRING_ARITH, NOSEG}, { "C_sde", EXTERNAL, SEGTXT}, { "C_sde_dlb", EXTERNAL_DLB, SEGTXT}, { "C_sde_dnam", EXTERNAL_DNAM, SEGTXT}, { "C_sdf", F_ARG, SEGTXT}, { "C_sdl", L_ARG, SEGTXT}, { "C_set", W_ARG, SEGTXT}, { "C_set_narg", NO_ARGS, SEGTXT}, { "C_sig", NO_ARGS, SEGTXT}, { "C_sil", L_ARG, SEGTXT}, { "C_sim", NO_ARGS, SEGTXT}, { "C_sli", W_ARG, SEGTXT}, { "C_sli_narg", NO_ARGS, SEGTXT}, { "C_slu", W_ARG, SEGTXT}, { "C_slu_narg", NO_ARGS, SEGTXT}, { "C_sri", W_ARG, SEGTXT}, { "C_sri_narg", NO_ARGS, SEGTXT}, { "C_sru", W_ARG, SEGTXT}, { "C_sru_narg", NO_ARGS, SEGTXT}, { "C_ste", EXTERNAL, SEGTXT}, { "C_ste_dlb", EXTERNAL_DLB, SEGTXT}, { "C_ste_dnam", EXTERNAL_DNAM, SEGTXT}, { "C_stf", F_ARG, SEGTXT}, { "C_sti", O_ARG, SEGTXT}, { "C_stl", L_ARG, SEGTXT}, { "C_str", R_ARG, SEGTXT}, { "C_sts", W_ARG, SEGTXT}, { "C_sts_narg", NO_ARGS, SEGTXT}, { "C_teq", NO_ARGS, SEGTXT}, { "C_tge", NO_ARGS, SEGTXT}, { "C_tgt", NO_ARGS, SEGTXT}, { "C_tle", NO_ARGS, SEGTXT}, { "C_tlt", NO_ARGS, SEGTXT}, { "C_tne", NO_ARGS, SEGTXT}, { "C_trp", NO_ARGS, SEGTXT}, { "C_ucon", STRING_ARITH, NOSEG}, { "C_xor", W_ARG, SEGTXT}, { "C_xor_narg", NO_ARGS, SEGTXT}, { "C_zeq", B_ARG, SEGTXT}, { "C_zer", W_ARG, SEGTXT}, { "C_zer_narg", NO_ARGS, SEGTXT}, { "C_zge", B_ARG, SEGTXT}, { "C_zgt", B_ARG, SEGTXT}, { "C_zle", B_ARG, SEGTXT}, { "C_zlt", B_ARG, SEGTXT}, { "C_zne", B_ARG, SEGTXT}, { "C_zre", EXTERNAL, SEGTXT}, { "C_zre_dlb", EXTERNAL_DLB, SEGTXT}, { "C_zre_dnam", EXTERNAL_DNAM, SEGTXT}, { "C_zrf", W_ARG, SEGTXT}, { "C_zrf_narg", NO_ARGS, SEGTXT}, { "C_zrl", L_ARG, SEGTXT}, { "jump", _STRING, SEGTXT}, { "locals", N_ARG, SEGTXT}, { "prolog", NO_ARGS, SEGTXT} }; set_C_instr_info( instr) char *instr; { int low, high, mid, rel; low = 0; high = N_INSTR - 1; while ( TRUE) { mid = ( low + high) / 2; rel = strcmp( instr, EM_instr[mid].name); if ( rel == 0 ) break; else if ( high == low) { out( "ERROR : can't find >>%s<< !!\n", instr); abort(); } else if ( rel < 0) high = mid; else /* pas op, mid is naar beneden afgerond !! */ low = ( mid == low ? low + 1: mid); } C_instr_info = &C_info[ EM_instr[mid].class]; segment = EM_instr[mid].segment; } int arg_type( arg) char *arg; /* return argument-type from $i */ { int i; i = *(arg+1) - '0' - 1; return( C_instr_info->arg_type[i]); }