|
| 1 | +import compiler |
| 2 | +from graph import UndirectedAdjList |
| 3 | +from typing import List, Tuple, Set, Dict |
| 4 | +from ast import * |
| 5 | +from x86_ast import * |
| 6 | +from typing import Set, Dict, Tuple |
| 7 | + |
| 8 | +# Skeleton code for the chapter on Register Allocation |
| 9 | + |
| 10 | +class Compiler(compiler.Compiler): |
| 11 | + |
| 12 | + ########################################################################### |
| 13 | + # Uncover Live |
| 14 | + ########################################################################### |
| 15 | + |
| 16 | + def read_vars(self, i: instr) -> Set[location]: |
| 17 | + # YOUR CODE HERE |
| 18 | + pass |
| 19 | + |
| 20 | + def write_vars(self, i: instr) -> Set[location]: |
| 21 | + # YOUR CODE HERE |
| 22 | + pass |
| 23 | + |
| 24 | + def uncover_live(self, p: X86Program) -> Dict[instr, Set[location]]: |
| 25 | + # YOUR CODE HERE |
| 26 | + pass |
| 27 | + |
| 28 | + ############################################################################ |
| 29 | + # Build Interference |
| 30 | + ############################################################################ |
| 31 | + |
| 32 | + def build_interference(self, p: X86Program, |
| 33 | + live_after: Dict[instr, Set[location]]) -> UndirectedAdjList: |
| 34 | + # YOUR CODE HERE |
| 35 | + pass |
| 36 | + |
| 37 | + ############################################################################ |
| 38 | + # Allocate Registers |
| 39 | + ############################################################################ |
| 40 | + |
| 41 | + # Returns the coloring and the set of spilled variables. |
| 42 | + def color_graph(self, graph: UndirectedAdjList, |
| 43 | + variables: Set[location]) -> Tuple[Dict[location, int], Set[location]]: |
| 44 | + # YOUR CODE HERE |
| 45 | + pass |
| 46 | + |
| 47 | + def allocate_registers(self, p: X86Program, |
| 48 | + graph: UndirectedAdjList) -> X86Program: |
| 49 | + # YOUR CODE HERE |
| 50 | + pass |
| 51 | + |
| 52 | + ############################################################################ |
| 53 | + # Assign Homes |
| 54 | + ############################################################################ |
| 55 | + |
| 56 | + def assign_homes(self, pseudo_x86: X86Program) -> X86Program: |
| 57 | + # YOUR CODE HERE |
| 58 | + pass |
| 59 | + |
| 60 | + ########################################################################### |
| 61 | + # Patch Instructions |
| 62 | + ########################################################################### |
| 63 | + |
| 64 | + def patch_instructions(self, p: X86Program) -> X86Program: |
| 65 | + # YOUR CODE HERE |
| 66 | + pass |
| 67 | + |
| 68 | + ########################################################################### |
| 69 | + # Prelude & Conclusion |
| 70 | + ########################################################################### |
| 71 | + |
| 72 | + def prelude_and_conclusion(self, p: X86Program) -> X86Program: |
| 73 | + # YOUR CODE HERE |
| 74 | + pass |
0 commit comments