Example #1
0
def gen_xed3(agi,ild_info,is_3dnow,ild_patterns,
            all_state_space,ild_gendir,all_ops_widths):
    all_cnames = set()
    ptrn_dict = {}
    maps = ild_info.get_maps(is_3dnow)
    for insn_map in maps:
            ptrn_dict[insn_map] = collections.defaultdict(list)
    for ptrn in ild_patterns:
        ptrn_dict[ptrn.insn_map][ptrn.opcode].append(ptrn)
    #FIXME:bad name
    vv_lu = {}
    #mapping between a operands to their look up function
    op_lu_map = {}

    for vv in sorted(all_state_space['VEXVALID'].keys()):
        #cdict is a 2D dictionary:
        #cdict[map][opcode] = ild_cdict.constraint_dict_t
        #each constraint_dict_t describes all the patterns that fall
        #into corresponding map-opcode
        #cnames is a set of all constraint names from the patterns
        #in the given vv space
        cdict,cnames = ild_cdict.get_constraints_lu_table(ptrn_dict,
                                                          is_3dnow,
                                                          all_state_space,
                                                          vv,
                                                          all_ops_widths)
        all_cnames = all_cnames.union(cnames)
        _msg("vv%s cnames: %s" % (vv,cnames))

        #now generate the C hash functions for the constraint
        #dictionaries
        (ph_lu,lu_fo_list,operands_lu_list) = ild_cdict.gen_ph_fos(
            agi, 
            cdict,
            is_3dnow,
            mbuild.join(ild_gendir,
                        'all_constraints_vv%s.txt' %vv),
            ptrn_dict, 
            vv)
        #hold only one instance of each function
        for op in operands_lu_list :
            if op.function_name not in op_lu_map:
                op_lu_map[op.function_name] = op

        vv_lu[str(vv)] = (ph_lu,lu_fo_list)
    _msg("all cnames: %s" % all_cnames)
    #dump the hash functions and lookup tables for obtaining these
    #hash functions in the decode time
    ild_codegen.dump_vv_map_lookup(agi,
                                   vv_lu,
                                   is_3dnow,
                                   list(op_lu_map.values()),
                                   h_fn='xed3-phash.h')
    #xed3_nt.work generates all the functions and lookup tables for
    #dynamic decoding
    xed3_nt.work(agi, all_state_space, all_ops_widths, ild_patterns)
Example #2
0
File: ild.py Project: xelxebar/xed
def gen_xed3(agi, ild_info, is_3dnow, ild_patterns, all_state_space,
             ild_gendir, all_ops_widths):
    all_cnames = set()
    ptrn_dict = {}  # map,opcode -> pattern
    maps = ild_info.get_maps(is_3dnow)
    for insn_map in maps:
        ptrn_dict[insn_map] = collections.defaultdict(list)
    for ptrn in ild_patterns:
        ptrn_dict[ptrn.insn_map][ptrn.opcode].append(ptrn)
    #FIXME:bad name
    vv_lu = {}  # vexvalid-space -> ( ph_lu, lu_fo_list)
    #mapping between a operands to their look up function
    op_lu_map = {}  # func name -> function (for unique-ifying)

    for vv in sorted(all_state_space['VEXVALID'].keys()):
        #cdict is a 2D dictionary:
        #cdict[map][opcode] = ild_cdict.constraint_dict_t
        #each constraint_dict_t describes all the patterns that fall
        #into corresponding map-opcode
        #cnames is a set of all constraint names from the patterns
        #in the given vv space
        cdict, cnames = ild_cdict.get_constraints_lu_table(
            ptrn_dict, is_3dnow, all_state_space, vv, all_ops_widths)

        #print "AAA VV={}: {}".format(vv, ild_cdict.replacement_stats())

        all_cnames = all_cnames.union(cnames)
        _msg("vv%s cnames: %s" % (vv, cnames))

        constraints_log_file = mbuild.join(ild_gendir,
                                           'all_constraints_vv%s.txt' % vv)

        #now generate the C hash functions for the constraint
        #dictionaries.
        #
        # ph_lu            map from map,opcode -> hash fn name
        # lu_fo_list       list of all phash fn objects
        # operands_lu_list list of operands lookup fns
        #
        (ph_lu, lu_fo_list,
         operands_lu_list) = ild_cdict.gen_ph_fos(agi, cdict, is_3dnow,
                                                  constraints_log_file,
                                                  ptrn_dict, vv)
        #hold only one instance of each function
        for op in operands_lu_list:
            if op.function_name not in op_lu_map:
                op_lu_map[op.function_name] = op

        vv_lu[str(vv)] = (ph_lu, lu_fo_list)
    _msg("all cnames: %s" % all_cnames)

    #dump the (a) hash functions and (b) lookup tables for obtaining
    #these hash functions (at decode time). ** Static decode **
    ild_codegen.dump_vv_map_lookup(agi,
                                   vv_lu,
                                   is_3dnow,
                                   list(op_lu_map.values()),
                                   h_fn='xed3-phash.h')

    #xed3_nt.work(...) generates all the functions and lookup tables for
    # ** Dynamic decode **
    xed3_nt.work(agi, all_state_space, all_ops_widths, ild_patterns)