def _dump_top_level_dispatch_array(agi, h_file, array_names, emit_array_name, sub_data_type): vv_max = max( [ ild_info.encoding_space_to_vexvalid(mi.space) for mi in agi.map_info ] ) max_maps = ild_info.get_maps_max_id(agi) + 1 h_file.add_code('#if !defined(XED_MAP_ROW_LIMIT)') h_file.add_code('# define XED_MAP_ROW_LIMIT {}'.format(max_maps)) h_file.add_code('#endif') h_file.add_code('#if !defined(XED_VEXVALID_LIMIT)') h_file.add_code('# define XED_VEXVALID_LIMIT {}'.format(vv_max+1)) h_file.add_code('#endif') h_file.add_code('const {}* {}[XED_VEXVALID_LIMIT][XED_MAP_ROW_LIMIT] = {{'.format( sub_data_type, emit_array_name)) for vv in range(0,vv_max+1): maps = ild_info.get_maps_for_space(agi,vv) dmap = {mi.map_id:mi for mi in maps} # dict indexed by map_id init_vals = ['0'] * max_maps for imap in range(0,max_maps): if imap in dmap: mi = dmap[imap] if mi.map_name in array_names: init_vals[imap] = array_names[mi.map_name] h_file.add_code('{{ {} }},'.format(', '.join(init_vals))) h_file.add_code('};')
def gen_static_decode(agi, vv_lu, op_lu_list, h_fn='xed3-phash.h'): """generate static decoder""" phash_headers = ['xed-ild-eosz-getters.h', 'xed-ild-easz-getters.h', 'xed-internal-header.h', 'xed-ild-private.h'] maplu_headers = [] all_zero_by_map = {} for vv in sorted(vv_lu.keys()): (phash_map_lu, lu_fo_list) = vv_lu[vv] all_zero_by_map[vv] = _test_map_all_zero(vv, phash_map_lu) # dump a file w/prototypes and per-opcode functions pointed to # by the elements of the various 256-entry arrays. pheader = 'xed3-phash-vv{}.h'.format(vv) dump_flist_2_header(agi, pheader, ['xed3-operand-lu.h'], lu_fo_list) # dump 256-entry arrays for each (vv,map) map_lu_cfn = 'xed3-phash-lu-vv{}.c'.format(vv) map_lu_hfn = 'xed3-phash-lu-vv{}.h'.format(vv) maplu_headers.append(map_lu_hfn) name_pfx = 'xed3_phash_vv{}'.format(vv) elem_type = 'xed3_find_func_t' dump_lookup(agi, #dump 256-entry arrays for maps in this encspace phash_map_lu, name_pfx, map_lu_cfn, [pheader], elem_type, output_dir=None, all_zero_by_map=all_zero_by_map[vv]) # dump a header with the decls for the 256-entry arrays or # #define NAME 0 for the empty arrays. h_file = agi.open_file(mbuild.join('include-private',map_lu_hfn), start=False) h_file.start() for insn_map in sorted(phash_map_lu.keys()): arr_name = _get_map_lu_name(name_pfx, insn_map) if all_zero_by_map[vv][insn_map]: #h_file.add_code("#define {} 0".format(arr_name)) pass else: h_file.add_code("extern const {} {}[256];".format( elem_type, arr_name)) h_file.close() #dump all the operand lookup functions in the list to a header file hdr = 'xed3-operand-lu.h' dump_flist_2_header(agi, hdr, phash_headers, op_lu_list, emit_bodies=False) dump_flist_2_header(agi, 'xed3-operand-lu.c', [hdr], op_lu_list, is_private=False, emit_headers=False) # write xed3-phash.h (top most thing). # # xed3-pash.h contains a table indexed by encoding-space & # decoding-map mapping to functions handling decoding that part of # the space. h_file = agi.open_file(mbuild.join('include-private',h_fn), start=False) for header in maplu_headers: h_file.add_header(header) h_file.start() maps = ild_info.get_maps(agi) vv_num = [ int(x) for x in vv_lu.keys() ] vv_max = max(vv_num) + 1 max_maps = ild_info.get_maps_max_id(agi) + 1 arr_name = 'xed3_phash_lu' h_file.add_code('#define XED_PHASH_MAP_LIMIT {}'.format(max_maps)) h_file.add_code('const xed3_find_func_t* {}[{}][XED_PHASH_MAP_LIMIT] = {{'.format( arr_name, vv_max)) for vv in range(0,vv_max): maps = ild_info.get_maps_for_space(agi,vv) dmap = {mi.map_id:mi for mi in maps} # dict indexed by map_id init_vals = ['0'] * max_maps for imap in range(0,max_maps): if imap in dmap: mi = dmap[imap] # if there are maps without instructions, then there # won't be top-level variables to look at for those # maps. if all_zero_by_map[str(vv)][mi.map_name]: init_vals[imap] = '0' else: init_vals[imap] = _get_map_lu_name( 'xed3_phash_vv{}'.format(vv), mi.map_name ) h_file.add_code('{{ {} }},'.format(', '.join(init_vals))) h_file.add_code('};') h_file.close()