示例#1
0
def _add_cgen_key_lines(fo,
                        nt_name,
                        gi,
                        all_ops_widths,
                        key_str='key',
                        inst='d'):
    """
    Add C code to compute the key from constraints' values.
    """
    fo.add_code_eol('%s %s = 0' % (_key_ctype, key_str))
    cdict = gi.xed3_cdict
    bit_shift = 0
    for i, cname in enumerate(cdict.cnames):
        #eosz_set=True indicates that current value of EOSZ is correct
        #in the _operands array and we can take it from there.
        #Otherwise we would have to use special eosz computing functions
        #the same way as we do in ILD.
        #eosz_set=True here because we are doing dynamic decoding
        #and have processed the NTs that come before the current NT.
        access_str = ild_codegen.emit_ild_access_call(cname,
                                                      inst,
                                                      eoasz_set=True)

        #constraints might have 1,2 or 3 bit widths
        #and we allocate bits in the key vector appropriately
        #e.g REXB operand gets only 1 bit in the key
        #and RM gets 3 bits
        shift_val = ('(%s)' % bit_shift)
        bit_shift += all_ops_widths[cname]
        fo.add_code_eol('%s += (%s) << (%s)' %
                        (key_str, access_str, shift_val))
示例#2
0
 def get_operand_accessor(self, cname):
     ''' return a tuple of the operand accessor function and the constraint 
     names that it represents '''
     
     ptrn_list = list(self.tuple2rule.values())
     if cname in list(_token_2_module.keys()):
         nt_module = _token_2_module[cname] # name of python module!
         getter_fn = nt_module.get_getter_fn(ptrn_list) # indirect module refs!
         if not getter_fn: # -> error
                 msg = 'Failed to resolve %s getter fn for '
                 msg += 'MAP:%s OPCODE:%s'
                 insn_map = ptrn_list[0].insn_map
                 opcode = ptrn_list[0].opcode
                 ildutil.ild_err(msg % (cname, insn_map, opcode))
         access_str = '%s(%s)' % (getter_fn, self.strings_dict['obj_str'])
         nt = ild_nt.get_nt_from_lufname(getter_fn)
         return access_str, nt
     else:
         access_str = ild_codegen.emit_ild_access_call(cname, 
                                                   self.strings_dict['obj_str'])
         return access_str, cname