-
Notifications
You must be signed in to change notification settings - Fork 0
/
peephole.c
79 lines (61 loc) · 1.38 KB
/
peephole.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*
* peephole.c
*
* Ryan Mallon (2005)
*
* Peephole optomiser for IC code
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "icg.h"
#include "debug.h"
extern int num_instructions;
static void remove_instruction(ic_list_t *);
/*
* Run the peephole optomiser on the given program listing and return a new
* list.
*
*/
void peephole_optomise(void) {
#if 0
ic_list_t *current, *next;
current = ic_list_head();
/* Free the unused instruction at the end of the list */
free(ic_list_tail->next);
ic_list_tail->next = NULL;
while(current) {
next = current->next;
switch(current->instruction->op) {
case IC_RET:
/* Remove duplicate return instructions */
if(current->next && current->next->instruction->op == IC_RET)
remove_instruction(current);
break;
case IC_JMP:
/* Remove jumps that jump to the next instruction */
if(current->jump == current->next)
remove_instruction(current);
break;
}
current = next;
}
/* Renumber and label the list */
ic_number_list();
#endif
}
static void remove_instruction(ic_list_t *node) {
#if 0
if(node == ic_list_head())
ic_list_head() = node->next;
else if(node == ic_list_tail)
ic_list_tail = node->prev;
else {
node->next->prev = node->prev;
node->prev->next = node->next;
}
free(node->instruction);
free(node);
#endif
}