Ejemplo n.º 1
0
def create_file_for_parsing(filename):
    path_for_parsing = filename[:-2] + '_parsing.c'
    content = get_content(filename)
    new_content = [line for line in content if check_entrance(line)]

    for_idx = 0
    for idx, line in enumerate(new_content[::-1]):
        if 'for' in line:
            for_idx = idx
            break

    tmp = new_content[len(new_content) - for_idx - 1]
    new_content[len(new_content) - for_idx - 1] = 'loop_1:' + tmp

    rewrite(path_for_parsing, new_content)
Ejemplo n.º 2
0
def statement_deletion(filename):
    first_entry = True

    content = get_content(filename)
    start_index = False
    for idx, line in enumerate(content):
        if '#pragma scop' in line:
            start_index = True
        if '#pragma endscop' in line:
            start_index = False
        if start_index and line[-1] == ';' and first_entry == True:
            first_entry = False
        elif start_index and line[-1] == ';' and first_entry == False:
            content[idx] = ''
    rewrite(filename, content)
Ejemplo n.º 3
0
def add_3D_tiling_label(filename):
    content = get_content(filename)
    start_index = False

    first = -1

    for idx, line in enumerate(content):
        if '#pragma scop' in line:
            start_index = True
        if '#pragma endscop' in line:
            start_index = False
        if start_index and 'for' in line:
            if first < 0:
                first = idx
    content[first] = '#pragma @ICE loop=tile ' + content[first]
    rewrite(filename, content)
Ejemplo n.º 4
0
def bounds_processing(filename):
    content = get_content(filename)
    start_index = False
    for idx, line in enumerate(content):
        if '#pragma scop' in line:
            start_index = True
        if '#pragma endscop' in line:
            start_index = False

        if start_index and 'for' in line:
            bound = line[line.rfind('<') + 2:line.rfind(';')]
            if bound != '1024':
                content[idx] = line[:line.rfind('<') +
                                    2] + '1024' + line[line.rfind(';'):]

    rewrite(filename, content)
Ejemplo n.º 5
0
def add_constant(filename):
    content = get_content(filename)
    start_index = False
    for idx, line in enumerate(content):
        if 'clock_t stop = clock();' in line:
            start_index = False

        if len(line) > 0:
            if start_index and line[-1] == ';':
                content[idx] = line[:-1] + '+' + str(random.randint(1,
                                                                    100)) + ';'

        if 'clock_t start = clock();' in line:
            start_index = True

    rewrite(filename, content)
Ejemplo n.º 6
0
def add_2D_tiling_label(filename):
    content = get_content(filename)
    start_index = False

    prev = 0
    next = 0

    for idx, line in enumerate(content):
        if '#pragma scop' in line:
            start_index = True
        if '#pragma endscop' in line:
            start_index = False
        if start_index and 'for' in line:
            prev = next
            next = idx

    content[prev] = 'tiling_2D: ' + content[prev]
    rewrite(filename, content)
Ejemplo n.º 7
0
def iterator_init(filename):
    content = get_content(filename)

    start = False
    start_index = 0

    for idx, line in enumerate(content):
        if '#pragma scop' in line:
            start = True
            start_index = idx
        if '#pragma endscop' in line:
            start = False

        if start and 'for (int' in line:
            content[idx] = line[:5] + line[8:]

    content.insert(start_index, 'int i,j,k,l;')

    rewrite(filename, content)
Ejemplo n.º 8
0
def add_2D_tiling_label(filename):
    content = get_content(filename)
    start_index = False
    first = -1

    second_entry = False

    for idx, line in enumerate(content):
        if 'clock_t start = clock();' in line:
            start_index = True
        if 'clock_t stop = clock();' in line:
            start_index = False
        if start_index and 'for' in line:
            if first < 0:
                first = idx
                second_entry = True
            else:
                if second_entry:
                    first = idx
                    second_entry = False

    content[first] = '#pragma @ICE loop=tile \n' + content[first]
    rewrite(filename, content)
def check_code_for_correctness(path):
    content = get_content(path)
    if len(content[-1]) == 0:  # last string of a file
        delete(path)