Example #1
0
    def _gen_generic_getter(self):
        ''' for xed's internal usage (printing) we need to be able to 
            get an operand based on its index.
            generating here a switch/case over the operand index to call the 
            correct getter function '''
        inst = 'd'
        fname = 'xed3_get_generic_operand'
        ret_arg = 'ret_arg'

        fo = codegen.function_object_t(fname,
                                       return_type='void',
                                       static=False,
                                       inline=False,
                                       dll_export=True)
        fo.add_arg('const xed_decoded_inst_t* %s' % inst)
        fo.add_arg('xed_operand_enum_t operand')
        fo.add_arg('void* %s' % ret_arg)

        switch_gen = codegen.c_switch_generator_t('operand', fo)
        op_names = sorted(self.operand_fields.keys())
        for op in op_names:
            switch_key = "XED_OPERAND_%s" % op
            ctype = self.get_ctype(op)
            func_getter = "%s(d)" % get_op_getter_fn(op)
            code = "*((%s*)%s)=%s;" % (ctype, ret_arg, func_getter)
            switch_gen.add_case(switch_key, [code])
        switch_gen.add_default(['xed_assert(0);'])
        switch_gen.finish()
        return fo
Example #2
0
    def _gen_generic_setter(self):
        ''' generating a switch/case over the operand index to call the 
            correct setter function '''
        inst = 'd'
        fname = 'xed3_set_generic_operand'
        in_value = 'val'

        fo = codegen.function_object_t(fname,
                                       return_type='void',
                                       static=False,
                                       inline=False,
                                       dll_export=True)
        fo.add_arg('xed_decoded_inst_t* %s' % inst)
        fo.add_arg('xed_operand_enum_t operand')
        fo.add_arg('xed_uint32_t %s' % in_value)

        switch_gen = codegen.c_switch_generator_t('operand', fo)
        op_names = sorted(self.operand_fields.keys())
        for op in op_names:
            switch_key = "XED_OPERAND_%s" % op
            ctype = self.get_ctype(op)
            func_setter = get_op_setter_fn(op)
            code = "%s(%s,(%s)%s);" % (func_setter, inst, ctype, in_value)
            switch_gen.add_case(switch_key, [code])
        switch_gen.add_default(['xed_assert(0);'])
        switch_gen.finish()
        return fo
Example #3
0
def _emit_function(fe, isa_sets, name):
    fo = codegen.function_object_t('xed_classify_{}'.format(name))
    fo.add_arg('const xed_decoded_inst_t* d')
    fo.add_code_eol(
        '    const xed_isa_set_enum_t isa_set = xed_decoded_inst_get_isa_set(d)'
    )
    # FIXME: 2017-07-14 optimization: could use a static array for faster checking, smaller code
    switch = codegen.c_switch_generator_t('isa_set', fo)
    for c in isa_sets:
        switch.add_case('XED_ISA_SET_{}'.format(c.upper()), [], do_break=False)
    if len(isa_sets) > 0:
        switch.add('return 1;')
    switch.add_default(['return 0;'], do_break=False)
    switch.finish()

    fo.emit_file_emitter(fe)