Пример #1
0
    'sve_intx_qdmulh_by_indexed_elem', 'sve_intx_qrdcmla_by_indexed_elem',
    'sve_intx_qrdmlah', 'sve_intx_qrdmlah_by_indexed_elem',
    'sve_intx_shift_insert', 'sve_intx_shift_long', 'sve_intx_shift_narrow',
    'sve_intx_sra', 'sve_maskimm', 'sve_mem32', 'sve_mem64',
    'sve_mem_32b_fill', 'sve_mem_32b_gld_sv_a', 'sve_mem_32b_gld_sv_b',
    'sve_mem_32b_gld_vi', 'sve_mem_32b_gld_vs', 'sve_mem_32b_gldnt_vs',
    'sve_mem_32b_pfill', 'sve_mem_32b_prfm_sv', 'sve_mem_32b_prfm_vi',
    'sve_mem_64b_gld_sv', 'sve_mem_64b_gld_sv2', 'sve_mem_64b_gld_vi',
    'sve_mem_64b_gld_vs', 'sve_mem_64b_gld_vs2', 'sve_mem_64b_gldnt_vs',
    'sve_mem_64b_prfm_sv', 'sve_mem_64b_prfm_sv2', 'sve_mem_64b_prfm_vi',
    'sve_mem_cld_si', 'sve_mem_cld_ss', 'sve_mem_cldff_ss', 'sve_mem_cldnf_si',
    'sve_mem_cldnt_si', 'sve_mem_cldnt_ss', 'sve_mem_cst_si', 'sve_mem_cst_ss',
    'sve_mem_cstnt_si', 'sve_mem_cstnt_ss', 'sve_mem_eld_si', 'sve_mem_eld_ss',
    'sve_mem_est_si', 'sve_mem_est_ss', 'sve_mem_ld_dup', 'sve_mem_ldqr_si',
    'sve_mem_ldqr_ss', 'sve_mem_prfm_si', 'sve_mem_prfm_ss', 'sve_mem_pspill',
    'sve_mem_spill', 'sve_mem_sst_sv2', 'sve_mem_sst_sv_a', 'sve_mem_sst_sv_b',
    'sve_mem_sst_vi_a', 'sve_mem_sst_vi_b', 'sve_mem_sst_vs2',
    'sve_mem_sst_vs_a', 'sve_mem_sst_vs_b', 'sve_mem_sstnt_32b_vs',
    'sve_mem_sstnt_64b_vs', 'sve_memcld', 'sve_memst_cs', 'sve_memst_nt',
    'sve_memst_si', 'sve_memst_ss', 'sve_memst_ss2', 'sve_perm_extract',
    'sve_perm_pred', 'sve_perm_predicates', 'sve_perm_unpred_d',
    'sve_pred_count_a', 'sve_pred_count_b', 'sve_pred_gen_b', 'sve_pred_gen_c',
    'sve_pred_gen_d', 'sve_pred_wrffr', 'sve_wideimm_pred',
    'sve_wideimm_unpred', 'systeminstrs', 'systeminstrswithreg', 'systemmove',
    'systemresult', 'testbranch'
]

if __name__ == '__main__':
    root = algorithm.hierarchy(inputs, lambda a, b: b.startswith(a))
    print(root)
Пример #2
0
items = [
    set([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]),
    set([4, 5]),
    set([6, 7]),
    set([8]),
    set([3, 4, 5, 6, 7]),
    set([4, 5, 6]),
    set([7, 8, 9, 10]),
    set([1, 2]),
    set([9, 10]),
    set([5]),
]

if __name__ == '__main__':
    ancestor_relation = lambda a, b: a > b
    root = algorithm.hierarchy(items, ancestor_relation)

    actual = str(root)
    print(actual)
    expected = 'root\n' + \
               '  {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}\n' + \
               '    {3, 4, 5, 6, 7}\n' + \
               '      {6, 7}\n' + \
               '      {4, 5, 6}\n' + \
               '        {4, 5}\n' + \
               '          {5}\n' + \
               '    {8, 9, 10, 7}\n' + \
               '      {8}\n' + \
               '      {9, 10}\n' + \
               '    {1, 2}'
    assert (actual == expected)
Пример #3
0
    '[0x194,0x198) p_flags=0x4', '[0x198,0x1A0) p_offset=0x574',
    '[0x1A0,0x1A8) p_vaddr=0x400574', '[0x1A8,0x1B0) p_paddr=0x400574',
    '[0x1B0,0x1B8) p_filesz=0x34', '[0x1B8,0x1C0) p_memsz=0x34',
    '[0x1C0,0x1C8) p_align=0x4', '[0x190,0x1C8) elf64_phdr 6 OS',
    '[0x1C8,0x1CC) p_type=0x6474E551', '[0x1CC,0x1D0) p_flags=0x6',
    '[0x1D0,0x1D8) p_offset=0x0', '[0x1D8,0x1E0) p_vaddr=0x0',
    '[0x1E0,0x1E8) p_paddr=0x0', '[0x1E8,0x1F0) p_filesz=0x0',
    '[0x1F0,0x1F8) p_memsz=0x0', '[0x1F8,0x200) p_align=0x10',
    '[0x1C8,0x200) elf64_phdr 7 OS', '[0x200,0x204) p_type=0x6474E552',
    '[0x204,0x208) p_flags=0x4', '[0x208,0x210) p_offset=0xE10',
    '[0x210,0x218) p_vaddr=0x600E10', '[0x218,0x220) p_paddr=0x600E10',
    '[0x220,0x228) p_filesz=0x1F0', '[0x228,0x230) p_memsz=0x1F0',
    '[0x230,0x238) p_align=0x1', '[0x200,0x238) elf64_phdr 8 OS'
]


def get_interval_values(string):
    (lhs, rhs) = re.match(r'^\[(.*?),(.*?)\) .*$', string).group(1, 2)
    return (int(lhs, 16), int(rhs, 16))


def ancestor(a, b):
    (a_left, a_right) = get_interval_values(a)
    (b_left, b_right) = get_interval_values(b)
    return a_left <= b_left and a_right >= b_right


if __name__ == '__main__':
    result = algorithm.hierarchy(items, ancestor)
    print(result.json())
Пример #4
0
#!/usr/bin/env python

# test on the instruction class and instruction form names from the A64 specification

import sys
import random
import algorithm

if __name__ == '__main__':
    # strings and substrings

    # doing this input list in any order should always produce the same hierarchy
    ancestor_relation = lambda a, b: b.startswith(a)
    sort_key = lambda x: x
    items = ['aardvark', 'ant', 'antelope', 'anteater', 'a']
    for i in range(10):
        random.shuffle(items)
        print('input: items')
        result = algorithm.hierarchy(items, ancestor_relation, sort_key)
        actual = str(result)
        expected = 'root\n  a\n    aardvark\n    ant\n      anteater\n      antelope'
        print('output:\n' + actual)
        assert (actual == expected)
        print('OK')
Пример #5
0
                           ('catherine', 'fay'), ('charles2', 'fay'),
                           ('james2', 'fay'), ('sophia', 'paul'),
                           ('elizabeth', 'claudia'), ('charles1', 'claudia')])


def ancestor(a, b):
    if (a, b) in parent_relationship:
        return True

    # a is not the parent of b
    # but is a the parent of x, and x is the ... parent of b?
    for (parent, child) in parent_relationship:
        if a == parent:
            if ancestor(child, b):
                return True

    return False


if __name__ == '__main__':
    # strings and substrings

    # doing this input list in any order should always produce the same hierarchy
    people = [
        'catherine', 'charles1', 'charles2', 'claudia', 'elizabeth', 'fay',
        'george1', 'james1', 'james2', 'paul', 'sam', 'sophia'
    ]

    result = algorithm.hierarchy(people, ancestor, lambda x: x)
    print(result)